]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups/freezer: fix and improve cgroup2 freezer implementation
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 3 Dec 2019 01:23:34 +0000 (02:23 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 3 Dec 2019 22:55:00 +0000 (23:55 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/commands.c

index 6d24be5f29851985d8becc3be35053c7e43b8caf..588006eb90cb7c4409873a14c834734e53833a3f 100644 (file)
@@ -1255,6 +1255,72 @@ static int lxc_cmd_unfreeze_callback(int fd, struct lxc_cmd_req *req,
        return lxc_cmd_rsp_send(fd, &rsp);
 }
 
+int lxc_cmd_freeze(const char *name, const char *lxcpath, int timeout)
+{
+       int ret, stopped;
+       struct lxc_cmd_rr cmd = {
+               .req = {
+                       .cmd = LXC_CMD_FREEZE,
+                       .data = INT_TO_PTR(timeout),
+               },
+       };
+
+       ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
+       if (ret <= 0 || cmd.rsp.ret < 0)
+               return error_log_errno(errno, "Failed to freeze container");
+
+       return cmd.rsp.ret;
+}
+
+static int lxc_cmd_freeze_callback(int fd, struct lxc_cmd_req *req,
+                                  struct lxc_handler *handler,
+                                  struct lxc_epoll_descr *descr)
+{
+       int timeout = PTR_TO_INT(req->data);
+       struct lxc_cmd_rsp rsp = {
+           .ret = -ENOENT,
+       };
+       struct cgroup_ops *ops = handler->cgroup_ops;
+
+       if (ops->cgroup_layout == CGROUP_LAYOUT_UNIFIED)
+               rsp.ret = ops->freeze(ops, timeout);
+
+       return lxc_cmd_rsp_send(fd, &rsp);
+}
+
+int lxc_cmd_unfreeze(const char *name, const char *lxcpath, int timeout)
+{
+       int ret, stopped;
+       struct lxc_cmd_rr cmd = {
+               .req = {
+                       .cmd = LXC_CMD_UNFREEZE,
+                       .data = INT_TO_PTR(timeout),
+               },
+       };
+
+       ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
+       if (ret <= 0 || cmd.rsp.ret < 0)
+               return error_log_errno(errno, "Failed to unfreeze container");
+
+       return cmd.rsp.ret;
+}
+
+static int lxc_cmd_unfreeze_callback(int fd, struct lxc_cmd_req *req,
+                                  struct lxc_handler *handler,
+                                  struct lxc_epoll_descr *descr)
+{
+       int timeout = PTR_TO_INT(req->data);
+       struct lxc_cmd_rsp rsp = {
+           .ret = -ENOENT,
+       };
+       struct cgroup_ops *ops = handler->cgroup_ops;
+
+       if (ops->cgroup_layout == CGROUP_LAYOUT_UNIFIED)
+               rsp.ret = ops->unfreeze(ops, timeout);
+
+       return lxc_cmd_rsp_send(fd, &rsp);
+}
+
 static int lxc_cmd_process(int fd, struct lxc_cmd_req *req,
                           struct lxc_handler *handler,
                           struct lxc_epoll_descr *descr)