[CRIU] [PATCH 07/10] cgroup: only inspect the root task for cgns prefixes

Tycho Andersen tycho.andersen at canonical.com
Wed Mar 2 15:17:05 PST 2016


Because we don't support nested cgroup namespaces, we can just grab the
cgns prefixes from the root cgset's prefix list. This means we only have to
query one task for its cgroup file, instead of potentially each of them.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 criu/cgroup.c  | 24 +++++++++++++++++++++++-
 criu/cr-dump.c | 11 ++++-------
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/criu/cgroup.c b/criu/cgroup.c
index 0ad70bf..f6a581d 100644
--- a/criu/cgroup.c
+++ b/criu/cgroup.c
@@ -701,9 +701,31 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_
 			BUG_ON(root_cgset);
 			root_cgset = cs;
 			pr_info("Set %d is root one\n", cs->id);
-		} else
+		} else {
+			struct cg_ctl *root, *stray;
+
+			BUG_ON(!root_cgset);
 			pr_info("Set %d is a stray\n", cs->id);
 
+			/* Copy the cgns prefix from the root cgset for each
+			 * controller. This is ok because we know that there is
+			 * only one cgroup namespace.
+			 */
+			list_for_each_entry(root, &root_cgset->ctls, l) {
+				list_for_each_entry(stray, &cs->ctls, l) {
+					if (strcmp(root->name, stray->name))
+						continue;
+
+					if (strlen(stray->path) < root->cgns_prefix) {
+						pr_err("cg %s shorter than path prefix %d?\n", stray->path, root->cgns_prefix);
+						return -1;
+					}
+
+					stray->cgns_prefix = root->cgns_prefix;
+				}
+			}
+		}
+
 		/*
 		 * The on-stack ctls is moved into cs inside
 		 * the get_cg_set routine.
diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 4ec2a55..1cb4608 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -728,14 +728,11 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
 	if (ret)
 		goto err;
 
-	/* If this is the root task and it has a cgroup ns id, it could be in
-	 * a cgroup namespace and we should try to figure out the prefix. Or,
-	 * if the task is not the parent task and its cgroup namespace differs
-	 * from its parent's, this is a nested cgns and we should compute the
-	 * prefix.
+	/* For now, we only need to dump the root task's cgroup ns, because we
+	 * know all the tasks are in the same cgroup namespace because we don't
+	 * allow nesting.
 	 */
-	if (item->ids->has_cgroup_ns_id && (!item->parent ||
-			(item->ids->cgroup_ns_id != item->parent->ids->cgroup_ns_id))) {
+	if (item->ids->has_cgroup_ns_id && !item->parent) {
 		info = &cgroup_args;
 		ret = parasite_dump_cgroup(ctl, &cgroup_args);
 		if (ret)
-- 
2.7.0



More information about the CRIU mailing list