The virDomainMemorySourceDefFormat() uses good old style of
formatting child buffer (virBufferAdjustIndent()). When switched
to virXMLFormatElement() we can save a couple of lines.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_conf.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 38ddbacd66..8f10fe14d3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -27877,37 +27877,32 @@ static int
virDomainMemorySourceDefFormat(virBufferPtr buf,
virDomainMemoryDefPtr def)
{
+ g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
g_autofree char *bitmap = NULL;
- if (!def->pagesize && !def->sourceNodes &&
!def->nvdimmPath)
- return 0;
-
- virBufferAddLit(buf, "<source>\n");
- virBufferAdjustIndent(buf, 2);
-
switch (def->model) {
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
if (def->sourceNodes) {
if (!(bitmap = virBitmapFormat(def->sourceNodes)))
return -1;
- virBufferAsprintf(buf, "<nodemask>%s</nodemask>\n",
bitmap);
+ virBufferAsprintf(&childBuf,
"<nodemask>%s</nodemask>\n", bitmap);
}
if (def->pagesize)
- virBufferAsprintf(buf, "<pagesize
unit='KiB'>%llu</pagesize>\n",
+ virBufferAsprintf(&childBuf, "<pagesize
unit='KiB'>%llu</pagesize>\n",
def->pagesize);
break;
case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
- virBufferEscapeString(buf, "<path>%s</path>\n",
def->nvdimmPath);
+ virBufferEscapeString(&childBuf, "<path>%s</path>\n",
def->nvdimmPath);
if (def->alignsize)
- virBufferAsprintf(buf, "<alignsize
unit='KiB'>%llu</alignsize>\n",
+ virBufferAsprintf(&childBuf, "<alignsize
unit='KiB'>%llu</alignsize>\n",
def->alignsize);
if (def->nvdimmPmem)
- virBufferAddLit(buf, "<pmem/>\n");
+ virBufferAddLit(&childBuf, "<pmem/>\n");
break;
case VIR_DOMAIN_MEMORY_MODEL_NONE:
@@ -27915,8 +27910,7 @@ virDomainMemorySourceDefFormat(virBufferPtr buf,
break;
}
- virBufferAdjustIndent(buf, -2);
- virBufferAddLit(buf, "</source>\n");
+ virXMLFormatElement(buf, "source", NULL, &childBuf);
return 0;
}
--
2.26.2