]> git.proxmox.com Git - mirror_lxc.git/commitdiff
Avoid double lxc-freeze/unfreeze
authorRachid Koucha <47061324+Rachid-Koucha@users.noreply.github.com>
Sat, 26 Jan 2019 22:46:34 +0000 (23:46 +0100)
committerGitHub <noreply@github.com>
Sat, 26 Jan 2019 22:46:34 +0000 (23:46 +0100)
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@gmail.com>
src/lxc/lxccontainer.c

index bee34db015115dddd250ceb6480dc6a1bca74c4e..364c6c7a784efc452e81b27381ff9bf2fcf55571 100644 (file)
@@ -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;
 }