]> xenbits.xensource.com Git - libvirt.git/commitdiff
Xen: support maxvcpus in xm and xl config
authorJim Fehlig <jfehlig@suse.com>
Tue, 15 Dec 2015 21:47:40 +0000 (14:47 -0700)
committerJim Fehlig <jfehlig@suse.com>
Sat, 19 Dec 2015 00:52:00 +0000 (17:52 -0700)
From: Ian Campbell <ian.campbell@citrix.com>

xend prior to 4.0 understands vcpus as maxvcpus and vcpu_avail
as a bit map of which cpus are online (default is all).

xend from 4.0 onwards understands maxvcpus as maxvcpus and
vcpus as the number which are online (from 0..N-1). The
upstream commit (68a94cf528e6 "xm: Add maxvcpus support")
claims that if maxvcpus is omitted then the old behaviour
(i.e. obeying vcpu_avail) is retained, but AFAICT it was not,
in this case vcpu==maxcpus==online cpus. This is good for us
because handling anything else would be fiddly.

This patch changes parsing of the virDomainDef maxvcpus and vcpus
entries to use the corresponding 'maxvcpus' and 'vcpus' settings
from xm and xl config. It also drops use of the old Xen 3.x
'vcpu_avail' setting.

The change also removes the maxvcpus limit of MAX_VIRT_VCPUS (since
maxvcpus is simply a count, not a bit mask), which is particularly
crucial on ARM where MAX_VIRT_CPUS == 1 (since all guests are
expected to support vcpu placement, and therefore only the boot
vcpu's info lives in the shared info page).

Existing tests adjusted accordingly, and new tests added for the
'maxvcpus' setting.

src/xenconfig/xen_common.c
tests/xlconfigdata/test-paravirt-maxvcpus.cfg [new file with mode: 0644]
tests/xlconfigdata/test-paravirt-maxvcpus.xml [new file with mode: 0644]
tests/xlconfigtest.c
tests/xmconfigdata/test-paravirt-maxvcpus.cfg [new file with mode: 0644]
tests/xmconfigdata/test-paravirt-maxvcpus.xml [new file with mode: 0644]
tests/xmconfigdata/test-paravirt-vcpu.cfg
tests/xmconfigtest.c

index f3e7e1864f46a9f7a700ad0640422b02f7752874..54f57919053882b569301111d9d92ede7f898802 100644 (file)
@@ -488,19 +488,22 @@ xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
     const char *str = NULL;
     int val = 0;
 
-    if (xenConfigGetULong(conf, "vcpus", &count, 1) < 0 ||
-        MAX_VIRT_CPUS < count)
+    if (xenConfigGetULong(conf, "vcpus", &count, 1) < 0)
         return -1;
 
     if (virDomainDefSetVcpusMax(def, count) < 0)
         return -1;
 
-    if (xenConfigGetULong(conf, "vcpu_avail", &count, -1) < 0)
+    if (virDomainDefSetVcpus(def, count) < 0)
         return -1;
 
-    if (virDomainDefSetVcpus(def, MIN(count_one_bits_l(count),
-                                      virDomainDefGetVcpusMax(def))) < 0)
-        return -1;
+    if (virConfGetValue(conf, "maxvcpus")) {
+        if (xenConfigGetULong(conf, "maxvcpus", &count, 0) < 0)
+            return -1;
+
+        if (virDomainDefSetVcpusMax(def, count) < 0)
+            return -1;
+    }
 
     if (xenConfigGetString(conf, "cpus", &str, NULL) < 0)
         return -1;
@@ -1494,14 +1497,10 @@ xenFormatCPUAllocation(virConfPtr conf, virDomainDefPtr def)
     int ret = -1;
     char *cpus = NULL;
 
-    if (xenConfigSetInt(conf, "vcpus", virDomainDefGetVcpusMax(def)) < 0)
+    if (virDomainDefGetVcpus(def) < virDomainDefGetVcpusMax(def) &&
+        xenConfigSetInt(conf, "maxvcpus", virDomainDefGetVcpusMax(def)) < 0)
         goto cleanup;
-
-    /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
-       either 32, or 64 on a platform where long is big enough.  */
-    if (virDomainDefHasVcpusOffline(def) &&
-        xenConfigSetInt(conf, "vcpu_avail",
-                        (1UL << virDomainDefGetVcpus(def)) - 1) < 0)
+    if (xenConfigSetInt(conf, "vcpus", virDomainDefGetVcpus(def)) < 0)
         goto cleanup;
 
     if ((def->cpumask != NULL) &&
diff --git a/tests/xlconfigdata/test-paravirt-maxvcpus.cfg b/tests/xlconfigdata/test-paravirt-maxvcpus.cfg
new file mode 100644 (file)
index 0000000..d506b75
--- /dev/null
@@ -0,0 +1,13 @@
+name = "XenGuest1"
+uuid = "45b60f51-88a9-47a8-a3b3-5e66d71b2283"
+maxmem = 512
+memory = 512
+maxvcpus = 8
+vcpus = 4
+localtime = 0
+on_poweroff = "preserve"
+on_reboot = "restart"
+on_crash = "preserve"
+vif = [ "mac=5a:36:0e:be:00:09" ]
+bootloader = "/usr/bin/pygrub"
+disk = [ "/var/lib/xen/images/debian/disk.qcow2,qcow2,xvda,w,backendtype=qdisk" ]
diff --git a/tests/xlconfigdata/test-paravirt-maxvcpus.xml b/tests/xlconfigdata/test-paravirt-maxvcpus.xml
new file mode 100644 (file)
index 0000000..2e1f8f8
--- /dev/null
@@ -0,0 +1,28 @@
+<domain type='xen'>
+  <name>XenGuest1</name>
+  <uuid>45b60f51-88a9-47a8-a3b3-5e66d71b2283</uuid>
+  <memory unit='KiB'>524288</memory>
+  <currentMemory unit='KiB'>524288</currentMemory>
+  <vcpu placement='static' current='4'>8</vcpu>
+  <bootloader>/usr/bin/pygrub</bootloader>
+  <os>
+    <type arch='x86_64' machine='xenpv'>linux</type>
+  </os>
+  <clock offset='utc' adjustment='reset'/>
+  <on_poweroff>preserve</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>preserve</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='qcow2'/>
+      <source file='/var/lib/xen/images/debian/disk.qcow2'/>
+      <target dev='xvda' bus='xen'/>
+    </disk>
+    <interface type='ethernet'>
+      <mac address='5a:36:0e:be:00:09'/>
+    </interface>
+    <console type='pty'>
+      <target type='xen' port='0'/>
+    </console>
+  </devices>
+</domain>
index de7f8718f5b47d63bca192837556da803449f8f3..1db11e74e7a6b271a29d1e7f7be46b9e861efeb3 100644 (file)
@@ -192,6 +192,7 @@ mymain(void)
             ret = -1;                                                   \
     } while (0)
 
+    DO_TEST("paravirt-maxvcpus");
     DO_TEST("new-disk");
     DO_TEST("spice");
     DO_TEST("spice-features");
diff --git a/tests/xmconfigdata/test-paravirt-maxvcpus.cfg b/tests/xmconfigdata/test-paravirt-maxvcpus.cfg
new file mode 100644 (file)
index 0000000..8d1ac4d
--- /dev/null
@@ -0,0 +1,13 @@
+name = "XenGuest1"
+uuid = "c7a5fdb0-cdaf-9455-926a-d65c16db1809"
+maxmem = 579
+memory = 394
+maxvcpus = 4
+vcpus = 2
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge" ]
+bootloader = "/usr/bin/pygrub"
+disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ]
diff --git a/tests/xmconfigdata/test-paravirt-maxvcpus.xml b/tests/xmconfigdata/test-paravirt-maxvcpus.xml
new file mode 100644 (file)
index 0000000..3b0e0ce
--- /dev/null
@@ -0,0 +1,31 @@
+<domain type='xen'>
+  <name>XenGuest1</name>
+  <uuid>c7a5fdb0-cdaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>592896</memory>
+  <currentMemory unit='KiB'>403456</currentMemory>
+  <vcpu placement='static' current='2'>4</vcpu>
+  <bootloader>/usr/bin/pygrub</bootloader>
+  <os>
+    <type arch='i686' machine='xenpv'>linux</type>
+  </os>
+  <clock offset='utc' adjustment='reset'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <disk type='block' device='disk'>
+      <driver name='phy'/>
+      <source dev='/dev/HostVG/XenGuest1'/>
+      <target dev='xvda' bus='xen'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='00:16:3e:66:94:9c'/>
+      <source bridge='br0'/>
+      <script path='vif-bridge'/>
+    </interface>
+    <console type='pty'>
+      <target type='xen' port='0'/>
+    </console>
+    <memballoon model='xen'/>
+  </devices>
+</domain>
index 1e7765d4e5ccef1c0277a838d65e8216725d6c1a..8d1ac4d78675d9c71d33f0ed84c8c5a3ea82a69b 100644 (file)
@@ -2,8 +2,8 @@ name = "XenGuest1"
 uuid = "c7a5fdb0-cdaf-9455-926a-d65c16db1809"
 maxmem = 579
 memory = 394
-vcpus = 4
-vcpu_avail = 3
+maxvcpus = 4
+vcpus = 2
 localtime = 0
 on_poweroff = "destroy"
 on_reboot = "restart"
index c2084c21d32f1367d9958398fc9910819bd2c645..3d47693434159c94c687021d27f70d80e09e430d 100644 (file)
@@ -215,6 +215,7 @@ mymain(void)
     DO_TEST("paravirt-net-e1000");
     DO_TEST("paravirt-net-vifname");
     DO_TEST("paravirt-vcpu");
+    DO_TEST("paravirt-maxvcpus");
     DO_TEST("fullvirt-new-cdrom");
     DO_TEST("fullvirt-utc");
     DO_TEST("fullvirt-localtime");