99cbc7
From ca59034c25fe39acb246f82587c0c32ba04d6c89 Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <ca59034c25fe39acb246f82587c0c32ba04d6c89@dist-git>
99cbc7
From: Bing Niu <bing.niu@intel.com>
99cbc7
Date: Mon, 15 Apr 2019 17:32:55 +0200
99cbc7
Subject: [PATCH] conf: Factor out vcpus parsing part from
99cbc7
 virDomainCachetuneDefParse
99cbc7
MIME-Version: 1.0
99cbc7
Content-Type: text/plain; charset=UTF-8
99cbc7
Content-Transfer-Encoding: 8bit
99cbc7
99cbc7
Extract vcpus parsing part from virDomainCachetuneDefParse into one
99cbc7
function called virDomainResctrlParseVcpus. So that vcpus parsing logic
99cbc7
can be reused by other resource control technologies. Adjust error
99cbc7
message and use node->name so that the error message can fit to all
99cbc7
technologies.
99cbc7
99cbc7
Signed-off-by: Bing Niu <bing.niu@intel.com>
99cbc7
Reviewed-by: John Ferlan <jferlan@redhat.com>
99cbc7
(cherry picked from commit 6021c3926ba62a2593f0db63e5413e9663c69a5f)
99cbc7
99cbc7
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1468650
99cbc7
99cbc7
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
99cbc7
Message-Id: <2f330b4bbface15dce23370d5f212b2240e031cd.1555342313.git.phrdina@redhat.com>
99cbc7
Reviewed-by: Ján Tomko <jtomko@redhat.com>
99cbc7
---
99cbc7
 src/conf/domain_conf.c | 48 +++++++++++++++++++++++++++++-------------
99cbc7
 1 file changed, 33 insertions(+), 15 deletions(-)
99cbc7
99cbc7
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
99cbc7
index 0c8afe78c6..07d21f8026 100644
99cbc7
--- a/src/conf/domain_conf.c
99cbc7
+++ b/src/conf/domain_conf.c
99cbc7
@@ -19045,6 +19045,38 @@ virDomainDefParseBootOptions(virDomainDefPtr def,
99cbc7
 }
99cbc7
 
99cbc7
 
99cbc7
+static int
99cbc7
+virDomainResctrlParseVcpus(virDomainDefPtr def,
99cbc7
+                           xmlNodePtr node,
99cbc7
+                           virBitmapPtr *vcpus)
99cbc7
+{
99cbc7
+    char *vcpus_str = NULL;
99cbc7
+    int ret = -1;
99cbc7
+
99cbc7
+    vcpus_str = virXMLPropString(node, "vcpus");
99cbc7
+    if (!vcpus_str) {
99cbc7
+        virReportError(VIR_ERR_XML_ERROR, _("Missing %s attribute 'vcpus'"),
99cbc7
+                       node->name);
99cbc7
+        goto cleanup;
99cbc7
+    }
99cbc7
+    if (virBitmapParse(vcpus_str, vcpus, VIR_DOMAIN_CPUMASK_LEN) < 0) {
99cbc7
+        virReportError(VIR_ERR_XML_ERROR,
99cbc7
+                       _("Invalid %s attribute 'vcpus' value '%s'"),
99cbc7
+                       node->name, vcpus_str);
99cbc7
+        goto cleanup;
99cbc7
+    }
99cbc7
+
99cbc7
+    /* We need to limit the bitmap to number of vCPUs.  If there's nothing left,
99cbc7
+     * then we can just clean up and return 0 immediately */
99cbc7
+    virBitmapShrink(*vcpus, def->maxvcpus);
99cbc7
+
99cbc7
+    ret = 0;
99cbc7
+ cleanup:
99cbc7
+    VIR_FREE(vcpus_str);
99cbc7
+    return ret;
99cbc7
+}
99cbc7
+
99cbc7
+
99cbc7
 static int
99cbc7
 virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt,
99cbc7
                                 xmlNodePtr node,
99cbc7
@@ -19145,22 +19177,8 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
99cbc7
     if (VIR_ALLOC(tmp_resctrl) < 0)
99cbc7
         goto cleanup;
99cbc7
 
99cbc7
-    vcpus_str = virXMLPropString(node, "vcpus");
99cbc7
-    if (!vcpus_str) {
99cbc7
-        virReportError(VIR_ERR_XML_ERROR, "%s",
99cbc7
-                       _("Missing cachetune attribute 'vcpus'"));
99cbc7
+    if (virDomainResctrlParseVcpus(def, node, &vcpus) < 0)
99cbc7
         goto cleanup;
99cbc7
-    }
99cbc7
-    if (virBitmapParse(vcpus_str, &vcpus, VIR_DOMAIN_CPUMASK_LEN) < 0) {
99cbc7
-        virReportError(VIR_ERR_XML_ERROR,
99cbc7
-                       _("Invalid cachetune attribute 'vcpus' value '%s'"),
99cbc7
-                       vcpus_str);
99cbc7
-        goto cleanup;
99cbc7
-    }
99cbc7
-
99cbc7
-    /* We need to limit the bitmap to number of vCPUs.  If there's nothing left,
99cbc7
-     * then we can just clean up and return 0 immediately */
99cbc7
-    virBitmapShrink(vcpus, def->maxvcpus);
99cbc7
 
99cbc7
     if (virBitmapIsAllClear(vcpus)) {
99cbc7
         ret = 0;
99cbc7
-- 
99cbc7
2.21.0
99cbc7