Jump to: navigation, search

Difference between revisions of "Nova/USB device&USB controller"

(Proposed solution)
(Proposed solution)
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
== USB device and USB controller Features ==  
+
== USB device and USB controller features ==  
 +
 
 +
=== Related Content ===
 +
https://wiki.openstack.org/wiki/Nova/USB_controller_hot_cold_plug
 +
 
 +
https://wiki.openstack.org/wiki/Nova/USB_device_hot_cold_plug
 +
 
 +
https://wiki.openstack.org/wiki/USB-api-support
 +
 
 
=== Background ===
 
=== Background ===
Currently, nova has already supported function of pci-passthrough, but dosen't support usb-passthrough.  
+
Currently, nova has supported function of pci-passthrough, but hasn't supported usb-passthrough.  
I think usb-passthrough is also a important and necessary function especially in private cloud.
+
I think usb-passthrough is also a important and necessary function especially in private cloud.
  
 
=== User scenarios ===
 
=== User scenarios ===
1. When a user transfer money online, him may need a usb-key provided by bank for authentication.
+
1. When a administrator wants to deploy a vm for running erp software which need usb-key for authentication,  him may need to insert usb-key to a host(compute node) first and then run vm with usb-key in this host.  
 
 
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.
+
2. When a user wants to copy data from vm to a removable media for business trip him may need a usb data disk
 +
    ps:  The usb redirection technology over spice or vnc connection maybe more appropriate in thest scenarios.
  
 
=== Technical verification ===
 
=== Technical verification ===
 
1. Test case
 
1. Test case
    Attach different number of usb devices to different type of usb controllers.
+
    Creating vm with different type and number usb controller and usb device.
 +
 
 
2. Xml definition
 
2. Xml definition
 
   (1)Sample of usb controller:
 
   (1)Sample of usb controller:
Line 36: Line 44:
 
       <address type='usb' bus='1' port='1'/>
 
       <address type='usb' bus='1' port='1'/>
 
     </disk>
 
     </disk>
 +
 
3. The test results
 
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.
+
   (1)Usb controllers have a maximum port restriction. Uhci controller supports a maxmum of 2 ports while ehci controller supports 6.
   (2)If create vm without usb controller, qemu will default create a uhci controller but not creating other type's controllers by default.
+
   (2)If creating vm without usb controller, qemu will default create a piix3-usb-uhci controller but not creating the other type's.
   (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.
+
   (3)If creating 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.
+
   (4)There are two ways to support more usb devices. 1. Adding cascaded hubs and attaching usb devices to them. 2.Creating more controllers and connect usb devices to different ones.
   (5)When create vm with a pair of usb hub and ehci controller, the vm crashed. Qemu thrown a error(why?)
+
   (5)When creating vm with a pair of usb hub and ehci controller, the vm crashed. Qemu thrown a error(why?)
  
 
=== Proposed solution ===
 
=== Proposed solution ===
 
1. Use cases  
 
1. Use cases  
 
     Case 1:
 
     Case 1:
     (1)Admin/User request to create a flavor with usb controllers(key arguments: type, quantity).
+
     (1)Admin/User request to create a flavor with usb controllers(key arguments: type, count).
     (2)System create a flavor.
+
     (2)System creates a flavor containing usb controller information.
 
     (3)Admin/User request to create a vm with flavor created above.  
 
     (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.  
+
     (4)System first validates usb arguments specified in flavor, if valid then create a vm with usb controllers.  
   
+
 
 
     Case 2:
 
     Case 2:
 
     (1)Admin/User request to create a flavor with usb devices(key arguments: unique identifiers of devices).
 
     (1)Admin/User request to create a flavor with usb devices(key arguments: unique identifiers of devices).
     (2)System create a flavor.
+
     (2)System creates a flavor containing usb device information.
 
     (3)Admin/User request to create a vm with flavor created above.  
 
     (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 .  
+
     (4)System first validates 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:     
 
     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).
+
     (1)Admin/User request to create a flavor with usb controllers(key argument: type, count) and usb devices(key arguments: identifiers and usb controller type).
     (2)System create a flavor.
+
     (2)System creates a flavor containing usb device information and usb controller information.
 
     (3)Admin/User request to create a vm with flavor created above.  
 
     (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.
+
     (4)Admin/User first validate if usb devices are exist, available,in the same host, and matching with controllers(type, have available port and so on), if valid then create a vm with usb devices and usb controllers in the host.
 +
 
 +
2. System requirements and things should be considered for usb controller(An optional Implementation):
 +
    (1)System supports creating a flavor with usb controller.
 +
        Adding a property for usb controller to extra_specs field of flavor. The scheme may like {"usb_controllers":[{"type":"ehci", "count": 1}]}
 +
        '''Note:''' Because libvirt/qemu will create a default pii3-uhi controller, so system will only create usb controllers except pii3-uhci. 
 +
 
 +
    (2)System supports creating vm with usb controller.
 +
        Driver(ibvirt) layper need to support constructing usb controller xml configuration.
 +
 
 +
    (3)System supports managing relationship between usb controllers and usb devices and storing them in instance_system_metadata table, so that
 +
      <1>every usb device will have unique port, <2>vm can create usb controller and attach usb devices correctly the next starting.
 +
        The usb controller schema may like:
 +
        {
 +
          "usb_controller_requests":
 +
          [
 +
            {
 +
                "type": "ehci",
 +
                "count": 2,
 +
                "usb_controllers":
 +
                [
 +
                  {
 +
                    "index": 1,
 +
                    "ports":
 +
                    [
 +
                      {
 +
                        "port": 1,
 +
                        "usb_device_id": 5
 +
                      }
 +
                    ]
 +
                  }
 +
                ]
 +
            }
 +
          ]
 +
        }
 +
 
 +
3. System requirements and things should be considered for usb device(An optional Implementation):
 +
    (1)System supports discovering usb devices and saving them to DB.
 +
        The main process can refer to pci-passthrough implements:
 +
        <1>Using white-list function and lsusb like commands to retrieve available usb devices of a host.
 +
        <2>Adding a table usb_devices in DB to store usb device information.
 +
        <3>Adding auto-update function to synchronize information between host(compute node) and DB.
 +
 
 +
    (2)System supports creating a flavor with usb device.
 +
        Adding a property for usb device to extra_specs field of flavor. The scheme may like {"usb_devices":[{"usb_device_id": 5}]}
 +
        '''Note:'''
 +
        It is necessary to exposure usb device id(maybe some other information also are necessary) information to admin/user because the most common scenarios are attaching specified usb device to vm.
 +
        The mechanism of automatically selecting compute node to provide pci devices is not appropriate in here.
 +
 
 +
    (3)System supports creating vm with usb devices.
 +
        <1>Scheduler layer needs to scheduler request to the appropriate compute node, so a UsbDeviceFilter.py filter may be needed.
 +
        <2>Driver(ibvirt) layper supports constructing usb device xml configuration.
 +
        <3>Compute layer supports allocating usb controller for usb device.
 +
              If not specifying usb controllers in request, compute layer not specify usb controller for usb device, then libvirt/qemu will attach usb device to the default pii3-uhci controller.
 +
              If specifying usb controllers in request, system will first create usb controller which processes have been described above. It then choose available controller(type and port) for usb device.
 +
        <4>DB layper supports storing usb devices. The instance_system_metadata table is a good choice.
 +
              The usb device schema may like
 +
              {
 +
                "usb_devices_requests":
 +
                [
 +
                  {
 +
                    "usb_device_id": 5
 +
                  }
 +
                ]
 +
              }
 +
 
 +
    (4)System supports detaching usb devices when suspending a vm with usb devices, and re-attaching usb devices when resuming the vm.
 +
 
 +
    (5)System supports detaching usb devices before making snapshot of a vm and re-attaching usb devices after making snapshot. System also support the protection of usb device when using snapshot to resume a vm.
  
2. Things that should be considered:
+
     (6)System supports reporting error when migrating vm with usb device.
     (1)Support creating usb controller
+
        If a vm has usb devices attached, it is not allowed to migrate.
    There already have a bp for this in https://blueprints.launchpad.net/nova/+spec/add-usb-controller, the key processes are described below:
 
      <1>In extra_specs of flavor add a property for usb controller: eg {'controllers':[{'type':'piix3-uhci', 'quantity': 1},{'type':'ehci', 'quantity': 2}]} 
 
      <2>Add function of create usb controller in libvirt driver.
 
          Detailed things: How to generate index field which not duplicate from other controllers)?
 
     
 
    (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.
 

Latest revision as of 06:50, 5 March 2014

USB device and USB controller features

Related Content

https://wiki.openstack.org/wiki/Nova/USB_controller_hot_cold_plug

https://wiki.openstack.org/wiki/Nova/USB_device_hot_cold_plug

https://wiki.openstack.org/wiki/USB-api-support

Background

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

User scenarios

1. When a administrator wants to deploy a vm for running erp software which need usb-key for authentication, him may need to insert usb-key to a host(compute node) first and then run vm with usb-key in this host.

2. When a user wants to copy data from vm to a removable media for business trip him may need a usb data disk.

   ps:  The usb redirection technology over spice or vnc connection maybe more appropriate in thest scenarios.

Technical verification

1. Test case

    Creating vm with different type and number usb controller and usb device.

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 supports a maxmum of 2 ports while ehci controller supports 6.
  (2)If creating vm without usb controller, qemu will default create a piix3-usb-uhci controller but not creating the other type's.
  (3)If creating 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 to support more usb devices. 1. Adding cascaded hubs and attaching usb devices to them. 2.Creating more controllers and connect usb devices to different ones.
  (5)When creating 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, count).
   (2)System creates a flavor containing usb controller information.
   (3)Admin/User request to create a vm with flavor created above. 
   (4)System first validates 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 creates a flavor containing usb device information.
   (3)Admin/User request to create a vm with flavor created above. 
   (4)System first validates 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, count) and usb devices(key arguments: identifiers and usb controller type).
   (2)System creates a flavor containing usb device information and usb controller information.
   (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, have available port and so on), if valid then create a vm with usb devices and usb controllers in the host.

2. System requirements and things should be considered for usb controller(An optional Implementation):

   (1)System supports creating a flavor with usb controller.
       Adding a property for usb controller to extra_specs field of flavor. The scheme may like {"usb_controllers":[{"type":"ehci", "count": 1}]} 
       Note: Because libvirt/qemu will create a default pii3-uhi controller, so system will only create usb controllers except pii3-uhci.   
   (2)System supports creating vm with usb controller.
        Driver(ibvirt) layper need to support constructing usb controller xml configuration.
   (3)System supports managing relationship between usb controllers and usb devices and storing them in instance_system_metadata table, so that 
      <1>every usb device will have unique port, <2>vm can create usb controller and attach usb devices correctly the next starting. 
        The usb controller schema may like:
        {
          "usb_controller_requests":
          [
            {
               "type": "ehci",
               "count": 2,
               "usb_controllers":
               [
                 {
                   "index": 1,
                   "ports":
                   [
                     {
                        "port": 1,
                        "usb_device_id": 5
                     }
                   ]
                 } 
               ]
            }
          ]
        }

3. System requirements and things should be considered for usb device(An optional Implementation):

   (1)System supports discovering usb devices and saving them to DB.
        The main process can refer to pci-passthrough implements:
        <1>Using white-list function and lsusb like commands to retrieve available usb devices of a host.
        <2>Adding a table usb_devices in DB to store usb device information.
        <3>Adding auto-update function to synchronize information between host(compute node) and DB. 
   (2)System supports creating a flavor with usb device.
        Adding a property for usb device to extra_specs field of flavor. The scheme may like {"usb_devices":[{"usb_device_id": 5}]}
        Note: 
        It is necessary to exposure usb device id(maybe some other information also are necessary) information to admin/user because the most common scenarios are attaching specified usb device to vm.
        The mechanism of automatically selecting compute node to provide pci devices is not appropriate in here.
   (3)System supports creating vm with usb devices.
        <1>Scheduler layer needs to scheduler request to the appropriate compute node, so a UsbDeviceFilter.py filter may be needed.
        <2>Driver(ibvirt) layper supports constructing usb device xml configuration.
        <3>Compute layer supports allocating usb controller for usb device.
              If not specifying usb controllers in request, compute layer not specify usb controller for usb device, then libvirt/qemu will attach usb device to the default pii3-uhci controller.
              If specifying usb controllers in request, system will first create usb controller which processes have been described above. It then choose available controller(type and port) for usb device. 
        <4>DB layper supports storing usb devices. The instance_system_metadata table is a good choice. 
              The usb device schema may like
              {
                "usb_devices_requests":
                [
                  {
                    "usb_device_id": 5
                  }
               ]
             }
   (4)System supports detaching usb devices when suspending a vm with usb devices, and re-attaching usb devices when resuming the vm.
   (5)System supports detaching usb devices before making snapshot of a vm and re-attaching usb devices after making snapshot. System also support the protection of usb device when using snapshot to resume a vm.
   (6)System supports reporting error when migrating vm with usb device.
        If a vm has usb devices attached, it is not allowed to migrate.