]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: don't modify cpu set string during parsing
authorEric Blake <eblake@redhat.com>
Fri, 18 Nov 2011 18:27:24 +0000 (11:27 -0700)
committerEric Blake <eblake@redhat.com>
Mon, 21 Nov 2011 21:50:28 +0000 (14:50 -0700)
None of the callers cared if str was updated to point to the next
byte after the parsed cpuset; simplifying this results in quite
a few code simplifications.  Additionally, virCPUDefParseXML was
strdup()'ing a malloc()'d string; avoiding a memory copy resulted
in less code.

* src/conf/domain_conf.h (virDomainCpuSetParse): Alter signature.
* src/conf/domain_conf.c (virDomainCpuSetParse): Don't modify str.
(virDomainVcpuPinDefParseXML, virDomainDefParseXML): Adjust
callers.
* src/conf/cpu_conf.c (virCPUDefParseXML): Likewise.
* src/xen/xend_internal.c (sexpr_to_xend_topology): Likewise.
* src/xen/xm_internal.c (xenXMDomainPinVcpu): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxpr): Likewise.
* src/xenxs/xen_xm.c (xenParseXM): Likewise.

src/conf/cpu_conf.c
src/conf/domain_conf.c
src/conf/domain_conf.h
src/xen/xend_internal.c
src/xen/xm_internal.c
src/xenxs/xen_sxpr.c
src/xenxs/xen_xm.c

index 7c5bf69a377443043e6a9223592be56b0cb3fa39..28823893c4c79d0da60aa52a1346ea3e871612a2 100644 (file)
@@ -311,42 +311,32 @@ virCPUDefParseXML(const xmlNodePtr node,
         def->ncells = n;
 
         for (i = 0 ; i < n ; i++) {
-            char *cpus, *cpus_parse, *memory;
+            char *cpus, *memory;
             int cpumasklen = VIR_DOMAIN_CPUMASK_LEN;
             int ret, ncpus = 0;
 
             def->cells[i].cellid = i;
-            cpus = cpus_parse = virXMLPropString(nodes[i], "cpus");
+            cpus = virXMLPropString(nodes[i], "cpus");
             if (!cpus) {
                 virCPUReportError(VIR_ERR_INTERNAL_ERROR,
                     "%s", _("Missing 'cpus' attribute in NUMA cell"));
                 goto error;
             }
+            def->cells[i].cpustr = cpus;
 
-            def->cells[i].cpustr = strdup(cpus);
-            if (!def->cells[i].cpustr) {
-                VIR_FREE(cpus);
+            if (VIR_ALLOC_N(def->cells[i].cpumask, cpumasklen) < 0)
                 goto no_memory;
-            }
 
-            if (VIR_ALLOC_N(def->cells[i].cpumask, cpumasklen) < 0) {
-                VIR_FREE(cpus);
-                goto no_memory;
-            }
-
-            ncpus = virDomainCpuSetParse((const char **)&cpus_parse,
-                                 0, def->cells[i].cpumask, cpumasklen);
-            if (ncpus <= 0) {
-                VIR_FREE(cpus);
+            ncpus = virDomainCpuSetParse(cpus, 0, def->cells[i].cpumask,
+                                         cpumasklen);
+            if (ncpus <= 0)
                 goto error;
-            }
             def->cells_cpus += ncpus;
 
             memory = virXMLPropString(nodes[i], "memory");
             if (!memory) {
                 virCPUReportError(VIR_ERR_INTERNAL_ERROR,
                     "%s", _("Missing 'memory' attribute in NUMA cell"));
-                VIR_FREE(cpus);
                 goto error;
             }
 
@@ -354,11 +344,9 @@ virCPUDefParseXML(const xmlNodePtr node,
             if (ret == -1) {
                 virCPUReportError(VIR_ERR_INTERNAL_ERROR,
                     "%s", _("Invalid 'memory' attribute in NUMA cell"));
-                VIR_FREE(cpus);
                 VIR_FREE(memory);
                 goto error;
             }
-            VIR_FREE(cpus);
             VIR_FREE(memory);
         }
     }
index e98625307f36c37d88ae60e2eb99da8c1cf13def..d365cee66d1b25781e5ecc2f928a7112247512ab 100644 (file)
@@ -6636,8 +6636,7 @@ virDomainVcpuPinDefParseXML(const xmlNodePtr node,
             virReportOOMError();
             goto error;
         }
-        if (virDomainCpuSetParse((const char **)&set,
-                                 0, def->cpumask,
+        if (virDomainCpuSetParse(set, 0, def->cpumask,
                                  cpumasklen) < 0)
            goto error;
         VIR_FREE(tmp);
@@ -6850,8 +6849,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
         if (VIR_ALLOC_N(def->cpumask, def->cpumasklen) < 0) {
             goto no_memory;
         }
-        if (virDomainCpuSetParse((const char **)&set,
-                                 0, def->cpumask,
+        if (virDomainCpuSetParse(set, 0, def->cpumask,
                                  def->cpumasklen) < 0)
             goto error;
         VIR_FREE(tmp);
@@ -6921,8 +6919,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
             }
 
             /* "nodeset" leads same syntax with "cpuset". */
-            if (virDomainCpuSetParse((const char **)&set,
-                                     0, def->numatune.memory.nodemask,
+            if (virDomainCpuSetParse(set, 0, def->numatune.memory.nodemask,
                                      nodemasklen) < 0)
                goto error;
             VIR_FREE(tmp);
@@ -9155,7 +9152,7 @@ virDomainCpuSetFormat(char *cpuset, int maxcpu)
 /**
  * virDomainCpuSetParse:
  * @conn: connection
- * @str: pointer to a CPU set string pointer
+ * @str: a CPU set string pointer
  * @sep: potential character used to mark the end of string if not 0
  * @cpuset: pointer to a char array for the CPU set
  * @maxcpu: number of elements available in @cpuset
@@ -9166,10 +9163,9 @@ virDomainCpuSetFormat(char *cpuset, int maxcpu)
  *
  * Returns the number of CPU found in that set, or -1 in case of error.
  *         @cpuset is modified accordingly to the value parsed.
- *         @str is updated to the end of the part parsed
  */
 int
-virDomainCpuSetParse(const char **str, char sep,
+virDomainCpuSetParse(const char *str, char sep,
                      char *cpuset, int maxcpu)
 {
     const char *cur;
@@ -9181,7 +9177,7 @@ virDomainCpuSetParse(const char **str, char sep,
         (maxcpu > 100000))
         return (-1);
 
-    cur = *str;
+    cur = str;
     virSkipSpaces(&cur);
     if (*cur == 0)
         goto parse_error;
@@ -9246,7 +9242,6 @@ virDomainCpuSetParse(const char **str, char sep,
         } else
             goto parse_error;
     }
-    *str = cur;
     return (ret);
 
   parse_error:
index 481dfc6d0bf6bf33d0563034dcc4872ed41c8bef..75111782826256d4c51e0697a72586c261fe90fa 100644 (file)
@@ -1747,7 +1747,7 @@ int virDomainDefFormatInternal(virDomainDefPtr def,
                                unsigned int flags,
                                virBufferPtr buf);
 
-int virDomainCpuSetParse(const char **str,
+int virDomainCpuSetParse(const char *str,
                          char sep,
                          char *cpuset,
                          int maxcpu);
index 80a247236b1feee8dc87e466e2d15777dac176ae..2318565396b69213bcac8f55199d78a302e6cba4 100644 (file)
@@ -1153,7 +1153,7 @@ sexpr_to_xend_topology(const struct sexpr *root,
             for (cpu = 0; cpu < numCpus; cpu++)
                 cpuset[cpu] = 0;
         } else {
-            nb_cpus = virDomainCpuSetParse(&cur, 'n', cpuset, numCpus);
+            nb_cpus = virDomainCpuSetParse(cur, 'n', cpuset, numCpus);
             if (nb_cpus < 0)
                 goto error;
         }
index 24311a70941ecb21b65342237536b4d34f372595..a250b6ff9efe43ae00fbff87c7c72bafa0a9fdb4 100644 (file)
@@ -893,8 +893,7 @@ int xenXMDomainPinVcpu(virDomainPtr domain,
         virReportOOMError();
         goto cleanup;
     }
-    if (virDomainCpuSetParse((const char **)&mapstr, 0,
-                             cpuset, maxcpu) < 0)
+    if (virDomainCpuSetParse(mapstr, 0, cpuset, maxcpu) < 0)
         goto cleanup;
 
     VIR_FREE(entry->def->cpumask);
index e0bc043a233bcc03b7a1d798a4d02831743c2d6b..124c36978633b07be94a74dd44303fd4e54f2812 100644 (file)
@@ -1140,8 +1140,7 @@ xenParseSxpr(const struct sexpr *root,
             goto error;
         }
 
-        if (virDomainCpuSetParse(&cpus,
-                                 0, def->cpumask,
+        if (virDomainCpuSetParse(cpus, 0, def->cpumask,
                                  def->cpumasklen) < 0) {
             XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
                          _("invalid CPU mask %s"), cpus);
index a2ef8c8d7b33c8fa53ff77eb0dbd7e367acac472..b415ce8c33abd8a302615203855f23d9e277db8b 100644 (file)
@@ -338,7 +338,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
         if (VIR_ALLOC_N(def->cpumask, def->cpumasklen) < 0)
             goto no_memory;
 
-        if (virDomainCpuSetParse(&str, 0,
+        if (virDomainCpuSetParse(str, 0,
                                  def->cpumask, def->cpumasklen) < 0)
             goto cleanup;
     }