openstack usb透传研究分析( centos7 )


The bus/device IDs can be obtained from virsh via the   'virsh nodedev-list --tree'   and   'virsh nodedev-dumpxml'   commands or using ' lsusb ' to determine the bus and device.
我采用的是lsusb来查看usb设备的编号,第一种方法,太麻烦了。
[root@nail-SBCJ-5-3-3 home]#   lsusb
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 004: ID 0930:6544 Toshiba Corp. Kingston DataTraveler 2.0 Stick (2GB)
修改xml文件,填好字段   vendor:product(0930:6544 )
[root@nail-SBCJ-5-3-3 home]# cat usb.xml
        
            
            
        
      
或者修改xml文件,填好字段address
[root@nail-SBCJ-5-3-3 home]# cat usb1.xml
        
            
        
      
挂载usb设备
[root@Nail-SBCJ-slot5 home]# virsh attach-device instance-0000005d usb.xml
Device attached successfully
挂载成功后,虚拟机的xml里面会添加一段
 
     
       
       
       
     
     
   
虚拟机里面也会看到相应的u盘设备,如下在控制台里面,看到虚拟机识别到u盘为sdb,mount u盘分区后,可以看到u盘的内容。




3 u盘已经挂载成功之后,再尝试把u盘挂载到新的虚拟机,挂载失败
[root@Nail-SBCJ-slot5 home]#
[root@Nail-SBCJ-slot5 home]# virsh attach-device instance-00000061 usb.xml
error: Failed to attach device from usb.xml
error: Requested operation is not valid: USB device 002:004 is in use by domain instance-0000005d

You have new mail in /var/spool/mail/root
[root@Nail-SBCJ-slot5 home]# 

解挂载命令
[root@Nail-SBCJ-slot5 home]# virsh detach-device instance-0000005d usb.xml
Device detached successfully


  
  遇到的问题:
   1 lsusb命令不识别
      解决:安装   usbutils-007-4.el7.x86_64.rpm --nodeps
   2 有多个usb的时候,怎么判断虚拟机要哪个usb设备
     ?
   3 attach的时候,提示   'usb-host' is not a valid device model name
      解决:编译qemu的时候,带参数   --enable-libusb,并且编译好之后,要安装 rbd包

    From qemu-1.7 release version, the old usb-host(host-linux.c) had been removed,
    re-implemented by libusbx. So you should build qemu with --enable-libusb, then
    you can use usb pass-through capacity.
   4 如果usb分区成两个分区,不清楚对挂载有没有影响,需要进行测试验证,没有影响。
   5 u盘被一个虚拟机挂载之后,其他虚拟机不可以再挂载这个u盘
   
参考资料
https://ask.openstack.org/en/question/2612/feature-to-attach-usb-on-guest-vm/
http://rolandtapken.de/blog/2011-04/how-auto-hotplug-usb-devices-libvirt-vms-update-1
http://lists.gnu.org/archive/html/qemu-devel/2014-05/msg03629.html

你可能感兴趣的:(openstack)