diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7b9de2e92d..139cdfc0a7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -25177,6 +25177,7 @@ virDomainSmartcardDefFormat(virBuffer *buf,
{
const char *mode = virDomainSmartcardTypeToString(def->type);
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
size_t i;
if (!mode) {
@@ -25209,19 +25210,13 @@ virDomainSmartcardDefFormat(virBuffer *buf,
}
virDomainDeviceInfoFormat(&childBuf, &def->info, flags);
- virBufferAsprintf(buf, "type == VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH &&
- virDomainChrAttrsDefFormat(buf, def->data.passthru, false) < 0) {
+ virDomainChrAttrsDefFormat(&attrBuf, def->data.passthru, false) < 0) {
return -1;
}
- if (virBufferUse(&childBuf)) {
- virBufferAddLit(buf, ">\n");
- virBufferAddBuffer(buf, &childBuf);
- virBufferAddLit(buf, "\n");
- } else {
- virBufferAddLit(buf, "/>\n");
- }
+ virXMLFormatElement(buf, "smartcard", &attrBuf, &childBuf);
return 0;
}
@@ -25300,6 +25295,7 @@ virDomainSoundDefFormat(virBuffer *buf,
{
const char *model = virDomainSoundModelTypeToString(def->model);
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
size_t i;
if (!model) {
@@ -25316,14 +25312,9 @@ virDomainSoundDefFormat(virBuffer *buf,
virDomainDeviceInfoFormat(&childBuf, &def->info, flags);
- virBufferAsprintf(buf, "\n");
- virBufferAddBuffer(buf, &childBuf);
- virBufferAddLit(buf, "\n");
- } else {
- virBufferAddLit(buf, "/>\n");
- }
+ virBufferAsprintf(&attrBuf, " model='%s'", model);
+
+ virXMLFormatElement(buf, "sound", &attrBuf, &childBuf);
return 0;
}
@@ -25453,6 +25444,7 @@ virDomainAudioDefFormat(virBuffer *buf,
virDomainAudioDef *def)
{
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) inputBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) outputBuf = VIR_BUFFER_INITIALIZER;
const char *type = virDomainAudioTypeTypeToString(def->type);
@@ -25463,10 +25455,10 @@ virDomainAudioDefFormat(virBuffer *buf,
return -1;
}
- virBufferAsprintf(buf, "\n");
- } else {
- virBufferAddLit(buf, "/>\n");
- }
+ virXMLFormatElement(buf, "audio", &attrBuf, &childBuf);
return 0;
}
@@ -27002,6 +26988,7 @@ virDomainCachetuneDefFormat(virBuffer *buf,
unsigned int flags)
{
g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
size_t i = 0;
g_autofree char *vcpus = NULL;
@@ -27024,19 +27011,17 @@ virDomainCachetuneDefFormat(virBuffer *buf,
if (!vcpus)
return -1;
- virBufferAsprintf(buf, "alloc);
if (!alloc_id)
return -1;
- virBufferAsprintf(buf, " id='%s'", alloc_id);
+ virBufferAsprintf(&attrBuf, " id='%s'", alloc_id);
}
- virBufferAddLit(buf, ">\n");
- virBufferAddBuffer(buf, &childrenBuf);
- virBufferAddLit(buf, "\n");
+ virXMLFormatElement(buf, "cachetune", &attrBuf, &childrenBuf);
return 0;
}
@@ -27062,6 +27047,7 @@ virDomainMemorytuneDefFormat(virBuffer *buf,
unsigned int flags)
{
g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
g_autofree char *vcpus = NULL;
size_t i = 0;
@@ -27084,19 +27070,17 @@ virDomainMemorytuneDefFormat(virBuffer *buf,
if (!vcpus)
return -1;
- virBufferAsprintf(buf, "alloc);
if (!alloc_id)
return -1;
- virBufferAsprintf(buf, " id='%s'", alloc_id);
+ virBufferAsprintf(&attrBuf, " id='%s'", alloc_id);
}
- virBufferAddLit(buf, ">\n");
- virBufferAddBuffer(buf, &childrenBuf);
- virBufferAddLit(buf, "\n");
+ virXMLFormatElement(buf, "memorytune", &attrBuf, &childrenBuf);
return 0;
}
@@ -27213,11 +27197,7 @@ virDomainCputuneDefFormat(virBuffer *buf,
for (i = 0; i < def->nresctrls; i++)
virDomainMemorytuneDefFormat(&childrenBuf, def->resctrls[i], flags);
- if (virBufferUse(&childrenBuf)) {
- virBufferAddLit(buf, "\n");
- virBufferAddBuffer(buf, &childrenBuf);
- virBufferAddLit(buf, "\n");
- }
+ virXMLFormatElement(buf, "cputune", NULL, &childrenBuf);
return 0;
}