Bug 1505809

Summary: release the physical usb stick from guest ,host can not work well
Product: Red Hat Enterprise Linux 7 Reporter: cliao <cliao>
Component: virt-viewerAssignee: Jonathon Jongsma <jjongsma>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: low    
Version: 7.5CC: chayang, coli, dblechte, fziglio, jjongsma, juzhang, juzhou, knoel, kraxel, ngu, qzhang, tzheng, victortoso, virt-maint, xiaodwan, xiaohli, xuma
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: virt-viewer-5.0-14.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1655957 (view as bug list) Environment:
Last Closed: 2019-08-06 13:07:26 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1655957    

Description cliao 2017-10-24 10:23:19 UTC
Description of problem:
when usb-redir device,release the physical usb  stick from guest ,host can not find the physical usb stick.

Version-Release number of selected component (if applicable):
Host/guest kernel: kernel-3.10.0-727.el7
qemu-kvm-rhev: qemu-kvm-rhev-2.10.0-3.el7.x86_64

How reproducible:
4/4

Steps to Reproduce:
1.boot guest with usb stick:
-device usb-ehci,id=ehci \
-spice port=5931,disable-ticketing \
-chardev spicevmc,name=usbredir,id=usbredirchardev1 \
-device usb-redir,id=redir1,chardev=usbredirchardev1,bus=ehci.0,port=1 \

2.shutdown guest:
shutdown now

3.check if the usb device work well on host:
fdisk -l 

Actual results:
can not find the usb stick.

Expected results:
the function of usb device are normal.

Additional info:

Comment 2 cliao 2017-10-27 00:45:16 UTC
Version-Release number of selected component:
Host/guest kernel: kernel-3.10.0-727.el7
qemu-kvm-rhev:qemu-kvm-rhev-2.9.0-16.el7 

also have the same problem as above

Comment 3 Gerd Hoffmann 2017-11-01 08:33:23 UTC
Reproduces, using virt-viewer-5.0-7.el7.x86_64

It is virt-viewer which handles the usb device so the bug is there (or in spice-gtk which is used by virt-viewer).  Re-assigning.

Handover the device back to the host works fine in case the device is unchecked in the device selection window.  It also works fine if you close virt-viewer with the window close button.

It fails in case qemu tears down the spice connection for whatever reason (guest shutdown, "virsh destroy").

Workaround: Checking and unchecking the device in the usb device selection box once makes the device show up on the host.

Comment 4 Li Xiaohui 2018-07-09 11:37:59 UTC
Hi all,
recently I test one case RHEL7-8997 [[usb device] [usb-redir] Release the physical USB stick/webcam from guest, check if it works well on usb-host, and reproduce this issue again in rhel-7.6

1.version info
(host)kernel-3.10.0-915.el7.x86_64 & qemu-img-rhev-2.12.0-7.el7.x86_64
(guest)kernel-3.10.0-915.el7.x86_64 & windows 2016

2.test steps
(1)Boot guest witch USB stick redirected
/usr/libexec/qemu-kvm -machine q35 -S \
...
-device usb-ehci,id=ehci \
-spice port=5931,disable-ticketing \
-chardev spicevmc,name=usbredir,id=usbredirchardev1 \
-device usb-redir,id=redir1,chardev=usbredirchardev1,bus=ehci.0,port=1 \
-boot menu=on \

(2)select usb stick(USB 2.0 stick and it's plugged in usb 3.0 controller on client) from File-USB device selection in guest, then execute "c" in qemu

(3)shutdown the guest, and then Check if the USB device works well on host
(host)#fdisk /dev/sdc

3.test result
Actual result: can see usb stick in boot menu, and find usb stick through "lsusb" in guest command.  but failed find usb stick on host after guest shutdown

Expected result: can see usb stick through "fdisk /dev/sdc" on host command after it released from guest.

Additional:
failed to find usb stick(any type usb stick and any usb controller) through "fdisk /dev/sdc" on host command after it released from guest.

Looking forward the bug fixed soon

Regards,
Li Xiaohui

Comment 5 Victor Toso 2018-12-19 16:04:37 UTC
Could you please provide --spice-debug logs when that happens?
The code has improved a bit so it might be the case that it is fixed thanks to, for example, bug 1625550

Comment 6 Li Xiaohui 2018-12-25 11:07:06 UTC
(In reply to Victor Toso from comment #5)
> Could you please provide --spice-debug logs when that happens?
> The code has improved a bit so it might be the case that it is fixed thanks
> to, for example, bug 1625550

Hi Victor Toso, 
sorry I have no rhel7.6 local host now, it upgrade to rhel8, I tried to reproduce this bug in followings environment, but get no useful infomation:
(1)use rhel7.6 host in beaker to boot guest, and connect guest via remote-viewer in local rhel8.0 host, but didn't hit this issue. 
(2)use one local rhel8 host to boot guest, and connect guest via remote-viewer in another local rhel8.0 host, couldn't find this passthrough device, maybe it's a new bug.

Regards,
Li Xiaohui

Comment 7 Jonathon Jongsma 2019-05-21 22:08:12 UTC
I have reproduced this issue, and it looks like it is an issue that I previously fixed some time ago. The problem was that there were some reference-counting issues in spice-gtk/virt-viewer that were preventing channel objects to be destroyed properly at application shutdown. When using a more recent virt-viewer/spice-gtk (git master in my case), the issue can no longer be reproduced. The following commits are required:

spice-gtk:
1c08a1171c3815f89be84b3678657fc9c50cd140 Add SpiceSession::disconnected signal
[This commit is included in spice-gtk 0.36]

virt-viewer:
65ef66e42a6db2a9826fffef0db49920a02d358f Spice: listen for new 'SpiceSession::disconnected' signal
[This commit is included in virt-viewer 8.0]

Comment 8 Victor Toso 2019-05-22 13:37:09 UTC
> spice-gtk:
> 1c08a1171c3815f89be84b3678657fc9c50cd140 Add SpiceSession::disconnected
> signal
> [This commit is included in spice-gtk 0.36]

Actually, this is present in 0.35, that means also RHEL 7

> virt-viewer:
> 65ef66e42a6db2a9826fffef0db49920a02d358f Spice: listen for new
> 'SpiceSession::disconnected' signal
> [This commit is included in virt-viewer 8.0]

Backport and scratch build seems fine but commit c2dabf0 "Fix a regression when
initial connection fails" in 2019-04-16 by Jonathon Jongsma <jjongsma>
seems to be needed as well to avoid regression.

I'll be doing the build with this bug fixed then. Thanks

Comment 10 zhoujunqin 2019-05-23 07:37:55 UTC
I can reproduce bug issue with packages:
virt-viewer-5.0-13.el7.x86_64
spice-gtk3-0.35-4.el7.x86_64

Steps:
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. Shutdown vm by "virsh destroy spice" command, and check on host again.
# 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  

Result: sdb can not be used by host again.

Then try to verify this bug with new build:
virt-viewer-5.0-14.el7.x86_64
spice-gtk3-0.35-4.el7.x86_64

Steps:
a. Loop reproduce step1-5.

Result:After step5, shutdown vm, then usb device can be added to host again.

# 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----->add to host again
sr0              11:0    1  1024M  0 rom  

b. I also do additional testing about different quit ways from virt-viewer after looping reproduce step1-4.
b.1 Click File->Quit
Result: usb device can be added to host again.

b.2 Click View->Displays->Display 1
Result: usb device can be added to host again.

b.3 Cick the "X" button on the top right corner of the window.
Result: usb device can be added to host again.

b.4 Use Ctrl+c to quit from virt-viewer command.
# virt-viewer  spice
^C
Result: usb device can not be added to host.

As a summary of my verification, usb device can be used by host again when I shutdown vm or use normal ways to quit from virt-viewer.
But it failed to used by host again when quitting from virt-viewer, I think it should be fixed together.

Hi Jonathon Jongsma, how about your idea, thanks.

Comment 11 Victor Toso 2019-05-23 08:35:58 UTC
> As a summary of my verification, usb device can be used by host again when I shutdown vm or use normal ways to quit from virt-viewer.
> But it failed to used by host again when quitting from virt-viewer, I think it should be fixed together.

When quitting with CTRL+C, on code this means handling SIGINT. I honestly think this would be nice thing to do but not to block this bug for it.
Shouldn't be a regression either as I don't see handlers in virt-viewer code for that.

Another point to make is that Virt-viewer is an App with GUI that user can use to Quit in different ways and from comment #10 bug is solved under all GUI possibilities (should also double check with shutting down the VM).
So, IMHO, handling CTRL+C from command line can be done later on.

Comment 12 zhoujunqin 2019-05-23 11:35:36 UTC
(In reply to Victor Toso from comment #11)
> > As a summary of my verification, usb device can be used by host again when I shutdown vm or use normal ways to quit from virt-viewer.
> > But it failed to used by host again when quitting from virt-viewer, I think it should be fixed together.
> 
> When quitting with CTRL+C, on code this means handling SIGINT. I honestly
> think this would be nice thing to do but not to block this bug for it.
> Shouldn't be a regression either as I don't see handlers in virt-viewer code
> for that.
> 
> Another point to make is that Virt-viewer is an App with GUI that user can
> use to Quit in different ways and from comment #10 bug is solved under all
> GUI possibilities (should also double check with shutting down the VM).
> So, IMHO, handling CTRL+C from command line can be done later on.

Thanks for your reply, i file a new bug 1713311 to track the ctrl+c issue, and I move this bug from ON_QA to VERIFIED since the bug issue has been fixed.

Comment 14 errata-xmlrpc 2019-08-06 13:07:26 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, 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/RHSA-2019:2229