Bug 1584571

Summary: RFE: qemu: support redirdev hotunplug
Product: Red Hat Enterprise Linux 7 Reporter: jiyan <jiyan>
Component: libvirtAssignee: Libvirt Maintainers <libvirt-maint>
Status: CLOSED ERRATA QA Contact: lijuan men <lmen>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.6CC: crobinso, dyuan, hhan, jiyan, jtomko, libvirt-maint, lmen, mtessun, mzhan, pkrempa, xuzhang
Target Milestone: rcKeywords: FutureFeature
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard: LibvirtFirstBug
Fixed In Version: libvirt-4.3.0-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1313272 Environment:
Last Closed: 2018-10-30 09:55:54 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:
Bug Depends On: 1313272    
Bug Blocks:    

Description jiyan 2018-05-31 08:46:01 UTC
+++ This bug was initially created as a clone of Bug #1313272 +++

Description of problem:
Since we already support attach redirdev, it's better to fix detach redirdev.

// This bug has been fixed in upstream while no downstream bug tracks this issue, so clone Bug #1313272 to RHEL7.6, libvirt. Please feel free to modify if there are something incorrect.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1.start a guest with redirdev

# virsh dumpxml vm1|grep redirdev -A 3
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir0'/>

2. prepare a redirdev xml like following

# cat usb-redir.xml 
<redirdev bus='usb' type='spicevmc'>

3.detach redirdev device

# virsh detach-device vm1 usb-redir.xml 
error: Failed to detach device from usb-redir.xml
error: Operation not supported: live detach of device 'redirdev' is not supported

# virsh detach-device vm1 usb-redir.xml --config
error: Failed to detach device from usb-redir.xml
error: Operation not supported: persistent detach of device 'redirdev' is not supported

Actual results:
As step3, fail to detach it.

Expected results:
It could be detached. 

Additional info:

using QMP to check :
before delete, using virt-viewer to open guest we could find that table "Redirect USB device" is useful. 
then we detach it via QMP
virsh # qemu-monitor-command vm1 --pretty '{"execute":"device_del","arguments":{"id":"redir0"}}'
    "return": {

    "id": "libvirt-25"

Then using virt-viewer to open guest to check again, we will find that table "Redirect USB device" is gray and it cannot be used.So actually it could be detached.

--- Additional comment from Cole Robinson on 2016-04-20 19:30:51 EDT ---

Fixing basically involves 2 places:

src/qemu/qemu_driver.c function qemuDomainDetachDeviceLive needs to handle REDIRDEV
a qemuDomainDetachRedirdevDevice function should be implemented in src/qemu/qemu_hotplug.c

The pattern to follow here is RNG devices and the qemuDomainDetachRNGDevice ... the actual qemu interaction logic will basically be identical, we just need to match that pattern and swap out the redirdev bits

--- Additional comment from Ján Tomko on 2018-05-30 09:16:33 EDT ---

Fixed by:
commit 91a3234f3a218a581ede975164e66ce7b0347f4c
Author:     Chen Hanxiao <chenhanxiao@gmail.com>
AuthorDate: 2018-01-05 10:47:47 +0800
Commit:     John Ferlan <jferlan@redhat.com>
CommitDate: 2018-01-08 11:49:26 -0500

    qemu: Add support for hot unplugging redirdev device
    Commit id '162efa1a' added support hotplug a redirdev, but
    did not add the hot unplug. This patch will add that support
    to allow usage of the detach-device --live on the device.
    Reviewed-by: John Ferlan <jferlan@redhat.com>
    Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>

git describe: v3.10.0-138-g91a3234f3a contains: v4.0.0-rc1~50

Comment 4 lijuan men 2018-09-12 07:06:26 UTC
verify the bug


the basic scenarios:

1)tcp type

[root@localhost ~]# cat redirdev-tcp.xml 
  <redirdev bus='usb' type='tcp'>
      <source mode='connect' host='localhost' service='4000' tls='no'/>
      <protocol type='raw'/>

[root@localhost ~]# virsh attach-device test redirdev-tcp.xml
Device attached successfully

in the guest,
[root@localhost ~]# lsusb
Bus 001 Device 002: ID 0951:1642 Kingston Technology DT101 G2

[root@localhost ~]# virsh detach-device test redirdev-tcp.xml
Device detached successfully

[root@localhost ~]# virsh dumpxml test | grep redi -A 2
[root@localhost ~]# 

in the guest,there is not the usb device

2)spicevmc type

[root@localhost ~]# cat redirdev-spice.xml
 <redirdev bus='usb' type='spicevmc'>

[root@localhost ~]# virsh attach-device test redirdev-spice.xml 
Device attached successfully

[root@localhost ~]# virsh dumpxml test | grep redi -A 2
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir0'/>
      <address type='usb' bus='0' port='1'/>

[root@localhost ~]# virsh detach-device test redirdev-spice.xml 
Device detached successfully

[root@localhost ~]# virsh dumpxml test | grep redi -A 2
[root@localhost ~]# 

the test matrix is:
    usb 1/2/3
    detach using alias/xml
    [--persistent] [--config] [--live] [--current]

Comment 6 errata-xmlrpc 2018-10-30 09:55:54 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.