[libvirt] [PATCH] Fix multiple bugs in LXC domainMemoryStats driver

Daniel P. Berrange berrange at redhat.com
Thu Feb 20 15:34:59 UTC 2014


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 at redhat.com>
---
 src/lxc/lxc_driver.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 50910df..10e0fbb 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -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 (!virCgroupGetMemoryUsage(priv->cgroup, &mem_usage))
+    if (virCgroupGetMemSwapUsage(priv->cgroup, &swap_usage) < 0)
         goto cleanup;
 
-    if (!virDomainObjIsActive(vm))
+    if (virCgroupGetMemoryUsage(priv->cgroup, &mem_usage) < 0)
         goto cleanup;
 
     ret = 0;
-- 
1.8.5.3




More information about the libvir-list mailing list