* src/qemu_driver.c: Add driver methods qemuGetSchedulerType,
qemuGetSchedulerParameters, qemuSetSchedulerParameters
---
src/qemu_driver.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 135 insertions(+), 3 deletions(-)
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index b336fef..f6d3f52 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -4965,6 +4965,138 @@ cleanup:
return ret;
}
+
+static char *qemuGetSchedulerType(virDomainPtr dom,
+ int *nparams)
+{
+ char *ret;
+
+ if (virCgroupHaveSupport() != 0) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
+ __FUNCTION__);
+ return NULL;
+ }
+
+ if (nparams)
+ *nparams = 1;
+
+ ret = strdup("posix");
+ if (!ret)
+ virReportOOMError(dom->conn);
+ return ret;
+}
+
+static int qemuSetSchedulerParameters(virDomainPtr dom,
+ virSchedParameterPtr params,
+ int nparams)
+{
+ struct qemud_driver *driver = dom->conn->privateData;
+ int i;
+ virCgroupPtr group = NULL;
+ virDomainObjPtr vm = NULL;
+ int ret = -1;
+
+ if (virCgroupHaveSupport() != 0) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
+ __FUNCTION__);
+ return -1;
+ }
+
+ qemuDriverLock(driver);
+ vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+ qemuDriverUnlock(driver);
+
+ if (vm == NULL) {
+ qemudReportError(dom->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("No such domain %s"), dom->uuid);
+ goto cleanup;
+ }
+
+ if (virCgroupForDomain(vm->def, "qemu", &group) != 0)
+ goto cleanup;
+
+ for (i = 0; i < nparams; i++) {
+ virSchedParameterPtr param = ¶ms[i];
+
+ if (STREQ(param->field, "cpu_shares")) {
+ int rc;
+ rc = virCgroupSetCpuShares(group, params[i].value.ui);
+ if (rc != 0) {
+ virReportSystemError(dom->conn, -rc, "%s",
+ _("unable to set cpu shares tunable"));
+ goto cleanup;
+ }
+ } else {
+ qemudReportError(dom->conn, domain, NULL, VIR_ERR_INVALID_ARG,
+ _("Invalid parameter `%s'"),
param->field);
+ goto cleanup;
+ }
+ }
+ ret = 0;
+
+cleanup:
+ virCgroupFree(&group);
+ if (vm)
+ virDomainObjUnlock(vm);
+ return ret;
+}
+
+static int qemuGetSchedulerParameters(virDomainPtr dom,
+ virSchedParameterPtr params,
+ int *nparams)
+{
+ struct qemud_driver *driver = dom->conn->privateData;
+ virCgroupPtr group = NULL;
+ virDomainObjPtr vm = NULL;
+ unsigned long val;
+ int ret = -1;
+ int rc;
+
+ if (virCgroupHaveSupport() != 0) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
+ __FUNCTION__);
+ return -1;
+ }
+
+ if ((*nparams) != 1) {
+ qemudReportError(dom->conn, domain, NULL, VIR_ERR_INVALID_ARG,
+ "%s", _("Invalid parameter count"));
+ return -1;
+ }
+
+ qemuDriverLock(driver);
+ vm = virDomainFindByUUID(&driver->domains, dom->uuid);
+ qemuDriverUnlock(driver);
+
+ if (vm == NULL) {
+ qemudReportError(dom->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("No such domain %s"), dom->uuid);
+ goto cleanup;
+ }
+
+ if (virCgroupForDomain(vm->def, "qemu", &group) != 0)
+ goto cleanup;
+
+ rc = virCgroupGetCpuShares(group, &val);
+ if (rc != 0) {
+ virReportSystemError(dom->conn, -rc, "%s",
+ _("unable to get cpu shares tunable"));
+ goto cleanup;
+ }
+ params[0].value.ul = val;
+ strncpy(params[0].field, "cpu_shares", sizeof(params[0].field));
+ params[0].type = VIR_DOMAIN_SCHED_FIELD_ULLONG;
+
+ ret = 0;
+
+cleanup:
+ virCgroupFree(&group);
+ if (vm)
+ virDomainObjUnlock(vm);
+ return ret;
+}
+
+
/* This uses the 'info blockstats' monitor command which was
* integrated into both qemu & kvm in late 2007. If the command is
* not supported we detect this and return the appropriate error.
@@ -5933,9 +6065,9 @@ static virDriver qemuDriver = {
qemudDomainDetachDevice, /* domainDetachDevice */
qemudDomainGetAutostart, /* domainGetAutostart */
qemudDomainSetAutostart, /* domainSetAutostart */
- NULL, /* domainGetSchedulerType */
- NULL, /* domainGetSchedulerParameters */
- NULL, /* domainSetSchedulerParameters */
+ qemuGetSchedulerType, /* domainGetSchedulerType */
+ qemuGetSchedulerParameters, /* domainGetSchedulerParameters */
+ qemuSetSchedulerParameters, /* domainSetSchedulerParameters */
NULL, /* domainMigratePrepare (v1) */
qemudDomainMigratePerform, /* domainMigratePerform */
NULL, /* domainMigrateFinish */
--
1.6.2.5