Hide Forgot
Description of problem: redirected usb device cannot release from guest to host when quit virt-viewer with ctrl+c Version-Release number of selected component (if applicable): virt-viewer-5.0-14.el7.x86_64 spice-gtk3-0.35-4.el7.x86_64 How reproducible: 100% Steps to Reproduce: 1. Have a usb device attached to your host. # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 465.8G 0 disk ├─sda1 8:1 0 250G 0 part / ├─sda2 8:2 0 10G 0 part │ └─rhel-swap 253:0 0 10G 0 lvm [SWAP] ├─sda3 8:3 0 5.8G 0 part │ └─rhel00-swap 253:1 0 5.8G 0 lvm ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 150G 0 part sdb 8:16 1 28.9G 0 disk -------------->usb device sr0 11:0 1 1024M 0 rom 2. Prepare a spice vm and start it. 3. Use virt-viewer to open vm. # virt-viewer spice 4. In virt-viewer menu bar, select "File"->"USB device selection", check the usb device you want to plug into vm and click "close" button. check vm: usb device is added # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 1 28.9G 0 disk ---------------newly added device vda 252:0 0 10G 0 disk ... check host by "lsblk": usb device "sdb" is not showing # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 465.8G 0 disk ├─sda1 8:1 0 250G 0 part / ├─sda2 8:2 0 10G 0 part │ └─rhel-swap 253:0 0 10G 0 lvm [SWAP] ├─sda3 8:3 0 5.8G 0 part │ └─rhel00-swap 253:1 0 5.8G 0 lvm ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 150G 0 part sr0 11:0 1 1024M 0 rom 5. Use Ctrl+c to quit from virt-viewer command. # virt-viewer spice ^C Result: usb device can not be added to host. Actual results: The redirected usb device can not be added to host. Expected results: The redirected usb device can be added to host again. Additional info:
Maybe would be helpful to use libusb_set_auto_detach_kernel_driver function? I didn't try but says that by default kernel driver will be automatically reattached when released.
Note that the title of this bug is confusing. virt-viewer redirect client devices, not host ones. Probably you tested on the same machine (so the host is also the client) but title should be "redirected usb device cannot release from guest to client when quit virt-viewer with ctrl+c". Similar considerations for the description comment.
(In reply to Frediano Ziglio from comment #4) > Note that the title of this bug is confusing. virt-viewer redirect client > devices, not host ones. Probably you tested on the same machine (so the host > is also the client) but title should be "redirected usb device cannot > release from guest to client when quit virt-viewer with ctrl+c". > Similar considerations for the description comment. Yes, i tested on the same machine. Thanks for your suggestion, i will update my bug title now.
When a usb device is redirected by virt-viewer the auto loaded kernel driver gets detached from the device. Then virt-viewer (spice-gtk) claims the device so that the kernel will not interfere any more trying to configure the usb device. If virt-viewer is not terminated in a clean way (like with CRTL-C, which throws a SIGINT signal to the application) the kernel is never told to manage the device: the device will stay with no driver attached. The solution here is to add a SIGINT handler to virt-viewer to allow proper termination, giving back the control of the device to the kernel. Note that the issue is present on linux client only. Patch proposed here: https://www.redhat.com/archives/virt-tools-list/2019-December/msg00052.html
Commit a724dff8a3ba6d5e8d3baf79b0041b1b73bd190d Author: Francesco Giudici <fgiudici@redhat.com> Date: Fri Jan 17 16:06:13 2020 +0100 remote-viewer: add handler for SIGINT signal
Reproduce with package: virt-viewer-5.0-17.el7.x86_64 Try to verify with package: virt-viewer-5.0-18.el7.x86_64 Steps: 1. Have a usb device attached to your testing client: # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 1 14.5G 0 disk └─sda1 8:1 1 14.5G 0 part /run/media/juzhou/UNTITLED ---> attached usb device vda 252:0 0 25G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 24G 0 part ├─rhel-root 253:0 0 21.5G 0 lvm / └─rhel-swap 253:1 0 2.5G 0 lvm [SWAP] 2. Prepare a spice guest and start it. #virsh dumpxml $guest <graphics type='spice' port='5900' autoport='yes' listen='127.0.0.1'> <listen type='address' address='127.0.0.1'/> <image compression='off'/> </graphics> ... <video> <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/> <alias name='video0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> 3. Use virt-viewer to connect to guest. # virt-viewer -c qemu:///system rhel7.8 4. In virt-viewer menu bar, select "File"->"USB device selection", check the usb device you want to plug into guest and click "close" button. check in guest: usb device is added(sda) # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 1 14.5G 0 disk └─sda1 8:1 1 14.5G 0 part /run/media/root/UNTITLED sr0 11:0 1 1024M 0 rom vda 252:0 0 7G 0 disk ... Check in client: by "lsblk": usb device "sda" is not showing # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 25G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 24G 0 part ├─rhel-root 253:0 0 21.5G 0 lvm / └─rhel-swap 253:1 0 2.5G 0 lvm [SWAP] 5. Use Ctrl+c to quit from virt-viewer command. # virt-viewer spice ^C Check in client: # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 1 14.5G 0 disk └─sda1 8:1 1 14.5G 0 part /run/media/juzhou/UNTITLED vda 252:0 0 25G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 24G 0 part ... Result: Redirected usb device is released from guest to client when quit virt-viewer with ctrl+c again. And It also works well when using 'remote-viewer spice://127.0.0.1:5900' command. So I move this bug from ON_QA to VERIFIED, thanks.
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory (virt-viewer bug fix and enhancement update), and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHBA-2020:3993