From Fedora Project Wiki
No edit summary
Line 13: Line 13:
== Current status ==
== Current status ==
* Targeted release: Fedora 16
* Targeted release: Fedora 16
* Last updated: Jul 26, 2011  
* Last updated: Sep 9, 2011  
* Percentage of completion: 75%
* Percentage of completion: 100%


== Detailed Description ==
== Detailed Description ==
Line 22: Line 22:
** redirecting a local attached usb-device through an application provided pipe
** redirecting a local attached usb-device through an application provided pipe
* Support for qemu to receive data from a usbredir pipe, and make the redirected USB device show up as being attached to the emulated host controller inside the virtual machine (done)
* Support for qemu to receive data from a usbredir pipe, and make the redirected USB device show up as being attached to the emulated host controller inside the virtual machine (done)
* Support for spice-server (80% done) and spice-gtk (the gtk spice client widget) to use usbredir
* Support for spice-server (done) and spice-gtk (the gtk spice client widget) to use usbredir
* A nice UI for redirecting USB devices from a spice-gtk based virtual machine viewer
* A nice UI for redirecting USB devices from a spice-gtk based virtual machine viewer (done, but only in spicy so far not in virt-manager / virt-viewer)


== Benefit to Fedora ==
== Benefit to Fedora ==
Line 32: Line 32:


== How To Test ==
== How To Test ==
Right now, to test the usb2 support:
First thing you need to do is download [http://cgit.freedesktop.org/spice/qemu/plain/docs/ich9-ehci-uhci.cfg this] file, and drop it in /etc/qemu.
* start qemu from the cmdline with your usual arguments and add: "-device ich9-usb-ehci1,addr=1d.7,multifunction=on,id=ehci -device ich9-usb-uhci1,addr=1d.0,multifunction=on,id=uhci-1,masterbus=ehci.0,firstport=0 -device ich9-usb-uhci2,addr=1d.1,multifunction=on,id=uhci-2,masterbus=ehci.0,firstport=2, -device ich9-usb-uhci3,addr=1d.2,multifunction=on,id=uhci-3,masterbus=ehci.0,firstport=4"
* A bug has been filed to add support for this to libvirt, see: https://bugzilla.redhat.com/show_bug.cgi?id=725670


Right now, to test the usb network redirection support:
Then create a new spice-enabled vm using using virt-manager, select spice as display type and qxl as video card model,
* install the usbredir-server package
when asked if you want to enable the agent channel, say yes.
* run lsusb and find the vendor-id:product-id of the device you want to redirect
* run usbredirserver as root like this: "usbredirserver -p 4000 vendor-id:product-id", ie: "usbredirserver -p 4000 15d9:0a41"
* start qemu from the cmdline with your usual arguments add then usb2 arguments from above and add: "-chardev socket,id=usbredirchardev,host=localhost,port=4000 -device usb-redir,chardev=usbredirchardev,id=usbredirdev,bus=ehci.0"
* note that:
** If the redirected device is on a different machine then were qemu is running localhost should be replaced by the hostname or ip-address of that machine
** You can use a different port by changing the "-p 4000" parameter to usbredirserver, this way you can also redirect multiple devices


Once most bits are in place:
When done, close virt-manager and edit the relevant /etc/libvirt/qemu/foo.xml file. Change the first line from:
* Create a virtual machine with virt-manager, select Spice as display protocol and select the QXL graphics card
<pre><domain type='kvm'></pre>
* Connect to the virtual machine from some machine with a gtk based spice-client to the virtual machine
to:
* Select a random USB device attached to your local machine to redirect to the vm
<pre><domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'></pre>
* Check that the USB device shows up in the vm, and works normally.
 
And add the following lines at the end, above the "<code></domain></code>" line:
 
<pre>
  <qemu:commandline>
    <qemu:arg value='-readconfig'/>
    <qemu:arg value='/etc/qemu/ich9-ehci-uhci.cfg'/>
    <qemu:arg value='-chardev'/>
    <qemu:arg value='spicevmc,name=usbredir,id=usbredirchardev1'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='usb-redir,chardev=usbredirchardev1,id=usbredirdev1,bus=ehci.0,debug=3'/>
    <qemu:arg value='-chardev'/>
    <qemu:arg value='spicevmc,name=usbredir,id=usbredirchardev2'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='usb-redir,chardev=usbredirchardev2,id=usbredirdev2,bus=ehci.0,debug=3'/>
    <qemu:arg value='-chardev'/>
    <qemu:arg value='spicevmc,name=usbredir,id=usbredirchardev3'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='usb-redir,chardev=usbredirchardev3,id=usbredirdev3,bus=ehci.0,debug=3'/>
  </qemu:commandline>
</pre>
 
Then close down any virtual machines you may have open, and restart libvirt:
<pre>sudo service libvirtd restart</pre>
 
Now start the vm with virt-manager, open it, select the details view, click on Display Spice and lookup and remember the port mentioned there (this will be 5900 if it is the only running vm).
 
Close virt-manager, and connect to the vm with spicy, like this:
<pre>sudo spicy -h localhost -p 5900</pre>
 
Where 5900 should be replaced by the port the vm is actually running on. Note that you need to start spicy as root, so that it can access the device nodes under <code>/dev/bus/usb</code>.
 
Select the options menu entry and make sure that the "auto redirect newly plugged in USB devices" option is checked. After this make sure the vm has keyboard focus (so close the options menu), plug in a new USB device and watch it show up in your vm :) Feel free to yank it out again at any time :)
 
If you plug in a device while the vm does not have keyboard focus, it will not get redirected, so you can use usb devices
normally as long as you don't have the vm focussed when you plug them in.
 
Enjoy, and be sure to send any feedback you may have my way!


== User Experience ==
== User Experience ==

Revision as of 12:00, 9 September 2011

= USB redirection over the network

Summary

Allow redirecting a USB device to another machine over the network. For example use an USB webcam attached to machine A on machine B. For Fedora 16 the focus will be on allowing using USB devices attached to some machine (not necessarily the host machine) inside a qemu-kvm virtual machine.

Owner

  • Name: Hans de Goede
  • Email: hdegoede@redhat.com

Current status

  • Targeted release: Fedora 16
  • Last updated: Sep 9, 2011
  • Percentage of completion: 100%

Detailed Description

The intend is to deliver the following for Fedora 16:

  • A usbredir package (done) with libraries for:
    • parsing the usbnetredir protocol
    • redirecting a local attached usb-device through an application provided pipe
  • Support for qemu to receive data from a usbredir pipe, and make the redirected USB device show up as being attached to the emulated host controller inside the virtual machine (done)
  • Support for spice-server (done) and spice-gtk (the gtk spice client widget) to use usbredir
  • A nice UI for redirecting USB devices from a spice-gtk based virtual machine viewer (done, but only in spicy so far not in virt-manager / virt-viewer)

Benefit to Fedora

Currently many Fedora users choose to not use qemu-kvm for virtual machines, but instead use a less open alternative not shipped with Fedora. One of the stated reasons for doing so is the less then stellar support for USB redirection with qemu-kvm. Besides adding support for USB redirection over the network, qemu's USB redirection support is being improved in general, including adding support for USB 2.

Scope

The needed changes are isolated to the new usbredir package, qemu and spice. Work is already underway to try and get all changes upstream.

How To Test

First thing you need to do is download this file, and drop it in /etc/qemu.

Then create a new spice-enabled vm using using virt-manager, select spice as display type and qxl as video card model, when asked if you want to enable the agent channel, say yes.

When done, close virt-manager and edit the relevant /etc/libvirt/qemu/foo.xml file. Change the first line from:

<domain type='kvm'>

to:

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>

And add the following lines at the end, above the "</domain>" line:

  <qemu:commandline>
     <qemu:arg value='-readconfig'/>
     <qemu:arg value='/etc/qemu/ich9-ehci-uhci.cfg'/>
     <qemu:arg value='-chardev'/>
     <qemu:arg value='spicevmc,name=usbredir,id=usbredirchardev1'/>
     <qemu:arg value='-device'/>
     <qemu:arg value='usb-redir,chardev=usbredirchardev1,id=usbredirdev1,bus=ehci.0,debug=3'/>
     <qemu:arg value='-chardev'/>
     <qemu:arg value='spicevmc,name=usbredir,id=usbredirchardev2'/>
     <qemu:arg value='-device'/>
     <qemu:arg value='usb-redir,chardev=usbredirchardev2,id=usbredirdev2,bus=ehci.0,debug=3'/>
     <qemu:arg value='-chardev'/>
     <qemu:arg value='spicevmc,name=usbredir,id=usbredirchardev3'/>
     <qemu:arg value='-device'/>
     <qemu:arg value='usb-redir,chardev=usbredirchardev3,id=usbredirdev3,bus=ehci.0,debug=3'/>
  </qemu:commandline>

Then close down any virtual machines you may have open, and restart libvirt:

sudo service libvirtd restart

Now start the vm with virt-manager, open it, select the details view, click on Display Spice and lookup and remember the port mentioned there (this will be 5900 if it is the only running vm).

Close virt-manager, and connect to the vm with spicy, like this:

sudo spicy -h localhost -p 5900

Where 5900 should be replaced by the port the vm is actually running on. Note that you need to start spicy as root, so that it can access the device nodes under /dev/bus/usb.

Select the options menu entry and make sure that the "auto redirect newly plugged in USB devices" option is checked. After this make sure the vm has keyboard focus (so close the options menu), plug in a new USB device and watch it show up in your vm :) Feel free to yank it out again at any time :)

If you plug in a device while the vm does not have keyboard focus, it will not get redirected, so you can use usb devices normally as long as you don't have the vm focussed when you plug them in.

Enjoy, and be sure to send any feedback you may have my way!

User Experience

Users wishing to redirect USB devices to virtual machines can do so easily from the virtual machine viewer UI, and can do so even when connected to the virtual machine from another machine then the host.

Dependencies

None

Contingency Plan

The plan is to deliver the various bits mentioned under "Detailed Description" one by one. If time runs out before we can deliver the lower bullets, the already delivered bits will stay in place and can still be used, but only from the cmdline rather then from a nice integrated UI experience.

Documentation

See:

Release Notes

Fedora 16 now comes with improved USB support for qemu-kvm virtual machines. The virtual machines are now capable of emulating or passing through USB 2 devices. It is now also possible to redirect a USB device over the network, this allows passing through a USB device from another pc then the host to a virtual machine. See: http://fedoraproject.org/wiki/Features/UsbNetworkRedirection for detailed instructions on how to enable these new features.

Comments and Discussion