Merge ~paelzer/uvtool:lp-1869185-host-model into uvtool:master

Proposed by Christian Ehrhardt 
Status: Merged
Merged at revision: 6bcf4666c03eca5cf6d4984bc97c44aec329839b
Proposed branch: ~paelzer/uvtool:lp-1869185-host-model
Merge into: uvtool:master
Diff against target: 162 lines (+43/-19)
3 files modified
man/uvt-kvm.1 (+18/-4)
template-aarch64.xml (+0/-3)
uvtool/libvirt/kvm.py (+25/-12)
Reviewer Review Type Date Requested Status
Robie Basak Approve
Canonical Server Pending
uvtool development Pending
Review via email: mp+382847@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

This is RFC for now as it is yet untested and it might take a while to get e.g. a KVM capable arm board again. But it is enough as RFC for a pre-review ahead of spending too much effort down that path.

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

I pushed a fix for emulation targets based on the testing

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :
Revision history for this message
Robie Basak (racb) wrote :

This looks good. Thanks! I have no architectural objections.

Some copyediting requests inline, and one question about the name of the new option.

review: Needs Fixing
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

I've done all the wording changes.
Except the one where you commented on a removed line - I'm not bringing it back to fix the word and then remove it :-P

--cpu-model is fine with me, changing that ...

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

pushed the fixes, ok to merge now?

Revision history for this message
Robie Basak (racb) :
review: Approve
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

thanks - pushed to master

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/man/uvt-kvm.1 b/man/uvt-kvm.1
2index 4e25ca7..689f0ee 100644
3--- a/man/uvt-kvm.1
4+++ b/man/uvt-kvm.1
5@@ -384,9 +384,23 @@ the sclp console used.
6
7 .TP
8 .B --host-passthrough
9-Instead of the default cpu model - which mostly is a compatibility focused
10-lowest denominator of cpu features - use host-passthrough which will try to
11-make all of the hosts cpu features available in the guest.
12+Instead of the default CPU model - which is host-model this will use
13+host-passthrough which will try to make all of the host's CPU features
14+(not migration safe) available in the guest.
15+This option is deprecated and will later be removed. Please use --model instead.
16+
17+.TP
18+.B --cpu-model
19+Set the CPU model that shall be used.
20+The default generally is \fBhost-model\fR, except on arm64 where
21+\fBhost-model\fR won't work - there the default is \fBhost-passthrough\fR.
22+If set to \fBhost-model\fR or \fBhost-passthrough\fR this will set the CPU mode.
23+If set to any other string it will be handled as a \fBnamed CPU\fR passed to
24+libvirt.
25+Allowed values are all CPUs listed on your host as usable=yes in
26+`virsh domcapabilities`.
27+This option has no effect if the target is emulated, in this case the safe
28+defaults of libvirt will be used.
29
30 .TP
31 .BI --machine-type\ type
32@@ -489,7 +503,7 @@ Default:
33 .BI --guest-arch\ architecture
34 Specify the architecture of the guest template file that will be selected.
35 If an explicit \fB--template\fR is given then \fB--guest-arch\fR has no effect.
36-If neither \fB--template\fR nor \fB--guest-arch\fR are set the hosts
37+If neither \fB--template\fR nor \fB--guest-arch\fR are set the host's
38 architecture will be used to determine the default xml template.
39
40 If you set an architecture that requires emulation on the current host
41diff --git a/template-aarch64.xml b/template-aarch64.xml
42index 4a8296c..515fe81 100644
43--- a/template-aarch64.xml
44+++ b/template-aarch64.xml
45@@ -10,9 +10,6 @@
46 <apic/>
47 <pae/>
48 </features>
49- <cpu mode='custom' match='exact'>
50- <model fallback='allow'>host</model>
51- </cpu>
52 <devices>
53 <interface type='network'>
54 <source network='default'/>
55diff --git a/uvtool/libvirt/kvm.py b/uvtool/libvirt/kvm.py
56index 71c6d68..9139ee2 100755
57--- a/uvtool/libvirt/kvm.py
58+++ b/uvtool/libvirt/kvm.py
59@@ -427,7 +427,7 @@ def get_boot_item(backing_volume_name, hostname, item, conn=None):
60
61
62 def compose_domain_xml(name, volumes, template_path, cpu=1, memory=512,
63- unsafe_caching=False, log_console_output=False, host_passthrough=False,
64+ unsafe_caching=False, log_console_output=False, model=False,
65 machine_type=None, bridge=None, mac=None, ssh_known_hosts=None,
66 kernel=None, initrd=None):
67 tree = etree.parse(template_path)
68@@ -511,12 +511,19 @@ def compose_domain_xml(name, volumes, template_path, cpu=1, memory=512,
69 etree.strip_elements(devices, 'serial')
70 devices.append(E.serial(E.target(port='0'), type='stdio'))
71
72- if host_passthrough:
73+ if model:
74+ if model == "host-passthrough" or model == "host-model":
75+ etree.SubElement(domain, 'cpu', mode=model)
76+ elif model != "unmodified-emulation":
77+ cpu = etree.SubElement(domain, 'cpu', match='exact')
78+ etree.SubElement(cpu, 'model', fallback='allow').text = model
79+ else:
80 if ARCH == 'aarch64':
81- print("Info: on aarch64 a host type cpu is the default",
82- file=sys.stderr)
83- else:
84+ # arm64 can't use host-model, there the default is passthrough
85 etree.SubElement(domain, 'cpu', mode='host-passthrough')
86+ else:
87+ # the default without any argument will be host-model
88+ etree.SubElement(domain, 'cpu', mode='host-model')
89
90 if machine_type:
91 domos = domain.find('os')
92@@ -524,12 +531,12 @@ def compose_domain_xml(name, volumes, template_path, cpu=1, memory=512,
93 domtype.set('machine', machine_type)
94
95 if initrd:
96- domos = domain.find('os')
97- etree.SubElement(domos, 'initrd').text = initrd
98+ domos = domain.find('os')
99+ etree.SubElement(domos, 'initrd').text = initrd
100
101 if kernel:
102- domos = domain.find('os')
103- etree.SubElement(domos, 'kernel').text = kernel
104+ domos = domain.find('os')
105+ etree.SubElement(domos, 'kernel').text = kernel
106
107 if ssh_known_hosts:
108 metadata = domain.find('metadata')
109@@ -568,7 +575,7 @@ def create(
110 disk=2,
111 unsafe_caching=False,
112 log_console_output=False,
113- host_passthrough=False,
114+ model=False,
115 bridge=None,
116 mac=None,
117 backing_image_file=None,
118@@ -622,6 +629,8 @@ def create(
119 if target_arch and uvtool.libvirt.is_emulation_target(target_arch):
120 kernel = get_boot_item(base_volume_name, hostname, "vmlinuz")
121 initrd = get_boot_item(base_volume_name, hostname, "initrd.img")
122+ # emulation always uses the default
123+ model = "unmodified-emulation"
124 else:
125 kernel = None
126 initrd = None
127@@ -632,7 +641,7 @@ def create(
128 mac=mac,
129 cpu=cpu,
130 log_console_output=log_console_output,
131- host_passthrough=host_passthrough,
132+ model=model,
133 memory=memory,
134 template_path=template_path,
135 unsafe_caching=unsafe_caching,
136@@ -881,6 +890,9 @@ def main_create(parser, args):
137 if args.template:
138 template = args.template
139
140+ if args.host_passthrough and not args.cpu_model:
141+ args.cpu_model = 'host-passthrough'
142+
143 if args.backing_image_file:
144 abs_image_backing_file = os.path.abspath(args.backing_image_file)
145 else:
146@@ -897,7 +909,7 @@ def main_create(parser, args):
147 cpu=args.cpu,
148 disk=args.disk,
149 log_console_output=args.log_console_output,
150- host_passthrough=args.host_passthrough,
151+ model=args.cpu_model,
152 memory=args.memory,
153 template_path=template,
154 unsafe_caching=args.unsafe_caching,
155@@ -1055,6 +1067,7 @@ def main(args):
156 help='guest arch to select template, default is the host architecture')
157 create_subparser.add_argument('--log-console-output', action='store_true')
158 create_subparser.add_argument('--host-passthrough', action='store_true')
159+ create_subparser.add_argument('--cpu-model')
160 create_subparser.add_argument('--machine-type')
161 create_subparser.add_argument('--backing-image-file')
162 create_subparser.add_argument('--run-script-once', action='append')

Subscribers

People subscribed via source and target branches