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

[libvirt] [PATCH 11/11] qemu: Remove virDomainLiveConfigHelperMethod from qemuDomainSetSchedulerParametersFlags



This refactor also makes a distinction between the pointer to the
original definition and copied one to prevent mixups.
---
 src/qemu/qemu_driver.c | 93 +++++++++++++++++++++++++-------------------------
 1 file changed, 47 insertions(+), 46 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 0fbce1b..a828a13 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9961,7 +9961,9 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
     virQEMUDriverPtr driver = dom->conn->privateData;
     size_t i;
     virDomainObjPtr vm = NULL;
-    virDomainDefPtr vmdef = NULL;
+    virDomainDefPtr def = NULL;
+    virDomainDefPtr persistentDef = NULL;
+    virDomainDefPtr persistentDefCopy = NULL;
     unsigned long long value_ul;
     long long value_l;
     int ret = -1;
@@ -10015,22 +10017,21 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
     if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
         goto cleanup;

-    if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags,
-                                        &vmdef) < 0)
+    if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
         goto endjob;

-    if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+    if (persistentDef) {
         /* Make a copy for updated domain. */
-        if (!(vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt)))
+        if (!(persistentDefCopy = virDomainObjCopyPersistentDef(vm, caps,
+                                                                driver->xmlopt)))
             goto endjob;
     }

-    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
-        if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                           "%s", _("cgroup CPU controller is not mounted"));
-            goto endjob;
-        }
+    if (def &&
+        !virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("cgroup CPU controller is not mounted"));
+        goto endjob;
     }

     for (i = 0; i < nparams; i++) {
@@ -10039,7 +10040,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
         value_l = param->value.l;

         if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
-            if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+            if (def) {
                 unsigned long long val;
                 if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0)
                     goto endjob;
@@ -10047,8 +10048,8 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                 if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
                     goto endjob;

-                vm->def->cputune.shares = val;
-                vm->def->cputune.sharesSpecified = true;
+                def->cputune.shares = val;
+                def->cputune.sharesSpecified = true;

                 if (virTypedParamsAddULLong(&eventParams, &eventNparams,
                                             &eventMaxNparams,
@@ -10057,9 +10058,9 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto endjob;
             }

-            if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-                vmdef->cputune.shares = value_ul;
-                vmdef->cputune.sharesSpecified = true;
+            if (persistentDef) {
+                persistentDefCopy->cputune.shares = value_ul;
+                persistentDefCopy->cputune.sharesSpecified = true;
             }


@@ -10067,11 +10068,11 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
             SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD,
                               QEMU_SCHED_MIN_PERIOD, QEMU_SCHED_MAX_PERIOD);

-            if (flags & VIR_DOMAIN_AFFECT_LIVE && value_ul) {
+            if (def && value_ul) {
                 if ((rc = qemuSetVcpusBWLive(vm, priv->cgroup, value_ul, 0)))
                     goto endjob;

-                vm->def->cputune.period = value_ul;
+                def->cputune.period = value_ul;

                 if (virTypedParamsAddULLong(&eventParams, &eventNparams,
                                             &eventMaxNparams,
@@ -10080,18 +10081,18 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto endjob;
             }

-            if (flags & VIR_DOMAIN_AFFECT_CONFIG)
-                vmdef->cputune.period = params[i].value.ul;
+            if (persistentDef)
+                persistentDefCopy->cputune.period = params[i].value.ul;

         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA)) {
             SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA,
                               QEMU_SCHED_MIN_QUOTA, QEMU_SCHED_MAX_QUOTA);

-            if (flags & VIR_DOMAIN_AFFECT_LIVE && value_l) {
+            if (def && value_l) {
                 if ((rc = qemuSetVcpusBWLive(vm, priv->cgroup, 0, value_l)))
                     goto endjob;

-                vm->def->cputune.quota = value_l;
+                def->cputune.quota = value_l;

                 if (virTypedParamsAddLLong(&eventParams, &eventNparams,
                                            &eventMaxNparams,
@@ -10100,18 +10101,18 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto endjob;
             }

-            if (flags & VIR_DOMAIN_AFFECT_CONFIG)
-                vmdef->cputune.quota = value_l;
+            if (persistentDef)
+                persistentDefCopy->cputune.quota = value_l;

         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD)) {
             SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD,
                               QEMU_SCHED_MIN_PERIOD, QEMU_SCHED_MAX_PERIOD);

-            if (flags & VIR_DOMAIN_AFFECT_LIVE && value_ul) {
+            if (def && value_ul) {
                 if ((rc = qemuSetGlobalBWLive(priv->cgroup, value_ul, 0)))
                     goto endjob;

-                vm->def->cputune.global_period = value_ul;
+                def->cputune.global_period = value_ul;

                 if (virTypedParamsAddULLong(&eventParams, &eventNparams,
                                             &eventMaxNparams,
@@ -10120,18 +10121,18 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto endjob;
             }

-            if (flags & VIR_DOMAIN_AFFECT_CONFIG)
-                vmdef->cputune.period = params[i].value.ul;
+            if (persistentDef)
+                persistentDefCopy->cputune.period = params[i].value.ul;

         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA)) {
             SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA,
                               QEMU_SCHED_MIN_QUOTA, QEMU_SCHED_MAX_QUOTA);

-            if (flags & VIR_DOMAIN_AFFECT_LIVE && value_l) {
+            if (def && value_l) {
                 if ((rc = qemuSetGlobalBWLive(priv->cgroup, 0, value_l)))
                     goto endjob;

-                vm->def->cputune.global_quota = value_l;
+                def->cputune.global_quota = value_l;

                 if (virTypedParamsAddLLong(&eventParams, &eventNparams,
                                            &eventMaxNparams,
@@ -10140,19 +10141,19 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto endjob;
             }

-            if (flags & VIR_DOMAIN_AFFECT_CONFIG)
-                vmdef->cputune.global_quota = value_l;
+            if (persistentDef)
+                persistentDefCopy->cputune.global_quota = value_l;

         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD)) {
             SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD,
                               QEMU_SCHED_MIN_PERIOD, QEMU_SCHED_MAX_PERIOD);

-            if (flags & VIR_DOMAIN_AFFECT_LIVE && value_ul) {
+            if (def && value_ul) {
                 if ((rc = qemuSetEmulatorBandwidthLive(priv->cgroup,
                                                        value_ul, 0)))
                     goto endjob;

-                vm->def->cputune.emulator_period = value_ul;
+                def->cputune.emulator_period = value_ul;

                 if (virTypedParamsAddULLong(&eventParams, &eventNparams,
                                             &eventMaxNparams,
@@ -10161,19 +10162,19 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto endjob;
             }

-            if (flags & VIR_DOMAIN_AFFECT_CONFIG)
-                vmdef->cputune.emulator_period = value_ul;
+            if (persistentDef)
+                persistentDefCopy->cputune.emulator_period = value_ul;

         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA)) {
             SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA,
                               QEMU_SCHED_MIN_QUOTA, QEMU_SCHED_MAX_QUOTA);

-            if (flags & VIR_DOMAIN_AFFECT_LIVE && value_l) {
+            if (def && value_l) {
                 if ((rc = qemuSetEmulatorBandwidthLive(priv->cgroup,
                                                        0, value_l)))
                     goto endjob;

-                vm->def->cputune.emulator_quota = value_l;
+                def->cputune.emulator_quota = value_l;

                 if (virTypedParamsAddLLong(&eventParams, &eventNparams,
                                            &eventMaxNparams,
@@ -10182,8 +10183,8 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto endjob;
             }

-            if (flags & VIR_DOMAIN_AFFECT_CONFIG)
-                vmdef->cputune.emulator_quota = value_l;
+            if (persistentDef)
+                persistentDefCopy->cputune.emulator_quota = value_l;
         }
     }

@@ -10196,13 +10197,13 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
         qemuDomainEventQueue(driver, event);
     }

-    if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-        rc = virDomainSaveConfig(cfg->configDir, driver->caps, vmdef);
+    if (persistentDef) {
+        rc = virDomainSaveConfig(cfg->configDir, driver->caps, persistentDefCopy);
         if (rc < 0)
             goto endjob;

-        virDomainObjAssignDef(vm, vmdef, false, NULL);
-        vmdef = NULL;
+        virDomainObjAssignDef(vm, persistentDefCopy, false, NULL);
+        persistentDefCopy = NULL;
     }

     ret = 0;
@@ -10211,7 +10212,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
     qemuDomainObjEndJob(driver, vm);

  cleanup:
-    virDomainDefFree(vmdef);
+    virDomainDefFree(persistentDefCopy);
     virDomainObjEndAPI(&vm);
     if (eventNparams)
         virTypedParamsFree(eventParams, eventNparams);
-- 
2.8.2


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