<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=us-ascii" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
On 05/27/2009 10:23 AM, Cole Robinson wrote:
<blockquote cite="mid:4A1D4CC6.1010102@redhat.com" type="cite">
  <pre wrap="">Robert L Cochran wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Why doesn't the hostdev xml shown below for a USB device work? I've 
shown the entire &lt;devices&gt; block for context.

&lt;devices&gt;
&lt;emulator&gt;/usr/bin/qemu-kvm&lt;/emulator&gt;
&lt;disk type='file' device='cdrom'&gt;
&lt;target dev='hdc' bus='ide'/&gt;
&lt;readonly/&gt;
&lt;/disk&gt;
&lt;disk type='file' device='disk'&gt;
&lt;source file='/var/lib/libvirt/images/Ubuntu9.img'/&gt;
&lt;target dev='vda' bus='virtio'/&gt;
&lt;/disk&gt;
&lt;interface type='network'&gt;
&lt;mac address='54:52:00:74:32:2f'/&gt;
&lt;source network='default'/&gt;
&lt;model type='virtio'/&gt;
&lt;/interface&gt;
&lt;serial type='pty'&gt;
&lt;target port='0'/&gt;
&lt;/serial&gt;
&lt;console type='pty'&gt;
&lt;target port='0'/&gt;
&lt;/console&gt;
&lt;hostdev mode='subsystem' type='usb'&gt;
&lt;source&gt;
&lt;vendor id='0403'/&gt;
&lt;product id='6001'/&gt;
&lt;/source&gt;
&lt;/hostdev&gt;
&lt;input type='mouse' bus='ps2'/&gt;
&lt;graphics type='vnc' port='-1' autoport='yes'/&gt;
&lt;sound model='es1370'/&gt;
&lt;/devices&gt;

The USB device of interest to me is an FTDI FT232RL chip. When I plug 
the board into a USB port on the host, I want it to be passed through to 
my Ubuntu guest so that it can be seen as /dev/ttyUSB0. The guest 
doesn't see it. I took the product and vendor id numbers from the 
/var/log/messages output, and these might be in hexadecimal (and I 
should be writing e.g. &lt;vendorid=0x0403'/&gt;. I might also be getting the 
physical handling of the device wrong: maybe it needs to be already 
plugged in at the time the Ubuntu guest is started up, or maybe I should 
start the guest first and then plug in the device?

Advice appreciated.

Bob Cochran

    </pre>
  </blockquote>
  <pre wrap=""><!---->
For future reference, easiest way to get device product + vendor info is
to use 'lsusb'.

I think you need to use the hex format you mention above to get this to
work correctly (&lt;vendor id='0x0403'/&gt; ...). Also, make sure that the
&lt;hostdev&gt; device is still listed in the domain xml when you use 'virsh
dumpxml &lt;domname&gt;': this will guarantee that libvirt is at least
recognizing the new xml.

You can also check /var/log/libvirt/qemu/&lt;domname&gt;.log to see what QEMU
command line libvirt is generating, which helps debugging these issues.

- Cole


  </pre>
</blockquote>
Cole,<br>
<br>
Thanks for your response. I modified the file
/etc/libvirt/qemu/Ubuntu9.xml so that it looks like this:<br>
<br>
&lt;domain type='kvm'&gt;<br>
&nbsp; &lt;name&gt;Ubuntu9&lt;/name&gt;<br>
&nbsp; &lt;uuid&gt;cb8c3d15-fe92-1bf2-5676-03370743e815&lt;/uuid&gt;<br>
&nbsp; &lt;memory&gt;1572864&lt;/memory&gt;<br>
&nbsp; &lt;currentMemory&gt;1572864&lt;/currentMemory&gt;<br>
&nbsp; &lt;vcpu&gt;1&lt;/vcpu&gt;<br>
&nbsp; &lt;os&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;type arch='x86_64' machine='pc'&gt;hvm&lt;/type&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;boot dev='hd'/&gt;<br>
&nbsp; &lt;/os&gt;<br>
&nbsp; &lt;features&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;acpi/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;apic/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;pae/&gt;<br>
&nbsp; &lt;/features&gt;<br>
&nbsp; &lt;clock offset='utc'/&gt;<br>
&nbsp; &lt;on_poweroff&gt;destroy&lt;/on_poweroff&gt;<br>
&nbsp; &lt;on_reboot&gt;restart&lt;/on_reboot&gt;<br>
&nbsp; &lt;on_crash&gt;restart&lt;/on_crash&gt;<br>
&nbsp; &lt;devices&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;emulator&gt;/usr/bin/qemu-kvm&lt;/emulator&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;disk type='file' device='cdrom'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target dev='hdc' bus='ide'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;readonly/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/disk&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;disk type='file' device='disk'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source file='/var/lib/libvirt/images/Ubuntu9.img'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target dev='vda' bus='virtio'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/disk&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;interface type='network'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mac address='54:52:00:74:32:2f'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source network='default'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;model type='virtio'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/interface&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;serial type='pty'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target port='0'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/serial&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;console type='pty'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target port='0'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/console&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;hostdev mode='subsystem' type='usb'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;vendor id='0x0403'/&gt;<br>
&nbsp;&nbsp;&nbsp; &nbsp; &lt;product id='0x6001'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/source&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/hostdev&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;input type='mouse' bus='ps2'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;graphics type='vnc' port='-1' autoport='yes'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;sound model='es1370'/&gt;<br>
&nbsp; &lt;/devices&gt;<br>
&lt;/domain&gt;<br>
<br>
<br>
<br>
My interest is getting the Ubuntu machine to recognize the FTDI device
indicated in the &lt;hostdev&gt; entry you see above. I did not start
the virtual machine or actually plug the USB device of interest into an
available port at this point. Instead I ran 'virsh' as you suggested
above. Here is the output:<br>
<br>
[root@deafeng3 qemu]# virsh dumpxml Ubuntu9<br>
&lt;domain type='kvm'&gt;<br>
&nbsp; &lt;name&gt;Ubuntu9&lt;/name&gt;<br>
&nbsp; &lt;uuid&gt;cb8c3d15-fe92-1bf2-5676-03370743e815&lt;/uuid&gt;<br>
&nbsp; &lt;memory&gt;1572864&lt;/memory&gt;<br>
&nbsp; &lt;currentMemory&gt;1572864&lt;/currentMemory&gt;<br>
&nbsp; &lt;vcpu&gt;1&lt;/vcpu&gt;<br>
&nbsp; &lt;os&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;type arch='x86_64' machine='pc'&gt;hvm&lt;/type&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;boot dev='hd'/&gt;<br>
&nbsp; &lt;/os&gt;<br>
&nbsp; &lt;features&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;acpi/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;apic/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;pae/&gt;<br>
&nbsp; &lt;/features&gt;<br>
&nbsp; &lt;clock offset='utc'/&gt;<br>
&nbsp; &lt;on_poweroff&gt;destroy&lt;/on_poweroff&gt;<br>
&nbsp; &lt;on_reboot&gt;restart&lt;/on_reboot&gt;<br>
&nbsp; &lt;on_crash&gt;restart&lt;/on_crash&gt;<br>
&nbsp; &lt;devices&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;emulator&gt;/usr/bin/qemu-kvm&lt;/emulator&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;disk type='file' device='cdrom'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target dev='hdc' bus='ide'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;readonly/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/disk&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;disk type='file' device='disk'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source file='/var/lib/libvirt/images/Ubuntu9.img'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target dev='vda' bus='virtio'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/disk&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;interface type='network'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mac address='54:52:00:74:32:2f'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source network='default'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;model type='virtio'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/interface&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;serial type='pty'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target port='0'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/serial&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;console type='pty'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target port='0'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/console&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;input type='mouse' bus='ps2'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;graphics type='vnc' port='-1' autoport='yes'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;sound model='es1370'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;hostdev mode='subsystem' type='usb' managed='no'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;vendor id='0x0103'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;product id='0x1771'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/source&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/hostdev&gt;<br>
&nbsp; &lt;/devices&gt;<br>
&lt;/domain&gt;<br>
<br>
At this point, I plugged in the USB device I am interested in and again
ran 'virsh', repeating the command above. Here is the output:<br>
<br>
[root@deafeng3 qemu]# virsh dumpxml Ubuntu9<br>
&lt;domain type='kvm'&gt;<br>
&nbsp; &lt;name&gt;Ubuntu9&lt;/name&gt;<br>
&nbsp; &lt;uuid&gt;cb8c3d15-fe92-1bf2-5676-03370743e815&lt;/uuid&gt;<br>
&nbsp; &lt;memory&gt;1572864&lt;/memory&gt;<br>
&nbsp; &lt;currentMemory&gt;1572864&lt;/currentMemory&gt;<br>
&nbsp; &lt;vcpu&gt;1&lt;/vcpu&gt;<br>
&nbsp; &lt;os&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;type arch='x86_64' machine='pc'&gt;hvm&lt;/type&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;boot dev='hd'/&gt;<br>
&nbsp; &lt;/os&gt;<br>
&nbsp; &lt;features&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;acpi/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;apic/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;pae/&gt;<br>
&nbsp; &lt;/features&gt;<br>
&nbsp; &lt;clock offset='utc'/&gt;<br>
&nbsp; &lt;on_poweroff&gt;destroy&lt;/on_poweroff&gt;<br>
&nbsp; &lt;on_reboot&gt;restart&lt;/on_reboot&gt;<br>
&nbsp; &lt;on_crash&gt;restart&lt;/on_crash&gt;<br>
&nbsp; &lt;devices&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;emulator&gt;/usr/bin/qemu-kvm&lt;/emulator&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;disk type='file' device='cdrom'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target dev='hdc' bus='ide'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;readonly/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/disk&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;disk type='file' device='disk'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source file='/var/lib/libvirt/images/Ubuntu9.img'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target dev='vda' bus='virtio'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/disk&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;interface type='network'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mac address='54:52:00:74:32:2f'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source network='default'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;model type='virtio'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/interface&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;serial type='pty'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target port='0'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/serial&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;console type='pty'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;target port='0'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/console&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;input type='mouse' bus='ps2'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;graphics type='vnc' port='-1' autoport='yes'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;sound model='es1370'/&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;hostdev mode='subsystem' type='usb' managed='no'&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;source&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;vendor id='0x0103'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;product id='0x1771'/&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/source&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/hostdev&gt;<br>
&nbsp; &lt;/devices&gt;<br>
&lt;/domain&gt;<br>
<br>
I'm not sure what device 0103:1771 is. Here is the output of lsusb.
Notice the device on bus 007 device 003. This is what I want the Ubuntu
machine to see and manage.<br>
<br>
[root@deafeng3 qemu]# lsusb<br>
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br>
Bus 007 Device 002: ID 0403:6001 Future Technology Devices
International, Ltd FT232 USB-Serial (UART) IC<br>
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br>
Bus 001 Device 006: ID 0c45:63f8 Microdia <br>
Bus 001 Device 011: ID 045e:0084 Microsoft Corp. Basic Optical Mouse<br>
Bus 001 Device 010: ID 046d:c315 Logitech, Inc. Classic New Touch
Keyboard<br>
Bus 001 Device 009: ID 051d:0002 American Power Conversion
Uninterruptible Power Supply<br>
Bus 001 Device 012: ID 413c:8153 Dell Computer Corp. <br>
Bus 001 Device 013: ID 413c:8154 Dell Computer Corp. <br>
Bus 001 Device 003: ID 413c:2513 Dell Computer Corp. <br>
Bus 001 Device 008: ID 0a5c:4500 Broadcom Corp. <br>
Bus 001 Device 007: ID 413c:8149 Dell Computer Corp. <br>
Bus 001 Device 004: ID 413c:2513 Dell Computer Corp. <br>
Bus 001 Device 002: ID 0424:2512 Standard Microsystems Corp. <br>
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<br>
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<br>
Bus 005 Device 002: ID 0a5c:5800 Broadcom Corp. <br>
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br>
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br>
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br>
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br>
<br>
Lastly, you wondered what command line qemu is using. I checked
/var/log/libvirt/qemu and at the very start of the file I see this:<br>
<br>
<br>
LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin /usr/bin/qemu-kvm -S -M pc
-m 1536 -smp 1 -name Ubuntu9 -uuid cb8c3d15-fe92-1bf2-5676-03370743e815
-monitor pty -pidfile /var/run/libvirt/qemu//Ubuntu9.pid -no-reboot
-boot d -drive
file=/home/rlc/Download/ubuntu-9.04-desktop-i386.iso,if=ide,media=cdrom,index=2
-drive file=/var/lib/libvirt/images/Ubuntu9.img,if=virtio,index=0 -net
nic,macaddr=54:52:00:74:32:2f,vlan=0,model=virtio -net
tap,fd=18,script=,vlan=0,ifname=vnet0 -serial pty -parallel none -usb
-vnc 127.0.0.1:0 <br>
char device redirected to /dev/pts/1<br>
char device redirected to /dev/pts/2<br>
info cpus<br>
* CPU #0: pc=0x00000000000ffff0 thread_id=3476
<br>
cont<br>
balloon 1536<br>
info balloon<br>
balloon: actual=1536
<br>
info balloon<br>
balloon: actual=1536
<br>
info balloon<br>
balloon: actual=1536
<br>
info balloon<br>
balloon: actual=1536
<br>
info balloon<br>
balloon: actual=1536<br>
[above two lines repeat for a few thousand lines]<br>
<br>
Advice appreciated. How can I get the USB device to work? By the way, I
thought I have an installed virtual machine on my hard drive, so I'm a
little puzzled that the reference <br>
<br>
-drive file=/home/rlc/Download/ubuntu-9.04-desktop-i386.iso<br>
<br>
still exists in the qemu-kvm command line. Am I still starting up from
the iso image? I'm confused.<br>
<br>
Bob<br>
<br>
</body>
</html>