Set default vCPUs to match pCPUs for OpenVZ containers (Evgeniy Sokolov )

This commit is contained in:
Daniel P. Berrange 2008-11-24 19:34:21 +00:00
parent c673689430
commit 1ad44362e3
4 changed files with 29 additions and 3 deletions

View File

@ -1,3 +1,9 @@
Mon Nov 24 19:32:40 GMT 2008 Dnaiel P. Berrange <berrange@redhat.com>
* 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 <berrange@redhat.com>
* examples/domain-events/events-python/event-test.py,

View File

@ -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)

View File

@ -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 */

View File

@ -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';