[CRIU] [PATCH 1/2] cgroup: collect_cgroups in get_cg_set

Tycho Andersen tycho.andersen at canonical.com
Thu Mar 3 09:14:36 PST 2016


Instead of all the flags and checks in dump_task_cgroup, let's just collect
every new non-criu cgset.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 criu/cgroup.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/criu/cgroup.c b/criu/cgroup.c
index fa7d4c9..3db6cbd 100644
--- a/criu/cgroup.c
+++ b/criu/cgroup.c
@@ -172,15 +172,15 @@ static bool cg_set_compare(struct cg_set *set, struct list_head *ctls, int what)
 	}
 }
 
-static struct cg_set *get_cg_set(struct list_head *ctls, unsigned int n_ctls, bool *existed)
+static int collect_cgroups(struct list_head *ctls);
+
+static struct cg_set *get_cg_set(struct list_head *ctls, unsigned int n_ctls, bool collect)
 {
 	struct cg_set *cs;
-	*existed = false;
 
 	list_for_each_entry(cs, &cg_sets, l)
 		if (cg_set_compare(cs, ctls, CGCMP_MATCH)) {
 			pr_debug(" `- Existing css %d found\n", cs->id);
-			*existed = true;
 			put_ctls(ctls);
 			return cs;
 		}
@@ -201,6 +201,12 @@ static struct cg_set *get_cg_set(struct list_head *ctls, unsigned int n_ctls, bo
 			list_for_each_entry(ctl, &cs->ctls, l)
 				pr_debug("    `- [%s] -> [%s] [%u]\n", ctl->name, ctl->path, ctl->cgns_prefix);
 		}
+
+		if (collect && collect_cgroups(&cs->ctls)) {
+			put_ctls(ctls);
+			xfree(cs);
+			return NULL;
+		}
 	}
 
 	return cs;
@@ -677,7 +683,6 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_
 	LIST_HEAD(ctls);
 	unsigned int n_ctls = 0;
 	struct cg_set *cs;
-	bool existed = false;
 
 	if (item)
 		pid = item->pid.real;
@@ -688,7 +693,7 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_
 	if (parse_task_cgroup(pid, args, &ctls, &n_ctls))
 		return -1;
 
-	cs = get_cg_set(&ctls, n_ctls, &existed);
+	cs = get_cg_set(&ctls, n_ctls, item);
 	if (!cs)
 		return -1;
 
@@ -725,13 +730,6 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_
 				}
 			}
 		}
-
-		/*
-		 * The on-stack ctls is moved into cs inside
-		 * the get_cg_set routine.
-		 */
-		if (cs != criu_cgset && !existed && collect_cgroups(&cs->ctls))
-			return -1;
 	}
 
 	*cg_id = cs->id;
-- 
2.7.0



More information about the CRIU mailing list