[CRIU] [PATCH] pstree: Add helper for adding helpers to pstree

Pavel Emelyanov xemul at parallels.com
Thu Oct 9 06:42:22 PDT 2014


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 files-reg.c      |  4 +---
 include/pstree.h |  1 +
 pstree.c         | 24 ++++++++++++++++--------
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/files-reg.c b/files-reg.c
index 98c71e9..06ff5de 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -240,17 +240,15 @@ static int open_remap_dead_process(struct reg_file_info *rfi,
 		}
 	}
 
-	helper = alloc_pstree_item_with_rst();
+	helper = alloc_pstree_helper();
 	if (!helper)
 		return -1;
 
 	helper->sid = root_item->sid;
 	helper->pgid = root_item->pgid;
 	helper->pid.virt = rfe->remap_id;
-	helper->state = TASK_HELPER;
 	helper->parent = root_item;
 	list_add_tail(&helper->sibling, &root_item->children);
-	task_entries->nr_helpers++;
 
 	pr_info("Added a helper for restoring /proc/%d\n", helper->pid.virt);
 
diff --git a/include/pstree.h b/include/pstree.h
index bd9c2e8..c0fdac6 100644
--- a/include/pstree.h
+++ b/include/pstree.h
@@ -62,6 +62,7 @@ extern void free_pstree(struct pstree_item *root_item);
 extern struct pstree_item *__alloc_pstree_item(bool rst);
 #define alloc_pstree_item() __alloc_pstree_item(false)
 #define alloc_pstree_item_with_rst() __alloc_pstree_item(true)
+extern struct pstree_item *alloc_pstree_helper(void);
 
 extern struct pstree_item *root_item;
 extern struct pstree_item *pstree_item_next(struct pstree_item *item);
diff --git a/pstree.c b/pstree.c
index 6bcfd91..5ea4283 100644
--- a/pstree.c
+++ b/pstree.c
@@ -189,6 +189,20 @@ struct pstree_item *__alloc_pstree_item(bool rst)
 	return item;
 }
 
+struct pstree_item *alloc_pstree_helper(void)
+{
+	struct pstree_item *ret;
+
+	ret = alloc_pstree_item_with_rst();
+	if (ret) {
+		ret->state = TASK_HELPER;
+		rsti(ret)->clone_flags = CLONE_FILES | CLONE_FS;
+		task_entries->nr_helpers++;
+	}
+
+	return ret;
+}
+
 /* Deep first search on children */
 struct pstree_item *pstree_item_next(struct pstree_item *item)
 {
@@ -457,17 +471,14 @@ static int prepare_pstree_ids(void)
 		if (item->sid == root_item->sid || item->sid == item->pid.virt)
 			continue;
 
-		helper = alloc_pstree_item_with_rst();
+		helper = alloc_pstree_helper();
 		if (helper == NULL)
 			return -1;
 		helper->sid = item->sid;
 		helper->pgid = item->sid;
 		helper->pid.virt = item->sid;
-		helper->state = TASK_HELPER;
 		helper->parent = root_item;
-		rsti(helper)->clone_flags = CLONE_FILES | CLONE_FS;
 		list_add_tail(&helper->sibling, &helpers);
-		task_entries->nr_helpers++;
 
 		pr_info("Add a helper %d for restoring SID %d\n",
 				helper->pid.virt, helper->sid);
@@ -578,17 +589,14 @@ static int prepare_pstree_ids(void)
 		if (current_pgid == item->pgid)
 			continue;
 
-		helper = alloc_pstree_item_with_rst();
+		helper = alloc_pstree_helper();
 		if (helper == NULL)
 			return -1;
 		helper->sid = item->sid;
 		helper->pgid = item->pgid;
 		helper->pid.virt = item->pgid;
-		helper->state = TASK_HELPER;
 		helper->parent = item;
-		rsti(helper)->clone_flags = CLONE_FILES | CLONE_FS;
 		list_add(&helper->sibling, &item->children);
-		task_entries->nr_helpers++;
 		rsti(item)->pgrp_leader = helper;
 
 		pr_info("Add a helper %d for restoring PGID %d\n",
-- 
1.8.4.2



More information about the CRIU mailing list