Blob Blame History Raw
From 26aacc4c603cd5f6bd3e4712e768db62c855b600 Mon Sep 17 00:00:00 2001
Message-Id: <26aacc4c603cd5f6bd3e4712e768db62c855b600@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 24 Aug 2016 16:10:43 -0400
Subject: [PATCH] conf: Extract code formatting vCPU info

https://bugzilla.redhat.com/show_bug.cgi?id=1097930
https://bugzilla.redhat.com/show_bug.cgi?id=1224341

(cherry picked from commit 54f875dc53057ddbde063b941d44442102e424e1)
---
 src/conf/domain_conf.c | 45 +++++++++++++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ffafef3..9571ee3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -22885,6 +22885,35 @@ virDomainCputuneDefFormat(virBufferPtr buf,
 }
 
 
+static int
+virDomainCpuDefFormat(virBufferPtr buf,
+                      const virDomainDef *def)
+{
+    char *cpumask = NULL;
+    int ret = -1;
+
+    virBufferAddLit(buf, "<vcpu");
+    virBufferAsprintf(buf, " placement='%s'",
+                      virDomainCpuPlacementModeTypeToString(def->placement_mode));
+
+    if (def->cpumask && !virBitmapIsAllSet(def->cpumask)) {
+        if ((cpumask = virBitmapFormat(def->cpumask)) == NULL)
+            goto cleanup;
+        virBufferAsprintf(buf, " cpuset='%s'", cpumask);
+    }
+    if (virDomainDefHasVcpusOffline(def))
+        virBufferAsprintf(buf, " current='%u'", virDomainDefGetVcpus(def));
+    virBufferAsprintf(buf, ">%u</vcpu>\n", virDomainDefGetVcpusMax(def));
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(cpumask);
+
+    return ret;
+}
+
+
 /* This internal version appends to an existing buffer
  * (possibly with auto-indent), rather than flattening
  * to string.
@@ -23060,20 +23089,8 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         virBufferAddLit(buf, "</memoryBacking>\n");
     }
 
-    virBufferAddLit(buf, "<vcpu");
-    virBufferAsprintf(buf, " placement='%s'",
-                      virDomainCpuPlacementModeTypeToString(def->placement_mode));
-
-    if (def->cpumask && !virBitmapIsAllSet(def->cpumask)) {
-        char *cpumask = NULL;
-        if ((cpumask = virBitmapFormat(def->cpumask)) == NULL)
-            goto error;
-        virBufferAsprintf(buf, " cpuset='%s'", cpumask);
-        VIR_FREE(cpumask);
-    }
-    if (virDomainDefHasVcpusOffline(def))
-        virBufferAsprintf(buf, " current='%u'", virDomainDefGetVcpus(def));
-    virBufferAsprintf(buf, ">%u</vcpu>\n", virDomainDefGetVcpusMax(def));
+    if (virDomainCpuDefFormat(buf, def) < 0)
+        goto error;
 
     if (def->niothreadids > 0) {
         virBufferAsprintf(buf, "<iothreads>%u</iothreads>\n",
-- 
2.10.0