Bug 1298070 - libvirt should support hotplug usb redirection device successfully
Summary: libvirt should support hotplug usb redirection device successfully
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Virtualization Tools
Classification: Community
Component: libvirt
Version: unspecified
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: ---
Assignee: Libvirt Maintainers
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-01-13 07:31 UTC by Pei Zhang
Modified: 2016-06-10 13:23 UTC (History)
6 users (show)

Fixed In Version: libvirt-1.3.6
Clone Of:
Environment:
Last Closed: 2016-06-10 13:23:22 UTC
Embargoed:


Attachments (Terms of Use)

Description Pei Zhang 2016-01-13 07:31:06 UTC
Description of problem:
currently it fails to hotplug usb redirection via libvirt, and for --live and --config options it gives different error info.
actually libvirt should support it. This is not only be reproduced on upstream, rhel7.2.

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

How reproducible:
100%

Steps to Reproduce:

1. prepare a usb redirection device like following 
# cat usb-redir.xml 
<redirdev bus='usb' type='spicevmc'/>

2. attach this usb redir device to a running guest 
# virsh attach-device vm1 usb-redir.xml 
error: Failed to attach device from usb-redir.xml
error: internal error: unable to execute QEMU command 'device_add': Property 'usb-redir.chardev' can't find value 'charredir0'

3. attach this usb redir device to a running guest with --config 
# virsh attach-device vm1 usb-redir.xml --config
error: Failed to attach device from usb-redir.xml
error: Operation not supported: persistent attach of device 'redirdev' is not supported

Actual results:
As above step 2 and stpe 3

Expected results:
We should hotplug usb redirection device successfully.
And if it doesn't support, we should give same error message for --live and --config.

Additional info:

For a usb redirection device it corresponds to two qemu cli :
-chardev spicevmc,id=charredir0,name=usbredir 
-device usb-redir,chardev=charredir0,id=redir0 
So before we do "device_add usb-redir", we should do "chardev-add spicevmc" first.

and, using QMP we could attach a usb redirdev to guest.
virsh # qemu-monitor-command  vm1 --pretty '{"execute":"chardev-add","arguments":{"id":"charredir0","backend":{"type":"spicevmc","data":{"type":"usbredir"}}}}'
{
    "return": {

    },
    "id": "libvirt-101"
}

virsh # qemu-monitor-command vm1 --pretty '{"execute":"device_add","arguments":{"driver":"usb-redir","chardev":"charredir0","id":"redir0"}}'
{
    "return": {

    },
    "id": "libvirt-102"
}

virsh # qemu-monitor-command --hmp vm1 info usb
  Device 0.0, Port 1, Speed 1.5 Mb/s, Product USB Redirection Device

Using virt-viewer login guest, can use usb redirection to redirect usb device into guest.


libvirt log :
2016-01-13 06:15:36.505+0000: 26772: debug : virDomainAttachDevice:8305 : dom=0x7f8c308e9cf0, (VM: name=vm1, uuid=29f1a1e1-3f8b-48bb-a8aa-c2a5902f86a1), xml=<redirdev bus='usb' type='spicevmc'/>
......
2016-01-13 06:15:36.506+0000: 26772: debug : qemuMonitorAddDeviceWithFd:2858 : device=usb-redir,chardev=charredir0,id=redir0 fd=-1 fdname=<null>
2016-01-13 06:15:36.506+0000: 26772: debug : qemuMonitorAddDeviceWithFd:2861 : mon:0x7f8c2400c1e0 vm:0x7f8bf02190a0 json:1 fd:26
2016-01-13 06:15:36.506+0000: 26772: debug : qemuMonitorJSONCommandWithFd:291 : Send command '{"execute":"device_add","arguments":{"driver":"usb-redir","chardev":"charredir0","id":"redir0"},"id":"libvirt-100"}' for write with FD -1
2016-01-13 06:15:36.506+0000: 26772: info : qemuMonitorSend:998 : QEMU_MONITOR_SEND_MSG: mon=0x7f8c2400c1e0 msg={"execute":"device_add","arguments":{"driver":"usb-redir","chardev":"charredir0","id":"redir0"},"id":"libvirt-100"}^M
 fd=-1
......

Comment 1 Pei Zhang 2016-01-13 07:35:34 UTC
sorry for missing libvirt version :
# rpm -q libvirt
libvirt-1.3.1-1.el7_v1.3.1_rc1_15_g71daae9.x86_64

Comment 2 Osier Yang 2016-02-19 11:05:00 UTC
Patch posted upstream:

https://www.redhat.com/archives/libvir-list/2016-February/msg01003.html

Comment 3 Michal Privoznik 2016-02-25 08:26:50 UTC
I've just pushed patch upstream:

commit c92547c34a85331f34df7d2fe1c55eb40fea3f71
Author:     Osier Yang <osier>
AuthorDate: Tue Feb 23 00:44:09 2016 +0800
Commit:     Michal Privoznik <mprivozn>
CommitDate: Thu Feb 25 09:17:41 2016 +0100

    Fix bug of attaching redirdev device
    
    RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1298070
    
    The corresponding chardev must be attached first, otherwise the
    the qemu command line won't be complete (missing the host part),

v1.3.2-rc1-4-gc92547c

Comment 4 Pei Zhang 2016-05-06 07:35:37 UTC
Hi,
This issue still can be reproduced with
libvirt-1.3.4-1.el7.x86_64

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

#virsh attach-device g1 usb-redir.xml 
error: Failed to attach device from usb-redir.xml
error: operation failed: Hotplug unsupported for char device type 'spicevmc'

Comment 5 Pei Zhang 2016-06-01 07:59:04 UTC
Hi Michal,
I tested this issue with libvirt-1.3.4-1 and think it needs further modification. It should be attached successfully. 

Could you help check it? thanks.

steps:
1. start a guest
2. prepare usb redirdev: 
<redirdev bus='usb' type='spicevmc'>
</redirdev>

3. attach-device 
# virsh attach-device rhel72 usb-redir.xml 
error: Failed to attach device from usb-redir.xml
error: operation failed: Hotplug unsupported for char device type 'spicevmc'


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

Comment 6 Michal Privoznik 2016-06-09 15:03:50 UTC
Hey, thanks for the testing. It looks like you're totally right. I've proposed the patches on the list:

https://www.redhat.com/archives/libvir-list/2016-June/msg00615.html

Comment 7 Michal Privoznik 2016-06-10 13:23:22 UTC
I've just pushed the patch upstream:

commit 3668526fa6f64f8de44f0faa639001b224ec6a15
Author:     Michal Privoznik <mprivozn>
AuthorDate: Wed Jun 8 15:51:27 2016 +0200
Commit:     Michal Privoznik <mprivozn>
CommitDate: Fri Jun 10 15:22:07 2016 +0200

    qemuMonitorJSONAttachCharDev: Teach spicevmc
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1298070
    
    We have the code for attaching redirdevs for ages now.
    Unfortunately, our monitor code that handles talking to the qemu
    process was missing a little piece of code that actually enabled
    the feature.
    
    BTW: it really is called "type" on the monitor, even though it's
    called "name" on the cmd line. Don't ask.
    
    Signed-off-by: Michal Privoznik <mprivozn>

v1.3.5-214-g3668526


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