[libvirt] [PATCH 1/3] lxc: make maximum and current settings same

Nikolay Shirokovskiy nshirokovskiy at virtuozzo.com
Mon Jan 18 12:46:27 UTC 2016


And keep cur_balloon and initial_memory the same internally.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy at virtuozzo.com>
---
 src/lxc/lxc_driver.c | 58 +++++++++++++---------------------------------------
 1 file changed, 14 insertions(+), 44 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 24b9622..6e298c6 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -725,54 +725,24 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
                                         &persistentDef) < 0)
         goto cleanup;
 
-    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"));
+    if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+        virDomainDefSetMemoryTotal(persistentDef, newmem);
+        persistentDef->mem.cur_balloon = newmem;
+        if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0)
             goto cleanup;
-        }
-
-        if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-            virDomainDefSetMemoryTotal(persistentDef, 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)
-            oldmax = virDomainDefGetMemoryActual(vm->def);
-        if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-            if (!oldmax || oldmax > virDomainDefGetMemoryActual(persistentDef))
-                oldmax = virDomainDefGetMemoryActual(persistentDef);
-        }
+    }
 
-        if (newmem > oldmax) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           "%s", _("Cannot set memory higher than max memory"));
+    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) {
-            if (virCgroupSetMemory(priv->cgroup, newmem) < 0) {
-                virReportError(VIR_ERR_OPERATION_FAILED,
-                               "%s", _("Failed to set memory for domain"));
-                goto cleanup;
-            }
-
-            vm->def->mem.cur_balloon = newmem;
-            if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
-                goto cleanup;
-        }
-
-        if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-            persistentDef->mem.cur_balloon = newmem;
-            if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0)
-                goto cleanup;
-        }
+        virDomainDefSetMemoryTotal(vm->def, newmem);
+        vm->def->mem.cur_balloon = newmem;
+        if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
+            goto cleanup;
     }
 
     ret = 0;
@@ -792,7 +762,7 @@ static int lxcDomainSetMemory(virDomainPtr dom, unsigned long newmem)
 
 static int lxcDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax)
 {
-    return lxcDomainSetMemoryFlags(dom, newmax, VIR_DOMAIN_MEM_MAXIMUM);
+    return lxcDomainSetMemoryFlags(dom, newmax, VIR_DOMAIN_MEM_CURRENT);
 }
 
 static int
-- 
1.8.3.1




More information about the libvir-list mailing list