1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

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
This commit is contained in:
Daniel P. Berrange 2010-01-29 18:07:04 +00:00
parent d8acc44672
commit 49a0f6cd99
6 changed files with 71 additions and 9 deletions

View File

@ -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)))

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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>

View File

@ -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);