Expose virNumaInterconnect XML formatter so that it can be
re-used by other parts of the code.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
Reviewed-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/conf/numa_conf.c | 101 +++++++++++++++++++--------------------
src/conf/numa_conf.h | 16 +++++++
src/libvirt_private.syms | 1 +
3 files changed, 66 insertions(+), 52 deletions(-)
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
index c8b3212e5c..9a9b5f4b60 100644
--- a/src/conf/numa_conf.c
+++ b/src/conf/numa_conf.c
@@ -82,8 +82,6 @@ VIR_ENUM_IMPL(virMemoryLatency,
"write"
);
-typedef struct _virNumaInterconnect virNumaInterconnect;
-
typedef struct _virDomainNumaNode virDomainNumaNode;
struct _virDomainNuma {
@@ -110,16 +108,7 @@ struct _virDomainNuma {
} *mem_nodes; /* guest node configuration */
size_t nmem_nodes;
- struct _virNumaInterconnect {
- virNumaInterconnectType type; /* whether structure describes latency
- or bandwidth */
- unsigned int initiator; /* the initiator NUMA node */
- unsigned int target; /* the target NUMA node */
- unsigned int cache; /* the target cache on @target; if 0 then the
- memory on @target */
- virMemoryLatency accessType; /* what type of access is defined */
- unsigned long value; /* value itself */
- } *interconnects;
+ virNumaInterconnect *interconnects;
size_t ninterconnects;
/* Future NUMA tuning related stuff should go here. */
@@ -1129,46 +1118,7 @@ virDomainNumaDefFormatXML(virBuffer *buf,
virXMLFormatElement(buf, "cell", &attrBuf, &childBuf);
}
- if (def->ninterconnects) {
- virBufferAddLit(buf, "<interconnects>\n");
- virBufferAdjustIndent(buf, 2);
- }
-
- for (i = 0; i < def->ninterconnects; i++) {
- virNumaInterconnect *l = &def->interconnects[i];
-
- switch (l->type) {
- case VIR_NUMA_INTERCONNECT_TYPE_LATENCY:
- virBufferAddLit(buf, "<latency");
- break;
- case VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH:
- virBufferAddLit(buf, "<bandwidth");
- }
-
- virBufferAsprintf(buf,
- " initiator='%u' target='%u'",
- l->initiator, l->target);
-
- if (l->cache > 0) {
- virBufferAsprintf(buf,
- " cache='%u'",
- l->cache);
- }
-
- virBufferAsprintf(buf,
- " type='%s' value='%lu'",
- virMemoryLatencyTypeToString(l->accessType),
- l->value);
-
- if (l->type == VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH)
- virBufferAddLit(buf, " unit='KiB'");
- virBufferAddLit(buf, "/>\n");
- }
-
- if (def->ninterconnects) {
- virBufferAdjustIndent(buf, -2);
- virBufferAddLit(buf, "</interconnects>\n");
- }
+ virNumaInterconnectFormat(buf, def->interconnects, def->ninterconnects);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</numa>\n");
@@ -1842,3 +1792,50 @@ virNumaCacheFormat(virBuffer *buf,
virXMLFormatElement(buf, "cache", &attrBuf, &childBuf);
}
}
+
+
+void
+virNumaInterconnectFormat(virBuffer *buf,
+ const virNumaInterconnect *interconnects,
+ size_t ninterconnects)
+{
+ g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+ size_t i;
+
+ for (i = 0; i < ninterconnects; i++) {
+ const virNumaInterconnect *l = &interconnects[i];
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+ const char *elem = NULL;
+
+ switch (l->type) {
+ case VIR_NUMA_INTERCONNECT_TYPE_LATENCY:
+ elem = "latency";
+ break;
+ case VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH:
+ elem = "bandwidth";
+ break;
+ }
+
+ virBufferAsprintf(&attrBuf,
+ " initiator='%u' target='%u'",
+ l->initiator, l->target);
+
+ if (l->cache > 0) {
+ virBufferAsprintf(&attrBuf,
+ " cache='%u'",
+ l->cache);
+ }
+
+ virBufferAsprintf(&attrBuf,
+ " type='%s' value='%lu'",
+ virMemoryLatencyTypeToString(l->accessType),
+ l->value);
+
+ if (l->type == VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH)
+ virBufferAddLit(&attrBuf, " unit='KiB'");
+
+ virXMLFormatElement(&childBuf, elem, &attrBuf, NULL);
+ }
+
+ virXMLFormatElement(buf, "interconnects", NULL, &childBuf);
+}
diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h
index 5baf68348c..1d1e816870 100644
--- a/src/conf/numa_conf.h
+++ b/src/conf/numa_conf.h
@@ -272,3 +272,19 @@ struct _virNumaCache {
void virNumaCacheFormat(virBuffer *buf,
const virNumaCache *caches,
size_t ncaches);
+
+typedef struct _virNumaInterconnect virNumaInterconnect;
+struct _virNumaInterconnect {
+ virNumaInterconnectType type; /* whether structure describes latency
+ or bandwidth */
+ unsigned int initiator; /* the initiator NUMA node */
+ unsigned int target; /* the target NUMA node */
+ unsigned int cache; /* the target cache on @target; if 0 then the
+ memory on @target */
+ virMemoryLatency accessType; /* what type of access is defined */
+ unsigned long value; /* value itself */
+};
+
+void virNumaInterconnectFormat(virBuffer *buf,
+ const virNumaInterconnect *interconnects,
+ size_t ninterconnects);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d7f6dfd534..8f0945f581 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -915,6 +915,7 @@ virNumaCacheFormat;
virNumaCachePolicyTypeFromString;
virNumaCachePolicyTypeToString;
virNumaDistanceFormat;
+virNumaInterconnectFormat;
# conf/nwfilter_conf.h
--
2.31.1