diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index d33423572c..545e8bb2d3 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -68,7 +68,12 @@ static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid); static int openvzGetMaxVCPUs(virConnectPtr conn, const char *type); static int openvzDomainGetMaxVcpus(virDomainPtr dom); static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus); -static int openvzDomainSetVcpusInternal(virConnectPtr conn, virDomainObjPtr vm, unsigned int nvcpus); +static int openvzDomainSetVcpusInternal(virConnectPtr conn, + virDomainObjPtr vm, + unsigned int nvcpus); +static int openvzDomainSetMemoryInternal(virConnectPtr conn, + virDomainObjPtr vm, + unsigned long memory); static void openvzDriverLock(struct openvz_driver *driver) { @@ -804,6 +809,14 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml) } } + if (vm->def->memory > 0) { + if (openvzDomainSetMemoryInternal(conn, vm, vm->def->memory) < 0) { + openvzError(conn, VIR_ERR_INTERNAL_ERROR, + "%s", _("Could not set memory size")); + goto cleanup; + } + } + dom = virGetDomain(conn, vm->def->name, vm->def->uuid); if (dom) dom->id = -1; @@ -1359,6 +1372,31 @@ static int openvzNumDefinedDomains(virConnectPtr conn) { return n; } +static int +openvzDomainSetMemoryInternal(virConnectPtr conn, virDomainObjPtr vm, + unsigned long mem) +{ + char str_mem[16]; + const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINAL, + "--kmemsize", str_mem, "--save", NULL + }; + + /* memory has to be changed its format from kbyte to byte */ + snprintf(str_mem, sizeof(str_mem), "%lu", mem * 1024); + + openvzSetProgramSentinal(prog, vm->def->name); + if (virRun(conn, prog, NULL) < 0) { + openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _("Could not exec %s"), VZCTL); + goto cleanup; + } + + return 0; + +cleanup: + return -1; +} + static virDriver openvzDriver = { VIR_DRV_OPENVZ, "OPENVZ",