[CRIU] [PATCH v2 22/36] ns: Make prepare_userns() have ns map parameter

Kirill Tkhai ktkhai at virtuozzo.com
Fri Feb 3 08:14:52 PST 2017


This is refactoring

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

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 1f1fb0787..63c6147c9 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1831,7 +1831,7 @@ static int restore_root_task(struct pstree_item *init)
 	 * uid_map and gid_map must be filled from a parent user namespace.
 	 * prepare_userns_creds() must be called after filling mappings.
 	 */
-	if ((root_ns_mask & CLONE_NEWUSER) && prepare_userns(init))
+	if ((root_ns_mask & CLONE_NEWUSER) && prepare_userns(init->pid->real, userns_entry))
 		goto out_kill;
 
 	pr_info("Wait until namespaces are created\n");
diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 46aa41ad2..21dc8beb7 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -135,6 +135,7 @@ extern struct ns_desc pid_ns_desc;
 extern struct ns_desc user_ns_desc;
 extern struct ns_desc net_ns_desc;
 extern unsigned long root_ns_mask;
+extern UsernsEntry *userns_entry;
 
 extern const struct fdtype_ops nsfile_dump_ops;
 extern struct collect_image_info nsfile_cinfo;
@@ -158,7 +159,7 @@ extern int rst_add_ns_id(unsigned int id, struct pstree_item *, struct ns_desc *
 extern struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd);
 
 extern int collect_user_namespaces(bool for_dump);
-extern int prepare_userns(struct pstree_item *item);
+extern int prepare_userns(pid_t real_pid, UsernsEntry *e);
 extern int stop_usernsd(void);
 
 extern uid_t userns_uid(uid_t uid);
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 520ff2ca9..7a8a79cac 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -794,7 +794,7 @@ static int set_ns_hookups(struct ns_id *ns)
 
 struct ns_id *root_user_ns = NULL;
 /* Mapping NS_ROOT to NS_CRIU */
-static UsernsEntry *userns_entry;
+UsernsEntry *userns_entry;
 
 unsigned int child_userns_xid(unsigned int id, UidGidExtent **map, int n)
 {
@@ -1890,14 +1890,12 @@ static int read_ns_hookups(void)
 	return ret;
 }
 
-int prepare_userns(struct pstree_item *item)
+int prepare_userns(pid_t real_pid, UsernsEntry *e)
 {
-	UsernsEntry *e = userns_entry;
-
-	if (write_id_map(item->pid->real, e->uid_map, e->n_uid_map, "uid_map"))
+	if (write_id_map(real_pid, e->uid_map, e->n_uid_map, "uid_map"))
 		return -1;
 
-	if (write_id_map(item->pid->real, e->gid_map, e->n_gid_map, "gid_map"))
+	if (write_id_map(real_pid, e->gid_map, e->n_gid_map, "gid_map"))
 		return -1;
 
 	return 0;



More information about the CRIU mailing list