Blame SOURCES/libvirt-conf-Factor-out-vcpus-parsing-part-from-virDomainCachetuneDefParse.patch

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