[lxc-devel] [lxc/master] cgroupfs: improve cgroup removal

brauner on Github lxc-bot at linuxcontainers.org
Wed Dec 11 06:39:46 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191210/bd617d35/attachment.bin>
-------------- next part --------------
From 8bc72a41d0d7579202ba052be4c5968c9965b271 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 11 Dec 2019 07:37:36 +0100
Subject: [PATCH] cgroupfs: improve cgroup removal

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/cgroups/cgfsng.c | 15 +++++++++++----
 src/lxc/cgroups/cgroup.h |  1 +
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index b5f64cc774..b0e246d2cd 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1111,20 +1111,27 @@ __cgfsng_ops static void cgfsng_monitor_destroy(struct cgroup_ops *ops,
 		return;
 
 	for (int i = 0; ops->hierarchies[i]; i++) {
-		__do_free char *base_path = NULL;
+		__do_free char *pivot_path = NULL;
 		struct hierarchy *h = ops->hierarchies[i];
 		int ret;
 
 		if (!h->monitor_full_path)
 			continue;
 
-		base_path = must_make_path(h->mountpoint, h->container_base_path, NULL);
-		ret = lxc_write_openat(base_path, "cgroup.procs", pidstr, len);
+		pivot_path = must_make_path(h->mountpoint, h->container_base_path,
+					    CGROUP_PIVOT, NULL);
+		ret = mkdir(pivot_path, 0755);
+		if (ret < 0 && errno != EEXIST)
+			log_error_errno(goto try_recursive_destroy, errno,
+					"Failed to create %s", pivot_path);
+
+		ret = lxc_write_openat(pivot_path, "cgroup.procs", pidstr, len);
 		if (ret != 0)
 			log_warn_errno(continue, errno,
 				       "Failed to move monitor %s to \"%s\"",
-				       pidstr, base_path);
+				       pidstr, pivot_path);
 
+try_recursive_destroy:
 		ret = recursive_destroy(h->monitor_full_path);
 		if (ret < 0)
 			WARN("Failed to destroy \"%s\"", h->monitor_full_path);
diff --git a/src/lxc/cgroups/cgroup.h b/src/lxc/cgroups/cgroup.h
index dccc454462..14daa1fc21 100644
--- a/src/lxc/cgroups/cgroup.h
+++ b/src/lxc/cgroups/cgroup.h
@@ -14,6 +14,7 @@
 #define DEFAULT_MONITOR_CGROUP_PREFIX "lxc.monitor."
 #define CGROUP_CREATE_RETRY "-NNNN"
 #define CGROUP_CREATE_RETRY_LEN (STRLITERALLEN(CGROUP_CREATE_RETRY))
+#define CGROUP_PIVOT "lxc.pivot"
 
 struct lxc_handler;
 struct lxc_conf;


More information about the lxc-devel mailing list