]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuBuildHostNetProps: Move all 'tap' code together
authorPeter Krempa <pkrempa@redhat.com>
Mon, 9 May 2022 14:16:35 +0000 (16:16 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 May 2022 07:15:46 +0000 (09:15 +0200)
Move the block guarded by 'is_tap' boolean to the only place where
'is_tap' is set to true.

This causes few arguments to change places.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/net-eth-unmanaged-tap.args
tests/qemuxml2argvdata/user-aliases.args

index 07627e3350d22c491824c467615d495c0091b233..f384f245e15e4f65531a60ad6873b81b524a015e 100644 (file)
@@ -4215,7 +4215,6 @@ qemuBuildHostNetProps(virDomainNetDef *net,
                       size_t vhostfdSize,
                       const char *slirpfd)
 {
-    bool is_tap = false;
     virDomainNetType netType = virDomainNetGetActualType(net);
     size_t i;
     qemuDomainNetworkPrivate *netpriv = QEMU_DOMAIN_NETWORK_PRIVATE(net);
@@ -4260,7 +4259,31 @@ qemuBuildHostNetProps(virDomainNetDef *net,
                 return NULL;
         }
 
-        is_tap = true;
+        if (vhostfdSize) {
+            if (virJSONValueObjectAppendBoolean(netprops, "vhost", true) < 0)
+                return NULL;
+
+            if (vhostfdSize == 1) {
+                if (virJSONValueObjectAdd(&netprops, "s:vhostfd", vhostfd[0], NULL) < 0)
+                    return NULL;
+            } else {
+                g_auto(virBuffer) fdsbuf = VIR_BUFFER_INITIALIZER;
+
+                for (i = 0; i < vhostfdSize; i++)
+                    virBufferAsprintf(&fdsbuf, "%s:", vhostfd[i]);
+
+                virBufferTrim(&fdsbuf, ":");
+
+                if (virJSONValueObjectAdd(&netprops,
+                                          "s:vhostfds", virBufferCurrentContent(&fdsbuf),
+                                          NULL) < 0)
+                    return NULL;
+            }
+        }
+
+        if (net->tune.sndbuf_specified &&
+            virJSONValueObjectAppendNumberUlong(netprops, "sndbuf", net->tune.sndbuf) < 0)
+            return NULL;
         break;
 
     case VIR_DOMAIN_NET_TYPE_CLIENT:
@@ -4373,34 +4396,6 @@ qemuBuildHostNetProps(virDomainNetDef *net,
     if (virJSONValueObjectAppendStringPrintf(netprops, "id", "host%s", net->info.alias) < 0)
         return NULL;
 
-    if (is_tap) {
-        if (vhostfdSize) {
-            if (virJSONValueObjectAppendBoolean(netprops, "vhost", true) < 0)
-                return NULL;
-
-            if (vhostfdSize == 1) {
-                if (virJSONValueObjectAdd(&netprops, "s:vhostfd", vhostfd[0], NULL) < 0)
-                    return NULL;
-            } else {
-                g_auto(virBuffer) fdsbuf = VIR_BUFFER_INITIALIZER;
-
-                for (i = 0; i < vhostfdSize; i++)
-                    virBufferAsprintf(&fdsbuf, "%s:", vhostfd[i]);
-
-                virBufferTrim(&fdsbuf, ":");
-
-                if (virJSONValueObjectAdd(&netprops,
-                                          "s:vhostfds", virBufferCurrentContent(&fdsbuf),
-                                          NULL) < 0)
-                    return NULL;
-            }
-        }
-
-        if (net->tune.sndbuf_specified &&
-            virJSONValueObjectAppendNumberUlong(netprops, "sndbuf", net->tune.sndbuf) < 0)
-            return NULL;
-    }
-
     return g_steal_pointer(&netprops);
 }
 
index 8722f27207a00dcec10642f5810c147bd381a24f..5909d60490e5e0a8bf7363ba64f9fb4ba91931e1 100644 (file)
@@ -29,6 +29,6 @@ QEMU_AUDIO_DRV=none \
 -usb \
 -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
 -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
--netdev tap,fd=3,id=hostnet0,vhost=on,vhostfd=44 \
+-netdev tap,fd=3,vhost=on,vhostfd=44,id=hostnet0 \
 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=fe:11:22:33:44:55,bus=pci.0,addr=0x2 \
 -msg timestamp=on
index f88ebbf11da142eecf13a086b97799df78c61363..c80be4b439bb0199d17466c7b4c13ae57e264c74 100644 (file)
@@ -47,7 +47,7 @@ QEMU_AUDIO_DRV=none \
 -drive file=/home/zippy/tmp/install-amd64-minimal-20140619.iso,format=raw,if=none,id=drive-ua-WhatAnAwesomeCDROM,readonly=on,cache=none \
 -device ide-cd,bus=ide.1,unit=0,drive=drive-ua-WhatAnAwesomeCDROM,id=ua-WhatAnAwesomeCDROM,bootindex=2 \
 -global isa-fdc.driveA=drive-ua-myDisk1 \
--netdev tap,fd=3,id=hostua-CheckoutThisNIC,vhost=on,vhostfd=44 \
+-netdev tap,fd=3,vhost=on,vhostfd=44,id=hostua-CheckoutThisNIC \
 -device virtio-net-pci,netdev=hostua-CheckoutThisNIC,id=ua-CheckoutThisNIC,mac=52:54:00:d6:c0:0b,bus=pci.0,addr=0x3 \
 -netdev socket,listen=127.0.0.1:1234,id=hostua-WeCanAlsoDoServerMode \
 -device rtl8139,netdev=hostua-WeCanAlsoDoServerMode,id=ua-WeCanAlsoDoServerMode,mac=52:54:00:22:c9:42,bus=pci.0,addr=0x9 \