[PATCH v2 2/4] qemu: introduce qemuSetSchedulerParametersFlags

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

 



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 5f3167a..9ba1e56 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4770,7 +4770,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;
@@ -4864,16 +4864,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,
@@ -4889,13 +4894,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;
@@ -4912,20 +4918,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:
@@ -4936,6 +4961,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)
@@ -4969,9 +5004,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) {
@@ -4986,6 +5020,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) {
@@ -7146,7 +7181,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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]