Currently, setmaxmem return success on an active domain, but nothing happened. This patch will disable this behaviour, also add support persistent config. And it will be used in a later patch. Signed-off-by: Chen Hanxiao <chenhanxiao@xxxxxxxxxxxxxx> --- v2: disable changing max memory on an active domain drop useless as_assert src/lxc/lxc_driver.c | 64 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 9e12ecc..d99ab3b 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -721,10 +721,10 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, virLXCDomainObjPrivatePtr priv; virLXCDriverPtr driver = dom->conn->privateData; virLXCDriverConfigPtr cfg = NULL; - unsigned long oldmax = 0; virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | - VIR_DOMAIN_AFFECT_CONFIG, -1); + VIR_DOMAIN_AFFECT_CONFIG | + VIR_DOMAIN_MEM_MAXIMUM, -1); if (!(vm = lxcDomObjFromDomain(dom))) goto cleanup; @@ -743,32 +743,50 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, &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 (flags & VIR_DOMAIN_MEM_MAXIMUM) { + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("Cannot resize the max memory " + "on an active domain")); + goto cleanup; + } - if (newmem > oldmax) { - virReportError(VIR_ERR_INVALID_ARG, - "%s", _("Cannot set memory higher than max memory")); - goto cleanup; - } + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + persistentDef->mem.max_balloon = newmem; + if (persistentDef->mem.cur_balloon > newmem) + persistentDef->mem.cur_balloon = newmem; + if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0) + goto cleanup; + } + } else { + unsigned long oldmax = 0; - if (flags & VIR_DOMAIN_AFFECT_LIVE) { - if (virCgroupSetMemory(priv->cgroup, newmem) < 0) { - virReportError(VIR_ERR_OPERATION_FAILED, - "%s", _("Failed to set memory for domain")); - 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 (flags & VIR_DOMAIN_AFFECT_CONFIG) { - sa_assert(persistentDef); - persistentDef->mem.cur_balloon = newmem; - if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0) + if (newmem > oldmax) { + virReportError(VIR_ERR_INVALID_ARG, + "%s", _("Cannot set memory higher than max memory")); goto cleanup; + } + + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + if (virCgroupSetMemory(priv->cgroup, newmem) < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, + "%s", _("Failed to set memory for domain")); + goto cleanup; + } + } + + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + persistentDef->mem.cur_balloon = newmem; + if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0) + goto cleanup; + } } ret = 0; -- 1.9.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list