[CRIU] [PATCH v5 04/42] pstree: Change type of init_pstree_helper() and check for parent

Kirill Tkhai ktkhai at virtuozzo.com
Fri May 5 09:13:04 PDT 2017


This is refactoring, which will be used in next patches.
BUG_ON() just to mention that parent must be set before
call of this function.

v5: New

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/files-reg.c      |    6 ++++--
 criu/include/pstree.h |    2 +-
 criu/pstree.c         |   14 +++++++++++---
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/criu/files-reg.c b/criu/files-reg.c
index cd30bd0d8..9c851f447 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -388,13 +388,15 @@ static int open_remap_dead_process(struct reg_file_info *rfi,
 		return 0;
 	}
 
-	init_pstree_helper(helper);
-
 	vsid(helper) = vsid(root_item);
 	vpgid(helper) = vpgid(root_item);
 	vpid(helper) = rfe->remap_id;
 	helper->parent = root_item;
 	helper->ids = root_item->ids;
+	if (init_pstree_helper(helper)) {
+		pr_err("Can't init helper\n");
+		return -1;
+	}
 	list_add_tail(&helper->sibling, &root_item->children);
 
 	pr_info("Added a helper for restoring /proc/%d\n", vpid(helper));
diff --git a/criu/include/pstree.h b/criu/include/pstree.h
index 313d85666..4cd98e122 100644
--- a/criu/include/pstree.h
+++ b/criu/include/pstree.h
@@ -89,7 +89,7 @@ extern void free_pstree_item(struct pstree_item *item);
 extern void free_pstree(struct pstree_item *root_item);
 extern struct pstree_item *__alloc_pstree_item(bool rst, int level);
 #define alloc_pstree_item() __alloc_pstree_item(false, 1)
-extern void init_pstree_helper(struct pstree_item *ret);
+extern int init_pstree_helper(struct pstree_item *ret);
 
 extern struct pstree_item *lookup_create_item(pid_t *pid, int level, uint32_t ns_id);
 extern void pstree_insert_pid(struct pid *pid_node, uint32_t ns_id);
diff --git a/criu/pstree.c b/criu/pstree.c
index b73f4405a..b18c04dbf 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -255,11 +255,13 @@ struct pstree_item *__alloc_pstree_item(bool rst, int level)
 	return item;
 }
 
-void init_pstree_helper(struct pstree_item *ret)
+int init_pstree_helper(struct pstree_item *ret)
 {
+	BUG_ON(!ret->parent);
 	ret->pid->state = TASK_HELPER;
 	rsti(ret)->clone_flags = CLONE_FILES | CLONE_FS;
 	task_entries->nr_helpers++;
+	return 0;
 }
 
 /* Deep first search on children */
@@ -805,7 +807,10 @@ static int prepare_pstree_ids(void)
 			helper->ids = root_item->ids;
 			list_add_tail(&helper->sibling, &helpers);
 		}
-		init_pstree_helper(helper);
+		if (init_pstree_helper(helper)) {
+			pr_err("Can't init helper\n");
+			return -1;
+		}
 
 		pr_info("Add a helper %d for restoring SID %d\n",
 				vpid(helper), vsid(helper));
@@ -893,13 +898,16 @@ static int prepare_pstree_ids(void)
 			continue;
 
 		helper = pid->item;
-		init_pstree_helper(helper);
 
 		vsid(helper) = vsid(item);
 		vpgid(helper) = vpgid(item);
 		vpid(helper) = vpgid(item);
 		helper->parent = item;
 		helper->ids = item->ids;
+		if (init_pstree_helper(helper)) {
+			pr_err("Can't init helper\n");
+			return -1;
+		}
 		list_add(&helper->sibling, &item->children);
 		rsti(item)->pgrp_leader = helper;
 



More information about the CRIU mailing list