[PATCH 0/7] virDomainNetDefFormat: Modernize XML formatting

A bit. After these, the function is still long and could be broken into smaller ones, but let's leave that as an exercise for future us. Michal Prívozník (7): qemuxml2xmloutdata: Turn net-mtu.xml into a symlink virDomainNetDefFormat: Rename @attrBuf to @targetAttrBuf virDomainNetDefFormat: Modernize <tune/> formatting virDomainNetDefFormat: Modernize <guest/> formatting virDomainNetDefFormat: Modernize <source/> formatting virDomainNetDefFormat: Simplify @sourceAttrBuf handling for some types of VIR_DOMAIN_NET virDomainNetDefFormat: Modernize <mac/> formatting src/conf/domain_conf.c | 151 ++++++++++----------------- tests/qemuxml2argvdata/net-mtu.xml | 26 +++-- tests/qemuxml2xmloutdata/net-mtu.xml | 72 +------------ 3 files changed, 74 insertions(+), 175 deletions(-) mode change 100644 => 120000 tests/qemuxml2xmloutdata/net-mtu.xml -- 2.39.1

There's nothing specific about net-mtu test. In fact, if device addresses are filled in (and some elements reordered), we get the same XML. Make those changes to the input XML and turn the output XML to be a symlink. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemuxml2argvdata/net-mtu.xml | 23 ++++++--- tests/qemuxml2xmloutdata/net-mtu.xml | 72 +--------------------------- 2 files changed, 18 insertions(+), 77 deletions(-) mode change 100644 => 120000 tests/qemuxml2xmloutdata/net-mtu.xml diff --git a/tests/qemuxml2argvdata/net-mtu.xml b/tests/qemuxml2argvdata/net-mtu.xml index 99258b97fa..900548b465 100644 --- a/tests/qemuxml2argvdata/net-mtu.xml +++ b/tests/qemuxml2argvdata/net-mtu.xml @@ -29,32 +29,43 @@ <readonly/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk> - <controller type='usb' index='0'/> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> <controller type='virtio-serial' index='0'> <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> </controller> - <controller type='ide' index='0'/> + <controller type='ide' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </controller> <controller type='pci' index='0' model='pci-root'/> <interface type='network'> - <source network='default'/> <mac address='52:54:00:e5:48:58'/> + <source network='default'/> <model type='virtio'/> <mtu size='1500'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </interface> <interface type='network'> - <source network='default'/> <mac address='52:54:00:e5:48:59'/> + <source network='default'/> <model type='virtio'/> <mtu size='9000'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <serial type='pty'> - <target port='0'/> + <target type='isa-serial' port='0'> + <model name='isa-serial'/> + </target> </serial> <console type='pty'> <target type='serial' port='0'/> </console> <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> - <memballoon model='virtio'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2xmloutdata/net-mtu.xml b/tests/qemuxml2xmloutdata/net-mtu.xml deleted file mode 100644 index 900548b465..0000000000 --- a/tests/qemuxml2xmloutdata/net-mtu.xml +++ /dev/null @@ -1,71 +0,0 @@ -<domain type='qemu'> - <name>test</name> - <uuid>15d091de-0181-456b-9554-e4382dc1f1ab</uuid> - <memory unit='KiB'>1048576</memory> - <currentMemory unit='KiB'>1048576</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='x86_64' machine='pc'>hvm</type> - <boot dev='cdrom'/> - <boot dev='hd'/> - <bootmenu enable='yes'/> - </os> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>restart</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <disk type='file' device='disk'> - <driver name='qemu' type='qcow2' event_idx='on'/> - <source file='/var/lib/libvirt/images/f14.img'/> - <target dev='vda' bus='virtio'/> - <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> - </disk> - <disk type='file' device='cdrom'> - <driver name='qemu' type='raw'/> - <source file='/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso'/> - <target dev='hdc' bus='ide'/> - <readonly/> - <address type='drive' controller='0' bus='1' target='0' unit='0'/> - </disk> - <controller type='usb' index='0'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> - </controller> - <controller type='virtio-serial' index='0'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> - </controller> - <controller type='ide' index='0'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> - </controller> - <controller type='pci' index='0' model='pci-root'/> - <interface type='network'> - <mac address='52:54:00:e5:48:58'/> - <source network='default'/> - <model type='virtio'/> - <mtu size='1500'/> - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> - </interface> - <interface type='network'> - <mac address='52:54:00:e5:48:59'/> - <source network='default'/> - <model type='virtio'/> - <mtu size='9000'/> - <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> - </interface> - <serial type='pty'> - <target type='isa-serial' port='0'> - <model name='isa-serial'/> - </target> - </serial> - <console type='pty'> - <target type='serial' port='0'/> - </console> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <audio id='1' type='none'/> - <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> - </memballoon> - </devices> -</domain> diff --git a/tests/qemuxml2xmloutdata/net-mtu.xml b/tests/qemuxml2xmloutdata/net-mtu.xml new file mode 120000 index 0000000000..a4a2e06bc6 --- /dev/null +++ b/tests/qemuxml2xmloutdata/net-mtu.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/net-mtu.xml \ No newline at end of file -- 2.39.1

The @attrBuf variable in virDomainNetDefFormat() is named too broadly. It holds attribute buffer to the <target/> element. Rename it to @targetAttrBuf then. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0cd6020ea3..382c32db67 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23685,7 +23685,7 @@ virDomainNetDefFormat(virBuffer *buf, const char *typeStr; virDomainHostdevDef *hostdef = NULL; char macstr[VIR_MAC_STRING_BUFLEN]; - g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) targetAttrBuf = VIR_BUFFER_INITIALIZER; const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL; /* publicActual is true if we should report the current state in @@ -23945,14 +23945,14 @@ virDomainNetDefFormat(virBuffer *buf, STRPREFIX(def->ifname, VIR_NET_GENERATED_MACVLAN_PREFIX) || (prefix && STRPREFIX(def->ifname, prefix)))))) { /* Skip auto-generated target names for inactive config. */ - virBufferEscapeString(&attrBuf, " dev='%s'", def->ifname); + virBufferEscapeString(&targetAttrBuf, " dev='%s'", def->ifname); } if (def->managed_tap != VIR_TRISTATE_BOOL_ABSENT) { - virBufferAsprintf(&attrBuf, " managed='%s'", + virBufferAsprintf(&targetAttrBuf, " managed='%s'", virTristateBoolTypeToString(def->managed_tap)); } - virXMLFormatElement(buf, "target", &attrBuf, NULL); + virXMLFormatElement(buf, "target", &targetAttrBuf, NULL); if (def->ifname_guest || def->ifname_guest_actual) { virBufferAddLit(buf, "<guest"); -- 2.39.1

The <tune/> child element of <interface/> is formatted the old way. Switch to virXMLFormatElement(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 10 +++++----- tests/qemuxml2argvdata/net-mtu.xml | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 382c32db67..4c6f79efe3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23993,11 +23993,11 @@ virDomainNetDefFormat(virBuffer *buf, } if (def->tune.sndbuf_specified) { - virBufferAddLit(buf, "<tune>\n"); - virBufferAdjustIndent(buf, 2); - virBufferAsprintf(buf, "<sndbuf>%llu</sndbuf>\n", def->tune.sndbuf); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "</tune>\n"); + g_auto(virBuffer) sndChildBuf = VIR_BUFFER_INIT_CHILD(buf); + + virBufferAsprintf(&sndChildBuf, "<sndbuf>%llu</sndbuf>\n", def->tune.sndbuf); + + virXMLFormatElement(buf, "tune", NULL, &sndChildBuf); } virDomainNetTeamingInfoFormat(def->teaming, buf); diff --git a/tests/qemuxml2argvdata/net-mtu.xml b/tests/qemuxml2argvdata/net-mtu.xml index 900548b465..092978bea0 100644 --- a/tests/qemuxml2argvdata/net-mtu.xml +++ b/tests/qemuxml2argvdata/net-mtu.xml @@ -50,6 +50,9 @@ <mac address='52:54:00:e5:48:59'/> <source network='default'/> <model type='virtio'/> + <tune> + <sndbuf>1600</sndbuf> + </tune> <mtu size='9000'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> -- 2.39.1

The <guest/> child element of <interface/> is formatted the old way. Switch to virXMLFormatElement(). Since this element is used in LXC driver, this part of the function is tested by lxcxml2xmltest (specifically lxc-ethernet* test cases). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4c6f79efe3..bab8f09e26 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23955,16 +23955,17 @@ virDomainNetDefFormat(virBuffer *buf, virXMLFormatElement(buf, "target", &targetAttrBuf, NULL); if (def->ifname_guest || def->ifname_guest_actual) { - virBufferAddLit(buf, "<guest"); + g_auto(virBuffer) guestAttrBuf = VIR_BUFFER_INITIALIZER; + /* Skip auto-generated target names for inactive config. */ - if (def->ifname_guest) - virBufferEscapeString(buf, " dev='%s'", def->ifname_guest); + virBufferEscapeString(&guestAttrBuf, " dev='%s'", def->ifname_guest); /* Only set if the host is running, so shouldn't pollute output */ - if (def->ifname_guest_actual) - virBufferEscapeString(buf, " actual='%s'", def->ifname_guest_actual); - virBufferAddLit(buf, "/>\n"); + virBufferEscapeString(&guestAttrBuf, " actual='%s'", def->ifname_guest_actual); + + virXMLFormatElement(buf, "guest", &guestAttrBuf, NULL); } + if (virDomainNetGetModelString(def)) { virBufferEscapeString(buf, "<model type='%s'/>\n", virDomainNetGetModelString(def)); -- 2.39.1

The <source/> child element of <interface/> is formatted the old way. Switch to virXMLFormatElement(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 103 ++++++++++++----------------------------- 1 file changed, 30 insertions(+), 73 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bab8f09e26..fb2455840a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23681,7 +23681,6 @@ virDomainNetDefFormat(virBuffer *buf, { virDomainNetType actualType = virDomainNetGetActualType(def); bool publicActual = false; - int sourceLines = 0; const char *typeStr; virDomainHostdevDef *hostdef = NULL; char macstr[VIR_MAC_STRING_BUFLEN]; @@ -23745,6 +23744,8 @@ virDomainNetDefFormat(virBuffer *buf, if (virDomainActualNetDefContentsFormat(buf, def, false, flags, xmlopt) < 0) return -1; } else { + g_auto(virBuffer) sourceAttrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) sourceChildBuf = VIR_BUFFER_INIT_CHILD(buf); /* ...but if we've asked for the inactive XML (rather than * status), or to report the ActualDef as a separate <actual> * subelement (this is how we privately store interface @@ -23754,17 +23755,16 @@ virDomainNetDefFormat(virBuffer *buf, */ switch (def->type) { case VIR_DOMAIN_NET_TYPE_NETWORK: - virBufferEscapeString(buf, "<source network='%s'", + virBufferEscapeString(&sourceAttrBuf, " network='%s'", def->data.network.name); - virBufferEscapeString(buf, " portgroup='%s'", + virBufferEscapeString(&sourceAttrBuf, " portgroup='%s'", def->data.network.portgroup); if (virUUIDIsValid(def->data.network.portid) && !(flags & (VIR_DOMAIN_DEF_FORMAT_INACTIVE))) { char portidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(def->data.network.portid, portidstr); - virBufferEscapeString(buf, " portid='%s'", portidstr); + virBufferEscapeString(&sourceAttrBuf, " portid='%s'", portidstr); } - sourceLines++; break; case VIR_DOMAIN_NET_TYPE_ETHERNET: @@ -23772,31 +23772,23 @@ virDomainNetDefFormat(virBuffer *buf, case VIR_DOMAIN_NET_TYPE_VHOSTUSER: if (def->data.vhostuser->type == VIR_DOMAIN_CHR_TYPE_UNIX) { - virBufferAddLit(buf, "<source type='unix'"); - virBufferEscapeString(buf, " path='%s'", + virBufferAddLit(&sourceAttrBuf, " type='unix'"); + virBufferEscapeString(&sourceAttrBuf, " path='%s'", def->data.vhostuser->data.nix.path); - virBufferAsprintf(buf, " mode='%s'", + virBufferAsprintf(&sourceAttrBuf, " mode='%s'", def->data.vhostuser->data.nix.listen ? "server" : "client"); - sourceLines++; if (def->data.vhostuser->data.nix.reconnect.enabled) { - virBufferAddLit(buf, ">\n"); - sourceLines++; - virBufferAdjustIndent(buf, 2); - virDomainChrSourceReconnectDefFormat(buf, + virDomainChrSourceReconnectDefFormat(&sourceChildBuf, &def->data.vhostuser->data.nix.reconnect); - virBufferAdjustIndent(buf, -2); } } break; case VIR_DOMAIN_NET_TYPE_BRIDGE: - if (def->data.bridge.brname) { - virBufferEscapeString(buf, "<source bridge='%s'", - def->data.bridge.brname); - sourceLines++; - } + virBufferEscapeString(&sourceAttrBuf, " bridge='%s'", + def->data.bridge.brname); break; case VIR_DOMAIN_NET_TYPE_SERVER: @@ -23804,42 +23796,32 @@ virDomainNetDefFormat(virBuffer *buf, case VIR_DOMAIN_NET_TYPE_MCAST: case VIR_DOMAIN_NET_TYPE_UDP: if (def->data.socket.address) { - virBufferAsprintf(buf, "<source address='%s' port='%d'", + virBufferAsprintf(&sourceAttrBuf, " address='%s' port='%d'", def->data.socket.address, def->data.socket.port); } else { - virBufferAsprintf(buf, "<source port='%d'", + virBufferAsprintf(&sourceAttrBuf, " port='%d'", def->data.socket.port); } - sourceLines++; if (def->type != VIR_DOMAIN_NET_TYPE_UDP) break; - virBufferAddLit(buf, ">\n"); - sourceLines++; - virBufferAdjustIndent(buf, 2); - - virBufferAsprintf(buf, "<local address='%s' port='%d'/>\n", + virBufferAsprintf(&sourceChildBuf, "<local address='%s' port='%d'/>\n", def->data.socket.localaddr, def->data.socket.localport); - virBufferAdjustIndent(buf, -2); break; case VIR_DOMAIN_NET_TYPE_INTERNAL: - if (def->data.internal.name) { - virBufferEscapeString(buf, "<source name='%s'", - def->data.internal.name); - sourceLines++; - } + virBufferEscapeString(&sourceAttrBuf, " name='%s'", + def->data.internal.name); break; case VIR_DOMAIN_NET_TYPE_DIRECT: - virBufferEscapeString(buf, "<source dev='%s'", + virBufferEscapeString(&sourceAttrBuf, " dev='%s'", def->data.direct.linkdev); - virBufferAsprintf(buf, " mode='%s'", + virBufferAsprintf(&sourceAttrBuf, " mode='%s'", virNetDevMacVLanModeTypeToString(def->data.direct.mode)); - sourceLines++; break; case VIR_DOMAIN_NET_TYPE_HOSTDEV: @@ -23850,33 +23832,24 @@ virDomainNetDefFormat(virBuffer *buf, break; case VIR_DOMAIN_NET_TYPE_VDPA: - if (def->data.vdpa.devicepath) { - virBufferEscapeString(buf, "<source dev='%s'", - def->data.vdpa.devicepath); - sourceLines++; - } - break; + virBufferEscapeString(&sourceAttrBuf, " dev='%s'", + def->data.vdpa.devicepath); + break; case VIR_DOMAIN_NET_TYPE_VDS: { char switchidstr[VIR_UUID_STRING_BUFLEN]; virUUIDFormat(def->data.vds.switch_id, switchidstr); - virBufferEscapeString(buf, "<source switchid='%s'", switchidstr); - virBufferAsprintf(buf, " portid='%lld'", def->data.vds.port_id); - virBufferEscapeString(buf, " portgroupid='%s'", def->data.vds.portgroup_id); - virBufferAsprintf(buf, " connectionid='%lld'", def->data.vds.connection_id); - - sourceLines++; - + virBufferEscapeString(&sourceAttrBuf, " switchid='%s'", switchidstr); + virBufferAsprintf(&sourceAttrBuf, " portid='%lld'", def->data.vds.port_id); + virBufferEscapeString(&sourceAttrBuf, " portgroupid='%s'", def->data.vds.portgroup_id); + virBufferAsprintf(&sourceAttrBuf, " connectionid='%lld'", def->data.vds.connection_id); break; } case VIR_DOMAIN_NET_TYPE_USER: - if (def->backend.type == VIR_DOMAIN_NET_BACKEND_PASST && - def->sourceDev) { - virBufferEscapeString(buf, "<source dev='%s'", def->sourceDev); - sourceLines++; - } + if (def->backend.type == VIR_DOMAIN_NET_BACKEND_PASST) + virBufferEscapeString(&sourceAttrBuf, " dev='%s'", def->sourceDev); break; case VIR_DOMAIN_NET_TYPE_NULL: @@ -23884,27 +23857,12 @@ virDomainNetDefFormat(virBuffer *buf, break; } - /* if sourceLines == 0 - no <source> info at all so far - * sourceLines == 1 - first line written, no terminating ">" - * sourceLines > 1 - multiple lines, including subelements - */ if (def->hostIP.nips || def->hostIP.nroutes) { - if (sourceLines == 0) { - virBufferAddLit(buf, "<source>\n"); - sourceLines += 2; - } else if (sourceLines == 1) { - virBufferAddLit(buf, ">\n"); - sourceLines++; - } - virBufferAdjustIndent(buf, 2); - if (virDomainNetIPInfoFormat(buf, &def->hostIP) < 0) + if (virDomainNetIPInfoFormat(&sourceChildBuf, &def->hostIP) < 0) return -1; - virBufferAdjustIndent(buf, -2); } - if (sourceLines == 1) - virBufferAddLit(buf, "/>\n"); - else if (sourceLines > 1) - virBufferAddLit(buf, "</source>\n"); + + virXMLFormatElement(buf, "source", &sourceAttrBuf, &sourceChildBuf); if (virNetDevVlanFormat(&def->vlan, buf) < 0) return -1; @@ -23922,7 +23880,6 @@ virDomainNetDefFormat(virBuffer *buf, (flags & VIR_DOMAIN_DEF_FORMAT_ACTUAL_NET) && (virDomainActualNetDefFormat(buf, def, flags, xmlopt) < 0)) return -1; - } if (virDomainNetIPInfoFormat(buf, &def->guestIP) < 0) -- 2.39.1

For VIR_DOMAIN_NET_TYPE_{SERVER,CLIENT,MCAST,UDP} we need to put (optionally) 'address' attribute and 'port' attributes of <source/> element. But the way we currently do that is particularly verbose. It can be shortened using virBufferEscapeString(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fb2455840a..b991a01af3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23795,14 +23795,10 @@ virDomainNetDefFormat(virBuffer *buf, case VIR_DOMAIN_NET_TYPE_CLIENT: case VIR_DOMAIN_NET_TYPE_MCAST: case VIR_DOMAIN_NET_TYPE_UDP: - if (def->data.socket.address) { - virBufferAsprintf(&sourceAttrBuf, " address='%s' port='%d'", - def->data.socket.address, - def->data.socket.port); - } else { - virBufferAsprintf(&sourceAttrBuf, " port='%d'", - def->data.socket.port); - } + virBufferEscapeString(&sourceAttrBuf, " address='%s'", + def->data.socket.address); + virBufferAsprintf(&sourceAttrBuf, " port='%d'", + def->data.socket.port); if (def->type != VIR_DOMAIN_NET_TYPE_UDP) break; -- 2.39.1

The <source/> child element of <mac/> is formatted the old way. Switch to virXMLFormatElement(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b991a01af3..1cf2bf84bc 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23685,6 +23685,7 @@ virDomainNetDefFormat(virBuffer *buf, virDomainHostdevDef *hostdef = NULL; char macstr[VIR_MAC_STRING_BUFLEN]; g_auto(virBuffer) targetAttrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) macAttrBuf = VIR_BUFFER_INITIALIZER; const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL; /* publicActual is true if we should report the current state in @@ -23725,13 +23726,13 @@ virDomainNetDefFormat(virBuffer *buf, virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); - virBufferAsprintf(buf, "<mac address='%s'", + virBufferAsprintf(&macAttrBuf, " address='%s'", virMacAddrFormat(&def->mac, macstr)); if (def->mac_type) - virBufferAsprintf(buf, " type='%s'", virDomainNetMacTypeTypeToString(def->mac_type)); + virBufferAsprintf(&macAttrBuf, " type='%s'", virDomainNetMacTypeTypeToString(def->mac_type)); if (def->mac_check != VIR_TRISTATE_BOOL_ABSENT) - virBufferAsprintf(buf, " check='%s'", virTristateBoolTypeToString(def->mac_check)); - virBufferAddLit(buf, "/>\n"); + virBufferAsprintf(&macAttrBuf, " check='%s'", virTristateBoolTypeToString(def->mac_check)); + virXMLFormatElement(buf, "mac", &macAttrBuf, NULL); if (publicActual) { /* when there is a virDomainActualNetDef, and we haven't been -- 2.39.1

On Tue, Jan 31, 2023 at 17:44:14 +0100, Michal Privoznik wrote:
A bit. After these, the function is still long and could be broken into smaller ones, but let's leave that as an exercise for future us.
Michal Prívozník (7): qemuxml2xmloutdata: Turn net-mtu.xml into a symlink virDomainNetDefFormat: Rename @attrBuf to @targetAttrBuf virDomainNetDefFormat: Modernize <tune/> formatting virDomainNetDefFormat: Modernize <guest/> formatting virDomainNetDefFormat: Modernize <source/> formatting virDomainNetDefFormat: Simplify @sourceAttrBuf handling for some types of VIR_DOMAIN_NET virDomainNetDefFormat: Modernize <mac/> formatting
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
participants (2)
-
Michal Privoznik
-
Peter Krempa