qemu: Generate cmd line for guestReset

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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2022-07-07 15:26:35 +02:00
parent 10a353c92c
commit 265d49896d
2 changed files with 22 additions and 1 deletions

View File

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

View File

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