[CRIU] [PATCH 1/6] pstree: move state from pstree_item to pid

Andrey Vagin avagin at openvz.org
Thu Mar 10 11:24:38 PST 2016


From: Andrew Vagin <avagin at virtuozzo.com>

I'm going to collect all pids in rbtree, but threads doesn't have
pstree-entries, so we need a field to distinguish pstree_item-s from
threads.

Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 criu/cr-dump.c        | 16 ++++++++--------
 criu/cr-restore.c     | 22 +++++++++++-----------
 criu/image.c          |  2 +-
 criu/include/pid.h    |  2 ++
 criu/include/pstree.h |  4 +---
 criu/pstree.c         |  8 ++++----
 criu/seccomp.c        |  2 +-
 criu/seize.c          | 16 ++++++++--------
 8 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 9910c1f..fbee1b1 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -631,7 +631,7 @@ int get_task_ids(struct pstree_item *item)
 
 	task_kobj_ids_entry__init(item->ids);
 
-	if (item->state != TASK_DEAD) {
+	if (item->pid.state != TASK_DEAD) {
 		ret = dump_task_kobj_ids(item);
 		if (ret)
 			goto err_free;
@@ -713,7 +713,7 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
 
 	strlcpy((char *)core->tc->comm, stat->comm, TASK_COMM_LEN);
 	core->tc->flags = stat->flags;
-	core->tc->task_state = item->state;
+	core->tc->task_state = item->pid.state;
 	core->tc->exit_code = 0;
 
 	ret = parasite_dump_thread_leader_seized(ctl, pid, core);
@@ -768,14 +768,14 @@ static int collect_pstree_ids_predump(void)
 	 * write_img_inventory().
 	 */
 
-	crt.i.state = TASK_ALIVE;
+	crt.i.pid.state = TASK_ALIVE;
 	crt.i.pid.real = getpid();
 
 	if (predump_task_ns_ids(&crt.i))
 		return -1;
 
 	for_each_pstree_item(item) {
-		if (item->state == TASK_DEAD)
+		if (item->pid.state == TASK_DEAD)
 			continue;
 
 		if (predump_task_ns_ids(item))
@@ -1060,7 +1060,7 @@ static int dump_zombies(void)
 	 */
 
 	for_each_pstree_item(item) {
-		if (item->state != TASK_DEAD)
+		if (item->pid.state != TASK_DEAD)
 			continue;
 
 		if (item->pid.virt < 0) {
@@ -1108,12 +1108,12 @@ static int pre_dump_one_task(struct pstree_item *item, struct list_head *ctls)
 	pr_info("Pre-dumping task (pid: %d)\n", pid);
 	pr_info("========================================\n");
 
-	if (item->state == TASK_STOPPED) {
+	if (item->pid.state == TASK_STOPPED) {
 		pr_warn("Stopped tasks are not supported\n");
 		return 0;
 	}
 
-	if (item->state == TASK_DEAD)
+	if (item->pid.state == TASK_DEAD)
 		return 0;
 
 	ret = collect_mappings(pid, &vmas);
@@ -1185,7 +1185,7 @@ static int dump_one_task(struct pstree_item *item)
 	pr_info("Dumping task (pid: %d)\n", pid);
 	pr_info("========================================\n");
 
-	if (item->state == TASK_DEAD)
+	if (item->pid.state == TASK_DEAD)
 		/*
 		 * zombies are dumped separately in dump_zombies()
 		 */
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 9d74959..d303cf5 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -216,7 +216,7 @@ static int root_prepare_shared(void)
 		return -1;
 
 	for_each_pstree_item(pi) {
-		if (pi->state == TASK_HELPER)
+		if (pi->pid.state == TASK_HELPER)
 			continue;
 
 		ret = prepare_mm_pid(pi);
@@ -772,7 +772,7 @@ static int collect_child_pids(int state, int *n)
 	list_for_each_entry(pi, &current->children, sibling) {
 		pid_t *child;
 
-		if (pi->state != state)
+		if (pi->pid.state != state)
 			continue;
 
 		child = rst_mem_alloc(sizeof(*child), RM_PRIVATE);
@@ -1053,9 +1053,9 @@ static int restore_one_task(int pid, CoreEntry *core)
 
 	if (task_alive(current))
 		ret = restore_one_alive_task(pid, core);
-	else if (current->state == TASK_DEAD)
+	else if (current->pid.state == TASK_DEAD)
 		ret = restore_one_zombie(core);
-	else if (current->state == TASK_HELPER) {
+	else if (current->pid.state == TASK_HELPER) {
 		restore_finish_stage(CR_STATE_RESTORE);
 		if (rsti(current)->helper_cb)
 			rsti(current)->helper_cb();
@@ -1128,7 +1128,7 @@ static inline int fork_with_pid(struct pstree_item *item)
 	int ret = -1;
 	pid_t pid = item->pid.virt;
 
-	if (item->state != TASK_HELPER) {
+	if (item->pid.state != TASK_HELPER) {
 		struct cr_img *img;
 
 		img = open_image(CR_FD_CORE, O_RSTR, pid);
@@ -1144,15 +1144,15 @@ static inline int fork_with_pid(struct pstree_item *item)
 		if (check_core(ca.core, item))
 			return -1;
 
-		item->state = ca.core->tc->task_state;
+		item->pid.state = ca.core->tc->task_state;
 		rsti(item)->cg_set = ca.core->tc->cg_set;
 
 		rsti(item)->has_seccomp = ca.core->tc->seccomp_mode != SECCOMP_MODE_DISABLED;
 
-		if (item->state == TASK_DEAD)
+		if (item->pid.state == TASK_DEAD)
 			rsti(item->parent)->nr_zombies++;
 		else if (!task_alive(item)) {
-			pr_err("Unknown task state %d\n", item->state);
+			pr_err("Unknown task state %d\n", item->pid.state);
 			return -1;
 		}
 
@@ -1302,7 +1302,7 @@ static void sigchld_handler(int signal, siginfo_t *siginfo, void *data)
 				break;
 
 		BUG_ON(&pi->sibling == &current->children);
-		if (pi->state != TASK_HELPER)
+		if (pi->pid.state != TASK_HELPER)
 			break;
 	}
 
@@ -1538,7 +1538,7 @@ static int restore_task_with_children(void *_arg)
 	if ( !(ca->clone_flags & CLONE_FILES))
 		close_safe(&ca->fd);
 
-	if (current->state != TASK_HELPER) {
+	if (current->pid.state != TASK_HELPER) {
 		ret = clone_service_fd(rsti(current)->service_fd_id);
 		if (ret)
 			goto err;
@@ -1823,7 +1823,7 @@ static void finalize_restore(void)
 
 		xfree(ctl);
 
-		if (item->state == TASK_STOPPED)
+		if (item->pid.state == TASK_STOPPED)
 			kill(item->pid.real, SIGSTOP);
 	}
 }
diff --git a/criu/image.c b/criu/image.c
index 595e1a2..e680e87 100644
--- a/criu/image.c
+++ b/criu/image.c
@@ -111,7 +111,7 @@ int prepare_inventory(InventoryEntry *he)
 	he->has_ns_per_id = true;
 	he->lsmtype = host_lsm_type();
 
-	crt.i.state = TASK_ALIVE;
+	crt.i.pid.state = TASK_ALIVE;
 	crt.i.pid.real = getpid();
 	if (get_task_ids(&crt.i))
 		return -1;
diff --git a/criu/include/pid.h b/criu/include/pid.h
index d073944..2a709a2 100644
--- a/criu/include/pid.h
+++ b/criu/include/pid.h
@@ -17,6 +17,8 @@ struct pid {
 	 * dumpee context, because the dumpee might have own pid namespace.
 	 */
 	pid_t virt;
+
+	int state;	/* TASK_XXX constants */
 };
 
 /*
diff --git a/criu/include/pstree.h b/criu/include/pstree.h
index 4bf6db7..495258e 100644
--- a/criu/include/pstree.h
+++ b/criu/include/pstree.h
@@ -21,8 +21,6 @@ struct pstree_item {
 	pid_t			sid;
 	pid_t			born_sid;
 
-	int			state;		/* TASK_XXX constants */
-
 	int			nr_threads;	/* number of threads */
 	struct pid		*threads;	/* array of threads */
 	CoreEntry		**core;
@@ -60,7 +58,7 @@ static inline int shared_fdtable(struct pstree_item *item)
 
 static inline bool task_alive(struct pstree_item *i)
 {
-	return (i->state == TASK_ALIVE) || (i->state == TASK_STOPPED);
+	return (i->pid.state == TASK_ALIVE) || (i->pid.state == TASK_STOPPED);
 }
 
 extern void free_pstree(struct pstree_item *root_item);
diff --git a/criu/pstree.c b/criu/pstree.c
index 8a2795f..58391c7 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -228,7 +228,7 @@ struct pstree_item *alloc_pstree_helper(void)
 
 	ret = alloc_pstree_item_with_rst();
 	if (ret) {
-		ret->state = TASK_HELPER;
+		ret->pid.state = TASK_HELPER;
 		rsti(ret)->clone_flags = CLONE_FILES | CLONE_FS;
 		task_entries->nr_helpers++;
 	}
@@ -558,7 +558,7 @@ static int prepare_pstree_ids(void)
 		if (!item->parent) /* skip the root task */
 			continue;
 
-		if (item->state == TASK_HELPER)
+		if (item->pid.state == TASK_HELPER)
 			continue;
 
 		if (item->sid != item->pid.virt) {
@@ -593,7 +593,7 @@ static int prepare_pstree_ids(void)
 
 		/* Try to find helpers, who should be connected to the leader */
 		list_for_each_entry(child, &helpers, sibling) {
-			if (child->state != TASK_HELPER)
+			if (child->pid.state != TASK_HELPER)
 				continue;
 
 			if (child->sid != item->sid)
@@ -806,7 +806,7 @@ static int prepare_pstree_for_unshare(void)
 
 		fake_root = alloc_pstree_item_with_rst();
 
-		fake_root->state = TASK_HELPER;
+		fake_root->pid.state = TASK_HELPER;
 		fake_root->pid.virt = INIT_PID;
 		fake_root->pgid = INIT_PID;
 		fake_root->sid = INIT_PID;
diff --git a/criu/seccomp.c b/criu/seccomp.c
index 69c4dfc..3baaac2 100644
--- a/criu/seccomp.c
+++ b/criu/seccomp.c
@@ -48,7 +48,7 @@ static int collect_filter_for_pstree(struct pstree_item *item)
 	struct sock_filter buf[BPF_MAXINSNS];
 	void *m;
 
-	if (item->state == TASK_DEAD ||
+	if (item->pid.state == TASK_DEAD ||
 	    dmpi(item)->pi_creds->seccomp_mode != SECCOMP_MODE_FILTER)
 		return 0;
 
diff --git a/criu/seize.c b/criu/seize.c
index d187b74..3fd3d62 100644
--- a/criu/seize.c
+++ b/criu/seize.c
@@ -393,7 +393,7 @@ static int collect_children(struct pstree_item *item)
 
 		c->pid.real = pid;
 		c->parent = item;
-		c->state = ret;
+		c->pid.state = ret;
 		list_add_tail(&c->sibling, &item->children);
 
 		/* Here is a recursive call (Depth-first search) */
@@ -410,7 +410,7 @@ static void unseize_task_and_threads(const struct pstree_item *item, int st)
 {
 	int i;
 
-	if (item->state == TASK_DEAD)
+	if (item->pid.state == TASK_DEAD)
 		return;
 
 	/*
@@ -418,7 +418,7 @@ static void unseize_task_and_threads(const struct pstree_item *item, int st)
 	 * the item->state is the state task was in when we seized one.
 	 */
 
-	unseize_task(item->pid.real, item->state, st);
+	unseize_task(item->pid.real, item->pid.state, st);
 
 	if (st == TASK_DEAD)
 		return;
@@ -435,7 +435,7 @@ static void pstree_wait(struct pstree_item *root_item)
 
 	for_each_pstree_item(item) {
 
-		if (item->state == TASK_DEAD)
+		if (item->pid.state == TASK_DEAD)
 			continue;
 
 		for (i = 0; i < item->nr_threads; i++) {
@@ -511,7 +511,7 @@ static int collect_threads(struct pstree_item *item)
 	if (ret < 0)
 		goto err;
 
-	if ((item->state == TASK_DEAD) && (nr_threads > 1)) {
+	if ((item->pid.state == TASK_DEAD) && (nr_threads > 1)) {
 		pr_err("Zombies with threads are not supported\n");
 		goto err;
 	}
@@ -628,7 +628,7 @@ static int collect_task(struct pstree_item *item)
 	if (ret < 0)
 		goto err_close;
 
-	if ((item->state == TASK_DEAD) && !list_empty(&item->children)) {
+	if ((item->pid.state == TASK_DEAD) && !list_empty(&item->children)) {
 		pr_err("Zombie with children?! O_o Run, run, run!\n");
 		goto err_close;
 	}
@@ -636,7 +636,7 @@ static int collect_task(struct pstree_item *item)
 	if (pstree_alloc_cores(item))
 		goto err_close;
 
-	pr_info("Collected %d in %d state\n", item->pid.real, item->state);
+	pr_info("Collected %d in %d state\n", item->pid.real, item->pid.state);
 	return 0;
 
 err_close:
@@ -675,7 +675,7 @@ int collect_pstree(pid_t pid)
 	if (ret < 0)
 		goto err;
 	pr_info("Seized task %d, state %d\n", pid, ret);
-	root_item->state = ret;
+	root_item->pid.state = ret;
 
 	ret = collect_task(root_item);
 	if (ret < 0)
-- 
2.5.0



More information about the CRIU mailing list