Blob Blame History Raw
From fc74342fd4e1f5c4de1d39d31f902c3f6d717e20 Mon Sep 17 00:00:00 2001
Message-Id: <fc74342fd4e1f5c4de1d39d31f902c3f6d717e20.1389183249.git.jdenemar@redhat.com>
From: Peter Krempa <pkrempa@redhat.com>
Date: Mon, 6 Jan 2014 17:02:27 +0100
Subject: [PATCH] qemu: Clean up qemuDomainSetNumaParameters

https://bugzilla.redhat.com/show_bug.cgi?id=1047234

Add whitespace to separate logical code blocks, reformat error messages
and clean up code flow.

This patch changes error handling in some cases where the the loop would
be continued to jump to cleanup instead and error out rather than modify
the domain any further.

(cherry picked from commit 8b573a6b0d1ee9d99862104f28fee8bc7f949a9d)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_driver.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a3d4725..215ac1b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8507,6 +8507,7 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
+
     if (virTypedParamsValidate(params, nparams,
                                VIR_DOMAIN_NUMA_MODE,
                                VIR_TYPED_PARAM_INT,
@@ -8533,43 +8534,40 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
 
     if (flags & VIR_DOMAIN_AFFECT_LIVE) {
         if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                           "%s", _("cgroup cpuset controller is not mounted"));
+            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                           _("cgroup cpuset controller is not mounted"));
             goto cleanup;
         }
     }
 
-    ret = 0;
     for (i = 0; i < nparams; i++) {
         virTypedParameterPtr param = &params[i];
 
         if (STREQ(param->field, VIR_DOMAIN_NUMA_MODE)) {
+            int mode = param->value.i;
+
             if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
-                vm->def->numatune.memory.mode != params[i].value.i) {
+                vm->def->numatune.memory.mode != mode) {
                 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                                _("can't change numa mode for running domain"));
-                ret = -1;
                 goto cleanup;
             }
 
-            if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-                persistentDef->numatune.memory.mode = params[i].value.i;
-            }
+            if (flags & VIR_DOMAIN_AFFECT_CONFIG)
+                persistentDef->numatune.memory.mode = mode;
+
         } else if (STREQ(param->field, VIR_DOMAIN_NUMA_NODESET)) {
             virBitmapPtr nodeset = NULL;
 
-            if (virBitmapParse(params[i].value.s,
-                               0, &nodeset,
+            if (virBitmapParse(param->value.s, 0, &nodeset,
                                VIR_DOMAIN_CPUMASK_LEN) < 0) {
-                ret = -1;
-                continue;
+                goto cleanup;
             }
 
             if (flags & VIR_DOMAIN_AFFECT_LIVE) {
                 if (qemuDomainSetNumaParamsLive(vm, caps, nodeset) < 0) {
                     virBitmapFree(nodeset);
-                    ret = -1;
-                    continue;
+                    goto cleanup;
                 }
 
                 /* update vm->def here so that dumpxml can read the new
@@ -8598,9 +8596,11 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
             persistentDef->numatune.memory.placement_mode =
                 VIR_NUMA_TUNE_MEM_PLACEMENT_MODE_AUTO;
         if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0)
-            ret = -1;
+            goto cleanup;
     }
 
+    ret = 0;
+
 cleanup:
     if (vm)
         virObjectUnlock(vm);
-- 
1.8.5.2