mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
lxc: Synchronize implementation of qemuDomainSetMemoryParameters
The impls are identical and I don't have a reasonable idea where to extract it. This also kills yet another use of virDomainLiveConfigHelperMethod.
This commit is contained in:
parent
bcdbab891b
commit
fcc3ccf3cd
@ -803,7 +803,7 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
|
|||||||
int nparams,
|
int nparams,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virCapsPtr caps = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
virDomainDefPtr persistentDef = NULL;
|
virDomainDefPtr persistentDef = NULL;
|
||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
virLXCDomainObjPrivatePtr priv = NULL;
|
virLXCDomainObjPrivatePtr priv = NULL;
|
||||||
@ -837,21 +837,20 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
|
|||||||
priv = vm->privateData;
|
priv = vm->privateData;
|
||||||
cfg = virLXCDriverGetConfig(driver);
|
cfg = virLXCDriverGetConfig(driver);
|
||||||
|
|
||||||
if (virDomainSetMemoryParametersEnsureACL(dom->conn, vm->def, flags) < 0 ||
|
if (virDomainSetMemoryParametersEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
!(caps = virLXCDriverGetCapabilities(driver, false)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0)
|
if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt,
|
/* QEMU and LXC implementation are identical */
|
||||||
vm, &flags, &persistentDef) < 0)
|
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE &&
|
if (def &&
|
||||||
!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_MEMORY)) {
|
!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_MEMORY)) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
"%s", _("cgroup memory controller is not mounted"));
|
_("cgroup memory controller is not mounted"));
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -868,8 +867,7 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
|
|||||||
|
|
||||||
#undef VIR_GET_LIMIT_PARAMETER
|
#undef VIR_GET_LIMIT_PARAMETER
|
||||||
|
|
||||||
/* Swap hard limit must be greater than hard limit.
|
/* Swap hard limit must be greater than hard limit. */
|
||||||
* Note that limit of 0 denotes unlimited */
|
|
||||||
if (set_swap_hard_limit || set_hard_limit) {
|
if (set_swap_hard_limit || set_hard_limit) {
|
||||||
unsigned long long mem_limit = vm->def->mem.hard_limit;
|
unsigned long long mem_limit = vm->def->mem.hard_limit;
|
||||||
unsigned long long swap_limit = vm->def->mem.swap_hard_limit;
|
unsigned long long swap_limit = vm->def->mem.swap_hard_limit;
|
||||||
@ -888,42 +886,43 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LXC_SET_MEM_PARAMETER(FUNC, VALUE) \
|
#define VIR_SET_MEM_PARAMETER(FUNC, VALUE) \
|
||||||
if (set_ ## VALUE) { \
|
if (set_ ## VALUE) { \
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) { \
|
if (def) { \
|
||||||
if ((rc = FUNC(priv->cgroup, VALUE)) < 0) { \
|
if ((rc = FUNC(priv->cgroup, VALUE)) < 0) \
|
||||||
virReportSystemError(-rc, _("unable to set memory %s tunable"), \
|
|
||||||
#VALUE); \
|
|
||||||
\
|
|
||||||
goto endjob; \
|
goto endjob; \
|
||||||
} \
|
def->mem.VALUE = VALUE; \
|
||||||
vm->def->mem.VALUE = VALUE; \
|
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) \
|
if (persistentDef) \
|
||||||
persistentDef->mem.VALUE = VALUE; \
|
persistentDef->mem.VALUE = VALUE; \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Soft limit doesn't clash with the others */
|
/* Soft limit doesn't clash with the others */
|
||||||
LXC_SET_MEM_PARAMETER(virCgroupSetMemorySoftLimit, soft_limit);
|
VIR_SET_MEM_PARAMETER(virCgroupSetMemorySoftLimit, soft_limit);
|
||||||
|
|
||||||
/* set hard limit before swap hard limit if decreasing it */
|
/* set hard limit before swap hard limit if decreasing it */
|
||||||
if (vm->def->mem.hard_limit > hard_limit) {
|
if (def && def->mem.hard_limit > hard_limit) {
|
||||||
LXC_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit);
|
VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit);
|
||||||
/* inhibit changing the limit a second time */
|
/* inhibit changing the limit a second time */
|
||||||
set_hard_limit = false;
|
set_hard_limit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LXC_SET_MEM_PARAMETER(virCgroupSetMemSwapHardLimit, swap_hard_limit);
|
VIR_SET_MEM_PARAMETER(virCgroupSetMemSwapHardLimit, swap_hard_limit);
|
||||||
|
|
||||||
/* otherwise increase it after swap hard limit */
|
/* otherwise increase it after swap hard limit */
|
||||||
LXC_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit);
|
VIR_SET_MEM_PARAMETER(virCgroupSetMemoryHardLimit, hard_limit);
|
||||||
|
|
||||||
#undef LXC_SET_MEM_PARAMETER
|
#undef VIR_SET_MEM_PARAMETER
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG &&
|
if (def &&
|
||||||
|
virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
|
||||||
|
goto endjob;
|
||||||
|
|
||||||
|
if (persistentDef &&
|
||||||
virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
|
virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
/* QEMU and LXC implementations are identical */
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
@ -932,7 +931,6 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
virObjectUnref(caps);
|
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -9134,6 +9134,7 @@ qemuDomainSetMemoryParameters(virDomainPtr dom,
|
|||||||
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
/* QEMU and LXC implementation are identical */
|
||||||
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
@ -9212,6 +9213,7 @@ qemuDomainSetMemoryParameters(virDomainPtr dom,
|
|||||||
if (persistentDef &&
|
if (persistentDef &&
|
||||||
virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
|
virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
/* QEMU and LXC implementations are identical */
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user