Jump to: navigation, search

Nova/USB device&USB controller

< Nova
Revision as of 03:11, 3 March 2014 by Yj.yuan@huawei.com (talk | contribs) (Technical verification)

USB device and USB controller Features

Background

Currently, nova has already supported function of pci-passthrough, but dosen't support usb-passthrough. I think usb-passthrough is also a important and necessary function especially in private cloud.

User scenarios

1. When a user transfer money online, him may need a usb-key provided by bank for authentication.

2. When a user run a ERP software, him may need a usb-key provided by software provider for authentication.

3. When a user want to copy data to a removable media for business trip him may want a usb data disk.

Technical verification

1. Test case

   Attach different number of usb devices to different type of usb controllers.

2. Xml definition

  (1)Sample of usb controller:
   <controller type='usb' index='2' model='piix3-uhci'/>
   <controller type='usb' index='1' model='ehci'/>
  (2)Sample of pass-through usb devices
   <hostdev mode='subsystem' type='usb'>
    < source>
     <vendor id='0x136b'/>
     <product id='0x0003'/>
     <address bus='2' device='2'/>
    </source>
    <address type='usb' bus='1' port='1'/>
   </hostdev>
  (3)Sample of emulated usb disks
     <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      < source file='/home/vms/usb/sdb.qcow2'/>
      <target dev='sdb' bus='usb'/>
      <address type='usb' bus='1' port='1'/>
    </disk>

3. The test results

  (1)Usb controllers have a maximum port restriction. Uhci controller support maxmum of 2 while ehci controller support maxmum of 6.
  (2)If create vm without usb controller, qemu will default create a piix3-usb-uhci controller but not creating other type's controllers by default.
  (3)If create vm with usb device but no usb controller, the usb device will default be attached to the default uhci controller, but speed may mismatch.
  (4)There are two ways for supporting more usb devices. 1. Add cascaded hubs and connect usb devices to them. 2.Create more controllers and connect usb devices to different controllers.
  (5)When create vm with a pair of usb hub and ehci controller, the vm crashed. Qemu thrown a error(why?)

Proposed solution

1. Use cases

   Case 1:
   (1)Admin/User request to create a flavor with usb controllers(key arguments: type, quantity).
   (2)System create a flavor.
   (3)Admin/User request to create a vm with flavor created above. 
   (4)System first validate usb arguments specified in flavor, if valid then create a vm with usb controllers. 
   Case 2:
   (1)Admin/User request to create a flavor with usb devices(key arguments: unique identifiers of devices).
   (2)System create a flavor.
   (3)Admin/User request to create a vm with flavor created above. 
   (4)System first validate if usb devices are exist, available, and in the same host, if valid then create a vm with usb devices in the host. The usb devices will be attached to the default uhci controller created by qemu . 
   Case 3:    
   (1)Admin/User request to create a flavor with usb controllers(key argument: type, quantity) and usb devices(key arguments: identifiers and usb controller type).
   (2)System create a flavor.
   (3)Admin/User request to create a vm with flavor created above. 
   (4)Admin/User first validate if usb devices are exist, available,in the same host, and matching with controllers(type, free port and so on), if valid then create a vm with usb devices and usb controllers in the host. The usb devices will be attached to the controllers by type.

2. System requirements and things should be considered:

   (1)The system should support creating usb controllers. An optional Implementation is as follows:
      <1>Add a property to extra_specs of flavor. The scheme may like {'usb_controllers':[{'type':'piix3-uhci', 'quantity': 1},{'type':'ehci', 'quantity': 1}]}  
      <2>Add function of construct usb controller configuration in libvirt driver and config.
      <3>Add function to store usb controller data????. The usb controller data schema may like {'usb_controllers':[{'type':'piix3-uhci', 'index':'1', 'address':{'type':'pci','domain':'0x0000', 'bus':'0x00', 'slot':'0x01', 'function':'0x2'}, ports':[{'port':‘0’, 'status':'available', 'usb_device':}, {'port':‘1’, 'status':'used', 'usb_device':'dev1'}]}]}  
      Detailed things: 
      Make sure index field of controllers should not be duplicate.
     
   (2)Support attach usb device when create vm
   The basic processes can refer to pci-passthrough, are described below:
     <1>System automatically discover usb devices and save them to db.
         Detailed things:
         How to distinguish usb devices from other devices like usb controllers in a host?
         A datatable usb_devices may been needed for storing usb devices information like pci_devices.
         How to uniquely identify a usb device? One choose is node id + device id(address or label or dev_id) which stored in usb_devices.
         key arguments: identifiers that can find the device, like in which host, bus number and device number and so on
     <2>In extra_specs of flavor add a property for usb devices: eg {'devices':[{'node_id':'1', 'dev_id':'pci_0000_00_03_0', 'usbcontroller_type':'piix3-uhci'},{{'node_id':'1', 'dev_id':'pci_0000_00_03_1', 'usbcontroller_type':'ehci'}]}  
     <3>Add UsbDeviceFilter for locating the correct node.
     <4>Add algorithm in libvirt driver for choosing usb controller.
     And so on.