]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
numa_conf: Expose virNumaCache formatter
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 3 May 2021 12:11:26 +0000 (14:11 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 15 Jun 2021 08:41:22 +0000 (10:41 +0200)
Expose virNumaCache XML formatter so that it can be re-used by
other parts of the code.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/numa_conf.c
src/conf/numa_conf.h
src/libvirt_private.syms

index 2a32b4ca0607669ebf8e5f861116a192d86fb420..c4f2ef10c1035899efab79e03781a34fcbf72a6a 100644 (file)
@@ -82,8 +82,6 @@ VIR_ENUM_IMPL(virDomainMemoryLatency,
               "write"
 );
 
-typedef struct _virNumaCache virNumaCache;
-
 typedef struct _virDomainNumaInterconnect virDomainNumaInterconnect;
 
 typedef struct _virDomainNumaNode virDomainNumaNode;
@@ -107,13 +105,7 @@ struct _virDomainNuma {
         virNumaDistance *distances; /* remote node distances */
         size_t ndistances;
 
-        struct _virNumaCache {
-            unsigned int level; /* cache level */
-            unsigned int size;  /* cache size */
-            unsigned int line;  /* line size, !!! in bytes !!! */
-            virNumaCacheAssociativity associativity; /* cache associativity */
-            virNumaCachePolicy policy; /* cache policy */
-        } *caches;
+        virNumaCache *caches;
         size_t ncaches;
     } *mem_nodes;           /* guest node configuration */
     size_t nmem_nodes;
@@ -1102,7 +1094,6 @@ virDomainNumaDefFormatXML(virBuffer *buf,
         virBitmap *cpumask = virDomainNumaGetNodeCpumask(def, i);
         g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
         g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
-        size_t j;
 
         memAccess = virDomainNumaGetNodeMemoryAccessMode(def, i);
         discard = virDomainNumaGetNodeDiscard(def, i);
@@ -1131,35 +1122,9 @@ virDomainNumaDefFormatXML(virBuffer *buf,
                               def->mem_nodes[i].distances,
                               def->mem_nodes[i].ndistances);
 
-        for (j = 0; j < def->mem_nodes[i].ncaches; j++) {
-            virNumaCache *cache = &def->mem_nodes[i].caches[j];
-
-            virBufferAsprintf(&childBuf, "<cache level='%u'", cache->level);
-            if (cache->associativity) {
-                virBufferAsprintf(&childBuf, " associativity='%s'",
-                                  virNumaCacheAssociativityTypeToString(cache->associativity));
-            }
-
-            if (cache->policy) {
-                virBufferAsprintf(&childBuf, " policy='%s'",
-                                  virNumaCachePolicyTypeToString(cache->policy));
-            }
-            virBufferAddLit(&childBuf, ">\n");
-
-            virBufferAdjustIndent(&childBuf, 2);
-            virBufferAsprintf(&childBuf,
-                              "<size value='%u' unit='KiB'/>\n",
-                              cache->size);
-
-            if (cache->line) {
-                virBufferAsprintf(&childBuf,
-                                  "<line value='%u' unit='B'/>\n",
-                                  cache->line);
-            }
-
-            virBufferAdjustIndent(&childBuf, -2);
-            virBufferAddLit(&childBuf, "</cache>\n");
-        }
+        virNumaCacheFormat(&childBuf,
+                           def->mem_nodes[i].caches,
+                           def->mem_nodes[i].ncaches);
 
         virXMLFormatElement(buf, "cell", &attrBuf, &childBuf);
     }
@@ -1839,3 +1804,41 @@ virNumaDistanceFormat(virBuffer *buf,
 
     virXMLFormatElement(buf, "distances", NULL, &childBuf);
 }
+
+
+void
+virNumaCacheFormat(virBuffer *buf,
+                   const virNumaCache *caches,
+                   size_t ncaches)
+{
+    size_t i;
+
+    for (i = 0; i < ncaches; i++) {
+        const virNumaCache *cache = &caches[i];
+        g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+        g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+
+        virBufferAsprintf(&attrBuf, " level='%u'", cache->level);
+        if (cache->associativity) {
+            virBufferAsprintf(&attrBuf, " associativity='%s'",
+                              virNumaCacheAssociativityTypeToString(cache->associativity));
+        }
+
+        if (cache->policy) {
+            virBufferAsprintf(&attrBuf, " policy='%s'",
+                              virNumaCachePolicyTypeToString(cache->policy));
+        }
+
+        virBufferAsprintf(&childBuf,
+                          "<size value='%u' unit='KiB'/>\n",
+                          cache->size);
+
+        if (cache->line) {
+            virBufferAsprintf(&childBuf,
+                              "<line value='%u' unit='B'/>\n",
+                              cache->line);
+        }
+
+        virXMLFormatElement(buf, "cache", &attrBuf, &childBuf);
+    }
+}
index 1ef6455fb5be5f11a36e86d804a1230a51040412..9dee4f3a406cef3a84dbd69a3708e1374515cc95 100644 (file)
@@ -259,3 +259,16 @@ struct _virNumaDistance {
 void virNumaDistanceFormat(virBuffer *buf,
                            const virNumaDistance *distances,
                            size_t ndistances);
+
+typedef struct _virNumaCache virNumaCache;
+struct _virNumaCache {
+    unsigned int level; /* cache level */
+    unsigned int size;  /* cache size */
+    unsigned int line;  /* line size, !!! in bytes !!! */
+    virNumaCacheAssociativity associativity; /* cache associativity */
+    virNumaCachePolicy policy; /* cache policy */
+};
+
+void virNumaCacheFormat(virBuffer *buf,
+                        const virNumaCache *caches,
+                        size_t ncaches);
index 9e9171a6d95ccf1b01fecc70a959700c8140b27e..abe4525163efc54dd70f14c3beb121f1ab4358b4 100644 (file)
@@ -911,6 +911,7 @@ virDomainNumatuneSet;
 virDomainNumatuneSpecifiedMaxNode;
 virNumaCacheAssociativityTypeFromString;
 virNumaCacheAssociativityTypeToString;
+virNumaCacheFormat;
 virNumaCachePolicyTypeFromString;
 virNumaCachePolicyTypeToString;
 virNumaDistanceFormat;