[PATCH v2 16/29] domain_conf: Use virXMLFormatElement() to format hyperv features

Michal Privoznik via Devel posted 29 patches 1 week, 6 days ago
[PATCH v2 16/29] domain_conf: Use virXMLFormatElement() to format hyperv features
Posted by Michal Privoznik via Devel 1 week, 6 days ago
From: Michal Privoznik <mprivozn@redhat.com>

Not only is it more modern that old virBufferAsprintf() of
opening and closing tag, it's also aware of child elements buffer
and thus formats a singleton properly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/domain_conf.c                              | 13 +++++++------
 .../hyperv-passthrough.x86_64-latest.xml            |  3 +--
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 585546d6fd..d095454283 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -28585,18 +28585,19 @@ static void
 virDomainFeaturesHyperVDefFormat(virBuffer *buf,
                                  const virDomainDef *def)
 {
-    virBuffer tmpChildBuf = VIR_BUFFER_INIT_CHILD(buf);
+    virBuffer childBuf = VIR_BUFFER_INIT_CHILD(buf);
+    virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
     size_t j;
 
     if (def->features[VIR_DOMAIN_FEATURE_HYPERV] == VIR_DOMAIN_HYPERV_MODE_NONE)
         return;
 
-    virBufferAsprintf(buf, "<hyperv mode='%s'>\n",
+    virBufferAsprintf(&attrBuf, " mode='%s'",
                       virDomainHyperVModeTypeToString(def->features[VIR_DOMAIN_FEATURE_HYPERV]));
 
     for (j = 0; j < VIR_DOMAIN_HYPERV_LAST; j++) {
         g_auto(virBuffer) hypervAttrBuf = VIR_BUFFER_INITIALIZER;
-        g_auto(virBuffer) hypervChildBuf = VIR_BUFFER_INIT_CHILD(&tmpChildBuf);
+        g_auto(virBuffer) hypervChildBuf = VIR_BUFFER_INIT_CHILD(&childBuf);
 
         if (def->hyperv_features[j] == VIR_TRISTATE_SWITCH_ABSENT)
             continue;
@@ -28656,14 +28657,14 @@ virDomainFeaturesHyperVDefFormat(virBuffer *buf,
             break;
         }
 
-        virXMLFormatElement(&tmpChildBuf, virDomainHypervTypeToString(j),
+        virXMLFormatElement(&childBuf, virDomainHypervTypeToString(j),
                             &hypervAttrBuf, &hypervChildBuf);
     }
 
-    virBufferAddBuffer(buf, &tmpChildBuf);
-    virBufferAddLit(buf, "</hyperv>\n");
+    virXMLFormatElement(buf, "hyperv", &attrBuf, &childBuf);
 }
 
+
 static int
 virDomainDefFormatFeatures(virBuffer *buf,
                            virDomainDef *def)
diff --git a/tests/qemuxmlconfdata/hyperv-passthrough.x86_64-latest.xml b/tests/qemuxmlconfdata/hyperv-passthrough.x86_64-latest.xml
index 2cfae8fa4c..0ce5bab605 100644
--- a/tests/qemuxmlconfdata/hyperv-passthrough.x86_64-latest.xml
+++ b/tests/qemuxmlconfdata/hyperv-passthrough.x86_64-latest.xml
@@ -10,8 +10,7 @@
   </os>
   <features>
     <acpi/>
-    <hyperv mode='passthrough'>
-    </hyperv>
+    <hyperv mode='passthrough'/>
   </features>
   <cpu mode='custom' match='exact' check='none'>
     <model fallback='forbid'>qemu64</model>
-- 
2.49.1