[PATCH v3 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 |   94 ++++++++++++++++++++++++++++++++++++------------
 1 files changed, 71 insertions(+), 23 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ccaae66..d3b832d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4835,7 +4835,7 @@ static int qemuDomainSetMemoryParameters(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;
@@ -5038,22 +5038,24 @@ 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;
+    bool isActive;
+
+    virCheckFlags(VIR_DOMAIN_SCHEDPARAM_LIVE |
+                  VIR_DOMAIN_SCHEDPARAM_CONFIG |
+                  VIR_DOMAIN_SCHEDPARAM_CURRENT, -1);
 
     qemuDriverLock(driver);
-    if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
-        qemuReportError(VIR_ERR_OPERATION_INVALID,
-                        "%s", _("cgroup CPU controller is not mounted"));
-        goto cleanup;
-    }
 
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
 
@@ -5063,16 +5065,32 @@ static int qemuSetSchedulerParameters(virDomainPtr dom,
         goto cleanup;
     }
 
-    if (!virDomainObjIsActive(vm)) {
+    isActive = virDomainObjIsActive(vm);
+
+    if (flags == VIR_DOMAIN_SCHEDPARAM_CURRENT) {
+        if (isActive)
+            flags = VIR_DOMAIN_SCHEDPARAM_LIVE;
+        else
+            flags = VIR_DOMAIN_SCHEDPARAM_CONFIG;
+    }
+
+    if (!isActive && (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) {
-        qemuReportError(VIR_ERR_INTERNAL_ERROR,
-                        _("cannot find cgroup for domain %s"), vm->def->name);
-        goto cleanup;
+    if (flags & VIR_DOMAIN_SCHEDPARAM_LIVE) {
+        if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
+            qemuReportError(VIR_ERR_OPERATION_INVALID,
+                            "%s", _("cgroup CPU controller is not mounted"));
+            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++) {
@@ -5086,20 +5104,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:
@@ -5110,6 +5147,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)
@@ -5143,9 +5190,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) {
@@ -5160,6 +5206,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) {
@@ -7675,6 +7722,7 @@ static virDriver qemuDriver = {
     .domainMigratePerform3 = qemuDomainMigratePerform3, /* 0.9.2 */
     .domainMigrateFinish3 = qemuDomainMigrateFinish3, /* 0.9.2 */
     .domainMigrateConfirm3 = qemuDomainMigrateConfirm3, /* 0.9.2 */
+    .domainSetSchedulerParametersFlags = qemuSetSchedulerParametersFlags, /* 0.9.2 */
 };
 
 
-- 
1.7.3.1

--
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]