diff --git a/docs/configuration.markdown b/docs/configuration.markdown index b1390dd..2307153 100644 --- a/docs/configuration.markdown +++ b/docs/configuration.markdown @@ -88,6 +88,11 @@ end set, which should be fine for paravirtualized guests, but some fully virtualized guests may require hda. NOTE: this option also applies only to disks associated with a box image. +* `disk_address_type` - The address type of disk device to emulate. + Libvirt uses a sensible default if not set, but some fully virtualized guests + may need to override this (e.g. Debian on _virt_ machine may need _virtio-mmio_). + Possible values are documented in libvirt's [description for + _address_](https://libvirt.org/formatdomain.html#elementsAddress). * `disk_driver` - Extra options for the main disk driver ([see Libvirt documentation](http://libvirt.org/formatdomain.html#elementsDisks)). NOTE: this option also applies only to disks associated with a box image. In all cases, the value `nil` can be used to force the hypervisor default behaviour (e.g. to override settings defined in top-level Vagrantfiles). Supported options include: * `:cache` - Controls the cache mechanism. Possible values are "default", "none", "writethrough", "writeback", "directsync" and "unsafe". @@ -96,6 +101,7 @@ end * `:discard` - Controls whether discard requests (also known as "trim" or "unmap") are ignored or passed to the filesystem. Possible values are "unmap" or "ignore". Note: for discard to work, you will likely also need to set `disk_bus = 'scsi'` * `:detect_zeroes` - Controls whether to detect zero write requests. The value can be "off", "on" or "unmap". + * `address_type` - Address type of disk device to emulate. If unspecified, Libvirt uses a sensible default. * `nic_model_type` - parameter specifies the model of the network adapter when you create a domain value by default virtio KVM believe possible values, see the [documentation for diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index fc102f6..7b0d4cc 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -50,6 +50,7 @@ module VagrantPlugins @machine_arch = config.machine_arch @disk_controller_model = config.disk_controller_model @disk_driver_opts = config.disk_driver_opts + @disk_address_type = config.disk_address_type @nested = config.nested @memory_size = config.memory.to_i * 1024 @memory_backing = config.memory_backing diff --git a/lib/vagrant-libvirt/action/resolve_disk_settings.rb b/lib/vagrant-libvirt/action/resolve_disk_settings.rb index 2726995..f1a3f67 100644 --- a/lib/vagrant-libvirt/action/resolve_disk_settings.rb +++ b/lib/vagrant-libvirt/action/resolve_disk_settings.rb @@ -23,6 +23,7 @@ module VagrantPlugins domain_name = env[:domain_name] # only set on create disk_bus = config.disk_bus disk_device = config.disk_device + disk_address_type = config.disk_address_type domain_volume_cache = config.volume_cache || 'default' # Storage @@ -84,6 +85,7 @@ module VagrantPlugins device: env[:box_volumes][index][:device], cache: domain_volume_cache, bus: disk_bus, + address_type: disk_address_type, absolute_path: domain_volume.path, virtual_size: env[:box_volumes][index][:virtual_size], pool: pool_name, diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 402e57b..08aac8d 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -107,6 +107,7 @@ module VagrantPlugins attr_accessor :machine_virtual_size attr_accessor :disk_bus attr_accessor :disk_device + attr_accessor :disk_address_type attr_accessor :disk_controller_model attr_accessor :disk_driver_opts attr_accessor :nic_model_type @@ -281,6 +282,7 @@ module VagrantPlugins @machine_virtual_size = UNSET_VALUE @disk_bus = UNSET_VALUE @disk_device = UNSET_VALUE + @disk_address_type = UNSET_VALUE @disk_controller_model = UNSET_VALUE @disk_driver_opts = {} @nic_model_type = UNSET_VALUE @@ -794,6 +796,7 @@ module VagrantPlugins disk = { device: options[:device], type: options[:type], + address_type: options[:address_type], size: options[:size], path: options[:path], bus: options[:bus], @@ -1006,6 +1009,7 @@ module VagrantPlugins @disk_controller_model = nil end end + @disk_address_type = nil if @disk_address_type == UNSET_VALUE @disk_driver_opts = {} if @disk_driver_opts == UNSET_VALUE @nic_model_type = nil if @nic_model_type == UNSET_VALUE @nested = false if @nested == UNSET_VALUE diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 53e48b3..51f2ea6 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -152,6 +152,9 @@ <%# we need to ensure a unique target dev -%> + <%- if volume[:address_type] -%> +
+ <%- end -%> <%- end -%> <%- scsi_volumes = @domain_volumes.select { |x| x[:bus] == 'scsi' } %> @@ -172,6 +175,9 @@ -%>/> + <%- if d[:address_type] || @disk_address_type -%> +
+ <%- end -%> <%- if d[:shareable] -%> <%- end -%> diff --git a/spec/unit/templates/domain_all_settings.xml b/spec/unit/templates/domain_all_settings.xml index 07ff12b..b12c5f5 100644 --- a/spec/unit/templates/domain_all_settings.xml +++ b/spec/unit/templates/domain_all_settings.xml @@ -58,24 +58,35 @@ +
+
+
+
+ + + + + + +
diff --git a/spec/unit/templates/domain_spec.rb b/spec/unit/templates/domain_spec.rb index a4065c1..d1b8495 100644 --- a/spec/unit/templates/domain_spec.rb +++ b/spec/unit/templates/domain_spec.rb @@ -80,9 +80,11 @@ describe 'templates/domain' do domain.instance_variable_set('@domain_volume_cache', 'deprecated') domain.disk_bus = 'ide' domain.disk_device = 'vda' + domain.disk_address_type = 'virtio-mmio' domain.disk_driver(:cache => 'unsafe', :io => 'threads', :copy_on_read => 'on', :discard => 'unmap', :detect_zeroes => 'on') domain.storage(:file, path: 'test-disk1.qcow2') domain.storage(:file, path: 'test-disk2.qcow2', io: 'threads', copy_on_read: 'on', discard: 'unmap', detect_zeroes: 'on') + domain.storage(:file, path: 'test-disk3.qcow2', address_type: 'pci') domain.storage(:file, device: :floppy) domain.storage(:file, device: :cdrom) domain.storage(:file, device: :cdrom) @@ -141,12 +143,14 @@ describe 'templates/domain' do domain.domain_volumes.push({ :cache => 'unsafe', :bus => domain.disk_bus, - :absolute_path => '/var/lib/libvirt/images/test.qcow2' + :absolute_path => '/var/lib/libvirt/images/test.qcow2', + :address_type => 'virtio-mmio', }) domain.domain_volumes.push({ :cache => 'unsafe', :bus => domain.disk_bus, - :absolute_path => '/var/lib/libvirt/images/test2.qcow2' + :absolute_path => '/var/lib/libvirt/images/test2.qcow2', + :address_type => 'virtio-mmio', }) resolve