File libvirt-conf-Split-out-NUMA-topology-formatting-to-simplify-access-to-data.patch of Package libvirt

From 1120c95713f61ef4575080b25dcc9714e7ec081f Mon Sep 17 00:00:00 2001
Message-Id: <1120c95713f61ef4575080b25dcc9714e7ec081f.1373271635.git.jdenemar@redhat.com>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 7 Feb 2013 18:28:20 +0100
Subject: [PATCH] conf: Split out NUMA topology formatting to simplify access
 to data

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

(cherry picked from commit 987fd7db4fc4ed8ff47339d440cdfb02ef1f0b58)
---
 src/conf/capabilities.c | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index a8ee2cf..5d034d5 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -680,6 +680,28 @@ virCapabilitiesDefaultGuestEmulator(virCapsPtr caps,
     return NULL;
 }
 
+static void
+virCapabilitiesFormatNUMATopology(virBufferPtr xml,
+                                  size_t ncells,
+                                  virCapsHostNUMACellPtr *cells)
+{
+    int i;
+    int j;
+
+    virBufferAddLit(xml, "    <topology>\n");
+    virBufferAsprintf(xml, "      <cells num='%zu'>\n", ncells);
+    for (i = 0; i < ncells; i++) {
+        virBufferAsprintf(xml, "        <cell id='%d'>\n", cells[i]->num);
+        virBufferAsprintf(xml, "          <cpus num='%d'>\n", cells[i]->ncpus);
+        for (j = 0; j < cells[i]->ncpus; j++)
+            virBufferAsprintf(xml, "            <cpu id='%d'/>\n",
+                              cells[i]->cpus[j]);
+        virBufferAddLit(xml, "          </cpus>\n");
+        virBufferAddLit(xml, "        </cell>\n");
+    }
+    virBufferAddLit(xml, "      </cells>\n");
+    virBufferAddLit(xml, "    </topology>\n");
+}
 
 /**
  * virCapabilitiesFormatXML:
@@ -753,24 +775,9 @@ virCapabilitiesFormatXML(virCapsPtr caps)
         virBufferAddLit(&xml, "    </migration_features>\n");
     }
 
-    if (caps->host.nnumaCell) {
-        virBufferAddLit(&xml, "    <topology>\n");
-        virBufferAsprintf(&xml, "      <cells num='%zu'>\n",
-                          caps->host.nnumaCell);
-        for (i = 0 ; i < caps->host.nnumaCell ; i++) {
-            virBufferAsprintf(&xml, "        <cell id='%d'>\n",
-                              caps->host.numaCell[i]->num);
-            virBufferAsprintf(&xml, "          <cpus num='%d'>\n",
-                              caps->host.numaCell[i]->ncpus);
-            for (j = 0 ; j < caps->host.numaCell[i]->ncpus ; j++)
-                virBufferAsprintf(&xml, "            <cpu id='%d'/>\n",
-                                  caps->host.numaCell[i]->cpus[j]);
-            virBufferAddLit(&xml, "          </cpus>\n");
-            virBufferAddLit(&xml, "        </cell>\n");
-        }
-        virBufferAddLit(&xml, "      </cells>\n");
-        virBufferAddLit(&xml, "    </topology>\n");
-    }
+    if (caps->host.nnumaCell)
+        virCapabilitiesFormatNUMATopology(&xml, caps->host.nnumaCell,
+                                          caps->host.numaCell);
 
     for (i = 0; i < caps->host.nsecModels; i++) {
         virBufferAddLit(&xml, "    <secmodel>\n");
-- 
1.8.2.1

openSUSE Build Service is sponsored by