From 49a0f6cd999232491138423e50707c9aff7f0db0 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 29 Jan 2010 18:07:04 +0000 Subject: [PATCH] Remove use of -netdev arg with QEMU 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 397e93280b..60471f0a5d 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=") && @@ -2380,7 +2391,7 @@ qemuBuildNicStr(virConnectPtr conn, char * -qemuBuildNicDevStr(virDomainNetDefPtr net) +qemuBuildNicDevStr(virDomainNetDefPtr net, int qemuCmdFlags) { virBuffer buf = VIR_BUFFER_INITIALIZER; const char *nic; @@ -2393,7 +2404,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], @@ -3621,7 +3636,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) { @@ -3646,14 +3666,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 { @@ -3661,7 +3691,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 66c17d7e8f..af732ce6c5 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 */ char *qemuBuildDriveStr(virDomainDiskDefPtr disk, diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-device.args b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-device.args index 698ad3aa20..32d28435ff 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 0000000000..698ad3aa20 --- /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 0000000000..5d34bd492c --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.xml @@ -0,0 +1,26 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 90c1cb06b8..67dc47e279 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);