[libvirt] [PATCH v2 14/17] conf: Factor out virDomainResctrlDef update from virDomainCachetuneDefParse

bing.niu at intel.com bing.niu at intel.com
Sat Jul 28 05:48:38 UTC 2018


From: Bing Niu <bing.niu at intel.com>

Factor out vcpus virDomainResctrlDef update from
virDomainCachetuneDefParse and introduce virDomainUpdateResctrl.
virDomainUpdateResctrl will format vcpus string and update
virDomainResctrlDef in virDomainDefPtr. So that this logic can
be reusable.

Signed-off-by: Bing Niu <bing.niu at intel.com>
---
 src/conf/domain_conf.c | 93 +++++++++++++++++++++++++++++---------------------
 1 file changed, 55 insertions(+), 38 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index da8681d..0efbdf4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19082,6 +19082,58 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr ctxt,
 
 
 static int
+virDomainResctrlUpdate(virDomainDefPtr def,
+                       xmlNodePtr node,
+                       virResctrlAllocPtr alloc,
+                       virBitmapPtr vcpus,
+                       unsigned int flags)
+{
+    char *vcpus_str = NULL;
+    char *alloc_id = NULL;
+    virDomainResctrlDefPtr tmp_resctrl = NULL;
+    int ret = -1;
+
+    if (VIR_ALLOC(tmp_resctrl) < 0)
+        goto cleanup;
+
+    /* We need to format it back because we need to be consistent in the naming
+     * even when users specify some "sub-optimal" string there. */
+    vcpus_str = virBitmapFormat(vcpus);
+    if (!vcpus_str)
+        goto cleanup;
+
+    if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
+        alloc_id = virXMLPropString(node, "id");
+
+    if (!alloc_id) {
+        /* The number of allocations is limited and the directory structure is flat,
+         * not hierarchical, so we need to have all same allocations in one
+         * directory, so it's nice to have it named appropriately.  For now it's
+         * 'vcpus_...' but it's designed in order for it to be changeable in the
+         * future (it's part of the status XML). */
+        if (virAsprintf(&alloc_id, "vcpus_%s", vcpus_str) < 0)
+            goto cleanup;
+    }
+
+    if (virResctrlAllocSetID(alloc, alloc_id) < 0)
+        goto cleanup;
+
+    tmp_resctrl->vcpus = vcpus;
+    tmp_resctrl->alloc = alloc;
+
+    if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, tmp_resctrl) < 0)
+        goto cleanup;
+
+    ret = 0;
+ cleanup:
+    virDomainResctrlDefFree(tmp_resctrl);
+    VIR_FREE(alloc_id);
+    VIR_FREE(vcpus_str);
+    return ret;
+}
+
+
+static int
 virDomainCachetuneDefParse(virDomainDefPtr def,
                            xmlXPathContextPtr ctxt,
                            xmlNodePtr node,
@@ -19091,19 +19143,12 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
     xmlNodePtr *nodes = NULL;
     virBitmapPtr vcpus = NULL;
     virResctrlAllocPtr alloc = NULL;
-    virDomainResctrlDefPtr tmp_resctrl = NULL;
-    char *tmp = NULL;
-    char *vcpus_str = NULL;
-    char *alloc_id = NULL;
     ssize_t i = 0;
     int n;
     int ret = -1;
 
     ctxt->node = node;
 
-    if (VIR_ALLOC(tmp_resctrl) < 0)
-        goto cleanup;
-
     if (virDomainResctrlParseVcpus(def, node, &vcpus) < 0)
         goto cleanup;
 
@@ -19141,45 +19186,17 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
         goto cleanup;
     }
 
-    /* We need to format it back because we need to be consistent in the naming
-     * even when users specify some "sub-optimal" string there. */
-    VIR_FREE(vcpus_str);
-    vcpus_str = virBitmapFormat(vcpus);
-    if (!vcpus_str)
-        goto cleanup;
-
-    if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
-        alloc_id = virXMLPropString(node, "id");
-
-    if (!alloc_id) {
-        /* The number of allocations is limited and the directory structure is flat,
-         * not hierarchical, so we need to have all same allocations in one
-         * directory, so it's nice to have it named appropriately.  For now it's
-         * 'vcpus_...' but it's designed in order for it to be changeable in the
-         * future (it's part of the status XML). */
-        if (virAsprintf(&alloc_id, "vcpus_%s", vcpus_str) < 0)
-            goto cleanup;
-    }
-
-    if (virResctrlAllocSetID(alloc, alloc_id) < 0)
-        goto cleanup;
-
-    VIR_STEAL_PTR(tmp_resctrl->vcpus, vcpus);
-    VIR_STEAL_PTR(tmp_resctrl->alloc, alloc);
-
-    if (VIR_APPEND_ELEMENT(def->resctrls, def->nresctrls, tmp_resctrl) < 0)
+    if (virDomainResctrlUpdate(def, node, alloc, vcpus, flags) < 0)
         goto cleanup;
+    vcpus = NULL;
+    alloc = NULL;
 
     ret = 0;
  cleanup:
     ctxt->node = oldnode;
-    virDomainResctrlDefFree(tmp_resctrl);
     virObjectUnref(alloc);
     virBitmapFree(vcpus);
-    VIR_FREE(alloc_id);
-    VIR_FREE(vcpus_str);
     VIR_FREE(nodes);
-    VIR_FREE(tmp);
     return ret;
 }
 
-- 
2.7.4




More information about the libvir-list mailing list