From: Nikunj A. Dadhania <nikunj(a)linux.vnet.ibm.com>
V4:
* prototype change: add unsigned int flags
Driver interface for getting memory parameters, eg. hard_limit, soft_limit and
swap_hard_limit.
Signed-off-by: Nikunj A. Dadhania <nikunj(a)linux.vnet.ibm.com>
---
src/qemu/qemu_driver.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 119 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 471db39..8eaa762 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9458,6 +9458,124 @@ cleanup:
return ret;
}
+static int qemuDomainGetMemoryParameters(virDomainPtr dom,
+ virMemoryParameterPtr params,
+ int *nparams,
+ unsigned int flags ATTRIBUTE_UNUSED)
+{
+ struct qemud_driver *driver = dom->conn->privateData;
+ int i;
+ virCgroupPtr group = NULL;
+ virDomainObjPtr vm = NULL;
+ unsigned long val;
+ int ret = -1;
+ int rc;
+
+ 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 ((*nparams) == 0) {
+ /* Current number of memory parameters supported by cgroups is 3
+ * FIXME: Magic number, need to see where should this go
+ */
+ *nparams = 3;
+ ret = 0;
+ goto cleanup;
+ }
+
+ if ((*nparams) != 3) {
+ qemuReportError(VIR_ERR_INVALID_ARG,
+ "%s", _("Invalid parameter count"));
+ 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 = ¶ms[i];
+ val = 0;
+ param->value.ul = 0;
+ param->type = VIR_DOMAIN_MEMORY_FIELD_ULLONG;
+
+ switch(i) {
+ case 0: /* fill memory hard limit here */
+ rc = virCgroupGetMemoryHardLimit(group, &val);
+ if (rc != 0) {
+ virReportSystemError(-rc, "%s",
+ _("unable to get memory hard limit"));
+ continue;
+ }
+ if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT) == NULL)
{
+ qemuReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("Field memory hard limit too long
for destination"));
+ continue;
+ }
+ param->value.ul = val;
+ break;
+
+ case 1: /* fill memory soft limit here */
+ rc = virCgroupGetMemorySoftLimit(group, &val);
+ if (rc != 0) {
+ virReportSystemError(-rc, "%s",
+ _("unable to get memory soft limit"));
+ continue;
+ }
+ if (virStrcpyStatic(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT) == NULL)
{
+ qemuReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("Field memory soft limit too long
for destination"));
+ continue;
+ }
+ param->value.ul = val;
+ break;
+
+ case 2: /* fill swap hard limit here */
+ rc = virCgroupGetSwapHardLimit(group, &val);
+ if (rc != 0) {
+ virReportSystemError(-rc, "%s",
+ _("unable to get swap hard limit"));
+ continue;
+ }
+ if (virStrcpyStatic(param->field, VIR_DOMAIN_SWAP_HARD_LIMIT) == NULL) {
+ qemuReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("Field swap hard limit too long
for destination"));
+ continue;
+ }
+ param->value.ul = val;
+ break;
+
+ default:
+ break;
+ /* should not hit here */
+ }
+ }
+ ret = 0;
+
+cleanup:
+ if (group)
+ virCgroupFree(&group);
+ if (vm)
+ virDomainObjUnlock(vm);
+ qemuDriverUnlock(driver);
+ return ret;
+}
+
static int qemuSetSchedulerParameters(virDomainPtr dom,
virSchedParameterPtr params,
int nparams)
@@ -12804,7 +12922,7 @@ static virDriver qemuDriver = {
qemuDomainSnapshotDelete, /* domainSnapshotDelete */
qemuDomainMonitorCommand, /* qemuDomainMonitorCommand */
qemuDomainSetMemoryParameters, /* domainSetMemoryParameters */
- NULL, /* domainGetMemoryParameters */
+ qemuDomainGetMemoryParameters, /* domainGetMemoryParameters */
};