mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
qemu: Remove virDomainLiveConfigHelperMethod from qemuDomainSetSchedulerParametersFlags
This refactor also makes a distinction between the pointer to the original definition and copied one to prevent mixups.
This commit is contained in:
parent
48dc930aab
commit
a5c70e58f2
@ -9962,7 +9962,9 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
virQEMUDriverPtr driver = dom->conn->privateData;
|
virQEMUDriverPtr driver = dom->conn->privateData;
|
||||||
size_t i;
|
size_t i;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
virDomainDefPtr vmdef = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
|
virDomainDefPtr persistentDef = NULL;
|
||||||
|
virDomainDefPtr persistentDefCopy = NULL;
|
||||||
unsigned long long value_ul;
|
unsigned long long value_ul;
|
||||||
long long value_l;
|
long long value_l;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -10016,22 +10018,21 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags,
|
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
||||||
&vmdef) < 0)
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
if (persistentDef) {
|
||||||
/* Make a copy for updated domain. */
|
/* Make a copy for updated domain. */
|
||||||
if (!(vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt)))
|
if (!(persistentDefCopy = virDomainObjCopyPersistentDef(vm, caps,
|
||||||
|
driver->xmlopt)))
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (def &&
|
||||||
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
|
!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
"%s", _("cgroup CPU controller is not mounted"));
|
_("cgroup CPU controller is not mounted"));
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nparams; i++) {
|
for (i = 0; i < nparams; i++) {
|
||||||
@ -10040,7 +10041,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
value_l = param->value.l;
|
value_l = param->value.l;
|
||||||
|
|
||||||
if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
|
if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (def) {
|
||||||
unsigned long long val;
|
unsigned long long val;
|
||||||
if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0)
|
if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
@ -10048,8 +10049,8 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
|
if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
vm->def->cputune.shares = val;
|
def->cputune.shares = val;
|
||||||
vm->def->cputune.sharesSpecified = true;
|
def->cputune.sharesSpecified = true;
|
||||||
|
|
||||||
if (virTypedParamsAddULLong(&eventParams, &eventNparams,
|
if (virTypedParamsAddULLong(&eventParams, &eventNparams,
|
||||||
&eventMaxNparams,
|
&eventMaxNparams,
|
||||||
@ -10058,9 +10059,9 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
if (persistentDef) {
|
||||||
vmdef->cputune.shares = value_ul;
|
persistentDefCopy->cputune.shares = value_ul;
|
||||||
vmdef->cputune.sharesSpecified = true;
|
persistentDefCopy->cputune.sharesSpecified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -10068,11 +10069,11 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD,
|
SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD,
|
||||||
QEMU_SCHED_MIN_PERIOD, QEMU_SCHED_MAX_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)))
|
if ((rc = qemuSetVcpusBWLive(vm, priv->cgroup, value_ul, 0)))
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
vm->def->cputune.period = value_ul;
|
def->cputune.period = value_ul;
|
||||||
|
|
||||||
if (virTypedParamsAddULLong(&eventParams, &eventNparams,
|
if (virTypedParamsAddULLong(&eventParams, &eventNparams,
|
||||||
&eventMaxNparams,
|
&eventMaxNparams,
|
||||||
@ -10081,18 +10082,18 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG)
|
if (persistentDef)
|
||||||
vmdef->cputune.period = params[i].value.ul;
|
persistentDefCopy->cputune.period = params[i].value.ul;
|
||||||
|
|
||||||
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA)) {
|
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA)) {
|
||||||
SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA,
|
SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA,
|
||||||
QEMU_SCHED_MIN_QUOTA, QEMU_SCHED_MAX_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)))
|
if ((rc = qemuSetVcpusBWLive(vm, priv->cgroup, 0, value_l)))
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
vm->def->cputune.quota = value_l;
|
def->cputune.quota = value_l;
|
||||||
|
|
||||||
if (virTypedParamsAddLLong(&eventParams, &eventNparams,
|
if (virTypedParamsAddLLong(&eventParams, &eventNparams,
|
||||||
&eventMaxNparams,
|
&eventMaxNparams,
|
||||||
@ -10101,18 +10102,18 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG)
|
if (persistentDef)
|
||||||
vmdef->cputune.quota = value_l;
|
persistentDefCopy->cputune.quota = value_l;
|
||||||
|
|
||||||
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD)) {
|
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD)) {
|
||||||
SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD,
|
SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD,
|
||||||
QEMU_SCHED_MIN_PERIOD, QEMU_SCHED_MAX_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)))
|
if ((rc = qemuSetGlobalBWLive(priv->cgroup, value_ul, 0)))
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
vm->def->cputune.global_period = value_ul;
|
def->cputune.global_period = value_ul;
|
||||||
|
|
||||||
if (virTypedParamsAddULLong(&eventParams, &eventNparams,
|
if (virTypedParamsAddULLong(&eventParams, &eventNparams,
|
||||||
&eventMaxNparams,
|
&eventMaxNparams,
|
||||||
@ -10121,18 +10122,18 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG)
|
if (persistentDef)
|
||||||
vmdef->cputune.period = params[i].value.ul;
|
persistentDefCopy->cputune.period = params[i].value.ul;
|
||||||
|
|
||||||
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA)) {
|
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA)) {
|
||||||
SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA,
|
SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA,
|
||||||
QEMU_SCHED_MIN_QUOTA, QEMU_SCHED_MAX_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)))
|
if ((rc = qemuSetGlobalBWLive(priv->cgroup, 0, value_l)))
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
vm->def->cputune.global_quota = value_l;
|
def->cputune.global_quota = value_l;
|
||||||
|
|
||||||
if (virTypedParamsAddLLong(&eventParams, &eventNparams,
|
if (virTypedParamsAddLLong(&eventParams, &eventNparams,
|
||||||
&eventMaxNparams,
|
&eventMaxNparams,
|
||||||
@ -10141,19 +10142,19 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG)
|
if (persistentDef)
|
||||||
vmdef->cputune.global_quota = value_l;
|
persistentDefCopy->cputune.global_quota = value_l;
|
||||||
|
|
||||||
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD)) {
|
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD)) {
|
||||||
SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD,
|
SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD,
|
||||||
QEMU_SCHED_MIN_PERIOD, QEMU_SCHED_MAX_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,
|
if ((rc = qemuSetEmulatorBandwidthLive(priv->cgroup,
|
||||||
value_ul, 0)))
|
value_ul, 0)))
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
vm->def->cputune.emulator_period = value_ul;
|
def->cputune.emulator_period = value_ul;
|
||||||
|
|
||||||
if (virTypedParamsAddULLong(&eventParams, &eventNparams,
|
if (virTypedParamsAddULLong(&eventParams, &eventNparams,
|
||||||
&eventMaxNparams,
|
&eventMaxNparams,
|
||||||
@ -10162,19 +10163,19 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG)
|
if (persistentDef)
|
||||||
vmdef->cputune.emulator_period = value_ul;
|
persistentDefCopy->cputune.emulator_period = value_ul;
|
||||||
|
|
||||||
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA)) {
|
} else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA)) {
|
||||||
SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA,
|
SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA,
|
||||||
QEMU_SCHED_MIN_QUOTA, QEMU_SCHED_MAX_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,
|
if ((rc = qemuSetEmulatorBandwidthLive(priv->cgroup,
|
||||||
0, value_l)))
|
0, value_l)))
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
vm->def->cputune.emulator_quota = value_l;
|
def->cputune.emulator_quota = value_l;
|
||||||
|
|
||||||
if (virTypedParamsAddLLong(&eventParams, &eventNparams,
|
if (virTypedParamsAddLLong(&eventParams, &eventNparams,
|
||||||
&eventMaxNparams,
|
&eventMaxNparams,
|
||||||
@ -10183,8 +10184,8 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG)
|
if (persistentDef)
|
||||||
vmdef->cputune.emulator_quota = value_l;
|
persistentDefCopy->cputune.emulator_quota = value_l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10197,13 +10198,13 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
qemuDomainEventQueue(driver, event);
|
qemuDomainEventQueue(driver, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
if (persistentDef) {
|
||||||
rc = virDomainSaveConfig(cfg->configDir, driver->caps, vmdef);
|
rc = virDomainSaveConfig(cfg->configDir, driver->caps, persistentDefCopy);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
virDomainObjAssignDef(vm, vmdef, false, NULL);
|
virDomainObjAssignDef(vm, persistentDefCopy, false, NULL);
|
||||||
vmdef = NULL;
|
persistentDefCopy = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -10212,7 +10213,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
qemuDomainObjEndJob(driver, vm);
|
qemuDomainObjEndJob(driver, vm);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainDefFree(vmdef);
|
virDomainDefFree(persistentDefCopy);
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
if (eventNparams)
|
if (eventNparams)
|
||||||
virTypedParamsFree(eventParams, eventNparams);
|
virTypedParamsFree(eventParams, eventNparams);
|
||||||
|
Loading…
Reference in New Issue
Block a user