From 1ad44362e30a4fddb73d90d287dae7d08e3d8286 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 24 Nov 2008 19:34:21 +0000 Subject: [PATCH] Set default vCPUs to match pCPUs for OpenVZ containers (Evgeniy Sokolov ) --- ChangeLog | 6 ++++++ src/openvz_conf.c | 19 +++++++++++++++++-- src/openvz_conf.h | 1 + src/openvz_driver.c | 6 +++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8414809c71..27acc62402 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Nov 24 19:32:40 GMT 2008 Dnaiel P. Berrange + + * src/openvz_conf.c, src/openvz_conf.h, src/openvz_driver.c: + Default vCPUs to equal host pCPU count if not set in config + (patch from Evgeniy Sokolov) + Mon Nov 24 19:27:40 GMT 2008 Dnaiel P. Berrange * examples/domain-events/events-python/event-test.py, diff --git a/src/openvz_conf.c b/src/openvz_conf.c index 70d510427d..fc4ef20025 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -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 @@ int openvzLoadDomains(struct openvz_driver *driver) { 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 @@ int openvzLoadDomains(struct openvz_driver *driver) { 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) diff --git a/src/openvz_conf.h b/src/openvz_conf.h index f30f0879bd..4328f15a65 100644 --- a/src/openvz_conf.h +++ b/src/openvz_conf.h @@ -68,5 +68,6 @@ int openvzLoadDomains(struct openvz_driver *driver); 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 */ diff --git a/src/openvz_driver.c b/src/openvz_driver.c index 6ea3557685..83cf19ab7b 100644 --- a/src/openvz_driver.c +++ b/src/openvz_driver.c @@ -834,7 +834,7 @@ static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) { 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 @@ static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) { return -1; } + pcpus = openvzGetNodeCPUs(); + if (pcpus > 0 && pcpus < nvcpus) + nvcpus = pcpus; + snprintf(str_vcpus, 31, "%d", nvcpus); str_vcpus[31] = '\0';