Fix multiple bugs in LXC domainMemoryStats driver

The virCgroupXXX APIs' return value must be checked for
being less than 0, not equal to 0.

An VIR_ERR_OPERATION_INVALID error must also be raised
when the VM is not running to prevent a crash on NULL
priv->cgroup field.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2014-02-20 15:32:49 +00:00
parent 5eb61e6846
commit cb9b3bc257

View File

@ -5410,13 +5410,16 @@ lxcDomainMemoryStats(virDomainPtr dom,
if (virDomainMemoryStatsEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
if (!virCgroupGetMemSwapUsage(priv->cgroup, &swap_usage))
if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("domain is not active"));
goto cleanup;
}
if (virCgroupGetMemSwapUsage(priv->cgroup, &swap_usage) < 0)
goto cleanup;
if (!virCgroupGetMemoryUsage(priv->cgroup, &mem_usage))
goto cleanup;
if (!virDomainObjIsActive(vm))
if (virCgroupGetMemoryUsage(priv->cgroup, &mem_usage) < 0)
goto cleanup;
ret = 0;