https://bugzilla.redhat.com/show_bug.cgi?id=1366505 So far, this function lacked support for VIR_DOMAIN_NET_TYPE_VHOSTUSER leaving callers to hack around the problem by constructing the command line on their own. This is not ideal as it blocks hot plug support. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/qemu/qemu_command.c | 43 +++++++++++++--------- .../qemuxml2argv-net-vhostuser-multiq.args | 6 +-- .../qemuxml2argv-net-vhostuser.args | 4 +- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 34594b3..e3dc34a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3670,7 +3670,13 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, return NULL; case VIR_DOMAIN_NET_TYPE_VHOSTUSER: - /* Unsupported yet. */ + virBufferAsprintf(&buf, "vhost-user%cchardev=char%s", + type_sep, + net->info.alias); + type_sep = ','; + if (net->driver.virtio.queues > 1) + virBufferAsprintf(&buf, ",queues=%u", + net->driver.virtio.queues); break; case VIR_DOMAIN_NET_TYPE_LAST: @@ -7854,14 +7860,15 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg, } static int -qemuBuildVhostuserCommandLine(virCommandPtr cmd, +qemuBuildVhostuserCommandLine(virQEMUDriverPtr driver, + virCommandPtr cmd, virDomainDefPtr def, virDomainNetDefPtr net, virQEMUCapsPtr qemuCaps, unsigned int bootindex) { char *chardev = NULL; - virBuffer netdev_buf = VIR_BUFFER_INITIALIZER; + char *netdev = NULL; unsigned int queues = net->driver.virtio.queues; char *nic = NULL; @@ -7898,25 +7905,27 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd, goto error; } - virBufferAsprintf(&netdev_buf, "vhost-user,id=host%s,chardev=char%s", - net->info.alias, net->info.alias); - - if (queues > 1) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VHOSTUSER_MULTIQUEUE)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("multi-queue is not supported for vhost-user " - "with this QEMU binary")); - goto error; - } - virBufferAsprintf(&netdev_buf, ",queues=%u", queues); + if (queues > 1 && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VHOSTUSER_MULTIQUEUE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("multi-queue is not supported for vhost-user " + "with this QEMU binary")); + goto error; } + if (!(netdev = qemuBuildHostNetStr(net, driver, + ',', -1, + NULL, 0, NULL, 0))) + goto error; + + virCommandAddArg(cmd, "-chardev"); virCommandAddArg(cmd, chardev); VIR_FREE(chardev); virCommandAddArg(cmd, "-netdev"); - virCommandAddArgBuffer(cmd, &netdev_buf); + virCommandAddArg(cmd, netdev); + VIR_FREE(netdev); if (!(nic = qemuBuildNicDevStr(def, net, -1, bootindex, queues, qemuCaps))) { @@ -7931,8 +7940,8 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd, return 0; error: + VIR_FREE(netdev); VIR_FREE(chardev); - virBufferFreeAndReset(&netdev_buf); VIR_FREE(nic); return -1; @@ -7969,7 +7978,7 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd, bootindex = net->info.bootIndex; if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER) - return qemuBuildVhostuserCommandLine(cmd, def, net, qemuCaps, bootindex); + return qemuBuildVhostuserCommandLine(driver, cmd, def, net, qemuCaps, bootindex); if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) { /* NET_TYPE_HOSTDEV devices are really hostdev devices, so diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser-multiq.args b/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser-multiq.args index 4360e5e..59929c1 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser-multiq.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser-multiq.args @@ -20,17 +20,17 @@ QEMU_AUDIO_DRV=none \ -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ -chardev socket,id=charnet0,path=/tmp/vhost0.sock,server \ --netdev vhost-user,id=hostnet0,chardev=charnet0 \ +-netdev vhost-user,chardev=charnet0,id=hostnet0 \ -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:ee:96:6b,bus=pci.0,\ addr=0x3 \ -chardev socket,id=charnet1,path=/tmp/vhost1.sock \ --netdev vhost-user,id=hostnet1,chardev=charnet1 \ +-netdev vhost-user,chardev=charnet1,id=hostnet1 \ -device virtio-net-pci,netdev=hostnet1,id=net1,mac=52:54:00:ee:96:6c,bus=pci.0,\ addr=0x4 \ -netdev socket,listen=:2015,id=hostnet2 \ -device rtl8139,netdev=hostnet2,id=net2,mac=52:54:00:95:db:c0,bus=pci.0,\ addr=0x5 \ -chardev socket,id=charnet3,path=/tmp/vhost2.sock \ --netdev vhost-user,id=hostnet3,chardev=charnet3,queues=4 \ +-netdev vhost-user,chardev=charnet3,queues=4,id=hostnet3 \ -device virtio-net-pci,mq=on,vectors=10,netdev=hostnet3,id=net3,\ mac=52:54:00:ee:96:6d,bus=pci.0,addr=0x6 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser.args b/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser.args index 47c1d84..e15d735 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser.args @@ -20,11 +20,11 @@ QEMU_AUDIO_DRV=none \ -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ -chardev socket,id=charnet0,path=/tmp/vhost0.sock,server \ --netdev vhost-user,id=hostnet0,chardev=charnet0 \ +-netdev vhost-user,chardev=charnet0,id=hostnet0 \ -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:ee:96:6b,bus=pci.0,\ addr=0x3 \ -chardev socket,id=charnet1,path=/tmp/vhost1.sock \ --netdev vhost-user,id=hostnet1,chardev=charnet1 \ +-netdev vhost-user,chardev=charnet1,id=hostnet1 \ -device virtio-net-pci,netdev=hostnet1,id=net1,mac=52:54:00:ee:96:6c,bus=pci.0,\ addr=0x4 \ -netdev socket,listen=:2015,id=hostnet2 \ -- 2.8.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list