[libvirt] [patch] Add openvzDomainSetMemoryInternal

Yuji NISHIDA nishidy at nict.go.jp
Tue Oct 27 07:12:47 UTC 2009


Hi all,

This patch is to set KMEMSIZE for OpenVZ.
This function is used for initializing the parameter of KMEMSIZE to  
start container.
openvzDomainSetMemory should be left for another purpose so I added  
new one.

I think users should specify memory as kbyte ( or bigger ).

---
  src/openvz/openvz_driver.c |   32 ++++++++++++++++++++++++++++++++
  1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index f64ad1e..5c1fefa 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -69,6 +69,7 @@ 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 openvzDomainSetMemoryInternal(virConnectPtr conn,  
virDomainObjPtr vm, unsigned long memory);

  static void openvzDriverLock(struct openvz_driver *driver)
  {
@@ -803,6 +804,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;
@@ -1364,6 +1373,29 @@ static int openvzNumDefinedDomains 
(virConnectPtr conn) {
      return ninactive;
  }

+static int openvzDomainSetMemoryInternal(virConnectPtr conn,  
virDomainObjPtr vm,
+                                 unsigned long mem) {
+    struct openvz_driver *driver = conn->privateData;
+    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",
-- 
1.5.3.4


-----
Yuji Nishida
nishidy at nict.go.jp




More information about the libvir-list mailing list