From: Michal Privoznik Date: Mon, 29 Sep 2025 14:05:31 +0000 (+0200) Subject: domain_conf: Use virXMLFormatElement() to format hyperv features X-Git-Tag: v11.9.0-rc1~66 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c9716c0e0904c86d7e1c9258bc6e808ba7bc8262;p=thirdparty%2Flibvirt.git domain_conf: Use virXMLFormatElement() to format hyperv features 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 Reviewed-by: Ján Tomko --- 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, "\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, "\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 @@ - - + qemu64