]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Factor out vcpus parsing part from virDomainCachetuneDefParse
authorBing Niu <bing.niu@intel.com>
Mon, 30 Jul 2018 03:12:36 +0000 (11:12 +0800)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 13 Aug 2018 18:19:41 +0000 (14:19 -0400)
Extract vcpus parsing part from virDomainCachetuneDefParse into one
function called virDomainResctrlParseVcpus. So that vcpus parsing logic
can be reused by other resource control technologies. Adjust error
message and use node->name so that the error message can fit to all
technologies.

Signed-off-by: Bing Niu <bing.niu@intel.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/conf/domain_conf.c

index f1094b0cde28e9b28dd27a880e7bf075d3fa605e..63bcb1cb1e2bca5ba2213abc33b616a83e290f5b 100644 (file)
@@ -19078,6 +19078,38 @@ virDomainDefParseBootOptions(virDomainDefPtr def,
 }
 
 
+static int
+virDomainResctrlParseVcpus(virDomainDefPtr def,
+                           xmlNodePtr node,
+                           virBitmapPtr *vcpus)
+{
+    char *vcpus_str = NULL;
+    int ret = -1;
+
+    vcpus_str = virXMLPropString(node, "vcpus");
+    if (!vcpus_str) {
+        virReportError(VIR_ERR_XML_ERROR, _("Missing %s attribute 'vcpus'"),
+                       node->name);
+        goto cleanup;
+    }
+    if (virBitmapParse(vcpus_str, vcpus, VIR_DOMAIN_CPUMASK_LEN) < 0) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("Invalid %s attribute 'vcpus' value '%s'"),
+                       node->name, vcpus_str);
+        goto cleanup;
+    }
+
+    /* We need to limit the bitmap to number of vCPUs.  If there's nothing left,
+     * then we can just clean up and return 0 immediately */
+    virBitmapShrink(*vcpus, def->maxvcpus);
+
+    ret = 0;
+ cleanup:
+    VIR_FREE(vcpus_str);
+    return ret;
+}
+
+
 static int
 virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt,
                                 xmlNodePtr node,
@@ -19178,22 +19210,8 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
     if (VIR_ALLOC(tmp_resctrl) < 0)
         goto cleanup;
 
-    vcpus_str = virXMLPropString(node, "vcpus");
-    if (!vcpus_str) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("Missing cachetune attribute 'vcpus'"));
-        goto cleanup;
-    }
-    if (virBitmapParse(vcpus_str, &vcpus, VIR_DOMAIN_CPUMASK_LEN) < 0) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("Invalid cachetune attribute 'vcpus' value '%s'"),
-                       vcpus_str);
+    if (virDomainResctrlParseVcpus(def, node, &vcpus) < 0)
         goto cleanup;
-    }
-
-    /* We need to limit the bitmap to number of vCPUs.  If there's nothing left,
-     * then we can just clean up and return 0 immediately */
-    virBitmapShrink(vcpus, def->maxvcpus);
 
     if (virBitmapIsAllClear(vcpus)) {
         ret = 0;