[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 06/12] Implement driver interface domainSetMemoryParamters for QEmu



Driver interface for setting memory hard_limit, soft_limit and swap
hard_limit. This patch also NULLs the other HV driver interface structure.

Signed-off-by: Nikunj A. Dadhania <nikunj linux vnet ibm com>
---
 src/esx/esx_driver.c       |    1 
 src/lxc/lxc_driver.c       |    1 
 src/openvz/openvz_driver.c |    1 
 src/phyp/phyp_driver.c     |    1 
 src/qemu/qemu_driver.c     |   93 ++++++++++++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c |    1 
 src/test/test_driver.c     |    1 
 src/uml/uml_driver.c       |    1 
 src/xen/xen_driver.c       |    1 
 9 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index e382950..be55796 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -4217,6 +4217,7 @@ static virDriver esxDriver = {
     esxDomainRevertToSnapshot,       /* domainRevertToSnapshot */
     esxDomainSnapshotDelete,         /* domainSnapshotDelete */
     NULL,                            /* qemuDomainMonitorCommand */
+    NULL,                            /* domainSetMemoryParameters */
 };
 
 
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index bcd4381..9e37906 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2620,6 +2620,7 @@ static virDriver lxcDriver = {
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
     NULL, /* qemuDomainMonitorCommand */
+    NULL, /* domainSetMemoryParameters */
 };
 
 static virStateDriver lxcStateDriver = {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index d6621f0..beee006 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1657,6 +1657,7 @@ static virDriver openvzDriver = {
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
     NULL, /* qemuDomainMonitorCommand */
+    NULL, /* domainSetMemoryParameters */
 };
 
 int openvzRegister(void) {
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 8eeba73..fce451c 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -3980,6 +3980,7 @@ static virDriver phypDriver = {
     NULL,                       /* domainRevertToSnapshot */
     NULL,                       /* domainSnapshotDelete */
     NULL,                       /* qemuMonitorCommand */
+    NULL,                       /* domainSetMemoryParameters */
 };
 
 static virStorageDriver phypStorageDriver = {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c4aacc9..06666e9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9365,6 +9365,98 @@ cleanup:
     return ret;
 }
 
+
+static int qemuDomainSetMemoryParameters(virDomainPtr dom,
+                                         virMemoryParameterPtr params,
+                                         int nparams)
+{
+    struct qemud_driver *driver = dom->conn->privateData;
+    int i;
+    virCgroupPtr group = NULL;
+    virDomainObjPtr vm = NULL;
+    int ret = -1;
+
+    qemuDriverLock(driver);
+    if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY)) {
+        qemuReportError(VIR_ERR_NO_SUPPORT,
+                        __FUNCTION__);
+        goto cleanup;
+    }
+
+    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+
+    if (vm == NULL) {
+        qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                        _("No such domain %s"), dom->uuid);
+        goto cleanup;
+    }
+
+    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
+        qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                        _("cannot find cgroup for domain %s"), vm->def->name);
+        goto cleanup;
+    }
+
+    for (i = 0; i < nparams; i++) {
+        virMemoryParameterPtr param = &params[i];
+
+        if (STREQ(param->field, "hard_limit")) {
+            int rc;
+            if (param->type != VIR_DOMAIN_MEMORY_FIELD_ULLONG) {
+                qemuReportError(VIR_ERR_INVALID_ARG, "%s",
+                                _("invalid type for memory hard_limit tunable, expected a 'ullong'"));
+                continue;
+            }
+
+            rc = virCgroupSetMemoryHardLimit(group, params[i].value.ul);
+            if (rc != 0) {
+                virReportSystemError(-rc, "%s",
+                                     _("unable to set memory hard_limit tunable"));
+            }
+        } else if (STREQ(param->field, "soft_limit")) {
+            int rc;
+            if (param->type != VIR_DOMAIN_MEMORY_FIELD_ULLONG) {
+                qemuReportError(VIR_ERR_INVALID_ARG, "%s",
+                                _("invalid type for memory soft_limit tunable, expected a 'ullong'"));
+                continue;
+            }
+
+            rc = virCgroupSetMemorySoftLimit(group, params[i].value.ul);
+            if (rc != 0) {
+                virReportSystemError(-rc, "%s",
+                                     _("unable to set memory soft_limit tunable"));
+            }
+        } else if (STREQ(param->field, "swap_hard_limit")) {
+            int rc;
+            if (param->type != VIR_DOMAIN_MEMORY_FIELD_ULLONG) {
+                qemuReportError(VIR_ERR_INVALID_ARG, "%s",
+                                _("invalid type for swap_hard_limit tunable, expected a 'ullong'"));
+                continue;
+            }
+
+            rc = virCgroupSetSwapHardLimit(group, params[i].value.ul);
+            if (rc != 0) {
+                virReportSystemError(-rc, "%s",
+                                     _("unable to set swap_hard_limit tunable"));
+            }
+        } else if (STREQ(param->field, "min_gaurantee")) {
+            qemuReportError(VIR_ERR_INVALID_ARG,
+                            _("Memory tunable `%s' not implemented"), param->field);
+        } else {
+            qemuReportError(VIR_ERR_INVALID_ARG,
+                            _("Parameter `%s' not supported"), param->field);
+        }
+    }
+    ret = 0;
+
+cleanup:
+    virCgroupFree(&group);
+    if (vm)
+        virDomainObjUnlock(vm);
+    qemuDriverUnlock(driver);
+    return ret;
+}
+
 static int qemuSetSchedulerParameters(virDomainPtr dom,
                                       virSchedParameterPtr params,
                                       int nparams)
@@ -12710,6 +12802,7 @@ static virDriver qemuDriver = {
     qemuDomainRevertToSnapshot, /* domainRevertToSnapshot */
     qemuDomainSnapshotDelete, /* domainSnapshotDelete */
     qemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
+    qemuDomainSetMemoryParameters, /* domainSetMemoryParameters */
 };
 
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index a945710..1e9cb6c 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -10358,6 +10358,7 @@ static virDriver remote_driver = {
     remoteDomainRevertToSnapshot, /* domainRevertToSnapshot */
     remoteDomainSnapshotDelete, /* domainSnapshotDelete */
     remoteQemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
+    NULL, /* domainSetMemoryParameters */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 729025e..382d5a8 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5327,6 +5327,7 @@ static virDriver testDriver = {
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
     NULL, /* qemuDomainMonitorCommand */
+    NULL, /* domainSetMemoryParameters */
 };
 
 static virNetworkDriver testNetworkDriver = {
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index de52db6..9003e9a 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -2196,6 +2196,7 @@ static virDriver umlDriver = {
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
     NULL, /* qemuDomainMonitorCommand */
+    NULL, /* domainSetMemoryParamters */
 };
 
 static int
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 56ba41b..e5ed3d7 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2006,6 +2006,7 @@ static virDriver xenUnifiedDriver = {
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
     NULL, /* qemuDomainMonitorCommand */
+    NULL, /* domainSetMemoryParameters */
 };
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]