Jump to: navigation, search

Nova/USB device hot cold plug

USB device hot/cold plug features

Related Content

https://wiki.openstack.org/wiki/Nova/USB_device%26USB_controller

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

Background

Adding usb devices to a exist vm is a necessary supplement features to usb device passthrough.

User scenarios

When a user transfers money online, him may need to attach a usb-key provided by bank to vm for authentication.

Technical verification

1. Test case

   (1)Attaching different type and number usb controllers and usb devices to vm when vm in diffrent status(running, stopped and so on).
   (2)Detaching usb devices from vm when vm in diffrent status(running, stopped and so on).

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)Command of adding usb controller:
       virsh attach-device vm usb.xml --config
       virsh attach-device vm usb.xml
  (4)Command of removing usb controller:
       virsh detach-device vm usb.xml --config
       virsh detach-device vm usb.xml

3. The test results

   (1)Libvirt/qemu support attaching usb device to vm or removing usb device from vm when vm in stopped status, just modify vm xml configuration.
   (2)Libvirt/qemu support attaching usb device to vm or removing usb device from vm when vm in running/suspended status, not only modify vm xml configuration but apply changes to guest os.

Proposed solution

1. Use cases

   Case 1:
  (1)Admin/User request to query usb devices information of a host(compute node).
  (2)System return usb devices information of a host.
   Case 2:
  (1)Admin/User request to attach usb devices(key arguments: unique identifiers of devices, usb controller type) to a vm.
  (2)System first validates usb arguments and vm's status, if valid then attach usb devices to vm.
  Case 3:
  (1)Admin/User request to detach usb devices(key arguments: unique identifiers of devices) from a vm.
  (2)System first validates usb arguments and vm's status, if valid then detach usb devices from vm.
  

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

   (1)System supports querying usb devices of a host.
   (2)System supports attaching usb devices to a vm.
       In case <1>usb devices have been used by other vm, <2> usb devices are not in the same host of vm, <3>vm have not matched usb controllers or no available port,  system throws an error.     
       If vm is stopped, then just adding xml configuration of usb devices.
       If vm is running or suspended, then both adding xml configuration of usb devices and attaching usb devices to guest os. 
       System updates usb_controller_requests property and usb_devices_requests property of instance_system_metadata table.
   (3)System supports attaching usb devices to a vm.
       If vm is stopped, then just removing xml configuration of usb devices.
       If vm is running or suspended, then both removing xml configuration of usb devices and detaching usb devices from guest os. 
       System updates usb_controller_requests property and usb_devices_requests property of instance_system_metadata table.