]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: command: Unify retrieval of NUMA cell count in qemuBuildNumaArgStr
authorPeter Krempa <pkrempa@redhat.com>
Mon, 16 Feb 2015 16:55:50 +0000 (17:55 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 20 Feb 2015 16:50:07 +0000 (17:50 +0100)
The function uses the cell count in 6 places. Add a temp variable to
hold the count as it will greatly simplify the refactor.

src/qemu/qemu_command.c

index 0e4cef94e5678071a872c33fd4a0d28e2396dda8..74f0bd36d8211d47f6fa920e4efe05ba20e309dc 100644 (file)
@@ -7121,6 +7121,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
     bool needBackend = false;
     int rc;
     int ret = -1;
+    size_t ncells = def->cpu->ncells;
     const long system_page_size = virGetSystemPageSizeKB();
 
     if (virDomainNumatuneHasPerNodeBinding(def->numa) &&
@@ -7153,10 +7154,10 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
             continue;
         }
 
-        if (def->cpu->ncells) {
+        if (ncells) {
             /* Fortunately, we allow only guest NUMA nodes to be continuous
              * starting from zero. */
-            pos = def->cpu->ncells - 1;
+            pos = ncells - 1;
         }
 
         next_bit = virBitmapNextSetBit(def->mem.hugepages[i].nodemask, pos);
@@ -7168,12 +7169,12 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
         }
     }
 
-    if (VIR_ALLOC_N(nodeBackends, def->cpu->ncells) < 0)
+    if (VIR_ALLOC_N(nodeBackends, ncells) < 0)
         goto cleanup;
 
     /* using of -numa memdev= cannot be combined with -numa mem=, thus we
      * need to check which approach to use */
-    for (i = 0; i < def->cpu->ncells; i++) {
+    for (i = 0; i < ncells; i++) {
         unsigned long long cellmem = VIR_DIV_UP(def->cpu->cells[i].mem, 1024);
         def->cpu->cells[i].mem = cellmem * 1024;
 
@@ -7196,7 +7197,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
         }
     }
 
-    for (i = 0; i < def->cpu->ncells; i++) {
+    for (i = 0; i < ncells; i++) {
         VIR_FREE(cpumask);
         if (!(cpumask = virBitmapFormat(def->cpu->cells[i].cpumask)))
             goto cleanup;
@@ -7235,7 +7236,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
     VIR_FREE(cpumask);
 
     if (nodeBackends) {
-        for (i = 0; i < def->cpu->ncells; i++)
+        for (i = 0; i < ncells; i++)
             VIR_FREE(nodeBackends[i]);
 
         VIR_FREE(nodeBackends);