[CRIU] [PATCH v3 07/55] pid: Add pid::level field and level argument for __alloc_pstree_item()

Kirill Tkhai ktkhai at virtuozzo.com
Mon Apr 10 01:16:15 PDT 2017


Pid may contain several levels, so add level field to this struct.
Currently, level is always "1".

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/include/pid.h    |    1 +
 criu/include/pstree.h |    4 ++--
 criu/pstree.c         |   27 +++++++++++++++++++--------
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/criu/include/pid.h b/criu/include/pid.h
index 81786ec4a..475b17a39 100644
--- a/criu/include/pid.h
+++ b/criu/include/pid.h
@@ -38,6 +38,7 @@ struct pid {
 	 * the pid value to be restored. This pid fetched from the
 	 * dumpee context, because the dumpee might have own pid namespace.
 	 */
+	int level;
 	struct {
 		pid_t virt;
 		struct rb_node node;
diff --git a/criu/include/pstree.h b/criu/include/pstree.h
index 5790943be..769dcf7d1 100644
--- a/criu/include/pstree.h
+++ b/criu/include/pstree.h
@@ -86,8 +86,8 @@ static inline bool task_alive(struct pstree_item *i)
 }
 
 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)
+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 struct pstree_item *lookup_create_item(pid_t pid);
diff --git a/criu/pstree.c b/criu/pstree.c
index 93c90ee2e..c02ddb219 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -191,31 +191,41 @@ void free_pstree(struct pstree_item *root_item)
 		list_del(&item->sibling);
 		pstree_free_cores(item);
 		xfree(item->threads);
+		xfree(item->pid);
 		xfree(item);
 		item = parent;
 	}
 }
 
-struct pstree_item *__alloc_pstree_item(bool rst)
+struct pstree_item *__alloc_pstree_item(bool rst, int level)
 {
 	struct pstree_item *item;
-	int sz;
+	int sz, p_sz;
 
+	p_sz = sizeof(struct pid) + (level - 1) * sizeof(((struct pid *)NULL)->ns[0]);
 	if (!rst) {
-		sz = sizeof(*item) + sizeof(struct dmp_info) + sizeof(struct pid);
+		sz = sizeof(*item) + sizeof(struct dmp_info);
 		item = xzalloc(sz);
 		if (!item)
 			return NULL;
-		item->pid = (void *)item + sizeof(*item) + sizeof(struct dmp_info);
+		item->pid = xmalloc(p_sz);
+		if (!item->pid) {
+			xfree(item);
+			return NULL;
+		}
 	} else {
-		sz = sizeof(*item) + sizeof(struct rst_info) + sizeof(struct pid);
+		sz = sizeof(*item) + sizeof(struct rst_info);
 		item = shmalloc(sz);
 		if (!item)
 			return NULL;
-
 		memset(item, 0, sz);
 		vm_area_list_init(&rsti(item)->vmas);
-		item->pid = (void *)item + sizeof(*item) + sizeof(struct rst_info);
+
+		item->pid = shmalloc(p_sz);
+		if (!item->pid) {
+			shfree_last(item);
+			return NULL;
+		}
 	}
 
 	INIT_LIST_HEAD(&item->children);
@@ -227,6 +237,7 @@ struct pstree_item *__alloc_pstree_item(bool rst)
 	item->born_sid = -1;
 	item->pid->item = item;
 	futex_init(&item->task_st);
+	item->pid->level = level;
 
 	return item;
 }
@@ -411,7 +422,7 @@ static struct pid *lookup_create_pid(pid_t pid, struct pid *pid_node)
 	if (!pid_node) {
 		struct pstree_item *item;
 
-		item = __alloc_pstree_item(true);
+		item = __alloc_pstree_item(true, 1);
 		if (item == NULL)
 			return NULL;
 



More information about the CRIU mailing list