[PATCH 3/4] numa_conf: Expose virNumaDistance formatter
Peter Krempa
pkrempa at redhat.com
Fri May 21 07:55:24 UTC 2021
On Thu, May 20, 2021 at 17:24:55 +0200, Michal Privoznik wrote:
> Expose virNumaDistance XML formatter so that it can be re-used by
> other parts of the code.
>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
> 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
[...]
> @@ -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, "<distances>\n");
A slight semantic difference between the two impls is that this will
format an empty <distances> pair tag ...
> - virBufferAdjustIndent(&childBuf, 2);
> - for (j = 0; j < def->mem_nodes[i].ndistances; j++) {
> - if (distances[j].value) {
... if all of these are 0.
> - virBufferAddLit(&childBuf, "<sibling");
> - virBufferAsprintf(&childBuf, " id='%d'", distances[j].cellid);
> - virBufferAsprintf(&childBuf, " value='%d'", distances[j].value);
> - virBufferAddLit(&childBuf, "/>\n");
> - }
> - }
> - virBufferAdjustIndent(&childBuf, -2);
> - virBufferAddLit(&childBuf, "</distances>\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, "<sibling");
> + virBufferAsprintf(&childBuf, " id='%d'", distances[i].cellid);
> + virBufferAsprintf(&childBuf, " value='%d'", distances[i].value);
> + virBufferAddLit(&childBuf, "/>\n");
> + }
> +
> + virXMLFormatElement(buf, "distances", NULL, &childBuf);
while here we won't.
> +}
In this case it shouldn't be a problem though unlike in the NBD part of
the migration cookie ;). If you think it might be a problem you can use
virXMLFormatElementEmpty.
Reviewed-by: Peter Krempa <pkrempa at redhat.com>
More information about the libvir-list
mailing list