]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Generate cmd line for guestReset
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 7 Jul 2022 13:26:35 +0000 (15:26 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 13 Jul 2022 14:01:14 +0000 (16:01 +0200)
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>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/hostdev-usb-address.x86_64-latest.args

index b307d3139cd40f7a68fa849324f4966adacfa937..262fffe5fe40dc224cb42e76e022cb243443711a 100644 (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;
 
index f59c463f5e5f1760e345b761742ba387d4879895..978e6a6e6de553f32281c696448d051203384f8a 100644 (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