Adding disk_address_type option. (#954)

This patch allows to specify the virtio-mmio address type, which is
needed for debian guests on virt machines that don't support the PCI
address type.

See also 
https://translatedcode.wordpress.com/2016/11/03/installing-debian-on-qemus-32-bit-arm-virt-board/
where it is explicitly said to use `virtio-blk-device` and
`virtio-net-device` instead of `virtio-blk-pci` and `virtio-net-pci`, for
that reason.

Apparently, libvirt will use the `virtio-blk-pci` and `virtio-net-pci`
by default. By setting address type to `virtio-mmio`, it uses
`virtio-blk-device` instead. It seems not necessary to do the same for
the network controller, since libvirt will also use `virtio-net-device`
if the disk address type is set to `virtio-mmio`.

While this should help with ARM machines, it won't solve all issues
as some machines will boot perfectly with the existing defaults
provided the correct loader binary is used.

Relates-to: #1608
This commit is contained in:
Bram de Greve
2022-11-14 13:52:22 +01:00
committed by GitHub
parent df41f6f037
commit 6c4b7758aa
7 changed files with 36 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -152,6 +152,9 @@
<source file='<%= volume[:absolute_path] %>'/>
<%# we need to ensure a unique target dev -%>
<target dev='<%= volume[:device] %>' bus='<%= volume[:bus] %>'/>
<%- if volume[:address_type] -%>
<address type='<%= volume[:address_type] %>'/>
<%- end -%>
</disk>
<%- end -%>
<%- scsi_volumes = @domain_volumes.select { |x| x[:bus] == 'scsi' } %>
@@ -172,6 +175,9 @@
-%>/>
<source file='<%= d[:absolute_path] %>'/>
<target dev='<%= d[:device] %>' bus='<%= d[:bus] %>'/>
<%- if d[:address_type] || @disk_address_type -%>
<address type='<%= d[:address_type] || @disk_address_type %>'/>
<%- end -%>
<%- if d[:shareable] -%>
<shareable/>
<%- end -%>

View File

@@ -58,24 +58,35 @@
<driver name='qemu' type='qcow2' cache='unsafe' io='threads' copy_on_read='on' discard='unmap' detect_zeroes='on'/>
<source file='/var/lib/libvirt/images/test.qcow2'/>
<target dev='vda' bus='ide'/>
<address type='virtio-mmio'/>
</disk>
<disk type='file' device='disk'>
<alias name='ua-box-volume-1'/>
<driver name='qemu' type='qcow2' cache='unsafe' io='threads' copy_on_read='on' discard='unmap' detect_zeroes='on'/>
<source file='/var/lib/libvirt/images/test2.qcow2'/>
<target dev='vdb' bus='ide'/>
<address type='virtio-mmio'/>
</disk>
<disk type='file' device='disk'>
<alias name='ua-disk-volume-0'/>
<driver name='qemu' type='qcow2' cache='default'/>
<source file='/var/lib/libvirt/images/test-disk1.qcow2'/>
<target dev='vdc' bus='virtio'/>
<address type='virtio-mmio'/>
</disk>
<disk type='file' device='disk'>
<alias name='ua-disk-volume-1'/>
<driver name='qemu' type='qcow2' cache='default' io='threads' copy_on_read='on' discard='unmap' detect_zeroes='on'/>
<source file='/var/lib/libvirt/images/test-disk2.qcow2'/>
<target dev='vdd' bus='virtio'/>
<address type='virtio-mmio'/>
</disk>
<disk type='file' device='disk'>
<alias name='ua-disk-volume-2'/>
<driver name='qemu' type='qcow2' cache='default'/>
<source file='/var/lib/libvirt/images/test-disk3.qcow2'/>
<target dev='vde' bus='virtio'/>
<address type='pci'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw' />

View File

@@ -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