[PATCH 4/7] qemu: introduce qemuGetSchedulerParametersFlags

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

 



* src/qemu/qemu_driver.c (qemuGetSchedulerParameters): Move
guts...
(qemuGetSchedulerParametersFlags): ...to new callback, and honor
flags more accurately.
---
 src/qemu/qemu_driver.c |   77 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 66 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fdb3b30..ba02379 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5073,7 +5073,7 @@ static int qemuSetSchedulerParametersFlags(virDomainPtr dom,
             flags = VIR_DOMAIN_SCHEDPARAM_CONFIG;
     }

-    if ((flags & VIR_DOMAIN_MEM_CONFIG) && !vm->persistent) {
+    if ((flags & VIR_DOMAIN_SCHEDPARAM_CONFIG) && !vm->persistent) {
         qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
                         _("cannot change persistent config of a transient domain"));
         goto cleanup;
@@ -5163,9 +5163,11 @@ static int qemuSetSchedulerParameters(virDomainPtr dom,
                                            VIR_DOMAIN_SCHEDPARAM_LIVE);
 }

-static int qemuGetSchedulerParameters(virDomainPtr dom,
-                                      virSchedParameterPtr params,
-                                      int *nparams)
+static int
+qemuGetSchedulerParametersFlags(virDomainPtr dom,
+                                virSchedParameterPtr params,
+                                int *nparams,
+                                unsigned int flags)
 {
     struct qemud_driver *driver = dom->conn->privateData;
     virCgroupPtr group = NULL;
@@ -5173,11 +5175,15 @@ static int qemuGetSchedulerParameters(virDomainPtr dom,
     unsigned long long val;
     int ret = -1;
     int rc;
+    bool isActive;

-    qemuDriverLock(driver);
-    if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
-        qemuReportError(VIR_ERR_OPERATION_INVALID,
-                        "%s", _("cgroup CPU controller is not mounted"));
+    virCheckFlags(VIR_DOMAIN_SCHEDPARAM_LIVE |
+                  VIR_DOMAIN_SCHEDPARAM_CONFIG, -1);
+
+    if ((flags & (VIR_DOMAIN_SCHEDPARAM_LIVE | VIR_DOMAIN_SCHEDPARAM_CONFIG)) ==
+        (VIR_DOMAIN_SCHEDPARAM_LIVE | VIR_DOMAIN_SCHEDPARAM_CONFIG)) {
+        qemuReportError(VIR_ERR_INVALID_ARG, "%s",
+                        _("cannot query live and config together"));
         goto cleanup;
     }

@@ -5187,6 +5193,7 @@ static int qemuGetSchedulerParameters(virDomainPtr dom,
         goto cleanup;
     }

+    qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);

     if (vm == NULL) {
@@ -5195,11 +5202,50 @@ static int qemuGetSchedulerParameters(virDomainPtr dom,
         goto cleanup;
     }

-    if (!virDomainObjIsActive(vm)) {
-        val = vm->def->cputune.shares;
+    isActive = virDomainObjIsActive(vm);
+
+    if (flags == VIR_DOMAIN_SCHEDPARAM_CURRENT) {
+        if (isActive)
+            flags = VIR_DOMAIN_SCHEDPARAM_LIVE;
+        else
+            flags = VIR_DOMAIN_SCHEDPARAM_CONFIG;
+    }
+
+    if (flags & VIR_DOMAIN_SCHEDPARAM_CONFIG) {
+        if (!vm->persistent) {
+            qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                            _("cannot query persistent config of a transient domain"));
+            goto cleanup;
+        }
+
+        if (isActive) {
+            virDomainDefPtr persistentDef;
+
+            persistentDef = virDomainObjGetPersistentDef(driver->caps, vm);
+            if (!persistentDef) {
+                qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                                _("can't get persistentDef"));
+                goto cleanup;
+            }
+            val = persistentDef->cputune.shares;
+        } else {
+            val = vm->def->cputune.shares;
+        }
         goto out;
     }

+    if (!isActive) {
+        qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                        _("domain is not running"));
+        goto cleanup;
+    }
+
+    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);
@@ -5231,6 +5277,14 @@ cleanup:
     return ret;
 }

+static int
+qemuGetSchedulerParameters(virDomainPtr dom,
+                           virSchedParameterPtr params,
+                           int *nparams)
+{
+    return qemuGetSchedulerParametersFlags(dom, params, nparams,
+                                           VIR_DOMAIN_SCHEDPARAM_CURRENT);
+}

 /* This uses the 'info blockstats' monitor command which was
  * integrated into both qemu & kvm in late 2007.  If the command is
@@ -7676,7 +7730,9 @@ static virDriver qemuDriver = {
     .domainSetAutostart = qemudDomainSetAutostart, /* 0.2.1 */
     .domainGetSchedulerType = qemuGetSchedulerType, /* 0.7.0 */
     .domainGetSchedulerParameters = qemuGetSchedulerParameters, /* 0.7.0 */
+    .domainGetSchedulerParametersFlags = qemuGetSchedulerParametersFlags, /* 0.9.2 */
     .domainSetSchedulerParameters = qemuSetSchedulerParameters, /* 0.7.0 */
+    .domainSetSchedulerParametersFlags = qemuSetSchedulerParametersFlags, /* 0.9.2 */
     .domainMigratePerform = qemudDomainMigratePerform, /* 0.5.0 */
     .domainBlockStats = qemudDomainBlockStats, /* 0.4.1 */
     .domainInterfaceStats = qemudDomainInterfaceStats, /* 0.4.1 */
@@ -7728,7 +7784,6 @@ 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.4.4

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