]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
domain_conf: Use virXMLFormatElement() to format hyperv features
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 29 Sep 2025 14:05:31 +0000 (16:05 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 15 Oct 2025 08:04:11 +0000 (10:04 +0200)
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>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c
tests/qemuxmlconfdata/hyperv-passthrough.x86_64-latest.xml

index 585546d6fd3a1287e3a48f4e72a3d09a03eae7fe..d09545428345e7946118dc967736d2687dc76edb 100644 (file)
@@ -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)
index 2cfae8fa4cac5c2e3dba625f0aded6edcd41fd43..0ce5bab605d88e17946e99683e12862fdb4d4dbb 100644 (file)
@@ -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>