QEMU offers two attributes for handling reset requests of an USB host device: guest-reset and guest-resets-all. When combined they act as follows: 1) guest-reset=false The guest is not allowed to reset the physical USB device. 2) guest-reset=true,guest-resets-all=false The guest is allowed to reset the device when it is not yet initialized (aka no USB bus address assigned). Usually this results in one guest reset being allowed. This is the default behavior. 3) guest-reset=true,guest-resets-all=true The guest is allowed to reset the device as it pleases. Now, there's a clear 1:1 mapping with our representation of guestReset, so generating cmd line is trivial. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/qemu/qemu_command.c | 21 +++++++++++++++++++ .../hostdev-usb-address.x86_64-latest.args | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b307d3139c..262fffe5fe 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5001,6 +5001,8 @@ qemuBuildUSBHostdevDevProps(const virDomainDef *def, unsigned int hostbus = 0; unsigned int hostaddr = 0; g_autofree char *hostdevice = NULL; + virTristateSwitch guestReset = VIR_TRISTATE_SWITCH_ABSENT; + virTristateSwitch guestResetsAll = VIR_TRISTATE_SWITCH_ABSENT; if (!dev->missing) { if (usbsrc->bus == 0 && usbsrc->device == 0) { @@ -5018,6 +5020,23 @@ qemuBuildUSBHostdevDevProps(const virDomainDef *def, } } + switch (usbsrc->guestReset) { + case VIR_DOMAIN_HOSTDEV_USB_GUEST_RESET_OFF: + guestReset = VIR_TRISTATE_SWITCH_OFF; + break; + case VIR_DOMAIN_HOSTDEV_USB_GUEST_RESET_UNINITIALIZED: + guestReset = VIR_TRISTATE_SWITCH_ON; + guestResetsAll = VIR_TRISTATE_SWITCH_OFF; + break; + case VIR_DOMAIN_HOSTDEV_USB_GUEST_RESET_ON: + guestReset = VIR_TRISTATE_SWITCH_ON; + guestResetsAll = VIR_TRISTATE_SWITCH_ON; + break; + case VIR_DOMAIN_HOSTDEV_USB_GUEST_RESET_DEFAULT: + case VIR_DOMAIN_HOSTDEV_USB_GUEST_RESET_LAST: + break; + } + if (virJSONValueObjectAdd(&props, "s:driver", "usb-host", "S:hostdevice", hostdevice, @@ -5025,6 +5044,8 @@ qemuBuildUSBHostdevDevProps(const virDomainDef *def, "p:hostaddr", hostaddr, "s:id", dev->info->alias, "p:bootindex", dev->info->bootIndex, + "T:guest-reset", guestReset, + "T:guest-resets-all", guestResetsAll, NULL) < 0) return NULL; diff --git a/tests/qemuxml2argvdata/hostdev-usb-address.x86_64-latest.args b/tests/qemuxml2argvdata/hostdev-usb-address.x86_64-latest.args index f59c463f5e..978e6a6e6d 100644 --- a/tests/qemuxml2argvdata/hostdev-usb-address.x86_64-latest.args +++ b/tests/qemuxml2argvdata/hostdev-usb-address.x86_64-latest.args @@ -32,6 +32,6 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw","file":"libvirt-1-storage"}' \ -device '{"driver":"ide-hd","bus":"ide.0","unit":0,"drive":"libvirt-1-format","id":"ide0-0-0","bootindex":1}' \ -audiodev '{"id":"audio1","driver":"none"}' \ --device '{"driver":"usb-host","hostdevice":"/dev/bus/usb/014/006","id":"hostdev0","bus":"usb.0","port":"1"}' \ +-device '{"driver":"usb-host","hostdevice":"/dev/bus/usb/014/006","id":"hostdev0","guest-reset":true,"guest-resets-all":false,"bus":"usb.0","port":"1"}' \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on -- 2.35.1