[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] PATCH: allow to set nvcpus = 0



OpenVZ uses all CPUs available in system
- by default (number of CPUs did not set)
- number of CPUs = 0

Currenty, libvirt don't allow to set nvcpus = 0.

Attached patch removes limitation in libvirt set nvcpu = 0, but add it to each driver which allow to set number of virtual CPU. For OpenVZ set default number of CPUs = 0.
Index: libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.174
diff -u -p -r1.174 libvirt.c
--- libvirt.c	17 Nov 2008 12:18:18 -0000	1.174
+++ libvirt.c	17 Nov 2008 15:11:12 -0000
@@ -3124,10 +3124,6 @@ virDomainSetVcpus(virDomainPtr domain, u
         return (-1);
     }
 
-    if (nvcpus < 1) {
-        virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
-        return (-1);
-    }
     conn = domain->conn;
 
     if (conn->driver->domainSetVcpus)
Index: openvz_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_conf.c,v
retrieving revision 1.50
diff -u -p -r1.50 openvz_conf.c
--- openvz_conf.c	17 Nov 2008 09:55:59 -0000	1.50
+++ openvz_conf.c	17 Nov 2008 15:11:12 -0000
@@ -428,7 +428,7 @@ int openvzLoadDomains(struct openvz_driv
         } else if (ret > 0) {
             dom->def->vcpus = strtoI(temp);
         } else {
-            dom->def->vcpus = 1;
+            dom->def->vcpus = 0;
         }
 
         /* XXX load rest of VM config data .... */
Index: openvz_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_driver.c,v
retrieving revision 1.60
diff -u -p -r1.60 openvz_driver.c
--- openvz_driver.c	17 Nov 2008 11:44:51 -0000	1.60
+++ openvz_driver.c	17 Nov 2008 15:11:12 -0000
@@ -842,12 +842,6 @@ static int openvzDomainSetVcpus(virDomai
         return -1;
     }
 
-    if (nvcpus <= 0) {
-        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
-                    "%s", _("VCPUs should be >= 1"));
-        return -1;
-    }
-
     snprintf(str_vcpus, 31, "%d", nvcpus);
     str_vcpus[31] = '\0';
 
Index: qemu_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_driver.c,v
retrieving revision 1.153
diff -u -p -r1.153 qemu_driver.c
--- qemu_driver.c	17 Nov 2008 11:44:51 -0000	1.153
+++ qemu_driver.c	17 Nov 2008 15:11:12 -0000
@@ -1969,6 +1969,12 @@ static int qemudDomainSetVcpus(virDomain
         return -1;
     }
 
+    if (nvcpus < 1) {
+        qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
+                         _("nvcpus '%u'"), nvcpus);
+        return -1;
+    }
+
     if (virDomainIsActive(vm)) {
         qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT, "%s",
                          _("cannot change vcpu count of an active domain"));
Index: test.c
===================================================================
RCS file: /data/cvs/libvirt/src/test.c,v
retrieving revision 1.96
diff -u -p -r1.96 test.c
--- test.c	17 Nov 2008 11:44:51 -0000	1.96
+++ test.c	17 Nov 2008 15:11:13 -0000
@@ -1180,7 +1180,7 @@ static int testSetVcpus(virDomainPtr dom
     GET_DOMAIN(domain, -1);
 
     /* We allow more cpus in guest than host */
-    if (nrCpus > 32) {
+    if (nrCpus > 32 || nrCpus < 1) {
         testError(domain->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
         return (-1);
     }
Index: virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.172
diff -u -p -r1.172 virsh.c
--- virsh.c	17 Nov 2008 11:03:25 -0000	1.172
+++ virsh.c	17 Nov 2008 15:11:13 -0000
@@ -1897,7 +1897,7 @@ cmdSetvcpus(vshControl *ctl, const vshCm
         return FALSE;
 
     count = vshCommandOptInt(cmd, "count", &count);
-    if (count <= 0) {
+    if (count < 0) {
         vshError(ctl, FALSE, "%s", _("Invalid number of virtual CPUs."));
         virDomainFree(dom);
         return FALSE;
Index: xen_unified.c
===================================================================
RCS file: /data/cvs/libvirt/src/xen_unified.c,v
retrieving revision 1.61
diff -u -p -r1.61 xen_unified.c
--- xen_unified.c	17 Nov 2008 11:44:51 -0000	1.61
+++ xen_unified.c	17 Nov 2008 15:11:13 -0000
@@ -884,6 +884,11 @@ xenUnifiedDomainSetVcpus (virDomainPtr d
     GET_PRIVATE(dom->conn);
     int i;
 
+    if (nvcpus < 1) {
+        xenUnifiedError (dom->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        return -1;
+    }
+
     /* Try non-hypervisor methods first, then hypervisor direct method
      * as a last resort.
      */

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]