USB controller configuration (#861)

* Add USB controller configuration

* Update README with USB controller configuration info

* Rename USB controller parameter to usb_controller

* Code style fixup
This commit is contained in:
David Scaife
2018-03-18 19:25:01 +11:00
committed by Dmitry Vasilets
parent c3e46a1f23
commit 60e93d4925
6 changed files with 58 additions and 0 deletions

View File

@@ -36,6 +36,7 @@ can help a lot :-)
- [CDROMs](#cdroms) - [CDROMs](#cdroms)
- [Input](#input) - [Input](#input)
- [PCI device passthrough](#pci-device-passthrough) - [PCI device passthrough](#pci-device-passthrough)
- [USB Controller Configuration](#usb-controller-configuration)
- [USB Redirector Devices](#usb-redirector-devices) - [USB Redirector Devices](#usb-redirector-devices)
- [Random number generator passthrough](#random-number-generator-passthrough) - [Random number generator passthrough](#random-number-generator-passthrough)
- [Watchdog·Device](#watchdog-device) - [Watchdog·Device](#watchdog-device)
@@ -833,6 +834,26 @@ Note! Above options affect configuration only at domain creation. It won't chang
Don't forget to [set](#domain-specific-options) `kvm_hidden` option to `true` especially if you are passthroughing NVIDIA GPUs. Otherwise GPU is visible from VM but cannot be operated. Don't forget to [set](#domain-specific-options) `kvm_hidden` option to `true` especially if you are passthroughing NVIDIA GPUs. Otherwise GPU is visible from VM but cannot be operated.
## USB Controller Configuration
The USB controller can be configured using `libvirt.usb_controller`, with the following options:
* `model` - The USB controller device model to emulate. (mandatory)
* `ports` - The number of devices that can be connected to the controller.
See the [libvirt documentation](https://libvirt.org/formatdomain.html#elementsControllers) for a list of valid models.
```ruby
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
# Set up a USB3 controller
libvirt.usb_controller :model => "nec-xhci"
end
end
```
## USB Redirector Devices ## USB Redirector Devices
You can specify multiple redirect devices via `libvirt.redirdev`. There are two types, `tcp` and `spicevmc` supported, for forwarding USB-devices to the guest. Available options are listed below. You can specify multiple redirect devices via `libvirt.redirdev`. There are two types, `tcp` and `spicevmc` supported, for forwarding USB-devices to the guest. Available options are listed below.

View File

@@ -95,6 +95,9 @@ module VagrantPlugins
# Watchdog device # Watchdog device
@watchdog_dev = config.watchdog_dev @watchdog_dev = config.watchdog_dev
# USB controller
@usbctl_dev = config.usbctl_dev
# USB device passthrough # USB device passthrough
@usbs = config.usbs @usbs = config.usbs
@@ -260,6 +263,12 @@ module VagrantPlugins
env[:ui].info(" -- Watchdog device: model=#{@watchdog_dev[:model]}, action=#{@watchdog_dev[:action]}") env[:ui].info(" -- Watchdog device: model=#{@watchdog_dev[:model]}, action=#{@watchdog_dev[:action]}")
end end
if not @usbctl_dev.empty?
msg = " -- USB controller: model=#{@usbctl_dev[:model]}"
msg += ", ports=#{@usbctl_dev[:ports]}" if @usbctl_dev[:ports]
env[:ui].info(msg)
end
@usbs.each do |usb| @usbs.each do |usb|
usb_dev = [] usb_dev = []
usb_dev.push("bus=#{usb[:bus]}") if usb[:bus] usb_dev.push("bus=#{usb[:bus]}") if usb[:bus]

View File

@@ -132,6 +132,9 @@ module VagrantPlugins
# Watchdog device # Watchdog device
attr_accessor :watchdog_dev attr_accessor :watchdog_dev
# USB controller
attr_accessor :usbctl_dev
# USB device passthrough # USB device passthrough
attr_accessor :usbs attr_accessor :usbs
@@ -245,6 +248,9 @@ module VagrantPlugins
# Watchdog device # Watchdog device
@watchdog_dev = UNSET_VALUE @watchdog_dev = UNSET_VALUE
# USB controller
@usbctl_dev = UNSET_VALUE
# USB device passthrough # USB device passthrough
@usbs = UNSET_VALUE @usbs = UNSET_VALUE
@@ -434,6 +440,19 @@ module VagrantPlugins
end end
def usb_controller(options = {})
if options[:model].nil?
raise 'USB controller model must be specified.'
end
if @usbctl_dev == UNSET_VALUE
@usbctl_dev = {}
end
@usbctl_dev[:model] = options[:model]
@usbctl_dev[:ports] = options[:ports]
end
def usb(options = {}) def usb(options = {})
if (options[:bus].nil? || options[:device].nil?) && options[:vendor].nil? && options[:product].nil? if (options[:bus].nil? || options[:device].nil?) && options[:vendor].nil? && options[:product].nil?
raise 'Bus and device and/or vendor and/or product must be specified. Check `lsusb` for these.' raise 'Bus and device and/or vendor and/or product must be specified. Check `lsusb` for these.'
@@ -709,6 +728,9 @@ module VagrantPlugins
# Watchdog device # Watchdog device
@watchdog_dev = {} if @watchdog_dev == UNSET_VALUE @watchdog_dev = {} if @watchdog_dev == UNSET_VALUE
# USB controller
@usbctl_dev = {} if @usbctl_dev == UNSET_VALUE
# USB device passthrough # USB device passthrough
@usbs = [] if @usbs == UNSET_VALUE @usbs = [] if @usbs == UNSET_VALUE

View File

@@ -243,6 +243,10 @@
</backend> </backend>
</tpm> </tpm>
<% end -%> <% end -%>
<% if not @usbctl_dev.empty? %>
<%# USB Controller -%>
<controller type='usb' model='<%= @usbctl_dev[:model] %>' <%= "ports=\"#{@usbctl_dev[:ports]}\" " if @usbctl_dev[:ports] %>/>
<% end %>
</devices> </devices>
<% unless @qargs.empty? %> <% unless @qargs.empty? %>

View File

@@ -128,6 +128,7 @@
<device path='/dev/tpm0'/> <device path='/dev/tpm0'/>
</backend> </backend>
</tpm> </tpm>
<controller type='usb' model='nec-xhci' ports="4" />
</devices> </devices>
<qemu:commandline> <qemu:commandline>

View File

@@ -64,6 +64,7 @@ describe 'templates/domain' do
domain.random(model: 'random') domain.random(model: 'random')
domain.pci(bus: '0x06', slot: '0x12', function: '0x5') domain.pci(bus: '0x06', slot: '0x12', function: '0x5')
domain.pci(bus: '0x03', slot: '0x00', function: '0x0') domain.pci(bus: '0x03', slot: '0x00', function: '0x0')
domain.usb_controller(model: 'nec-xhci', ports: '4')
domain.usb(bus: '1', device: '2', vendor: '0x1234', product: '0xabcd') domain.usb(bus: '1', device: '2', vendor: '0x1234', product: '0xabcd')
domain.redirdev(type: 'tcp', host: 'localhost', port: '4000') domain.redirdev(type: 'tcp', host: 'localhost', port: '4000')
domain.redirfilter(class: '0x0b', vendor: '0x08e6', domain.redirfilter(class: '0x0b', vendor: '0x08e6',