[libvirt] [PATCH] lxc: Exit on first error in lxcDomainGetMemoryParameters

Matthias Bolte matthias.bolte at googlemail.com
Sun Nov 7 12:39:24 UTC 2010


There is no point in trying to fill params beyond the first error,
because when lxcDomainGetMemoryParameters returns -1 then the caller
cannot detect which values in params are valid.
---
 src/lxc/lxc_driver.c |   21 ++++++++-------------
 1 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index d39b60e..f7630dd 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -823,7 +823,6 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
         goto cleanup;
     }
 
-    ret = 0;
     for (i = 0; i < *nparams; i++) {
         virMemoryParameterPtr param = &params[i];
         val = 0;
@@ -836,14 +835,12 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
             if (rc != 0) {
                 virReportSystemError(-rc, "%s",
                                      _("unable to get memory hard limit"));
-                ret = -1;
-                continue;
+                goto cleanup;
             }
             if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT) == NULL) {
                 lxcError(VIR_ERR_INTERNAL_ERROR,
                          "%s", _("Field memory hard limit too long for destination"));
-                ret = -1;
-                continue;
+                goto cleanup;
             }
             param->value.ul = val;
             break;
@@ -853,14 +850,12 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
             if (rc != 0) {
                 virReportSystemError(-rc, "%s",
                                      _("unable to get memory soft limit"));
-                ret = -1;
-                continue;
+                goto cleanup;
             }
             if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT) == NULL) {
                 lxcError(VIR_ERR_INTERNAL_ERROR,
                          "%s", _("Field memory soft limit too long for destination"));
-                ret = -1;
-                continue;
+                goto cleanup;
             }
             param->value.ul = val;
             break;
@@ -870,14 +865,12 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
             if (rc != 0) {
                 virReportSystemError(-rc, "%s",
                                      _("unable to get swap hard limit"));
-                ret = -1;
-                continue;
+                goto cleanup;
             }
             if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT) == NULL) {
                 lxcError(VIR_ERR_INTERNAL_ERROR,
                          "%s", _("Field swap hard limit too long for destination"));
-                ret = -1;
-                continue;
+                goto cleanup;
             }
             param->value.ul = val;
             break;
@@ -888,6 +881,8 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
         }
     }
 
+    ret = 0;
+
 cleanup:
     if (cgroup)
         virCgroupFree(&cgroup);
-- 
1.7.0.4




More information about the libvir-list mailing list