From 773118632e1012131dc58350fc8e9f2b0780307b Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 14 May 2021 15:25:47 +0200 Subject: [PATCH] numa_conf: Expose virNumaDistance formatter Expose virNumaDistance XML formatter so that it can be re-used by other parts of the code. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/numa_conf.c | 47 +++++++++++++++++++++------------------- src/conf/numa_conf.h | 10 +++++++++ src/libvirt_private.syms | 1 + 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index fa39c1ccc0..8fd5635aca 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -82,8 +82,6 @@ VIR_ENUM_IMPL(virDomainMemoryLatency, "write" ); -typedef struct _virNumaDistance virNumaDistance; - typedef struct _virDomainNumaCache virDomainNumaCache; typedef struct _virDomainNumaInterconnect virDomainNumaInterconnect; @@ -106,10 +104,7 @@ struct _virDomainNuma { virDomainMemoryAccess memAccess; /* shared memory access configuration */ virTristateBool discard; /* discard-data for memory-backend-file */ - struct _virNumaDistance { - unsigned int value; /* locality value for node i->j or j->i */ - unsigned int cellid; - } *distances; /* remote node distances */ + virNumaDistance *distances; /* remote node distances */ size_t ndistances; struct _virDomainNumaCache { @@ -1132,22 +1127,9 @@ virDomainNumaDefFormatXML(virBuffer *buf, virBufferAsprintf(&attrBuf, " discard='%s'", virTristateBoolTypeToString(discard)); - if (def->mem_nodes[i].ndistances) { - virNumaDistance *distances = def->mem_nodes[i].distances; - - virBufferAddLit(&childBuf, "\n"); - virBufferAdjustIndent(&childBuf, 2); - for (j = 0; j < def->mem_nodes[i].ndistances; j++) { - if (distances[j].value) { - virBufferAddLit(&childBuf, "\n"); - } - } - virBufferAdjustIndent(&childBuf, -2); - virBufferAddLit(&childBuf, "\n"); - } + virNumaDistanceFormat(&childBuf, + def->mem_nodes[i].distances, + def->mem_nodes[i].ndistances); for (j = 0; j < def->mem_nodes[i].ncaches; j++) { virDomainNumaCache *cache = &def->mem_nodes[i].caches[j]; @@ -1836,3 +1818,24 @@ virDomainNumaGetInterconnect(const virDomainNuma *numa, *value = l->value; return 0; } + + +void +virNumaDistanceFormat(virBuffer *buf, + const virNumaDistance *distances, + size_t ndistances) +{ + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); + size_t i; + + for (i = 0; i < ndistances; i++) { + if (distances[i].value == 0) + continue; + virBufferAddLit(&childBuf, "\n"); + } + + virXMLFormatElement(buf, "distances", NULL, &childBuf); +} diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h index 8f6597b0b7..6682580ded 100644 --- a/src/conf/numa_conf.h +++ b/src/conf/numa_conf.h @@ -249,3 +249,13 @@ int virDomainNumaGetInterconnect(const virDomainNuma *numa, unsigned int *cache, virDomainMemoryLatency *accessType, unsigned long *value); + +typedef struct _virNumaDistance virNumaDistance; +struct _virNumaDistance { + unsigned int value; /* locality value for node i->j or j->i */ + unsigned int cellid; +}; + +void virNumaDistanceFormat(virBuffer *buf, + const virNumaDistance *distances, + size_t ndistances); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7c7627052b..baca9dc1b3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -915,6 +915,7 @@ virDomainNumatunePlacementTypeFromString; virDomainNumatunePlacementTypeToString; virDomainNumatuneSet; virDomainNumatuneSpecifiedMaxNode; +virNumaDistanceFormat; # conf/nwfilter_conf.h