mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
LXC: add support for --config in setmem command
In lxc, we could not use setmem command with --config options. This patch will add support for this. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
This commit is contained in:
parent
d1abf819cf
commit
1387c0a415
@ -711,46 +711,81 @@ static int lxcDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lxcDomainSetMemory(virDomainPtr dom, unsigned long newmem)
|
static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
|
virDomainDefPtr persistentDef = NULL;
|
||||||
|
virCapsPtr caps = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virLXCDomainObjPrivatePtr priv;
|
virLXCDomainObjPrivatePtr priv;
|
||||||
|
virLXCDriverPtr driver = dom->conn->privateData;
|
||||||
|
virLXCDriverConfigPtr cfg = NULL;
|
||||||
|
unsigned long oldmax = 0;
|
||||||
|
|
||||||
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
|
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||||
|
|
||||||
if (!(vm = lxcDomObjFromDomain(dom)))
|
if (!(vm = lxcDomObjFromDomain(dom)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
cfg = virLXCDriverGetConfig(driver);
|
||||||
|
|
||||||
priv = vm->privateData;
|
priv = vm->privateData;
|
||||||
|
|
||||||
if (virDomainSetMemoryEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainSetMemoryFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (newmem > vm->def->mem.max_balloon) {
|
if (!(caps = virLXCDriverGetCapabilities(driver, false)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags,
|
||||||
|
&persistentDef) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_AFFECT_LIVE)
|
||||||
|
oldmax = vm->def->mem.max_balloon;
|
||||||
|
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||||
|
if (!oldmax || oldmax > persistentDef->mem.max_balloon)
|
||||||
|
oldmax = persistentDef->mem.max_balloon;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newmem > oldmax) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
"%s", _("Cannot set memory higher than max memory"));
|
"%s", _("Cannot set memory higher than max memory"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virDomainObjIsActive(vm)) {
|
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
||||||
"%s", _("Domain is not running"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virCgroupSetMemory(priv->cgroup, newmem) < 0) {
|
if (virCgroupSetMemory(priv->cgroup, newmem) < 0) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
"%s", _("Failed to set memory for domain"));
|
"%s", _("Failed to set memory for domain"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||||
|
sa_assert(persistentDef);
|
||||||
|
persistentDef->mem.cur_balloon = newmem;
|
||||||
|
if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (vm)
|
if (vm)
|
||||||
virObjectUnlock(vm);
|
virObjectUnlock(vm);
|
||||||
|
virObjectUnref(caps);
|
||||||
|
virObjectUnref(cfg);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int lxcDomainSetMemory(virDomainPtr dom, unsigned long newmem)
|
||||||
|
{
|
||||||
|
return lxcDomainSetMemoryFlags(dom, newmem, VIR_DOMAIN_AFFECT_LIVE);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
lxcDomainSetMemoryParameters(virDomainPtr dom,
|
lxcDomainSetMemoryParameters(virDomainPtr dom,
|
||||||
virTypedParameterPtr params,
|
virTypedParameterPtr params,
|
||||||
@ -5697,6 +5732,7 @@ static virDriver lxcDriver = {
|
|||||||
.domainGetMaxMemory = lxcDomainGetMaxMemory, /* 0.7.2 */
|
.domainGetMaxMemory = lxcDomainGetMaxMemory, /* 0.7.2 */
|
||||||
.domainSetMaxMemory = lxcDomainSetMaxMemory, /* 0.7.2 */
|
.domainSetMaxMemory = lxcDomainSetMaxMemory, /* 0.7.2 */
|
||||||
.domainSetMemory = lxcDomainSetMemory, /* 0.7.2 */
|
.domainSetMemory = lxcDomainSetMemory, /* 0.7.2 */
|
||||||
|
.domainSetMemoryFlags = lxcDomainSetMemoryFlags, /* 1.2.7 */
|
||||||
.domainSetMemoryParameters = lxcDomainSetMemoryParameters, /* 0.8.5 */
|
.domainSetMemoryParameters = lxcDomainSetMemoryParameters, /* 0.8.5 */
|
||||||
.domainGetMemoryParameters = lxcDomainGetMemoryParameters, /* 0.8.5 */
|
.domainGetMemoryParameters = lxcDomainGetMemoryParameters, /* 0.8.5 */
|
||||||
.domainSetBlkioParameters = lxcDomainSetBlkioParameters, /* 0.9.8 */
|
.domainSetBlkioParameters = lxcDomainSetBlkioParameters, /* 0.9.8 */
|
||||||
|
Loading…
Reference in New Issue
Block a user