]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Set KMEMSIZE for OpenVZ domains being defined
authorYuji NISHIDA <nishidy@nict.go.jp>
Mon, 2 Nov 2009 16:39:46 +0000 (17:39 +0100)
committerDaniel Veillard <veillard@redhat.com>
Mon, 2 Nov 2009 16:39:46 +0000 (17:39 +0100)
* src/openvz/openvz_driver.c: add a new openvzDomainSetMemoryInternal()
  function, used to initialize the KMEMSIZE parameter of a container.

src/openvz/openvz_driver.c

index d33423572c617180ad786a6da75b2b63bb4cebe2..545e8bb2d3b5c053d77edcc098764ff6e0168253 100644 (file)
@@ -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",