[v4,18/31] ns: Make prepare_userns() have ns map parameter

Submitted by Kirill Tkhai on Feb. 22, 2017, 11:33 a.m.

Details

Message ID 148776319250.17334.12078906558755317697.stgit@localhost.localdomain
State New
Series "Nested user namespaces support"
Headers show

Commit Message

Kirill Tkhai Feb. 22, 2017, 11:33 a.m.
This is refactoring

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

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 4e2b8d0e8..6933cf42c 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1875,7 +1875,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 978c089b7..447040758 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -137,6 +137,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;
@@ -161,7 +162,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 488246bc7..b6a801652 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -805,7 +805,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)
 {
@@ -1925,14 +1925,12 @@  int read_ns_with_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;