Add disk driver options with minor refactor (#1000)

Adds disk driver options: io, copy_on_read, discard and detect_zeroes
for both the primary vm disk and additional disks.

Minor refactor of existing volume_cache to deprecate and replace with a
single call to disk_driver that contains all of the options. Usage of
the volume_cache option will now result in a message to ui that it has
been replaced, as well as a warning that it is ignored if disk_driveris
set.

The old option volume_cache is only used if disk_driver is not present
(even if :cache is not set - in that case, the hypervisor default is
always used).

Resolves #998
This commit is contained in:
David Scaife
2020-12-17 22:03:47 +11:00
committed by GitHub
parent d0787c803d
commit 5471caabe5
6 changed files with 72 additions and 21 deletions

View File

@@ -55,11 +55,12 @@ module VagrantPlugins
@machine_arch = config.machine_arch
@disk_bus = config.disk_bus
@disk_device = config.disk_device
@disk_driver_opts = config.disk_driver_opts
@nested = config.nested
@memory_size = config.memory.to_i * 1024
@memory_backing = config.memory_backing
@management_network_mac = config.management_network_mac
@domain_volume_cache = config.volume_cache
@domain_volume_cache = config.volume_cache || 'default'
@kernel = config.kernel
@cmd_line = config.cmd_line
@emulator_path = config.emulator_path
@@ -250,7 +251,13 @@ module VagrantPlugins
end
env[:ui].info(" -- Storage pool: #{@storage_pool_name}")
env[:ui].info(" -- Image: #{@domain_volume_path} (#{env[:box_virtual_size]}G)")
env[:ui].info(" -- Volume Cache: #{@domain_volume_cache}")
if not @disk_driver_opts.empty?
env[:ui].info(" -- Disk driver opts: #{@disk_driver_opts.reject { |k,v| v.nil? }.map { |k,v| "#{k}='#{v}'"}.join(' ')}")
else
env[:ui].info(" -- Disk driver opts: cache='#{@domain_volume_cache}'")
end
env[:ui].info(" -- Kernel: #{@kernel}")
env[:ui].info(" -- Initrd: #{@initrd}")
env[:ui].info(" -- Graphics Type: #{@graphics_type}")

View File

@@ -95,9 +95,10 @@ module VagrantPlugins
attr_accessor :machine_virtual_size
attr_accessor :disk_bus
attr_accessor :disk_device
attr_accessor :disk_driver_opts
attr_accessor :nic_model_type
attr_accessor :nested
attr_accessor :volume_cache
attr_accessor :volume_cache # deprecated, kept for backwards compatibility; use disk_driver
attr_accessor :kernel
attr_accessor :cmd_line
attr_accessor :initrd
@@ -234,6 +235,7 @@ module VagrantPlugins
@machine_virtual_size = UNSET_VALUE
@disk_bus = UNSET_VALUE
@disk_device = UNSET_VALUE
@disk_driver_opts = {}
@nic_model_type = UNSET_VALUE
@nested = UNSET_VALUE
@volume_cache = UNSET_VALUE
@@ -587,6 +589,12 @@ module VagrantPlugins
@smartcard_dev[:source_service] = options[:source_service] if @smartcard_dev[:type] == 'tcp'
end
# Disk driver options for primary disk
def disk_driver(options = {})
supported_opts = [:cache, :io, :copy_on_read, :discard, :detect_zeroes]
@disk_driver_opts = options.select { |k,_| supported_opts.include? k }
end
# NOTE: this will run twice for each time it's needed- keep it idempotent
def storage(storage_type, options = {})
if storage_type == :file
@@ -641,6 +649,10 @@ module VagrantPlugins
allow_existing: options[:allow_existing],
shareable: options[:shareable],
serial: options[:serial],
io: options[:io],
copy_on_read: options[:copy_on_read],
discard: options[:discard],
detect_zeroes: options[:detect_zeroes],
pool: options[:pool], # overrides storage_pool setting for additional disks
wwn: options[:wwn],
}
@@ -795,9 +807,10 @@ module VagrantPlugins
@machine_virtual_size = nil if @machine_virtual_size == UNSET_VALUE
@disk_bus = 'virtio' if @disk_bus == UNSET_VALUE
@disk_device = 'vda' if @disk_device == 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
@volume_cache = 'default' if @volume_cache == UNSET_VALUE
@volume_cache = nil if @volume_cache == UNSET_VALUE
@kernel = nil if @kernel == UNSET_VALUE
@cmd_line = '' if @cmd_line == UNSET_VALUE
@initrd = '' if @initrd == UNSET_VALUE
@@ -915,6 +928,14 @@ module VagrantPlugins
end
end
if !machine.provider_config.volume_cache.nil? and machine.provider_config.volume_cache != UNSET_VALUE
machine.ui.warn("Libvirt Provider: volume_cache is deprecated. Use disk_driver :cache => '#{machine.provider_config.volume_cache}' instead.")
if !machine.provider_config.disk_driver_opts.empty?
machine.ui.warn("Libvirt Provider: volume_cache has no effect when disk_driver is defined.")
end
end
{ 'Libvirt Provider' => errors }
end
@@ -928,6 +949,8 @@ module VagrantPlugins
c += other.cdroms
result.cdroms = c
result.disk_driver_opts = disk_driver_opts.merge(other.disk_driver_opts)
c = clock_timers.dup
c += other.clock_timers
result.clock_timers = c

View File

@@ -115,7 +115,11 @@
<% end %>
<% if @domain_volume_path %>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='<%= @domain_volume_cache %>'/>
<driver name='qemu' type='qcow2' <%=
@disk_driver_opts.empty? ? "cache='#{@domain_volume_cache}'" :
@disk_driver_opts.reject { |k,v| v.nil? }
.map { |k,v| "#{k}='#{v}'"}
.join(' ') -%>/>
<source file='<%= @domain_volume_path %>'/>
<%# we need to ensure a unique target dev -%>
<target dev='<%= @disk_device %>' bus='<%= @disk_bus %>'/>
@@ -124,7 +128,12 @@
<%# additional disks -%>
<% @disks.each do |d| -%>
<disk type='file' device='disk'>
<driver name='qemu' type='<%= d[:type] %>' cache='<%= d[:cache] %>'/>
<driver name='qemu' type='<%= d[:type] %>' <%=
d.select { |k,_| [:cache, :io, :copy_on_read, :discard, :detect_zeroes].include? k }
.reject { |k,v| v.nil? }
.map { |k,v| "#{k}='#{v}'"}
.join(' ')
-%>/>
<source file='<%= d[:absolute_path] %>'/>
<target dev='<%= d[:device] %>' bus='<%= d[:bus] %>'/>
<% if d[:shareable] %>