From: Ján Tomko Date: Fri, 1 Jul 2016 12:20:44 +0000 (+0200) Subject: Allow omitting USB port X-Git-Tag: v2.1.0-rc1~142 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f903643186d0a59c4590fc8a6e8d9493c4d3d6b;p=thirdparty%2Flibvirt.git Allow omitting USB port We were requiring a USB port path in the schema, but not enforcing it. Omitting the USB port would lead to libvirt formatting it as (null). Such domain cannot be started and will disappear after libvirtd restart (since it cannot parse back the XML). Only format the port if it has been specified and mark it as optional in the XML schema. --- diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 348dbfe6b1..741f2689f3 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4068,9 +4068,11 @@ - - - + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 13a059e21d..44d9857941 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4839,9 +4839,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf, break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB: - virBufferAsprintf(buf, " bus='%d' port='%s'", - info->addr.usb.bus, - info->addr.usb.port); + virBufferAsprintf(buf, " bus='%d'", info->addr.usb.bus); + virBufferEscapeString(buf, " port='%s'", info->addr.usb.port); break; case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO: diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index fe4bb88f9f..7a3ee81514 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -375,7 +375,8 @@ qemuBuildDeviceAddressStr(virBufferPtr buf, VIR_DOMAIN_CONTROLLER_TYPE_USB, info->addr.usb.bus))) goto cleanup; - virBufferAsprintf(buf, ",bus=%s.0,port=%s", contAlias, info->addr.usb.port); + virBufferAsprintf(buf, ",bus=%s.0", contAlias); + virBufferEscapeString(buf, ",port=%s", info->addr.usb.port); } else if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO) { if (info->addr.spaprvio.has_reg) virBufferAsprintf(buf, ",reg=0x%llx", info->addr.spaprvio.reg); diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args new file mode 100644 index 0000000000..3b9d9dfcd1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.args @@ -0,0 +1,26 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1 \ +-S \ +-M pc \ +-m 214 \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefconfig \ +-nodefaults \ +-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\ +server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=readline \ +-no-acpi \ +-boot c \ +-usb \ +-device usb-hub,id=hub0,bus=usb.0 \ +-device usb-hub,id=hub1,bus=usb.0 \ +-device usb-mouse,id=input0,bus=usb.0 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml new file mode 100644 index 0000000000..593fcd1e0e --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-port-missing.xml @@ -0,0 +1,25 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + /usr/bin/qemu + + + +
+ + +
+ + +
+ + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index e0d07e80a6..8abc4b050b 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1163,6 +1163,9 @@ mymain(void) DO_TEST("usb-hub", QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB, QEMU_CAPS_NODEFCONFIG); + DO_TEST("usb-port-missing", + QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB, + QEMU_CAPS_NODEFCONFIG); DO_TEST("usb-ports", QEMU_CAPS_CHARDEV, QEMU_CAPS_USB_HUB, QEMU_CAPS_NODEFCONFIG); diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml new file mode 100644 index 0000000000..2e29cbdb19 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-usb-port-missing.xml @@ -0,0 +1,36 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + +
+ + + +
+ + + + +
+ + +
+ + +
+ + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 86408bf9fa..8a184d271f 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -591,6 +591,7 @@ mymain(void) DO_TEST("interface-server"); DO_TEST("virtio-lun"); + DO_TEST("usb-port-missing"); DO_TEST("usb-redir"); DO_TEST("usb-redir-filter"); DO_TEST("usb-redir-filter-version");