daemon: Move TLS initialization to virInitialize
[libvirt/zwu.git] / docs / api_extension / 0012-improve-vcpu-support-in-xen-command-line.patch
blob0a7b2fccff9cf3c7db73ef79153263d7e976871a
1 From 0fab10e5ed971ab4f960a53e9640b0672f4b8ac3 Mon Sep 17 00:00:00 2001
2 From: Eric Blake <eblake@redhat.com>
3 Date: Tue, 5 Oct 2010 08:18:52 -0600
4 Subject: [PATCH 12/15] vcpu: improve vcpu support in xen command line
6 This patch series focuses on xendConfigVersion 2 (xm_internal) and 3
7 (xend_internal), but leaves out changes for xenapi drivers.
9 See this link for more details about vcpu_avail for xm usage.
10 http://lists.xensource.com/archives/html/xen-devel/2009-11/msg01061.html
12 This relies on the fact that def->maxvcpus can be at most 32 with xen.
14 * src/xen/xend_internal.c (xenDaemonParseSxpr)
15 (sexpr_to_xend_domain_info, xenDaemonFormatSxpr): Use vcpu_avail
16 when current vcpus is less than maximum.
17 * src/xen/xm_internal.c (xenXMDomainConfigParse)
18 (xenXMDomainConfigFormat): Likewise.
19 * tests/xml2sexprdata/xml2sexpr-pv-vcpus.sexpr: New file.
20 * tests/sexpr2xmldata/sexpr2xml-pv-vcpus.sexpr: Likewise.
21 * tests/sexpr2xmldata/sexpr2xml-pv-vcpus.xml: Likewise.
22 * tests/xmconfigdata/test-paravirt-vcpu.cfg: Likewise.
23 * tests/xmconfigdata/test-paravirt-vcpu.xml: Likewise.
24 * tests/xml2sexprtest.c (mymain): New test.
25 * tests/sexpr2xmltest.c (mymain): Likewise.
26 * tests/xmconfigtest.c (mymain): Likewise.
27 ---
28 src/xen/xend_internal.c | 19 +++++++++++++--
29 src/xen/xm_internal.c | 10 ++++++-
30 tests/sexpr2xmldata/sexpr2xml-pv-vcpus.sexpr | 1 +
31 tests/sexpr2xmldata/sexpr2xml-pv-vcpus.xml | 27 +++++++++++++++++++++
32 tests/sexpr2xmltest.c | 1 +
33 tests/xmconfigdata/test-paravirt-vcpu.cfg | 17 +++++++++++++
34 tests/xmconfigdata/test-paravirt-vcpu.xml | 32 ++++++++++++++++++++++++++
35 tests/xmconfigtest.c | 1 +
36 tests/xml2sexprdata/xml2sexpr-pv-vcpus.sexpr | 1 +
37 tests/xml2sexprtest.c | 1 +
38 10 files changed, 105 insertions(+), 5 deletions(-)
39 create mode 100644 tests/sexpr2xmldata/sexpr2xml-pv-vcpus.sexpr
40 create mode 100644 tests/sexpr2xmldata/sexpr2xml-pv-vcpus.xml
41 create mode 100644 tests/xmconfigdata/test-paravirt-vcpu.cfg
42 create mode 100644 tests/xmconfigdata/test-paravirt-vcpu.xml
43 create mode 100644 tests/xml2sexprdata/xml2sexpr-pv-vcpus.sexpr
45 diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
46 index 456b477..dfc6415 100644
47 --- a/src/xen/xend_internal.c
48 +++ b/src/xen/xend_internal.c
49 @@ -44,6 +44,7 @@
50 #include "xen_hypervisor.h"
51 #include "xs_internal.h" /* To extract VNC port & Serial console TTY */
52 #include "memory.h"
53 +#include "count-one-bits.h"
55 /* required for cpumap_t */
56 #include <xen/dom0_ops.h>
57 @@ -2191,7 +2192,9 @@ xenDaemonParseSxpr(virConnectPtr conn,
60 def->maxvcpus = sexpr_int(root, "domain/vcpus");
61 - def->vcpus = def->maxvcpus;
62 + def->vcpus = count_one_bits(sexpr_int(root, "domain/vcpu_avail"));
63 + if (!def->vcpus || def->maxvcpus < def->vcpus)
64 + def->vcpus = def->maxvcpus;
66 tmp = sexpr_node(root, "domain/on_poweroff");
67 if (tmp != NULL) {
68 @@ -2433,7 +2436,7 @@ sexpr_to_xend_domain_info(virDomainPtr domain, const struct sexpr *root,
69 virDomainInfoPtr info)
71 const char *flags;
73 + int vcpus;
75 if ((root == NULL) || (info == NULL))
76 return (-1);
77 @@ -2464,7 +2467,11 @@ sexpr_to_xend_domain_info(virDomainPtr domain, const struct sexpr *root,
78 info->state = VIR_DOMAIN_NOSTATE;
80 info->cpuTime = sexpr_float(root, "domain/cpu_time") * 1000000000;
81 - info->nrVirtCpu = sexpr_int(root, "domain/vcpus");
82 + vcpus = sexpr_int(root, "domain/vcpus");
83 + info->nrVirtCpu = count_one_bits(sexpr_int(root, "domain/vcpu_avail"));
84 + if (!info->nrVirtCpu || vcpus < info->nrVirtCpu)
85 + info->nrVirtCpu = vcpus;
87 return (0);
90 @@ -5668,6 +5675,9 @@ xenDaemonFormatSxpr(virConnectPtr conn,
91 virBufferAsprintf(&buf, "(memory %lu)(maxmem %lu)",
92 def->mem.cur_balloon/1024, def->mem.max_balloon/1024);
93 virBufferAsprintf(&buf, "(vcpus %u)", def->maxvcpus);
94 + /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is 32. */
95 + if (def->vcpus < def->maxvcpus)
96 + virBufferAsprintf(&buf, "(vcpu_avail %u)", (1U << def->vcpus) - 1);
98 if (def->cpumask) {
99 char *ranges = virDomainCpuSetFormat(def->cpumask, def->cpumasklen);
100 @@ -5763,6 +5773,9 @@ xenDaemonFormatSxpr(virConnectPtr conn,
101 virBufferAsprintf(&buf, "(kernel '%s')", def->os.loader);
103 virBufferAsprintf(&buf, "(vcpus %u)", def->maxvcpus);
104 + if (def->vcpus < def->maxvcpus)
105 + virBufferAsprintf(&buf, "(vcpu_avail %u)",
106 + (1U << def->vcpus) - 1);
108 for (i = 0 ; i < def->os.nBootDevs ; i++) {
109 switch (def->os.bootDevs[i]) {
110 diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
111 index bf20a64..f7121ab 100644
112 --- a/src/xen/xm_internal.c
113 +++ b/src/xen/xm_internal.c
114 @@ -46,6 +46,7 @@
115 #include "util.h"
116 #include "memory.h"
117 #include "logging.h"
118 +#include "count-one-bits.h"
120 #define VIR_FROM_THIS VIR_FROM_XENXM
122 @@ -772,10 +773,12 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
123 def->mem.max_balloon *= 1024;
125 if (xenXMConfigGetULong(conf, "vcpus", &count, 1) < 0 ||
126 - (unsigned short) count != count)
127 + MAX_VIRT_CPUS < count)
128 goto cleanup;
129 def->maxvcpus = count;
130 - def->vcpus = def->maxvcpus;
131 + if (xenXMConfigGetULong(conf, "vcpu_avail", &count, -1) < 0)
132 + goto cleanup;
133 + def->vcpus = MIN(count_one_bits(count), def->maxvcpus);
135 if (xenXMConfigGetString(conf, "cpus", &str, NULL) < 0)
136 goto cleanup;
137 @@ -2246,6 +2249,9 @@ virConfPtr xenXMDomainConfigFormat(virConnectPtr conn,
139 if (xenXMConfigSetInt(conf, "vcpus", def->maxvcpus) < 0)
140 goto no_memory;
141 + if (def->vcpus < def->maxvcpus &&
142 + xenXMConfigSetInt(conf, "vcpu_avail", (1U << def->vcpus) - 1) < 0)
143 + goto no_memory;
145 if ((def->cpumask != NULL) &&
146 ((cpus = virDomainCpuSetFormat(def->cpumask,
147 diff --git a/tests/sexpr2xmldata/sexpr2xml-pv-vcpus.sexpr b/tests/sexpr2xmldata/sexpr2xml-pv-vcpus.sexpr
148 new file mode 100644
149 index 0000000..2be6822
150 --- /dev/null
151 +++ b/tests/sexpr2xmldata/sexpr2xml-pv-vcpus.sexpr
152 @@ -0,0 +1 @@
153 +(domain (domid 6)(name 'pvtest')(memory 420)(maxmem 420)(vcpus 4)(vcpu_avail 3)(uuid '596a5d2171f48fb2e068e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
154 diff --git a/tests/sexpr2xmldata/sexpr2xml-pv-vcpus.xml b/tests/sexpr2xmldata/sexpr2xml-pv-vcpus.xml
155 new file mode 100644
156 index 0000000..0d6bf11
157 --- /dev/null
158 +++ b/tests/sexpr2xmldata/sexpr2xml-pv-vcpus.xml
159 @@ -0,0 +1,27 @@
160 +<domain type='xen' id='6'>
161 + <name>pvtest</name>
162 + <uuid>596a5d21-71f4-8fb2-e068-e2386a5c413e</uuid>
163 + <memory>430080</memory>
164 + <currentMemory>430080</currentMemory>
165 + <vcpu current='2'>4</vcpu>
166 + <os>
167 + <type>linux</type>
168 + <kernel>/var/lib/xen/vmlinuz.2Dn2YT</kernel>
169 + <initrd>/var/lib/xen/initrd.img.0u-Vhq</initrd>
170 + <cmdline> method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os </cmdline>
171 + </os>
172 + <clock offset='utc'/>
173 + <on_poweroff>destroy</on_poweroff>
174 + <on_reboot>destroy</on_reboot>
175 + <on_crash>destroy</on_crash>
176 + <devices>
177 + <disk type='file' device='disk'>
178 + <driver name='file'/>
179 + <source file='/root/some.img'/>
180 + <target dev='xvda' bus='xen'/>
181 + </disk>
182 + <console type='pty'>
183 + <target type='xen' port='0'/>
184 + </console>
185 + </devices>
186 +</domain>
187 diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c
188 index d62b44f..f100dd8 100644
189 --- a/tests/sexpr2xmltest.c
190 +++ b/tests/sexpr2xmltest.c
191 @@ -132,6 +132,7 @@ mymain(int argc, char **argv)
192 DO_TEST("pv-vfb-type-crash", "pv-vfb-type-crash", 3);
193 DO_TEST("fv-autoport", "fv-autoport", 3);
194 DO_TEST("pv-bootloader", "pv-bootloader", 1);
195 + DO_TEST("pv-vcpus", "pv-vcpus", 1);
197 DO_TEST("disk-file", "disk-file", 2);
198 DO_TEST("disk-block", "disk-block", 2);
199 diff --git a/tests/xmconfigdata/test-paravirt-vcpu.cfg b/tests/xmconfigdata/test-paravirt-vcpu.cfg
200 new file mode 100644
201 index 0000000..24c78f4
202 --- /dev/null
203 +++ b/tests/xmconfigdata/test-paravirt-vcpu.cfg
204 @@ -0,0 +1,17 @@
205 +name = "XenGuest1"
206 +uuid = "c7a5fdb0-cdaf-9455-926a-d65c16db1809"
207 +maxmem = 579
208 +memory = 394
209 +vcpus = 4
210 +vcpu_avail = 3
211 +bootloader = "/usr/bin/pygrub"
212 +on_poweroff = "destroy"
213 +on_reboot = "restart"
214 +on_crash = "restart"
215 +sdl = 0
216 +vnc = 1
217 +vncunused = 1
218 +vnclisten = "127.0.0.1"
219 +vncpasswd = "123poi"
220 +disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ]
221 +vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge" ]
222 diff --git a/tests/xmconfigdata/test-paravirt-vcpu.xml b/tests/xmconfigdata/test-paravirt-vcpu.xml
223 new file mode 100644
224 index 0000000..0be9456
225 --- /dev/null
226 +++ b/tests/xmconfigdata/test-paravirt-vcpu.xml
227 @@ -0,0 +1,32 @@
228 +<domain type='xen'>
229 + <name>XenGuest1</name>
230 + <uuid>c7a5fdb0-cdaf-9455-926a-d65c16db1809</uuid>
231 + <memory>592896</memory>
232 + <currentMemory>403456</currentMemory>
233 + <vcpu current='2'>4</vcpu>
234 + <bootloader>/usr/bin/pygrub</bootloader>
235 + <os>
236 + <type arch='i686' machine='xenpv'>linux</type>
237 + </os>
238 + <clock offset='utc'/>
239 + <on_poweroff>destroy</on_poweroff>
240 + <on_reboot>restart</on_reboot>
241 + <on_crash>restart</on_crash>
242 + <devices>
243 + <disk type='block' device='disk'>
244 + <driver name='phy'/>
245 + <source dev='/dev/HostVG/XenGuest1'/>
246 + <target dev='xvda' bus='xen'/>
247 + </disk>
248 + <interface type='bridge'>
249 + <mac address='00:16:3e:66:94:9c'/>
250 + <source bridge='br0'/>
251 + <script path='vif-bridge'/>
252 + </interface>
253 + <console type='pty'>
254 + <target type='xen' port='0'/>
255 + </console>
256 + <input type='mouse' bus='xen'/>
257 + <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1' passwd='123poi'/>
258 + </devices>
259 +</domain>
260 diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
261 index 221b322..ea00747 100644
262 --- a/tests/xmconfigtest.c
263 +++ b/tests/xmconfigtest.c
264 @@ -210,6 +210,7 @@ mymain(int argc, char **argv)
265 DO_TEST("paravirt-new-pvfb-vncdisplay", 3);
266 DO_TEST("paravirt-net-e1000", 3);
267 DO_TEST("paravirt-net-vifname", 3);
268 + DO_TEST("paravirt-vcpu", 2);
269 DO_TEST("fullvirt-old-cdrom", 1);
270 DO_TEST("fullvirt-new-cdrom", 2);
271 DO_TEST("fullvirt-utc", 2);
272 diff --git a/tests/xml2sexprdata/xml2sexpr-pv-vcpus.sexpr b/tests/xml2sexprdata/xml2sexpr-pv-vcpus.sexpr
273 new file mode 100644
274 index 0000000..e886545
275 --- /dev/null
276 +++ b/tests/xml2sexprdata/xml2sexpr-pv-vcpus.sexpr
277 @@ -0,0 +1 @@
278 +(vm (name 'pvtest')(memory 420)(maxmem 420)(vcpus 4)(vcpu_avail 3)(uuid '596a5d21-71f4-8fb2-e068-e2386a5c413e')(on_poweroff 'destroy')(on_reboot 'destroy')(on_crash 'destroy')(image (linux (kernel '/var/lib/xen/vmlinuz.2Dn2YT')(ramdisk '/var/lib/xen/initrd.img.0u-Vhq')(args ' method=http://download.fedora.devel.redhat.com/pub/fedora/linux/core/test/5.91/x86_64/os ')))(device (vbd (dev 'xvda')(uname 'file:/root/some.img')(mode 'w'))))
279 \ No newline at end of file
280 diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c
281 index 77cf760..9cf8d39 100644
282 --- a/tests/xml2sexprtest.c
283 +++ b/tests/xml2sexprtest.c
284 @@ -118,6 +118,7 @@ mymain(int argc, char **argv)
285 DO_TEST("pv-vfb-new", "pv-vfb-new", "pvtest", 3);
286 DO_TEST("pv-vfb-new-auto", "pv-vfb-new-auto", "pvtest", 3);
287 DO_TEST("pv-bootloader", "pv-bootloader", "pvtest", 1);
288 + DO_TEST("pv-vcpus", "pv-vcpus", "pvtest", 1);
290 DO_TEST("disk-file", "disk-file", "pvtest", 2);
291 DO_TEST("disk-block", "disk-block", "pvtest", 2);
293 1.7.2.3