diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5d9148c1b1e673214a949df8a7801de303edccf8..6786d81c9b0a6014d5496661c68b3958af641417 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -26555,6 +26555,67 @@ virDomainIOMMUDefFormat(virBufferPtr buf,
}
+static int
+virDomainMemtuneFormat(virBufferPtr buf,
+ const virDomainMemtune *mem)
+{
+ virBuffer childBuf = VIR_BUFFER_INITIALIZER;
+ int ret = -1;
+
+ virBufferSetChildIndent(&childBuf, buf);
+
+ if (virMemoryLimitIsSet(mem->hard_limit)) {
+ virBufferAsprintf(&childBuf,
+ "%llu\n",
+ mem->hard_limit);
+ }
+ if (virMemoryLimitIsSet(mem->soft_limit)) {
+ virBufferAsprintf(&childBuf,
+ "%llu\n",
+ mem->soft_limit);
+ }
+ if (mem->min_guarantee) {
+ virBufferAsprintf(&childBuf,
+ "%llu\n",
+ mem->min_guarantee);
+ }
+ if (virMemoryLimitIsSet(mem->swap_hard_limit)) {
+ virBufferAsprintf(&childBuf,
+ "%llu\n",
+ mem->swap_hard_limit);
+ }
+
+ if (virXMLFormatElement(buf, "memtune", NULL, &childBuf) < 0)
+ goto cleanup;
+
+ virBufferSetChildIndent(&childBuf, buf);
+
+ if (mem->nhugepages)
+ virDomainHugepagesFormat(&childBuf, mem->hugepages, mem->nhugepages);
+ if (mem->nosharepages)
+ virBufferAddLit(&childBuf, "\n");
+ if (mem->locked)
+ virBufferAddLit(&childBuf, "\n");
+ if (mem->source)
+ virBufferAsprintf(&childBuf, "\n",
+ virDomainMemorySourceTypeToString(mem->source));
+ if (mem->access)
+ virBufferAsprintf(&childBuf, "\n",
+ virDomainMemoryAccessTypeToString(mem->access));
+ if (mem->allocation)
+ virBufferAsprintf(&childBuf, "\n",
+ virDomainMemoryAllocationTypeToString(mem->allocation));
+
+ if (virXMLFormatElement(buf, "memoryBacking", NULL, &childBuf) < 0)
+ goto cleanup;
+
+ ret = 0;
+ cleanup:
+ virBufferFreeAndReset(&childBuf);
+ return ret;
+}
+
+
/* This internal version appends to an existing buffer
* (possibly with auto-indent), rather than flattening
* to string.
@@ -26693,57 +26754,8 @@ virDomainDefFormatInternal(virDomainDefPtr def,
}
virBufferFreeAndReset(&childrenBuf);
- /* add memtune only if there are any */
- if (virMemoryLimitIsSet(def->mem.hard_limit) ||
- virMemoryLimitIsSet(def->mem.soft_limit) ||
- virMemoryLimitIsSet(def->mem.swap_hard_limit) ||
- def->mem.min_guarantee) {
- virBufferAddLit(buf, "\n");
- virBufferAdjustIndent(buf, 2);
- if (virMemoryLimitIsSet(def->mem.hard_limit)) {
- virBufferAsprintf(buf, ""
- "%llu\n", def->mem.hard_limit);
- }
- if (virMemoryLimitIsSet(def->mem.soft_limit)) {
- virBufferAsprintf(buf, ""
- "%llu\n", def->mem.soft_limit);
- }
- if (def->mem.min_guarantee) {
- virBufferAsprintf(buf, ""
- "%llu\n", def->mem.min_guarantee);
- }
- if (virMemoryLimitIsSet(def->mem.swap_hard_limit)) {
- virBufferAsprintf(buf, ""
- "%llu\n", def->mem.swap_hard_limit);
- }
- virBufferAdjustIndent(buf, -2);
- virBufferAddLit(buf, "\n");
- }
-
- if (def->mem.nhugepages || def->mem.nosharepages || def->mem.locked
- || def->mem.source || def->mem.access || def->mem.allocation)
- {
- virBufferAddLit(buf, "\n");
- virBufferAdjustIndent(buf, 2);
- if (def->mem.nhugepages)
- virDomainHugepagesFormat(buf, def->mem.hugepages, def->mem.nhugepages);
- if (def->mem.nosharepages)
- virBufferAddLit(buf, "\n");
- if (def->mem.locked)
- virBufferAddLit(buf, "\n");
- if (def->mem.source)
- virBufferAsprintf(buf, "\n",
- virDomainMemorySourceTypeToString(def->mem.source));
- if (def->mem.access)
- virBufferAsprintf(buf, "\n",
- virDomainMemoryAccessTypeToString(def->mem.access));
- if (def->mem.allocation)
- virBufferAsprintf(buf, "\n",
- virDomainMemoryAllocationTypeToString(def->mem.allocation));
-
- virBufferAdjustIndent(buf, -2);
- virBufferAddLit(buf, "\n");
- }
+ if (virDomainMemtuneFormat(buf, &def->mem) < 0)
+ goto error;
if (virDomainCpuDefFormat(buf, def) < 0)
goto error;