mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
Use virDomainObjGetDefs in lxcDomainSetMemoryFlags
On LXC domain startup we have already called virDomainObjSetDefTransient to fill vm->newDef. There is no need to call virDomainLiveConfigHelperMethod which has the ability to fill newDef if it's NULL.
This commit is contained in:
parent
c646cd742a
commit
15654cc594
@ -695,8 +695,8 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
|
virDomainDefPtr def = NULL;
|
||||||
virDomainDefPtr persistentDef = NULL;
|
virDomainDefPtr persistentDef = NULL;
|
||||||
virCapsPtr caps = NULL;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virLXCDomainObjPrivatePtr priv;
|
virLXCDomainObjPrivatePtr priv;
|
||||||
virLXCDriverPtr driver = dom->conn->privateData;
|
virLXCDriverPtr driver = dom->conn->privateData;
|
||||||
@ -719,22 +719,18 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0)
|
if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(caps = virLXCDriverGetCapabilities(driver, false)))
|
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
||||||
goto endjob;
|
|
||||||
|
|
||||||
if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags,
|
|
||||||
&persistentDef) < 0)
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_MEM_MAXIMUM) {
|
if (flags & VIR_DOMAIN_MEM_MAXIMUM) {
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (def) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
_("Cannot resize the max memory "
|
_("Cannot resize the max memory "
|
||||||
"on an active domain"));
|
"on an active domain"));
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
if (persistentDef) {
|
||||||
virDomainDefSetMemoryTotal(persistentDef, newmem);
|
virDomainDefSetMemoryTotal(persistentDef, newmem);
|
||||||
if (persistentDef->mem.cur_balloon > newmem)
|
if (persistentDef->mem.cur_balloon > newmem)
|
||||||
persistentDef->mem.cur_balloon = newmem;
|
persistentDef->mem.cur_balloon = newmem;
|
||||||
@ -745,9 +741,9 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
} else {
|
} else {
|
||||||
unsigned long oldmax = 0;
|
unsigned long oldmax = 0;
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE)
|
if (def)
|
||||||
oldmax = virDomainDefGetMemoryActual(vm->def);
|
oldmax = virDomainDefGetMemoryActual(def);
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
if (persistentDef) {
|
||||||
if (!oldmax || oldmax > virDomainDefGetMemoryActual(persistentDef))
|
if (!oldmax || oldmax > virDomainDefGetMemoryActual(persistentDef))
|
||||||
oldmax = virDomainDefGetMemoryActual(persistentDef);
|
oldmax = virDomainDefGetMemoryActual(persistentDef);
|
||||||
}
|
}
|
||||||
@ -758,19 +754,19 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
if (def) {
|
||||||
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 endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
vm->def->mem.cur_balloon = newmem;
|
def->mem.cur_balloon = newmem;
|
||||||
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
|
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
if (persistentDef) {
|
||||||
persistentDef->mem.cur_balloon = newmem;
|
persistentDef->mem.cur_balloon = newmem;
|
||||||
if (virDomainSaveConfig(cfg->configDir, driver->caps,
|
if (virDomainSaveConfig(cfg->configDir, driver->caps,
|
||||||
persistentDef) < 0)
|
persistentDef) < 0)
|
||||||
@ -785,7 +781,6 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
virObjectUnref(caps);
|
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user