From 77358b63ead0562675642296fc267f50d73de400 Mon Sep 17 00:00:00 2001 From: Mihai Petracovici Date: Sun, 12 Nov 2017 16:25:13 -0600 Subject: [PATCH] Add memory backing configuration --- README.md | 18 ++++++++++++++++++ lib/vagrant-libvirt/action/create_domain.rb | 4 ++++ lib/vagrant-libvirt/config.rb | 18 ++++++++++++++++++ lib/vagrant-libvirt/templates/domain.xml.erb | 7 +++++++ 4 files changed, 47 insertions(+) diff --git a/README.md b/README.md index 14ed0cd..8b40d88 100644 --- a/README.md +++ b/README.md @@ -974,6 +974,24 @@ Vagrant.configure("2") do |config| end ``` +## Memory Backing + +You can specify memoryBacking options via `libvirt.memorybacking`. Available options are shown below. Full documentation is available at the [libvirt _memoryBacking_ section](https://libvirt.org/formatdomain.html#elementsMemoryBacking). + +NOTE: The hugepages `` element is not yet supported + +```ruby +Vagrant.configure("2") do |config| + config.vm.provider :libvirt do |libvirt| + libvirt.memorybacking :hugepages + libvirt.memorybacking :nosharepages + libvirt.memorybacking :locked + libvirt.memorybacking :source, :type => 'file' + libvirt.memorybacking :access, :mode => 'shared' + libvirt.memorybacking :allocation, :mode => 'immediate' + end +end +``` ## USB device passthrough You can specify multiple USB devices to passthrough to the VM via diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 7a4b5e0..8bc28f3 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -46,6 +46,7 @@ module VagrantPlugins @disk_device = config.disk_device @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 @kernel = config.kernel @@ -182,6 +183,9 @@ module VagrantPlugins env[:ui].info(" -- Feature: #{feature}") end env[:ui].info(" -- Memory: #{@memory_size / 1024}M") + @memory_backing.each do |backing| + env[:ui].info(" -- Memory Backing: #{backing[:name]}: #{backing[:config].map { |k,v| "#{k}='#{v}'"}.join(' ')}") + end env[:ui].info(" -- Management MAC: #{@management_network_mac}") env[:ui].info(" -- Loader: #{@loader}") if env[:machine].config.vm.box diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index d75a08c..68e0312 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -58,6 +58,7 @@ module VagrantPlugins # Domain specific settings used while creating new domain. attr_accessor :uuid attr_accessor :memory + attr_accessor :memory_backing attr_accessor :channel attr_accessor :cpus attr_accessor :cpu_mode @@ -164,6 +165,7 @@ module VagrantPlugins # Domain specific settings. @uuid = UNSET_VALUE @memory = UNSET_VALUE + @memory_backing = UNSET_VALUE @cpus = UNSET_VALUE @cpu_mode = UNSET_VALUE @cpu_model = UNSET_VALUE @@ -313,6 +315,21 @@ module VagrantPlugins policy: options[:policy]) end + def memorybacking(option, config = {}) + case option + when :source + raise 'Source type must be specified' if config[:type].nil? + when :access + raise 'Access mode must be specified' if config[:mode].nil? + when :allocation + raise 'Allocation mode must be specified' if config[:mode].nil? + end + + @memory_backing = [] if @memory_backing == UNSET_VALUE + @memory_backing.push(name: option, + config: config) + end + def input(options = {}) if options[:type].nil? || options[:bus].nil? raise 'Input type AND bus must be specified' @@ -569,6 +586,7 @@ module VagrantPlugins # Domain specific settings. @uuid = '' if @uuid == UNSET_VALUE @memory = 512 if @memory == UNSET_VALUE + @memory_backing = [] if @memory_backing == UNSET_VALUE @cpus = 1 if @cpus == UNSET_VALUE @cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE @cpu_model = if (@cpu_model == UNSET_VALUE) && (@cpu_mode == 'custom') diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 7fd991e..c513cbf 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -25,6 +25,13 @@ <% end %> +<% unless @memory_backing.empty? %> + + <% @memory_backing.each do |backing| %> + <<%= backing[:name] %> <%= backing[:config].map { |k,v| "#{k}='#{v}'"}.join(' ') %>/> + <% end %> + +<% end%> <% if @machine_type %>