[lxc-devel] [lxc/master] Avoid double lxc-freeze/unfreeze
Rachid-Koucha on Github
lxc-bot at linuxcontainers.org
Sat Jan 26 22:47:13 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 699 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190126/a413646e/attachment.bin>
-------------- next part --------------
From 2341916a0367130d5a084a89884c15c3a835a4b4 Mon Sep 17 00:00:00 2001
From: Rachid Koucha <47061324+Rachid-Koucha at users.noreply.github.com>
Date: Sat, 26 Jan 2019 23:46:34 +0100
Subject: [PATCH] Avoid double lxc-freeze/unfreeze
If we call lxc-freeze multiple times for an already frozen container, LXC
triggers useless freezing by writing into the "freezer.state" cgroup file.
This is the same when we call lxc-unfreeze multiple times.
Checking the current state with a LXC_CMD_GET_STATE
(calling c->state) would permit to check if the container is FROZEN
or not.
Signed-off-by: Rachid Koucha <rachid.koucha at gmail.com>
---
src/lxc/lxccontainer.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index bee34db015..364c6c7a78 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -525,13 +525,17 @@ WRAP_API(bool, lxcapi_is_running)
static bool do_lxcapi_freeze(struct lxc_container *c)
{
int ret;
+ lxc_state_t s;
if (!c)
return false;
- ret = lxc_freeze(c->lxc_conf, c->name, c->config_path);
- if (ret < 0)
- return false;
+ s = lxc_getstate(c->name, c->config_path);
+ if (s != FROZEN) {
+ ret = lxc_freeze(c->lxc_conf, c->name, c->config_path);
+ if (ret < 0)
+ return false;
+ }
return true;
}
@@ -541,13 +545,17 @@ WRAP_API(bool, lxcapi_freeze)
static bool do_lxcapi_unfreeze(struct lxc_container *c)
{
int ret;
+ lxc_state_t s;
if (!c)
return false;
- ret = lxc_unfreeze(c->lxc_conf, c->name, c->config_path);
- if (ret < 0)
- return false;
+ s = lxc_getstate(c->name, c->config_path);
+ if (s == FROZEN) {
+ ret = lxc_unfreeze(c->lxc_conf, c->name, c->config_path);
+ if (ret < 0)
+ return false;
+ }
return true;
}
More information about the lxc-devel
mailing list