RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1713311 - redirected usb device cannot release from guest to client when quit virt-viewer with ctrl+c
Summary: redirected usb device cannot release from guest to client when quit virt-view...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: virt-viewer
Version: 7.7
Hardware: x86_64
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Francesco Giudici
QA Contact: zhoujunqin
URL:
Whiteboard:
Depends On:
Blocks: 1732653
TreeView+ depends on / blocked
 
Reported: 2019-05-23 11:34 UTC by zhoujunqin
Modified: 2020-09-29 20:25 UTC (History)
10 users (show)

Fixed In Version: virt-viewer-5.0-18.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1732653 (view as bug list)
Environment:
Last Closed: 2020-09-29 20:25:24 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2020:3993 0 None None None 2020-09-29 20:25:32 UTC

Description zhoujunqin 2019-05-23 11:34:29 UTC
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:

Comment 3 Frediano Ziglio 2019-10-14 16:35:22 UTC
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.

Comment 4 Frediano Ziglio 2019-10-14 16:38:30 UTC
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.

Comment 5 zhoujunqin 2019-10-15 03:25:34 UTC
(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.

Comment 7 Francesco Giudici 2019-12-20 14:56:32 UTC
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

Comment 8 Victor Toso 2020-02-06 14:14:33 UTC
Commit a724dff8a3ba6d5e8d3baf79b0041b1b73bd190d
Author: Francesco Giudici <fgiudici>
Date:   Fri Jan 17 16:06:13 2020 +0100

    remote-viewer: add handler for SIGINT signal

Comment 13 zhoujunqin 2020-04-22 03:10:34 UTC
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.

Comment 15 errata-xmlrpc 2020-09-29 20:25:24 UTC
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


Note You need to log in before you can comment on or make changes to this bug.