The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/3018
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Closes #3017 Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From 3ac6d174807b371336b50ab3a134f282f8216e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com> Date: Sat, 4 Mar 2017 18:19:43 -0500 Subject: [PATCH] Properly revert memory limits on failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3017 Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- lxd/container_lxc.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go index acb5217..efd7c72 100644 --- a/lxd/container_lxc.go +++ b/lxd/container_lxc.go @@ -3367,21 +3367,57 @@ func (c *containerLXC) Update(args containerArgs, userRequested bool) error { memory = fmt.Sprintf("%d", valueInt) } + // Store the old values for revert + oldMemswLimit := "" + if cgSwapAccounting { + oldMemswLimit, err = c.CGroupGet("memory.memsw.limit_in_bytes") + if err != nil { + oldMemswLimit = "" + } + } + + oldLimit, err := c.CGroupGet("memory.limit_in_bytes") + if err != nil { + oldLimit = "" + } + + oldSoftLimit, err := c.CGroupGet("memory.soft_limit_in_bytes") + if err != nil { + oldSoftLimit = "" + } + + revertMemory := func() { + if oldSoftLimit != "" { + c.CGroupSet("memory.soft_limit_in_bytes", oldSoftLimit) + } + + if oldLimit != "" { + c.CGroupSet("memory.limit_in_bytes", oldLimit) + } + + if oldMemswLimit != "" { + c.CGroupSet("memory.memsw.limit_in_bytes", oldMemswLimit) + } + } + // Reset everything if cgSwapAccounting { err = c.CGroupSet("memory.memsw.limit_in_bytes", "-1") if err != nil { + revertMemory() return err } } err = c.CGroupSet("memory.limit_in_bytes", "-1") if err != nil { + revertMemory() return err } err = c.CGroupSet("memory.soft_limit_in_bytes", "-1") if err != nil { + revertMemory() return err } @@ -3390,21 +3426,26 @@ func (c *containerLXC) Update(args containerArgs, userRequested bool) error { // Set new limit err = c.CGroupSet("memory.soft_limit_in_bytes", memory) if err != nil { + revertMemory() return err } } else { if cgSwapAccounting && (memorySwap == "" || shared.IsTrue(memorySwap)) { err = c.CGroupSet("memory.limit_in_bytes", memory) if err != nil { + revertMemory() return err } + err = c.CGroupSet("memory.memsw.limit_in_bytes", memory) if err != nil { + revertMemory() return err } } else { err = c.CGroupSet("memory.limit_in_bytes", memory) if err != nil { + revertMemory() return err } }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel