[CRIU] [PATCH v2 3/4] ns: Replace task argument rst_add_ns_id() with pid

Kirill Tkhai ktkhai at virtuozzo.com
Wed Mar 1 02:14:24 PST 2017


We don't need task in that function, also this allows
to delete fake task in read_ns_with_hookups().

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

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 05c08b52e..62fa091fb 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -160,7 +160,7 @@ extern int restore_ns(int rst, struct ns_desc *nd);
 extern int dump_task_ns_ids(struct pstree_item *);
 extern int predump_task_ns_ids(struct pstree_item *);
 extern struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd, enum ns_type t);
-extern int rst_add_ns_id(unsigned int id, struct pstree_item *, struct ns_desc *nd);
+extern int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd);
 extern struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd);
 
 extern int collect_user_namespaces(bool for_dump);
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 7731cf081..04ce9e325 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -312,9 +312,8 @@ struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid,
 	return nsid;
 }
 
-int rst_add_ns_id(unsigned int id, struct pstree_item *i, struct ns_desc *nd)
+int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd)
 {
-	pid_t pid = vpid(i);
 	struct ns_id *nsid;
 
 	nsid = lookup_ns_by_id(id, nd);
@@ -1855,15 +1854,10 @@ int read_ns_with_hookups(void)
 {
 	struct ns_id *ns, *p_ns, *u_ns;
 	struct delayed_ns *d_ns = NULL;
-	struct pstree_item fake;
 	NsEntry *e = NULL;
 	int ret = 0, nr_d = 0;
 	struct ns_desc *desc;
 	struct cr_img *img;
-	struct pid pid;
-
-	pid.ns[0].virt = -1;
-	fake.pid = &pid;
 
 	img = open_image(CR_FD_NS, O_RSTR);
 	if (!img)
@@ -1882,7 +1876,7 @@ int read_ns_with_hookups(void)
 		else if (e->ns_cflag == CLONE_NEWNET)
 			desc = &net_ns_desc;
 
-		if (rst_add_ns_id(e->id, &fake, desc)) {
+		if (rst_add_ns_id(e->id, -1, desc)) {
 			pr_err("Can't add user ns\n");
 			goto close;
 		}
diff --git a/criu/pstree.c b/criu/pstree.c
index b497e1989..f86b75a70 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -462,6 +462,7 @@ struct pid *pstree_pid_by_virt(pid_t pid)
 
 static int read_pstree_ids(struct pstree_item *pi)
 {
+	pid_t pid = vpid(pi);
 	int ret;
 	struct cr_img *img;
 
@@ -476,31 +477,31 @@ static int read_pstree_ids(struct pstree_item *pi)
 		return ret;
 
 	if (pi->ids->has_mnt_ns_id) {
-		if (rst_add_ns_id(pi->ids->mnt_ns_id, pi, &mnt_ns_desc))
+		if (rst_add_ns_id(pi->ids->mnt_ns_id, pid, &mnt_ns_desc))
 			return -1;
 	}
 	if (pi->ids->has_net_ns_id) {
-		if (rst_add_ns_id(pi->ids->net_ns_id, pi, &net_ns_desc))
+		if (rst_add_ns_id(pi->ids->net_ns_id, pid, &net_ns_desc))
 			return -1;
 	}
 	if (pi->ids->has_user_ns_id) {
-		if (rst_add_ns_id(pi->ids->user_ns_id, pi, &user_ns_desc))
+		if (rst_add_ns_id(pi->ids->user_ns_id, pid, &user_ns_desc))
 			return -1;
 	}
 	if (pi->ids->has_pid_ns_id) {
-		if (rst_add_ns_id(pi->ids->pid_ns_id, pi, &pid_ns_desc))
+		if (rst_add_ns_id(pi->ids->pid_ns_id, pid, &pid_ns_desc))
 			return -1;
 	}
 	if (pi->ids->has_ipc_ns_id) {
-		if (rst_add_ns_id(pi->ids->ipc_ns_id, pi, &ipc_ns_desc))
+		if (rst_add_ns_id(pi->ids->ipc_ns_id, pid, &ipc_ns_desc))
 			return -1;
 	}
 	if (pi->ids->has_uts_ns_id) {
-		if (rst_add_ns_id(pi->ids->uts_ns_id, pi, &uts_ns_desc))
+		if (rst_add_ns_id(pi->ids->uts_ns_id, pid, &uts_ns_desc))
 			return -1;
 	}
 	if (pi->ids->has_cgroup_ns_id) {
-		if (rst_add_ns_id(pi->ids->cgroup_ns_id, pi, &cgroup_ns_desc))
+		if (rst_add_ns_id(pi->ids->cgroup_ns_id, pid, &cgroup_ns_desc))
 			return -1;
 	}
 



More information about the CRIU mailing list