[lxc-devel] [PATCH 3/1] stop cmd callback: unfreeze by path only

Serge Hallyn serge.hallyn at ubuntu.com
Wed Jan 15 19:40:53 UTC 2014


in particular, regular unfreeze uses the cmd api to request the cgroup
of the container.  If we are already in the lxc-start monitor, we can't
use the cmd api.

(I knew when I started this would be a problem but then as it didn't
reliably crash, I forgot to handle it)

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 src/lxc/cgmanager.c | 13 +++++++++++++
 src/lxc/cgroup.c    | 21 +++++++++++++++++++++
 src/lxc/cgroup.h    |  2 ++
 src/lxc/commands.c  |  2 +-
 4 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/lxc/cgmanager.c b/src/lxc/cgmanager.c
index 53a1802..21083da 100644
--- a/src/lxc/cgmanager.c
+++ b/src/lxc/cgmanager.c
@@ -358,6 +358,18 @@ out_free:
 	return false;
 }
 
+static int cgm_unfreeze_fromhandler(struct lxc_handler *handler)
+{
+	struct cgm_data *d = handler->cgroup_info->data;
+
+	if (cgmanager_set_value_sync(NULL, cgroup_manager, "freezer", d->cgroup_path,
+			"freezer.state", "THAWED") != 0) {
+		ERROR("Error unfreezing %s", d->cgroup_path);
+		return false;
+	}
+	return true;
+}
+
 static struct cgroup_ops cgmanager_ops = {
 	.destroy = cgm_destroy,
 	.init = cgm_init,
@@ -367,6 +379,7 @@ static struct cgroup_ops cgmanager_ops = {
 	.get_cgroup = cgm_get_cgroup,
 	.get = cgm_get,
 	.set = cgm_set,
+	.unfreeze_fromhandler = cgm_unfreeze_fromhandler,
 	.name = "cgmanager"
 };
 #endif
diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c
index efc3e23..2b7eca0 100644
--- a/src/lxc/cgroup.c
+++ b/src/lxc/cgroup.c
@@ -2153,6 +2153,21 @@ static char *cgfs_get_cgroup(struct lxc_handler *handler, const char *subsystem)
 	return lxc_cgroup_get_hierarchy_path_handler(subsystem, handler);
 }
 
+static int cgfs_unfreeze_fromhandler(struct lxc_handler *handler)
+{
+	char *cgabspath, *cgrelpath;
+	int ret;
+
+	cgrelpath = lxc_cgroup_get_hierarchy_path_handler("freezer", handler);
+	cgabspath = lxc_cgroup_find_abs_path("freezer", cgrelpath, true, NULL);
+	if (!cgabspath)
+		return -1;
+
+	ret = do_cgroup_set(cgabspath, "freezer.state", "THAWED");
+	free(cgabspath);
+	return ret;
+}
+
 static struct cgroup_ops cgfs_ops = {
 	.destroy = cgfs_destroy,
 	.init = cgfs_init,
@@ -2162,6 +2177,7 @@ static struct cgroup_ops cgfs_ops = {
 	.get_cgroup = cgfs_get_cgroup,
 	.get = lxc_cgroupfs_get,
 	.set = lxc_cgroupfs_set,
+	.unfreeze_fromhandler = cgfs_unfreeze_fromhandler,
 	.name = "cgroupfs",
 };
 static void init_cg_ops(void)
@@ -2266,3 +2282,8 @@ int lxc_cgroup_get(const char *filename, char *value, size_t len, const char *na
 	init_cg_ops();
 	return active_cg_ops->get(filename, value, len, name, lxcpath);
 }
+
+int lxc_unfreeze_fromhandler(struct lxc_handler *handler)
+{
+	return active_cg_ops->unfreeze_fromhandler(handler);
+}
diff --git a/src/lxc/cgroup.h b/src/lxc/cgroup.h
index 8316e79..2b5a183 100644
--- a/src/lxc/cgroup.h
+++ b/src/lxc/cgroup.h
@@ -178,6 +178,7 @@ struct cgroup_ops {
 	char *(*get_cgroup)(struct lxc_handler *handler, const char *subsystem);
 	int (*set)(const char *filename, const char *value, const char *name, const char *lxcpath);
 	int (*get)(const char *filename, char *value, size_t len, const char *name, const char *lxcpath);
+	int (*unfreeze_fromhandler)(struct lxc_handler *handler);
 	const char *name;
 };
 
@@ -214,5 +215,6 @@ extern bool cgroup_create_legacy(struct lxc_handler *handler);
 extern char *cgroup_get_cgroup(struct lxc_handler *handler, const char *subsystem);
 extern int lxc_cgroup_set(const char *filename, const char *value, const char *name, const char *lxcpath);
 extern int lxc_cgroup_get(const char *filename, char *value, size_t len, const char *name, const char *lxcpath);
+extern int lxc_unfreeze_fromhandler(struct lxc_handler *handler);
 
 #endif
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 29aa905..8b42c59 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -591,7 +591,7 @@ static int lxc_cmd_stop_callback(int fd, struct lxc_cmd_req *req,
 	memset(&rsp, 0, sizeof(rsp));
 	rsp.ret = kill(handler->pid, stopsignal);
 	if (!rsp.ret) {
-		ret = lxc_unfreeze(handler->name, handler->lxcpath);
+		ret = lxc_unfreeze_fromhandler(handler);
 		if (!ret)
 			return 0;
 		ERROR("Failed to unfreeze %s:%s", handler->lxcpath, handler->name);
-- 
1.8.5.2



More information about the lxc-devel mailing list