render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
0a7476
From 7551c4a8b453278e7a27a8e7a722851af1f23efc Mon Sep 17 00:00:00 2001
0a7476
Message-Id: <7551c4a8b453278e7a27a8e7a722851af1f23efc@dist-git>
0a7476
From: Bing Niu <bing.niu@intel.com>
0a7476
Date: Mon, 15 Apr 2019 17:32:57 +0200
0a7476
Subject: [PATCH] conf: Factor out virDomainResctrlDef update from
0a7476
 virDomainCachetuneDefParse
0a7476
MIME-Version: 1.0
0a7476
Content-Type: text/plain; charset=UTF-8
0a7476
Content-Transfer-Encoding: 8bit
0a7476
0a7476
Factor out vcpus virDomainResctrlDef update from
0a7476
virDomainCachetuneDefParse and introduce virDomainResctrlAppend.
0a7476
virDomainResctrlAppend will format vcpus string and append a new
0a7476
virDomainResctrlDef to virDomainDefPtr. So that this logic can
0a7476
be reusable.
0a7476
0a7476
Signed-off-by: Bing Niu <bing.niu@intel.com>
0a7476
Reviewed-by: John Ferlan <jferlan@redhat.com>
0a7476
(cherry picked from commit 72824f67cdb9c474034539e81fb03fb1bc94495f)
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: <b3da60a6b3ca4eea6712bbbdfba03b6037e41239.1555342313.git.phrdina@redhat.com>
0a7476
Reviewed-by: Ján Tomko <jtomko@redhat.com>
0a7476
---
0a7476
 src/conf/domain_conf.c | 93 +++++++++++++++++++++++++-----------------
0a7476
 1 file changed, 55 insertions(+), 38 deletions(-)
0a7476
0a7476
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
0a7476
index fb5adbcd10..44bfd75b72 100644
0a7476
--- a/src/conf/domain_conf.c
0a7476
+++ b/src/conf/domain_conf.c
0a7476
@@ -19176,6 +19176,58 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt,
0a7476
 }
0a7476
 
0a7476
 
0a7476
+static int
0a7476
+virDomainResctrlAppend(virDomainDefPtr def,
0a7476
+                       xmlNodePtr node,
0a7476
+                       virResctrlAllocPtr alloc,
0a7476
+                       virBitmapPtr vcpus,
0a7476
+                       unsigned int flags)
0a7476
+{
0a7476
+    char *vcpus_str = NULL;
0a7476
+    char *alloc_id = NULL;
0a7476
+    virDomainResctrlDefPtr tmp_resctrl = NULL;
0a7476
+    int ret = -1;
0a7476
+
0a7476
+    if (VIR_ALLOC(tmp_resctrl) < 0)
0a7476
+        goto cleanup;
0a7476
+
0a7476
+    /* We need to format it back because we need to be consistent in the naming
0a7476
+     * even when users specify some "sub-optimal" string there. */
0a7476
+    vcpus_str = virBitmapFormat(vcpus);
0a7476
+    if (!vcpus_str)
0a7476
+        goto cleanup;
0a7476
+
0a7476
+    if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
0a7476
+        alloc_id = virXMLPropString(node, "id");
0a7476
+
0a7476
+    if (!alloc_id) {
0a7476
+        /* The number of allocations is limited and the directory structure is flat,
0a7476
+         * not hierarchical, so we need to have all same allocations in one
0a7476
+         * directory, so it's nice to have it named appropriately.  For now it's
0a7476
+         * 'vcpus_...' but it's designed in order for it to be changeable in the
0a7476
+         * future (it's part of the status XML). */
0a7476
+        if (virAsprintf(&alloc_id, "vcpus_%s", vcpus_str) < 0)
0a7476
+            goto cleanup;
0a7476
+    }
0a7476
+
0a7476
+    if (virResctrlAllocSetID(alloc, alloc_id) < 0)
0a7476
+        goto cleanup;
0a7476
+
0a7476
+    tmp_resctrl->vcpus = vcpus;
0a7476
+    tmp_resctrl->alloc = alloc;
0a7476
+
0a7476
+    if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, tmp_resctrl) < 0)
0a7476
+        goto cleanup;
0a7476
+
0a7476
+    ret = 0;
0a7476
+ cleanup:
0a7476
+    virDomainResctrlDefFree(tmp_resctrl);
0a7476
+    VIR_FREE(alloc_id);
0a7476
+    VIR_FREE(vcpus_str);
0a7476
+    return ret;
0a7476
+}
0a7476
+
0a7476
+
0a7476
 static int
0a7476
 virDomainCachetuneDefParse(virDomainDefPtr def,
0a7476
                            xmlXPathContextPtr ctxt,
0a7476
@@ -19186,19 +19238,12 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
0a7476
     xmlNodePtr *nodes = NULL;
0a7476
     virBitmapPtr vcpus = NULL;
0a7476
     virResctrlAllocPtr alloc = NULL;
0a7476
-    virDomainResctrlDefPtr tmp_resctrl = NULL;
0a7476
-    char *tmp = NULL;
0a7476
-    char *vcpus_str = NULL;
0a7476
-    char *alloc_id = NULL;
0a7476
     ssize_t i = 0;
0a7476
     int n;
0a7476
     int ret = -1;
0a7476
 
0a7476
     ctxt->node = node;
0a7476
 
0a7476
-    if (VIR_ALLOC(tmp_resctrl) < 0)
0a7476
-        goto cleanup;
0a7476
-
0a7476
     if (virDomainResctrlParseVcpus(def, node, &vcpus) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
@@ -19236,45 +19281,17 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
0a7476
         goto cleanup;
0a7476
     }
0a7476
 
0a7476
-    /* We need to format it back because we need to be consistent in the naming
0a7476
-     * even when users specify some "sub-optimal" string there. */
0a7476
-    VIR_FREE(vcpus_str);
0a7476
-    vcpus_str = virBitmapFormat(vcpus);
0a7476
-    if (!vcpus_str)
0a7476
-        goto cleanup;
0a7476
-
0a7476
-    if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
0a7476
-        alloc_id = virXMLPropString(node, "id");
0a7476
-
0a7476
-    if (!alloc_id) {
0a7476
-        /* The number of allocations is limited and the directory structure is flat,
0a7476
-         * not hierarchical, so we need to have all same allocations in one
0a7476
-         * directory, so it's nice to have it named appropriately.  For now it's
0a7476
-         * 'vcpus_...' but it's designed in order for it to be changeable in the
0a7476
-         * future (it's part of the status XML). */
0a7476
-        if (virAsprintf(&alloc_id, "vcpus_%s", vcpus_str) < 0)
0a7476
-            goto cleanup;
0a7476
-    }
0a7476
-
0a7476
-    if (virResctrlAllocSetID(alloc, alloc_id) < 0)
0a7476
-        goto cleanup;
0a7476
-
0a7476
-    VIR_STEAL_PTR(tmp_resctrl->vcpus, vcpus);
0a7476
-    VIR_STEAL_PTR(tmp_resctrl->alloc, alloc);
0a7476
-
0a7476
-    if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, tmp_resctrl) < 0)
0a7476
+    if (virDomainResctrlAppend(def, node, alloc, vcpus, flags) < 0)
0a7476
         goto cleanup;
0a7476
+    vcpus = NULL;
0a7476
+    alloc = NULL;
0a7476
 
0a7476
     ret = 0;
0a7476
  cleanup:
0a7476
     ctxt->node = oldnode;
0a7476
-    virDomainResctrlDefFree(tmp_resctrl);
0a7476
     virObjectUnref(alloc);
0a7476
     virBitmapFree(vcpus);
0a7476
-    VIR_FREE(alloc_id);
0a7476
-    VIR_FREE(vcpus_str);
0a7476
     VIR_FREE(nodes);
0a7476
-    VIR_FREE(tmp);
0a7476
     return ret;
0a7476
 }
0a7476
 
0a7476
-- 
0a7476
2.21.0
0a7476