mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Merge pull request #490 from petRUShka/add_pcis
Add PCI device passthrough functionality
This commit is contained in:
commit
3bac45efb6
29
README.md
29
README.md
@ -28,6 +28,7 @@ welcome and can help a lot :-)
|
|||||||
- [Reload behavior](#reload-behavior-1)
|
- [Reload behavior](#reload-behavior-1)
|
||||||
- [CDROMs](#cdroms)
|
- [CDROMs](#cdroms)
|
||||||
- [Input](#input)
|
- [Input](#input)
|
||||||
|
- [PCI device passthrough](#pci-device-passthrough)
|
||||||
- [No box and PXE boot](#no-box-and-pxe-boot)
|
- [No box and PXE boot](#no-box-and-pxe-boot)
|
||||||
- [SSH Access To VM](#ssh-access-to-vm)
|
- [SSH Access To VM](#ssh-access-to-vm)
|
||||||
- [Forwarded Ports](#forwarded-ports)
|
- [Forwarded Ports](#forwarded-ports)
|
||||||
@ -502,6 +503,34 @@ Vagrant.configure("2") do |config|
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## PCI device passthrough
|
||||||
|
|
||||||
|
You can specify multiple PCI devices to passthrough to the VM via `libvirt.pci`. Available options are listed below. Note that all options are required:
|
||||||
|
|
||||||
|
* `bus` - The bus of the PCI device
|
||||||
|
* `slot` - The slot of the PCI device
|
||||||
|
* `function` - The function of the PCI device
|
||||||
|
|
||||||
|
You can extract that information from output of `lspci` command. First characters of each line are in format `[<bus>]:[<slot>].[<func>]`. Example
|
||||||
|
|
||||||
|
```
|
||||||
|
$ lspci| grep NVIDIA
|
||||||
|
03:00.0 VGA compatible controller: NVIDIA Corporation GK110B [GeForce GTX TITAN Black] (rev a1)
|
||||||
|
```
|
||||||
|
|
||||||
|
In that case `bus` is `0x03`, `slot` is `0x00` and `function` is `0x0`.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
Vagrant.configure("2") do |config|
|
||||||
|
config.vm.provider :libvirt do |libvirt|
|
||||||
|
libvirt.input :bus => '0x06', slot => '0x12', function => '0x5'
|
||||||
|
|
||||||
|
# Add another one if it is neccessary
|
||||||
|
libvirt.input :bus => '0x03', slot => '0x00', function => '0x0'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
## No box and PXE boot
|
## No box and PXE boot
|
||||||
|
|
||||||
There is support for PXE booting VMs with no disks as well as PXE booting VMs with blank disks. There are some limitations:
|
There is support for PXE booting VMs with no disks as well as PXE booting VMs with blank disks. There are some limitations:
|
||||||
|
@ -69,6 +69,9 @@ module VagrantPlugins
|
|||||||
# Input
|
# Input
|
||||||
@inputs = config.inputs
|
@inputs = config.inputs
|
||||||
|
|
||||||
|
# PCI device passthrough
|
||||||
|
@pcis = config.pcis
|
||||||
|
|
||||||
config = env[:machine].provider_config
|
config = env[:machine].provider_config
|
||||||
@domain_type = config.driver
|
@domain_type = config.driver
|
||||||
|
|
||||||
@ -180,9 +183,15 @@ module VagrantPlugins
|
|||||||
@cdroms.each do |cdrom|
|
@cdroms.each do |cdrom|
|
||||||
env[:ui].info(" -- CDROM(#{cdrom[:dev]}): #{cdrom[:path]}")
|
env[:ui].info(" -- CDROM(#{cdrom[:dev]}): #{cdrom[:path]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
@inputs.each do |input|
|
@inputs.each do |input|
|
||||||
env[:ui].info(" -- INPUT: type=#{input[:type]}, bus=#{input[:bus]}")
|
env[:ui].info(" -- INPUT: type=#{input[:type]}, bus=#{input[:bus]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@pcis.each do |pci|
|
||||||
|
env[:ui].info(" -- PCI passthrough: #{pci[:bus]}:#{pci[:slot]}.#{pci[:function]}")
|
||||||
|
end
|
||||||
|
|
||||||
env[:ui].info(" -- Command line : #{@cmd_line}")
|
env[:ui].info(" -- Command line : #{@cmd_line}")
|
||||||
|
|
||||||
# Create libvirt domain.
|
# Create libvirt domain.
|
||||||
|
@ -90,6 +90,9 @@ module VagrantPlugins
|
|||||||
# Inputs
|
# Inputs
|
||||||
attr_accessor :inputs
|
attr_accessor :inputs
|
||||||
|
|
||||||
|
# PCI device passthrough
|
||||||
|
attr_accessor :pcis
|
||||||
|
|
||||||
# Suspend mode
|
# Suspend mode
|
||||||
attr_accessor :suspend_mode
|
attr_accessor :suspend_mode
|
||||||
|
|
||||||
@ -144,6 +147,9 @@ module VagrantPlugins
|
|||||||
# Inputs
|
# Inputs
|
||||||
@inputs = UNSET_VALUE
|
@inputs = UNSET_VALUE
|
||||||
|
|
||||||
|
# PCI device passthrough
|
||||||
|
@pcis = UNSET_VALUE
|
||||||
|
|
||||||
# Suspend mode
|
# Suspend mode
|
||||||
@suspend_mode = UNSET_VALUE
|
@suspend_mode = UNSET_VALUE
|
||||||
end
|
end
|
||||||
@ -198,6 +204,22 @@ module VagrantPlugins
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pci(options={})
|
||||||
|
if options[:bus].nil? || options[:slot].nil? || options[:function].nil?
|
||||||
|
raise 'Bus AND slot AND function must be specified. Check `lspci` for that numbers.'
|
||||||
|
end
|
||||||
|
|
||||||
|
if @pcis == UNSET_VALUE
|
||||||
|
@pcis = []
|
||||||
|
end
|
||||||
|
|
||||||
|
@pcis.push({
|
||||||
|
bus: options[:bus],
|
||||||
|
slot: options[:slot],
|
||||||
|
function: options[:function]
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
# NOTE: this will run twice for each time it's needed- keep it idempotent
|
# NOTE: this will run twice for each time it's needed- keep it idempotent
|
||||||
def storage(storage_type, options={})
|
def storage(storage_type, options={})
|
||||||
if storage_type == :file
|
if storage_type == :file
|
||||||
|
@ -92,5 +92,15 @@
|
|||||||
<model type='<%= @video_type %>' vram='<%= @video_vram %>' heads='1'/>
|
<model type='<%= @video_type %>' vram='<%= @video_vram %>' heads='1'/>
|
||||||
</video>
|
</video>
|
||||||
<%#End Video -%>
|
<%#End Video -%>
|
||||||
|
<% @pcis.each do |pci| %>
|
||||||
|
<hostdev mode='subsystem' type='pci' managed='yes'>
|
||||||
|
<source>
|
||||||
|
<address domain='0x0000'
|
||||||
|
bus='<%= pci[:bus] %>'
|
||||||
|
slot='<%= pci[:slot] %>'
|
||||||
|
function='<%= pci[:function] %>'/>
|
||||||
|
</source>
|
||||||
|
</hostdev>
|
||||||
|
<% end %>
|
||||||
</devices>
|
</devices>
|
||||||
</domain>
|
</domain>
|
||||||
|
Loading…
Reference in New Issue
Block a user