[libvirt] [PATCHv3 0/3] Add usb controller model="none"

This series adds support for completely disabling USB bus for a host if a user requires this. For this to work a new USB controller model "none" was added that removes the USB bus. This series incorporates fixes for comments of Dan's and Eric's review and is rebased on top of Dan's error handling cleanup. Peter Krempa (3): domain_conf: Add USB controler model "none" domain_conf: Add helpers to verify if device configuration is valid qemu: Add support for "none" USB controller docs/formatdomain.html.in | 6 +- docs/schemas/domaincommon.rng | 1 + src/conf/domain_conf.c | 107 +++++++++++++++++++- src/conf/domain_conf.h | 4 + src/libvirt_private.syms | 1 + src/qemu/qemu_command.c | 10 ++- src/qemu/qemu_driver.c | 6 + .../qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml | 19 ++++ .../qemuxml2argv-usb-none-other.xml | 19 ++++ .../qemuxml2argv-usb-none-usbtablet.xml | 21 ++++ tests/qemuxml2argvdata/qemuxml2argv-usb-none.args | 5 + tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml | 16 +++ tests/qemuxml2argvtest.c | 10 ++ 13 files changed, 221 insertions(+), 4 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none-other.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none-usbtablet.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml -- 1.7.8.6

Libvirt adds a USB controller to the guest even if the user does not specify any in the XML. This is due to back-compat reasons. To allow disabling USB for a guest this patch adds a new USB controller type "none" that disables USB support for the guest. --- Diff to v2: - added docs to formatdomain.hmtl - changed error reporting functions to global ones --- docs/formatdomain.html.in | 6 +++- docs/schemas/domaincommon.rng | 1 + src/conf/domain_conf.c | 55 ++++++++++++++++++++++++++++++++++++++++- src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 3 +- 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index b8db76e..d898eaf 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1839,8 +1839,10 @@ A "usb" controller has an optional attribute <code>model</code>, which is one of "piix3-uhci", "piix4-uhci", "ehci", "ich9-ehci1", "ich9-uhci1", "ich9-uhci2", "ich9-uhci3", - "vt82c686b-uhci", "pci-ohci" or "nec-xhci". The PowerPC64 - "spapr-vio" addresses do not have an associated controller. + "vt82c686b-uhci", "pci-ohci" or "nec-xhci". Additionally, + <span class="since">since 0.9.14</span>, if the USB bus needs to be + explicitly disabled for the guest, <code>model='none'</code> may be used. + The PowerPC64 "spapr-vio" addresses do not have an associated controller. </p> <p> diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index b7562ad..c85d763 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1222,6 +1222,7 @@ <value>vt82c686b-uhci</value> <value>pci-ohci</value> <value>nec-xhci</value> + <value>none</value> </choice> </attribute> </optional> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c53722a..cf3b1c4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -258,7 +258,8 @@ VIR_ENUM_IMPL(virDomainControllerModelUSB, VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST, "ich9-uhci3", "vt82c686b-uhci", "pci-ohci", - "nec-xhci") + "nec-xhci", + "none") VIR_ENUM_IMPL(virDomainFS, VIR_DOMAIN_FS_TYPE_LAST, "mount", @@ -7917,6 +7918,8 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, virBitmapPtr bootMap = NULL; unsigned long bootMapSize = 0; xmlNodePtr cur; + bool usb_none = false; + bool usb_other = false; if (VIR_ALLOC(def) < 0) { virReportOOMError(); @@ -8642,6 +8645,27 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (!controller) goto error; + /* sanitize handling of "none" usb controller */ + if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) { + if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) { + if (usb_other || usb_none) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("Can't add another USB controller: " + "USB is disabled for this domain")); + goto error; + } + usb_none = true; + } else { + if (usb_none) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("Can't add another USB controller: " + "USB is disabled for this domain")); + goto error; + } + usb_other = true; + } + } + virDomainControllerInsertPreAlloced(def, controller); } VIR_FREE(nodes); @@ -8916,6 +8940,13 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (!input) goto error; + /* Check if USB bus is required */ + if (input->bus == VIR_DOMAIN_INPUT_BUS_USB && usb_none) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Can't add USB input device. " + "USB bus is disabled")); + goto error; + } /* With QEMU / KVM / Xen graphics, mouse + PS/2 is implicit * with graphics, so don't store it. @@ -9043,6 +9074,14 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (!hostdev) goto error; + if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && + usb_none) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Can't add USB device passthrough: " + "USB is disabled in this host")); + goto error; + } + def->hostdevs[def->nhostdevs++] = hostdev; } VIR_FREE(nodes); @@ -9112,6 +9151,13 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (!hub) goto error; + if (hub->type == VIR_DOMAIN_HUB_TYPE_USB && usb_none) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Can't add USB hub: " + "USB is disabled for this domain")); + goto error; + } + def->hubs[def->nhubs++] = hub; } VIR_FREE(nodes); @@ -9128,6 +9174,13 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (!redirdev) goto error; + if (redirdev->bus == VIR_DOMAIN_REDIRDEV_BUS_USB && usb_none) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Can't add USB redir device: " + "USB is disabled for this domain")); + goto error; + } + def->redirdevs[def->nredirdevs++] = redirdev; } VIR_FREE(nodes); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 469d3b6..203eebf 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -633,6 +633,7 @@ enum virDomainControllerModelUSB { VIR_DOMAIN_CONTROLLER_MODEL_USB_VT82C686B_UHCI, VIR_DOMAIN_CONTROLLER_MODEL_USB_PCI_OHCI, VIR_DOMAIN_CONTROLLER_MODEL_USB_NEC_XHCI, + VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE, VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST }; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index edd1840..7127e70 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -107,7 +107,8 @@ VIR_ENUM_IMPL(qemuControllerModelUSB, VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST, "ich9-usb-uhci3", "vt82c686b-usb-uhci", "pci-ohci", - "nec-usb-xhci"); + "nec-usb-xhci", + "none"); VIR_ENUM_DECL(qemuDomainFSDriver) VIR_ENUM_IMPL(qemuDomainFSDriver, VIR_DOMAIN_FS_DRIVER_TYPE_LAST, -- 1.7.8.6

On Mon, Jul 23, 2012 at 14:19:13 +0200, Peter Krempa wrote:
Libvirt adds a USB controller to the guest even if the user does not specify any in the XML. This is due to back-compat reasons.
To allow disabling USB for a guest this patch adds a new USB controller type "none" that disables USB support for the guest. --- Diff to v2: - added docs to formatdomain.hmtl - changed error reporting functions to global ones --- docs/formatdomain.html.in | 6 +++- docs/schemas/domaincommon.rng | 1 + src/conf/domain_conf.c | 55 ++++++++++++++++++++++++++++++++++++++++- src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 3 +- 5 files changed, 62 insertions(+), 4 deletions(-)
...
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c53722a..cf3b1c4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c ... @@ -9043,6 +9074,14 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (!hostdev) goto error;
+ if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && + usb_none) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Can't add USB device passthrough: "
I think "Can't add host USB device" would better fit the name of the element.
+ "USB is disabled in this host")); + goto error; + } + def->hostdevs[def->nhostdevs++] = hostdev; } VIR_FREE(nodes); ... @@ -9128,6 +9174,13 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (!redirdev) goto error;
+ if (redirdev->bus == VIR_DOMAIN_REDIRDEV_BUS_USB && usb_none) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Can't add USB redir device: "
"Can't add redirected USB device" seems better to me.
+ "USB is disabled for this domain")); + goto error; + } + def->redirdevs[def->nredirdevs++] = redirdev; } VIR_FREE(nodes); ...
ACK Jirka

On 08/02/12 11:00, Jiri Denemark wrote:
On Mon, Jul 23, 2012 at 14:19:13 +0200, Peter Krempa wrote:
Libvirt adds a USB controller to the guest even if the user does not specify any in the XML. This is due to back-compat reasons.
To allow disabling USB for a guest this patch adds a new USB controller type "none" that disables USB support for the guest. --- Diff to v2: - added docs to formatdomain.hmtl - changed error reporting functions to global ones --- docs/formatdomain.html.in | 6 +++- docs/schemas/domaincommon.rng | 1 + src/conf/domain_conf.c | 55 ++++++++++++++++++++++++++++++++++++++++- src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 3 +- 5 files changed, 62 insertions(+), 4 deletions(-)
...
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c53722a..cf3b1c4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c ... @@ -9043,6 +9074,14 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (!hostdev) goto error;
+ if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && + usb_none) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Can't add USB device passthrough: "
I think "Can't add host USB device" would better fit the name of the element.
Yep, those are indeed better than my try.
+ "USB is disabled in this host")); + goto error; + } + def->hostdevs[def->nhostdevs++] = hostdev; } VIR_FREE(nodes); ... @@ -9128,6 +9174,13 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps, if (!redirdev) goto error;
+ if (redirdev->bus == VIR_DOMAIN_REDIRDEV_BUS_USB && usb_none) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Can't add USB redir device: "
"Can't add redirected USB device" seems better to me.
+ "USB is disabled for this domain")); + goto error; + } + def->redirdevs[def->nredirdevs++] = redirdev; } VIR_FREE(nodes); ...
ACK
Jirka
I changed the error messages to those you suggested and changed the version statement docs/formatdomain.html.in to 0.10.0 and pushed with the rest of the series. Thanks for the review! Peter

This patch adds helpers that validate domain's device configuration. This will be needed later on to verify devices being hot-plugged to guests. If the guest has no USB bus, then it's not valid to plug a USB device to that guest. --- Diff to v2: - split out USB device checking to a separate function - made virDomainDefHasUSB static as it's not used outside of domain_conf.c --- src/conf/domain_conf.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 3 ++ src/libvirt_private.syms | 1 + 3 files changed, 56 insertions(+), 0 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index cf3b1c4..b980e60 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13265,6 +13265,58 @@ error: return NULL; } +static bool +virDomainDefHasUSB(virDomainDefPtr def) +{ + int i; + + for (i = 0; i < def->ncontrollers; i++) { + if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_USB && + def->controllers[i]->model != VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) + return true; + } + + return false; +} + +static bool +virDomainDeviceIsUSB(virDomainDeviceDefPtr dev) +{ + int t = dev->type; + if ((t == VIR_DOMAIN_DEVICE_DISK && + dev->data.disk->bus == VIR_DOMAIN_DISK_BUS_USB) || + (t == VIR_DOMAIN_DEVICE_CONTROLLER && + dev->data.controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) || + (t == VIR_DOMAIN_DEVICE_INPUT && + dev->data.input->type == VIR_DOMAIN_INPUT_BUS_USB) || + (t == VIR_DOMAIN_DEVICE_HOSTDEV && + dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + dev->data.hostdev->source.subsys.type == + VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) || + (t == VIR_DOMAIN_DEVICE_HUB && + dev->data.hub->type == VIR_DOMAIN_HUB_TYPE_USB) || + (t == VIR_DOMAIN_DEVICE_REDIRDEV && + dev->data.redirdev->bus == VIR_DOMAIN_REDIRDEV_BUS_USB)) + return true; + + return false; +} + +int +virDomainDefCompatibleDevice(virDomainDefPtr def, + virDomainDeviceDefPtr dev) +{ + if (!virDomainDefHasUSB(def) && + virDomainDeviceIsUSB(dev)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Device configuration is not compatible: " + "Domain has no USB bus support")); + return -1; + } + + return 0; +} + int virDomainSaveXML(const char *configDir, virDomainDefPtr def, const char *xml) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 203eebf..1c2b76b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1971,6 +1971,9 @@ int virDomainDefFormatInternal(virDomainDefPtr def, unsigned int flags, virBufferPtr buf); +int virDomainDefCompatibleDevice(virDomainDefPtr def, + virDomainDeviceDefPtr dev); + int virDomainCpuSetParse(const char *str, char sep, char *cpuset, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 734c881..24a36b9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -281,6 +281,7 @@ virDomainDefAddImplicitControllers; virDomainDefCheckABIStability; virDomainDefClearDeviceAliases; virDomainDefClearPCIAddresses; +virDomainDefCompatibleDevice; virDomainDefFormat; virDomainDefFormatInternal; virDomainDefFree; -- 1.7.8.6

On Mon, Jul 23, 2012 at 14:19:14 +0200, Peter Krempa wrote:
This patch adds helpers that validate domain's device configuration. This will be needed later on to verify devices being hot-plugged to guests. If the guest has no USB bus, then it's not valid to plug a USB device to that guest. --- Diff to v2: - split out USB device checking to a separate function - made virDomainDefHasUSB static as it's not used outside of domain_conf.c --- src/conf/domain_conf.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 3 ++ src/libvirt_private.syms | 1 + 3 files changed, 56 insertions(+), 0 deletions(-)
ACK Jirka

This patch enables the "none" USB controller for qemu guests and adds valdiation on hot-plugged devices if the guest has USB disabled. This patch also adds a set of tests to check parsing of domain XMLs that use the "none" controller and some forbidden situations concerning it. --- Diff to v2: - tests squashed in directly --- src/qemu/qemu_command.c | 7 ++++++ src/qemu/qemu_driver.c | 6 +++++ .../qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml | 19 ++++++++++++++++++ .../qemuxml2argv-usb-none-other.xml | 19 ++++++++++++++++++ .../qemuxml2argv-usb-none-usbtablet.xml | 21 ++++++++++++++++++++ tests/qemuxml2argvdata/qemuxml2argv-usb-none.args | 5 ++++ tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml | 16 +++++++++++++++ tests/qemuxml2argvtest.c | 10 +++++++++ 8 files changed, 103 insertions(+), 0 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none-other.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none-usbtablet.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 7127e70..5164f49 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4787,6 +4787,13 @@ qemuBuildCommandLine(virConnectPtr conn, cont->type == VIR_DOMAIN_CONTROLLER_TYPE_FDC) continue; + /* Also, skip USB controllers with type none.*/ + if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_USB && + cont->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) { + usbcontroller = -1; /* mark we don't want a controller */ + continue; + } + /* Only recent QEMU implements a SATA (AHCI) controller */ if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_SATA) { if (!qemuCapsGet(qemuCaps, QEMU_CAPS_ICH9_AHCI)) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f3ff5b2..18b6ebd 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5833,6 +5833,9 @@ qemuDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, } if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + if (virDomainDefCompatibleDevice(vmdef, dev) < 0) + goto endjob; + /* Make a copy for updated domain. */ vmdef = virDomainObjCopyPersistentDef(driver->caps, vm); if (!vmdef) @@ -5858,6 +5861,9 @@ qemuDomainModifyDeviceFlags(virDomainPtr dom, const char *xml, } if (flags & VIR_DOMAIN_AFFECT_LIVE) { + if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0) + goto endjob; + switch (action) { case QEMU_DEVICE_ATTACH: ret = qemuDomainAttachDeviceLive(vm, dev_copy, dom); diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml new file mode 100644 index 0000000..9eeb953 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml @@ -0,0 +1,19 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <devices> + <emulator>/usr/bin/qemu</emulator> + <controller type='usb' model='none' index='0'/> + <memballoon model='virtio'/> + <hub type='usb'> + <address type='usb' bus='0' port='1'/> + </hub> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-none-other.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-none-other.xml new file mode 100644 index 0000000..64bbba6 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-none-other.xml @@ -0,0 +1,19 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <devices> + <emulator>/usr/bin/qemu</emulator> + <controller type='usb' index='0' model='none'/> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-none-usbtablet.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-none-usbtablet.xml new file mode 100644 index 0000000..9d53cc0 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-none-usbtablet.xml @@ -0,0 +1,21 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>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> + <controller type='usb' model='none' index='0'/> + <input type='tablet' bus='usb'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-none.args b/tests/qemuxml2argvdata/qemuxml2argv-usb-none.args new file mode 100644 index 0000000..085b66f --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-none.args @@ -0,0 +1,5 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S \ +-M pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults \ +-chardev socket,id=charmonitor,path=/tmp/test-monitor,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=readline -no-acpi -boot c \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml b/tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml new file mode 100644 index 0000000..69ace41 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml @@ -0,0 +1,16 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <devices> + <emulator>/usr/bin/qemu</emulator> + <controller type='usb' index='0' model='none'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index c4aa7c4..39fcd9f 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -683,6 +683,16 @@ mymain(void) QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_PCI_MULTIFUNCTION, QEMU_CAPS_PIIX3_USB_UHCI, QEMU_CAPS_USB_HUB, QEMU_CAPS_ICH9_USB_EHCI1); + DO_TEST("usb-none", + QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST_PARSE_ERROR("usb-none-other", + QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST_PARSE_ERROR("usb-none-hub", + QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG, + QEMU_CAPS_USB_HUB); + DO_TEST_PARSE_ERROR("usb-none-usbtablet", + QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST("smbios", QEMU_CAPS_SMBIOS_TYPE); -- 1.7.8.6

On Mon, Jul 23, 2012 at 14:19:15 +0200, Peter Krempa wrote:
This patch enables the "none" USB controller for qemu guests and adds valdiation on hot-plugged devices if the guest has USB disabled.
This patch also adds a set of tests to check parsing of domain XMLs that use the "none" controller and some forbidden situations concerning it. --- Diff to v2: - tests squashed in directly --- src/qemu/qemu_command.c | 7 ++++++ src/qemu/qemu_driver.c | 6 +++++ .../qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml | 19 ++++++++++++++++++ .../qemuxml2argv-usb-none-other.xml | 19 ++++++++++++++++++ .../qemuxml2argv-usb-none-usbtablet.xml | 21 ++++++++++++++++++++ tests/qemuxml2argvdata/qemuxml2argv-usb-none.args | 5 ++++ tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml | 16 +++++++++++++++ tests/qemuxml2argvtest.c | 10 +++++++++ 8 files changed, 103 insertions(+), 0 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none-hub.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none-other.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none-usbtablet.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-usb-none.xml
ACK Jirka

On 07/23/12 14:19, Peter Krempa wrote:
This series adds support for completely disabling USB bus for a host if a user requires this. For this to work a new USB controller model "none" was added that removes the USB bus.
This series incorporates fixes for comments of Dan's and Eric's review and is rebased on top of Dan's error handling cleanup.
Peter Krempa (3): domain_conf: Add USB controler model "none" domain_conf: Add helpers to verify if device configuration is valid qemu: Add support for "none" USB controller
Ping?
participants (2)
-
Jiri Denemark
-
Peter Krempa