[libvirt] [PATCH 08/13] Remove use of -netdev arg with QEMU

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The QEMU 0.12.x tree has the -netdev command line argument, but not
corresponding monitor command. We can't enable the former, without
the latter since it will break hotplug/unplug.

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Disable -netdev usage
  until 0.13 at earliest
* tests/qemuxml2argvtest.c: Add test for -netdev syntax
* tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.args,
  tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.xml: Test
  data files for -netdev syntax
---
 src/qemu/qemu_conf.c                               |   46 +++++++++++++++++---
 src/qemu/qemu_conf.h                               |    4 +-
 .../qemuxml2argv-net-virtio-device.args            |    2 +-
 .../qemuxml2argv-net-virtio-netdev.args            |    1 +
 .../qemuxml2argv-net-virtio-netdev.xml             |   26 +++++++++++
 tests/qemuxml2argvtest.c                           |    1 +
 6 files changed, 71 insertions(+), 9 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.xml

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index a70848c..c998fe2 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1154,6 +1154,17 @@ static unsigned int qemudComputeCmdFlags(const char *help,
         flags |= QEMUD_CMD_FLAG_BALLOON;
     if (strstr(help, "-device"))
         flags |= QEMUD_CMD_FLAG_DEVICE;
+    /* Keep disabled till we're actually ready to turn on netdev mode
+     * The plan is todo it in 0.13.0 QEMU, but lets wait & see... */
+#if 0
+    if (strstr(help, "-netdev")) {
+        /* Disable -netdev on 0.12 since although it exists,
+         * the corresponding netdev_add/remove monitor commands
+         * do not, and we need them to be able todo hotplug */
+        if (version >= 13000)
+            flags |= QEMUD_CMD_FLAG_NETDEV;
+    }
+#endif
     if (strstr(help, "-sdl"))
         flags |= QEMUD_CMD_FLAG_SDL;
     if (strstr(help, "cores=") &&
@@ -2379,7 +2390,7 @@ qemuBuildNicStr(virConnectPtr conn,
 
 
 char *
-qemuBuildNicDevStr(virDomainNetDefPtr net)
+qemuBuildNicDevStr(virDomainNetDefPtr net, int qemuCmdFlags)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     const char *nic;
@@ -2392,7 +2403,11 @@ qemuBuildNicDevStr(virDomainNetDefPtr net)
         nic = net->model;
     }
 
-    virBufferVSprintf(&buf, "%s,netdev=%s", nic, net->hostnet_name);
+    virBufferAdd(&buf, nic, strlen(nic));
+    if (qemuCmdFlags & QEMUD_CMD_FLAG_NETDEV)
+        virBufferVSprintf(&buf, ",netdev=%s", net->hostnet_name);
+    else
+        virBufferVSprintf(&buf, ",vlan=%d", net->vlan);
     virBufferVSprintf(&buf, ",id=%s", net->info.alias);
     virBufferVSprintf(&buf, ",mac=%02x:%02x:%02x:%02x:%02x:%02x",
                       net->mac[0], net->mac[1],
@@ -3620,7 +3635,12 @@ int qemudBuildCommandLine(virConnectPtr conn,
             char *nic, *host;
             char tapfd_name[50];
 
-            net->vlan = i;
+            /* VLANs are not used with -netdev, so don't record them */
+            if ((qemuCmdFlags & QEMUD_CMD_FLAG_NETDEV) &&
+                (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE))
+                net->vlan = -1;
+            else
+                net->vlan = i;
 
             if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
                 net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
@@ -3645,14 +3665,24 @@ int qemudBuildCommandLine(virConnectPtr conn,
                     goto no_memory;
             }
 
-            if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) {
+            /* Possible combinations:
+             *
+             *  1. Old way:   -net nic,model=e1000,vlan=1 -net tap,vlan=1
+             *  2. Semi-new:  -device e1000,vlan=1        -net tap,vlan=1
+             *  3. Best way:  -netdev type=tap,id=netdev1 -device e1000,id=netdev1
+             *
+             * NB, no support for -netdev without use of -device
+             */
+            if ((qemuCmdFlags & QEMUD_CMD_FLAG_NETDEV) &&
+                (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE)) {
                 ADD_ARG_LIT("-netdev");
                 if (!(host = qemuBuildNetDevStr(conn, net, tapfd_name)))
                     goto error;
                 ADD_ARG(host);
-
+            }
+            if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) {
                 ADD_ARG_LIT("-device");
-                if (!(nic = qemuBuildNicDevStr(net)))
+                if (!(nic = qemuBuildNicDevStr(net, qemuCmdFlags)))
                     goto error;
                 ADD_ARG(nic);
             } else {
@@ -3660,7 +3690,9 @@ int qemudBuildCommandLine(virConnectPtr conn,
                 if (!(nic = qemuBuildNicStr(conn, net, "nic,", net->vlan)))
                     goto error;
                 ADD_ARG(nic);
-
+            }
+            if (!((qemuCmdFlags & QEMUD_CMD_FLAG_NETDEV) &&
+                  (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE))) {
                 ADD_ARG_LIT("-net");
                 if (!(host = qemuBuildHostNetStr(conn, net, ',',
                                                  net->vlan, tapfd_name)))
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index b94153f..3787e28 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -81,6 +81,7 @@ enum qemud_cmd_flags {
     QEMUD_CMD_FLAG_DEVICE        = (1 << 26), /* Is the new -device arg available */
     QEMUD_CMD_FLAG_SDL           = (1 << 27), /* Is the new -sdl arg available */
     QEMUD_CMD_FLAG_SMP_TOPOLOGY  = (1 << 28), /* Is sockets=s,cores=c,threads=t available for -smp? */
+    QEMUD_CMD_FLAG_NETDEV        = (1 << 29), /* The -netdev flag & netdev_add/remove monitor commands */
 };
 
 /* Main driver state */
@@ -210,7 +211,8 @@ char * qemuBuildNicStr(virConnectPtr conn,
                        int vlan);
 
 /* Current, best practice */
-char * qemuBuildNicDevStr(virDomainNetDefPtr net);
+char * qemuBuildNicDevStr(virDomainNetDefPtr net,
+                          int qemuCmdFlags);
 
 /* Both legacy & current support support */
 char *qemuBuildDriveStr(virDomainDiskDefPtr disk,
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-device.args b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-device.args
index 698ad3a..32d2843 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-device.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-device.args
@@ -1 +1 @@
-LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefaults -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -netdev user,id=netdev0 -device virtio-net-pci,netdev=netdev0,id=virtio-nic0,mac=00:11:22:33:44:55,bus=pci.0,addr=0x4 -usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefaults -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -device virtio-net-pci,vlan=0,id=virtio-nic0,mac=00:11:22:33:44:55,bus=pci.0,addr=0x4 -net user,vlan=0,name=netdev0 -usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.args b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.args
new file mode 100644
index 0000000..698ad3a
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.args
@@ -0,0 +1 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefaults -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -netdev user,id=netdev0 -device virtio-net-pci,netdev=netdev0,id=virtio-nic0,mac=00:11:22:33:44:55,bus=pci.0,addr=0x4 -usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.xml
new file mode 100644
index 0000000..5d34bd4
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.xml
@@ -0,0 +1,26 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219200</memory>
+  <currentMemory>219200</currentMemory>
+  <vcpu>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+    </disk>
+    <interface type='user'>
+      <mac address='00:11:22:33:44:55'/>
+      <model type='virtio'/>
+    </interface>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 90c1cb0..67dc47e 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -280,6 +280,7 @@ mymain(int argc, char **argv)
     DO_TEST("net-user", 0);
     DO_TEST("net-virtio", 0);
     DO_TEST("net-virtio-device", QEMUD_CMD_FLAG_DEVICE);
+    DO_TEST("net-virtio-netdev", QEMUD_CMD_FLAG_DEVICE | QEMUD_CMD_FLAG_NETDEV);
     DO_TEST("net-eth", 0);
     DO_TEST("net-eth-ifname", 0);
     DO_TEST("net-eth-names", QEMUD_CMD_FLAG_NET_NAME);
-- 
1.6.5.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]