[libvirt-users] How to attach USB disk to specified USB controller in domian?

Hi guys, I want to attach a few USB disks to specified USB controller in domain on libvirt layer, but I didn't find any method to deal with it. Anyone can help me on that? I added some USB type disk to my domain, started it, I found all USB disk had been attached to same USB controller automatically, I want to assign some USB disks to another controller manually but I can't find the entry. qemu-kvm has provided command line to support it by using "bus" argument.(like: device_add usb-storage,id=my_usb_disk,drive=my_usb_disk,bus=usb.0 ) Action steps: 1. Add some USB disks to domain xml, <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-1.img'/> <target dev='sda' bus='usb'/> <alias name='usb-disk0'/> </disk> <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-2.img'/> <target dev='sdb' bus='usb'/> <alias name='usb-disk1'/> </disk> ... 2. Added more than 2 USB controller to domain xml <controller type='usb' index='0'> <alias name='usb0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='usb' index='1'> <alias name='usb1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/> </controller> <controller type='usb' index='2'> <alias name='usb2'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> </controller> <controller type='usb' index='3'> <alias name='usb3'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/> </controller> 3. Enter into guest OS to check those usb device [root@localhost ~]# lsusb -t /: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M |__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 2: Dev 3, If 0, Class=Hub, Driver=hub/8p, 12M |__ Port 1: Dev 4, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 2: Dev 5, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 3: Dev 6, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 4: Dev 7, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 5: Dev 8, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 6: Dev 9, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 7: Dev 10, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 8: Dev 11, If 0, Class=Hub, Driver=hub/8p, 12M |__ Port 1: Dev 12, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 2: Dev 13, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 3: Dev 14, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 4: Dev 15, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 5: Dev 16, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 6: Dev 17, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 7: Dev 18, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 8: Dev 19, If 0, Class=Hub, Driver=hub/8p, 12M |__ Port 1: Dev 20, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 2: Dev 21, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 3: Dev 22, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 4: Dev 23, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 5: Dev 24, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 6: Dev 25, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 7: Dev 26, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 8: Dev 27, If 0, Class=Hub, Driver=hub/8p, 12M |__ Port 1: Dev 28, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 2: Dev 29, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 3: Dev 30, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 4: Dev 31, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 5: Dev 32, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 6: Dev 33, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 7: Dev 34, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 8: Dev 35, If 0, Class=Hub, Driver=hub/8p, 12M |__ Port 1: Dev 36, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 2: Dev 37, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 3: Dev 38, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 4: Dev 39, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 5: Dev 40, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 6: Dev 41, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 7: Dev 42, If 0, Class=Mass Storage, Driver=usb-storage, 12M |__ Port 8: Dev 43, If 0, Class=Mass Storage, Driver=usb-storage, 12M /: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M [root@localhost ~]# BR, Jianwei

On 12/17/2013 02:47 AM, Jianwei Hu wrote:
Hi guys,
I want to attach a few USB disks to specified USB controller in domain on libvirt layer, but I didn't find any method to deal with it. Anyone can help me on that?
I added some USB type disk to my domain, started it, I found all USB disk had been attached to same USB controller automatically, I want to assign some USB disks to another controller manually but I can't find the entry. qemu-kvm has provided command line to support it by using "bus" argument.(like: device_add usb-storage,id=my_usb_disk,drive=my_usb_disk,bus=usb.0 )
Action steps: 1. Add some USB disks to domain xml, <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-1.img'/> <target dev='sda' bus='usb'/> <alias name='usb-disk0'/> </disk>
To force the guest to see the device under a particular UBS controller, you need to include an <address> designation in your XML. Check the 'virsh dumpxml' output to see what <address> got autogenerated for your use case, then adjust the bus number in that address to instead point to the controller number you want it associated with. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Hi all, According to Eric's approach, I dumped its xml, but can not find its address as mentioned in former mail(Or,is it a bug?). Could you show me a detailed example for my doubt, thanks. # virsh dumpxml rhel <domain type='kvm' id='7'> <name>rhel</name> <uuid>205c40e0-e917-47fe-9c4a-1f35748ffd21</uuid> <memory unit='KiB'>1048576</memory> <currentMemory unit='KiB'>1048576</currentMemory> ... <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source file='/mnt/jiahu/images/rhel.img'> <seclabel model='selinux' labelskip='yes'/> </source> <target dev='vda' bus='virtio'/> <alias name='virtio-disk0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </disk> <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-1.img'/> <target dev='sda' bus='usb'/> <======== no USB bus related address or other address assigned to it. <alias name='usb-disk0'/> </disk> <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-2.img'/> <target dev='sdb' bus='usb'/> <alias name='usb-disk1'/> </disk> <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-3.img'/> <target dev='sdc' bus='usb'/> <alias name='usb-disk2'/> </disk> <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-4.img'/> <target dev='sdd' bus='usb'/> <alias name='usb-disk3'/> </disk> ... BR, Jianwei ----- Original Message ----- From: "Eric Blake" <eblake@redhat.com> To: "Jianwei Hu" <jiahu@redhat.com>, libvirt-users@redhat.com Sent: Tuesday, December 17, 2013 11:58:08 PM Subject: Re: [libvirt-users] How to attach USB disk to specified USB controller in domian? On 12/17/2013 02:47 AM, Jianwei Hu wrote:
Hi guys,
I want to attach a few USB disks to specified USB controller in domain on libvirt layer, but I didn't find any method to deal with it. Anyone can help me on that?
I added some USB type disk to my domain, started it, I found all USB disk had been attached to same USB controller automatically, I want to assign some USB disks to another controller manually but I can't find the entry. qemu-kvm has provided command line to support it by using "bus" argument.(like: device_add usb-storage,id=my_usb_disk,drive=my_usb_disk,bus=usb.0 )
Action steps: 1. Add some USB disks to domain xml, <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-1.img'/> <target dev='sda' bus='usb'/> <alias name='usb-disk0'/> </disk>
To force the guest to see the device under a particular UBS controller, you need to include an <address> designation in your XML. Check the 'virsh dumpxml' output to see what <address> got autogenerated for your use case, then adjust the bus number in that address to instead point to the controller number you want it associated with. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Is there anyone who know detailed address formats for particular USB controller in attached USB disk of Domain XML? BR, Jianwei ----- Original Message ----- From: "Jianwei Hu" <jiahu@redhat.com> To: "Eric Blake" <eblake@redhat.com>, libvirt-users@redhat.com Sent: Wednesday, December 18, 2013 11:21:36 AM Subject: Re: [libvirt-users] How to attach USB disk to specified USB controller in domian? Hi all, According to Eric's approach, I dumped its xml, but can not find its address as mentioned in former mail(Or,is it a bug?). Could you show me a detailed example for my doubt, thanks. # virsh dumpxml rhel <domain type='kvm' id='7'> <name>rhel</name> <uuid>205c40e0-e917-47fe-9c4a-1f35748ffd21</uuid> <memory unit='KiB'>1048576</memory> <currentMemory unit='KiB'>1048576</currentMemory> ... <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source file='/mnt/jiahu/images/rhel.img'> <seclabel model='selinux' labelskip='yes'/> </source> <target dev='vda' bus='virtio'/> <alias name='virtio-disk0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> </disk> <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-1.img'/> <target dev='sda' bus='usb'/> <======== no USB bus related address or other address assigned to it. <alias name='usb-disk0'/> </disk> <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-2.img'/> <target dev='sdb' bus='usb'/> <alias name='usb-disk1'/> </disk> <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-3.img'/> <target dev='sdc' bus='usb'/> <alias name='usb-disk2'/> </disk> <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-4.img'/> <target dev='sdd' bus='usb'/> <alias name='usb-disk3'/> </disk> ... BR, Jianwei ----- Original Message ----- From: "Eric Blake" <eblake@redhat.com> To: "Jianwei Hu" <jiahu@redhat.com>, libvirt-users@redhat.com Sent: Tuesday, December 17, 2013 11:58:08 PM Subject: Re: [libvirt-users] How to attach USB disk to specified USB controller in domian? On 12/17/2013 02:47 AM, Jianwei Hu wrote:
Hi guys,
I want to attach a few USB disks to specified USB controller in domain on libvirt layer, but I didn't find any method to deal with it. Anyone can help me on that?
I added some USB type disk to my domain, started it, I found all USB disk had been attached to same USB controller automatically, I want to assign some USB disks to another controller manually but I can't find the entry. qemu-kvm has provided command line to support it by using "bus" argument.(like: device_add usb-storage,id=my_usb_disk,drive=my_usb_disk,bus=usb.0 )
Action steps: 1. Add some USB disks to domain xml, <disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/var/lib/libvirt/images/usb-img/usb-1.img'/> <target dev='sda' bus='usb'/> <alias name='usb-disk0'/> </disk>
To force the guest to see the device under a particular UBS controller, you need to include an <address> designation in your XML. Check the 'virsh dumpxml' output to see what <address> got autogenerated for your use case, then adjust the bus number in that address to instead point to the controller number you want it associated with. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Jianwei Hu