On Mon, Nov 17, 2008 at 06:44:07PM +0300, Evgeniy Sokolov wrote:
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.
This is the wrong way to handle this. If OpenVZ allows the container
to use all the host CPUs, then the vCPUs number should reflect the
number of pCPUs, not 0. So when loading the openvz config, if there
is no CPUS= setting in the config file, the driver should fill in
the number of host pCPUs. Likewise, when setting the openvz config,
if the vCPUs in the XML is >= pCPUs, then it should just leave
out the CPUS= setting, so OpenVZ uses all CPUs.
It is not like in OpenVZ, but good way. Attached patch implement it.
Index: openvz_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_conf.c,v
retrieving revision 1.50
diff -u -r1.50 openvz_conf.c
--- openvz_conf.c 17 Nov 2008 09:55:59 -0000 1.50
+++ openvz_conf.c 19 Nov 2008 16:16:39 -0000
@@ -49,6 +49,7 @@
#include "buf.h"
#include "memory.h"
#include "util.h"
+#include "nodeinfo.h"
static char *openvzLocateConfDir(void);
static int openvzGetVPSUUID(int vpsid, char *uuidstr);
@@ -427,10 +428,11 @@
goto cleanup;
} else if (ret > 0) {
dom->def->vcpus = strtoI(temp);
- } else {
- dom->def->vcpus = 1;
}
+ if (ret == 0 || dom->def->vcpus == 0)
+ dom->def->vcpus = openvzGetNodeCPUs();
+
/* XXX load rest of VM config data .... */
openvzReadNetworkConf(NULL, dom->def, veid);
@@ -457,6 +459,19 @@
return -1;
}
+unsigned int
+openvzGetNodeCPUs(void)
+{
+ virNodeInfo nodeinfo;
+
+ if (virNodeInfoPopulate(NULL, &nodeinfo) < 0) {
+ openvzError(NULL, VIR_ERR_INTERNAL_ERROR,
+ _("Cound not read nodeinfo"));
+ return 0;
+ }
+
+ return nodeinfo.cpus;
+}
int
openvzWriteConfigParam(int vpsid, const char *param, const char *value)
Index: openvz_conf.h
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_conf.h,v
retrieving revision 1.17
diff -u -r1.17 openvz_conf.h
--- openvz_conf.h 12 Nov 2008 16:35:47 -0000 1.17
+++ openvz_conf.h 19 Nov 2008 16:16:39 -0000
@@ -68,5 +68,6 @@
void openvzFreeDriver(struct openvz_driver *driver);
int strtoI(const char *str);
int openvzSetDefinedUUID(int vpsid, unsigned char *uuid);
+unsigned int openvzGetNodeCPUs(void);
#endif /* OPENVZ_CONF_H */
Index: openvz_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_driver.c,v
retrieving revision 1.60
diff -u -r1.60 openvz_driver.c
--- openvz_driver.c 17 Nov 2008 11:44:51 -0000 1.60
+++ openvz_driver.c 19 Nov 2008 16:16:39 -0000
@@ -834,7 +834,7 @@
char str_vcpus[32];
const char *prog[] = { VZCTL, "--quiet", "set", vm ? vm->def->name : NULL,
"--cpus", str_vcpus, "--save", NULL };
-
+ unsigned int pcpus;
if (!vm) {
openvzError(conn, VIR_ERR_INVALID_DOMAIN,
@@ -848,6 +848,10 @@
return -1;
}
+ pcpus = openvzGetNodeCPUs();
+ if (pcpus > 0 && pcpus < nvcpus)
+ nvcpus = pcpus;
+
snprintf(str_vcpus, 31, "%d", nvcpus);
str_vcpus[31] = '\0';
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list