diff --git a/README.md b/README.md index 623ad85..8c0f4d5 100644 --- a/README.md +++ b/README.md @@ -297,12 +297,14 @@ end Libvirt](https://libvirt.org/formatdomain.html#elementsNICSModel). * `memory` - Amount of memory in MBytes. Defaults to 512 if not set. * `cpus` - Number of virtual cpus. Defaults to 1 if not set. +* `cpuset` - Physical cpus to which the vcpus can be pinned. For more details see [documentation](https://libvirt.org/formatdomain.html#elementsCPUAllocation). * `cputopology` - Number of CPU sockets, cores and threads running per core. All fields of `:sockets`, `:cores` and `:threads` are mandatory, `cpus` domain option must be present and must be equal to total count of **sockets * cores * threads**. For more details see [documentation](https://libvirt.org/formatdomain.html#elementsCPU). ```ruby Vagrant.configure("2") do |config| config.vm.provider :libvirt do |libvirt| libvirt.cpus = 4 + libvirt.cpuset = '1-4,^3,6' libvirt.cputopology :sockets => '2', :cores => '2', :threads => '1' end end diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 0c02ba2..c860a3f 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -33,6 +33,7 @@ module VagrantPlugins @name = env[:domain_name] @uuid = config.uuid @cpus = config.cpus.to_i + @cpuset = config.cpuset @cpu_features = config.cpu_features @cpu_topology = config.cpu_topology @features = config.features @@ -189,6 +190,9 @@ module VagrantPlugins env[:ui].info(" -- Forced UUID: #{@uuid}") if @uuid != '' env[:ui].info(" -- Domain type: #{@domain_type}") env[:ui].info(" -- Cpus: #{@cpus}") + unless @cpuset.nil? + env[:ui].info(" -- Cpuset: #{@cpuset}") + end if not @cpu_topology.empty? env[:ui].info(" -- CPU topology: sockets=#{@cpu_topology[:sockets]}, cores=#{@cpu_topology[:cores]}, threads=#{@cpu_topology[:threads]}") end diff --git a/lib/vagrant-libvirt/action/start_domain.rb b/lib/vagrant-libvirt/action/start_domain.rb index cc58cba..2659600 100644 --- a/lib/vagrant-libvirt/action/start_domain.rb +++ b/lib/vagrant-libvirt/action/start_domain.rb @@ -68,7 +68,7 @@ module VagrantPlugins end # vCpu count - if config.cpus.to_i != libvirt_domain.vcpus.length + if config.cpus.to_i != libvirt_domain.num_vcpus(0) descr_changed = true REXML::XPath.first(xml_descr, '/domain/vcpu').text = config.cpus end diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 89feb92..d6bd1da 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -72,6 +72,7 @@ module VagrantPlugins attr_accessor :memory_backing attr_accessor :channel attr_accessor :cpus + attr_accessor :cpuset attr_accessor :cpu_mode attr_accessor :cpu_model attr_accessor :cpu_fallback @@ -195,6 +196,7 @@ module VagrantPlugins @memory = UNSET_VALUE @memory_backing = UNSET_VALUE @cpus = UNSET_VALUE + @cpuset = UNSET_VALUE @cpu_mode = UNSET_VALUE @cpu_model = UNSET_VALUE @cpu_fallback = UNSET_VALUE @@ -672,6 +674,7 @@ module VagrantPlugins @memory = 512 if @memory == UNSET_VALUE @memory_backing = [] if @memory_backing == UNSET_VALUE @cpus = 1 if @cpus == UNSET_VALUE + @cpuset = nil if @cpuset == UNSET_VALUE @cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE @cpu_model = if (@cpu_model == UNSET_VALUE) && (@cpu_mode == 'custom') 'qemu64' diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index b42d6bb..a8f4e46 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -2,7 +2,7 @@ <%= @name %> <%= @uuid %> <%= @memory_size %> - <%= @cpus %> + cpuset='<%= @cpuset %>'<% end %>><%= @cpus %> diff --git a/spec/unit/templates/domain_all_settings.xml b/spec/unit/templates/domain_all_settings.xml index b3c4821..4ed0d25 100644 --- a/spec/unit/templates/domain_all_settings.xml +++ b/spec/unit/templates/domain_all_settings.xml @@ -2,7 +2,7 @@ - 1 + 1 diff --git a/spec/unit/templates/domain_spec.rb b/spec/unit/templates/domain_spec.rb index c235d0a..7406621 100644 --- a/spec/unit/templates/domain_spec.rb +++ b/spec/unit/templates/domain_spec.rb @@ -76,6 +76,7 @@ describe 'templates/domain' do domain.qemuargs(value: '-device') domain.qemuargs(value: 'dummy-device') + domain.cpuset = '1-4,^3,6' end let(:test_file) { 'domain_all_settings.xml' } it 'renders template' do