[v3,20/33] ns: Make prepare_userns() have ns map parameter

Submitted by Kirill Tkhai on Feb. 16, 2017, 12:09 p.m.

Details

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

Commit Message

Kirill Tkhai Feb. 16, 2017, 12:09 p.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 2ee170323..f66e4cd8d 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1876,7 +1876,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 9d578d806..f70d7ffd3 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 fd55336a9..8c4ea7915 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -800,7 +800,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)
 {
@@ -1934,14 +1934,12 @@  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;