Support for virDomainSetSchedulerParametersFlags of qemu driver.
---
src/qemu/qemu_driver.c | 67 ++++++++++++++++++++++++++++++++++++-----------
1 files changed, 51 insertions(+), 16 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 15c5744..c769637 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4768,7 +4768,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
goto cleanup;
}
- if (!virDomainObjIsActive(vm)) {
+ if (!virDomainObjIsActive(vm) && (flags & VIR_DOMAIN_SCHEDPARAM_LIVE)) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
goto cleanup;
@@ -4862,16 +4862,21 @@ cleanup:
return ret;
}
-static int qemuSetSchedulerParameters(virDomainPtr dom,
- virSchedParameterPtr params,
- int nparams)
+static int qemuSetSchedulerParametersFlags(virDomainPtr dom,
+ virSchedParameterPtr params,
+ int nparams,
+ unsigned int flags)
{
struct qemud_driver *driver = dom->conn->privateData;
int i;
virCgroupPtr group = NULL;
virDomainObjPtr vm = NULL;
+ virDomainDefPtr persistentDef = NULL;
int ret = -1;
+ virCheckFlags(VIR_DOMAIN_SCHEDPARAM_LIVE |
+ VIR_DOMAIN_SCHEDPARAM_CONFIG, -1);
+
qemuDriverLock(driver);
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
@@ -4887,13 +4892,14 @@ static int qemuSetSchedulerParameters(virDomainPtr dom,
goto cleanup;
}
- if (!virDomainObjIsActive(vm)) {
+ if (!virDomainObjIsActive(vm) && (flags & VIR_DOMAIN_SCHEDPARAM_LIVE)) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is not running"));
goto cleanup;
}
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0)
{
+ if ((flags & VIR_DOMAIN_SCHEDPARAM_LIVE) &&
+ 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;
@@ -4910,20 +4916,39 @@ static int qemuSetSchedulerParameters(virDomainPtr dom,
goto cleanup;
}
- rc = virCgroupSetCpuShares(group, params[i].value.ul);
- if (rc != 0) {
- virReportSystemError(-rc, "%s",
- _("unable to set cpu shares tunable"));
- goto cleanup;
+ if (flags & VIR_DOMAIN_SCHEDPARAM_LIVE) {
+ rc = virCgroupSetCpuShares(group, params[i].value.ul);
+ if (rc != 0) {
+ virReportSystemError(-rc, "%s",
+ _("unable to set cpu shares
tunable"));
+ goto cleanup;
+ }
+
+ vm->def->cputune.shares = params[i].value.ul;
}
- vm->def->cputune.shares = params[i].value.ul;
+ if (flags & VIR_DOMAIN_SCHEDPARAM_CONFIG) {
+ persistentDef = virDomainObjGetPersistentDef(driver->caps, vm);
+ if (!persistentDef) {
+ qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("can't get persistentDef"));
+ goto cleanup;
+ }
+ persistentDef->cputune.shares = params[i].value.ul;
+ rc = virDomainSaveConfig(driver->configDir, persistentDef);
+ if (rc) {
+ qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("can't save config"));
+ goto cleanup;
+ }
+ }
} else {
qemuReportError(VIR_ERR_INVALID_ARG,
_("Invalid parameter `%s'"), param->field);
goto cleanup;
}
}
+
ret = 0;
cleanup:
@@ -4934,6 +4959,16 @@ cleanup:
return ret;
}
+static int qemuSetSchedulerParameters(virDomainPtr dom,
+ virSchedParameterPtr params,
+ int nparams)
+{
+ return qemuSetSchedulerParametersFlags(dom,
+ params,
+ nparams,
+ VIR_DOMAIN_SCHEDPARAM_LIVE);
+}
+
static int qemuGetSchedulerParameters(virDomainPtr dom,
virSchedParameterPtr params,
int *nparams)
@@ -4967,9 +5002,8 @@ static int qemuGetSchedulerParameters(virDomainPtr dom,
}
if (!virDomainObjIsActive(vm)) {
- qemuReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("domain is not running"));
- goto cleanup;
+ val = vm->def->cputune.shares;
+ goto out;
}
if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0)
{
@@ -4984,6 +5018,7 @@ static int qemuGetSchedulerParameters(virDomainPtr dom,
_("unable to get cpu shares tunable"));
goto cleanup;
}
+out:
params[0].value.ul = val;
params[0].type = VIR_DOMAIN_SCHED_FIELD_ULLONG;
if (virStrcpyStatic(params[0].field, "cpu_shares") == NULL) {
@@ -7148,7 +7183,7 @@ static virDriver qemuDriver = {
qemuGetSchedulerType, /* domainGetSchedulerType */
qemuGetSchedulerParameters, /* domainGetSchedulerParameters */
qemuSetSchedulerParameters, /* domainSetSchedulerParameters */
- NULL, /* domainSetSchedulerParametersFlags */
+ qemuSetSchedulerParametersFlags, /* domainSetSchedulerParametersFlags */
NULL, /* domainMigratePrepare (v1) */
qemudDomainMigratePerform, /* domainMigratePerform */
NULL, /* domainMigrateFinish */
--
1.7.3.1
--
Thanks,
Hu Tao