---
 src/conf/cpu_conf.c     |   17 ++++++-----------
 src/conf/cpu_conf.h     |    3 ++-
 src/qemu/qemu_command.c |   43 +++++++------------------------------------
 3 files changed, 15 insertions(+), 48 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 87e9540..48d5740 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -83,7 +83,7 @@ virCPUDefFree(virCPUDefPtr def)
     virCPUDefFreeModel(def);
 
     for (i = 0 ; i < def->ncells ; i++) {
-        VIR_FREE(def->cells[i].cpumask);
+        virBitmapFree(def->cells[i].cpumask);
         VIR_FREE(def->cells[i].cpustr);
     }
     VIR_FREE(def->cells);
@@ -164,11 +164,10 @@ virCPUDefCopy(const virCPUDefPtr cpu)
             copy->cells[i].cellid = cpu->cells[i].cellid;
             copy->cells[i].mem = cpu->cells[i].mem;
 
-            if (VIR_ALLOC_N(copy->cells[i].cpumask,
-                            VIR_DOMAIN_CPUMASK_LEN) < 0)
+            copy->cells[i].cpumask = virBitmapNewCopy(cpu->cells[i].cpumask);
+
+            if (!copy->cells[i].cpumask)
                 goto no_memory;
-            memcpy(copy->cells[i].cpumask, cpu->cells[i].cpumask,
-                   VIR_DOMAIN_CPUMASK_LEN);
 
             if (!(copy->cells[i].cpustr = strdup(cpu->cells[i].cpustr)))
                 goto no_memory;
@@ -454,7 +453,6 @@ virCPUDefParseXML(const xmlNodePtr node,
 
         for (i = 0 ; i < n ; i++) {
             char *cpus, *memory;
-            int cpumasklen = VIR_DOMAIN_CPUMASK_LEN;
             int ret, ncpus = 0;
 
             def->cells[i].cellid = i;
@@ -466,11 +464,8 @@ virCPUDefParseXML(const xmlNodePtr node,
             }
             def->cells[i].cpustr = cpus;
 
-            if (VIR_ALLOC_N(def->cells[i].cpumask, cpumasklen) < 0)
-                goto no_memory;
-
-            ncpus = virDomainCpuSetParse(cpus, 0, def->cells[i].cpumask,
-                                         cpumasklen);
+            ncpus = virBitmapParse(cpus, 0, &def->cells[i].cpumask,
+                                   VIR_DOMAIN_CPUMASK_LEN);
             if (ncpus <= 0)
                 goto error;
             def->cells_cpus += ncpus;
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 601e208..4e03fd2 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -27,6 +27,7 @@
 # include "util.h"
 # include "buf.h"
 # include "xml.h"
+# include "bitmap.h"
 
 # define VIR_CPU_VENDOR_ID_LENGTH 12
 
@@ -92,7 +93,7 @@ typedef struct _virCellDef virCellDef;
 typedef virCellDef *virCellDefPtr;
 struct _virCellDef {
    int cellid;
-   char *cpumask;      /* CPUs that are part of this node */
+   virBitmapPtr cpumask;       /* CPUs that are part of this node */
    char *cpustr;       /* CPUs stored in string form for dumpxml */
    unsigned int mem;   /* Node memory in kB */
 };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index cd4ee93..b5359f2 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4261,54 +4261,25 @@ qemuBuildSmpArgStr(const virDomainDefPtr def,
     return virBufferContentAndReset(&buf);
 }
 
-static void
-qemuBuildNumaCPUArgStr(char *cpumask, virBufferPtr buf)
-{
-    int i, first, last;
-    int cpuSet = 0;
-
-    first = last = 0;
-    for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {
-        if (cpumask[i]) {
-            if (cpuSet) {
-                last = i;
-            } else {
-                first = last = i;
-                cpuSet = 1;
-            }
-        } else {
-            if (!cpuSet)
-                continue;
-            if (first == last)
-                virBufferAsprintf(buf, "%d,", first);
-            else
-                virBufferAsprintf(buf, "%d-%d,", first, last);
-            cpuSet = 0;
-        }
-    }
-
-    if (cpuSet) {
-        if (first == last)
-            virBufferAsprintf(buf, "%d,", first);
-        else
-            virBufferAsprintf(buf, "%d-%d,", first, last);
-    }
-}
-
 static int
 qemuBuildNumaArgStr(const virDomainDefPtr def, virCommandPtr cmd)
 {
     int i;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
+    char *cpumask;
 
     for (i = 0; i < def->cpu->ncells; i++) {
         virCommandAddArg(cmd, "-numa");
         virBufferAsprintf(&buf, "node,nodeid=%d", def->cpu->cells[i].cellid);
         virBufferAddLit(&buf, ",cpus=");
-        qemuBuildNumaCPUArgStr(def->cpu->cells[i].cpumask, &buf);
+        cpumask = virBitmapFormat(def->cpu->cells[i].cpumask);
+        if (cpumask) {
+            virBufferAsprintf(&buf, "%s", cpumask);
+            VIR_FREE(cpumask);
+        }
         def->cpu->cells[i].mem = VIR_DIV_UP(def->cpu->cells[i].mem,
                                             1024) * 1024;
-        virBufferAsprintf(&buf, "mem=%d", def->cpu->cells[i].mem / 1024);
+        virBufferAsprintf(&buf, ",mem=%d", def->cpu->cells[i].mem / 1024);
 
         if (virBufferError(&buf))
             goto error;
-- 
1.7.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to