]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virDomainNetDefFormat: Modernize <guest/> formatting
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 31 Jan 2023 12:42:13 +0000 (13:42 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 1 Feb 2023 07:36:26 +0000 (08:36 +0100)
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>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/conf/domain_conf.c

index 4c6f79efe3564fefb76e6dd3acf270af4fc818dc..bab8f09e261a24771bb9443654c9a7b08f3f4b85 100644 (file)
@@ -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));