From 98f2eaed5e6d3c450c3962c60100f1b50234342c Mon Sep 17 00:00:00 2001 From: Gerben Meijer Date: Mon, 14 Mar 2016 15:11:20 +0100 Subject: [PATCH 1/6] Add cpu_model and cpu_fallback. This allows for specific CPU selection and enforcement when cpu_mode = custom, which is important when emulating CPUs of different architecture than the host. --- README.md | 4 +++- lib/vagrant-libvirt/action/create_domain.rb | 2 ++ lib/vagrant-libvirt/action/start_domain.rb | 11 ++++++++++- lib/vagrant-libvirt/config.rb | 6 ++++++ lib/vagrant-libvirt/templates/domain.xml.erb | 2 +- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 546c6df..2ac4837 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,9 @@ end * `memory` - Amount of memory in MBytes. Defaults to 512 if not set. * `cpus` - Number of virtual cpus. Defaults to 1 if not set. * `nested` - [Enable nested virtualization](https://github.com/torvalds/linux/blob/master/Documentation/virtual/kvm/nested-vmx.txt). Default is false. -* `cpu_mode` - [CPU emulation mode](https://libvirt.org/formatdomain.html#elementsCPU). Defaults to 'host-model' if not set. Allowed values: host-model, host-passthrough. +* `cpu_mode` - [CPU emulation mode](https://libvirt.org/formatdomain.html#elementsCPU). Defaults to 'host-model' if not set. Allowed values: host-model, host-passthrough, custom. +* `cpu_model` - CPU Model. Defaults to 'qemu64' if not set. This can really only be used when setting `cpu_mode` to `custom`. +* `cpu_fallback` - Whether to allow libvirt to fall back to a CPU model close to the specified model if features in the guest CPU are not supported on the host. Defaults to 'allow' if not set. Allowed values: `allow`, `forbid`. * `loader` - Sets path to custom UEFI loader. * `volume_cache` - Controls the cache mechanism. Possible values are "default", "none", "writethrough", "writeback", "directsync" and "unsafe". [See driver->cache in libvirt documentation](http://libvirt.org/formatdomain.html#elementsDisks). * `kernel` - To launch the guest with a kernel residing on host filesystems. Equivalent to qemu `-kernel`. diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 5be6bef..5f8f12c 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -35,6 +35,8 @@ module VagrantPlugins @cpus = config.cpus.to_i @cpu_features = config.cpu_features @cpu_mode = config.cpu_mode + @cpu_model = config.cpu_model + @cpu_fallback = config.cpu_fallback @loader = config.loader @machine_type = config.machine_type @machine_arch = config.machine_arch diff --git a/lib/vagrant-libvirt/action/start_domain.rb b/lib/vagrant-libvirt/action/start_domain.rb index 19fd221..30d8701 100644 --- a/lib/vagrant-libvirt/action/start_domain.rb +++ b/lib/vagrant-libvirt/action/start_domain.rb @@ -88,7 +88,16 @@ module VagrantPlugins descr_changed = true cpu_model = REXML::Element.new('model', REXML::XPath.first(xml_descr,'/domain/cpu')) cpu_model.attributes['fallback'] = 'allow' - cpu_model.text = 'qemu64' + cpu_model.text = config.cpu_model + else + if cpu_model.text != config.cpu_model + descr_changed = true + cpu_model.text = config.cpu_model + end + if cpu_model.attributes['fallback'] != config.cpu_fallback + descr_changed = true + cpu_model.attributes['fallback'] = config.cpu_fallback + end end vmx_feature = REXML::XPath.first(xml_descr,'/domain/cpu/feature[@name="vmx"]') svm_feature = REXML::XPath.first(xml_descr,'/domain/cpu/feature[@name="svm"]') diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index b9eafc8..69c3656 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -58,6 +58,8 @@ module VagrantPlugins attr_accessor :memory attr_accessor :cpus attr_accessor :cpu_mode + attr_accessor :cpu_model + attr_accessor :cpu_fallback attr_accessor :cpu_features attr_accessor :loader attr_accessor :boot_order @@ -133,6 +135,8 @@ module VagrantPlugins @memory = UNSET_VALUE @cpus = UNSET_VALUE @cpu_mode = UNSET_VALUE + @cpu_model = UNSET_VALUE + @cpu_fallback = UNSET_VALUE @cpu_features = UNSET_VALUE @loader = UNSET_VALUE @machine_type = UNSET_VALUE @@ -415,6 +419,8 @@ module VagrantPlugins @memory = 512 if @memory == UNSET_VALUE @cpus = 1 if @cpus == UNSET_VALUE @cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE + @cpu_model = 'qemu64' if @cpu_model == UNSET_VALUE + @cpu_fallback = 'allow' if @cpu_fallback == UNSET_VALUE @cpu_features = [] if @cpu_features == UNSET_VALUE @loader = nil if @loader == UNSET_VALUE @machine_type = nil if @machine_type == UNSET_VALUE diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 971e4b5..765aa39 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -7,7 +7,7 @@ <% if @cpu_mode != 'host-passthrough' %> - qemu64 + <%= @cpu_model %> <% if @nested %> From dc1a8d421fbb451dc168fef36fcd7dce92fe26a1 Mon Sep 17 00:00:00 2001 From: Gerben Meijer Date: Mon, 14 Mar 2016 16:00:23 +0100 Subject: [PATCH 2/6] Add device tree binary image support This is required for correct emulation of ARM devices --- lib/vagrant-libvirt/action/create_domain.rb | 1 + lib/vagrant-libvirt/action/start_domain.rb | 14 ++++++++++++++ lib/vagrant-libvirt/config.rb | 3 +++ lib/vagrant-libvirt/templates/domain.xml.erb | 3 +++ 4 files changed, 21 insertions(+) diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index 5f8f12c..ab0db55 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -49,6 +49,7 @@ module VagrantPlugins @cmd_line = config.cmd_line @emulator_path = config.emulator_path @initrd = config.initrd + @dtb = config.dtb @graphics_type = config.graphics_type @graphics_autoport = config.graphics_autoport @graphics_port = config.graphics_port diff --git a/lib/vagrant-libvirt/action/start_domain.rb b/lib/vagrant-libvirt/action/start_domain.rb index 30d8701..6aaa4e9 100644 --- a/lib/vagrant-libvirt/action/start_domain.rb +++ b/lib/vagrant-libvirt/action/start_domain.rb @@ -202,6 +202,20 @@ module VagrantPlugins video.attributes['vram'] = config.video_vram end + # dtb + if config.dtb + dtb = REXML::XPath.first(xml_descr,'/domain/os/dtb') + if dtb.nil? + dtb = REXML::Element.new('dtb', REXML::XPath.first(xml_descr,'/domain/os')) + dtb.text = config.dtb + else + if dtb.text != config.dtb + descr_changed = true + dtb.text = config.dtb + end + end + end + # Apply if descr_changed begin diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 69c3656..21b95d7 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -73,6 +73,7 @@ module VagrantPlugins attr_accessor :kernel attr_accessor :cmd_line attr_accessor :initrd + attr_accessor :dtb attr_accessor :emulator_path attr_accessor :graphics_type attr_accessor :graphics_autoport @@ -148,6 +149,7 @@ module VagrantPlugins @volume_cache = UNSET_VALUE @kernel = UNSET_VALUE @initrd = UNSET_VALUE + @dtb = UNSET_VALUE @cmd_line = UNSET_VALUE @emulator_path = UNSET_VALUE @graphics_type = UNSET_VALUE @@ -433,6 +435,7 @@ module VagrantPlugins @kernel = nil if @kernel == UNSET_VALUE @cmd_line = '' if @cmd_line == UNSET_VALUE @initrd = '' if @initrd == UNSET_VALUE + @dtb = nil if @dtb == UNSET_VALUE @graphics_type = 'vnc' if @graphics_type == UNSET_VALUE @graphics_autoport = 'yes' if @graphics_port == UNSET_VALUE @graphics_autoport = 'no' if @graphics_port != UNSET_VALUE diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 765aa39..bdae96c 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -42,6 +42,9 @@ <%= @kernel %> <%= @initrd %> <%= @cmd_line %> + <% if @dtb %> + <%= @dtb %> + <% end %> From 0016f348511d3ae4b71e27a410898b386748d42e Mon Sep 17 00:00:00 2001 From: Gerben Meijer Date: Thu, 17 Mar 2016 03:19:50 +0100 Subject: [PATCH 3/6] Support graphics_type = none Devices which do not support any default vga device (e.g. ARM boards) can't be started when a video device is present. Libvirt automatically adds a