[v4,05/31] ns: Change arguments of dump_user_ns()

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

Details

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

Commit Message

Kirill Tkhai Feb. 22, 2017, 11:31 a.m.
Make ns as only argument of dump_user_ns(). As the only ns,
which it may be called for is root_item's ns, the logic
after this patch remains the same as it was before.
Also make dump_user_ns() static.

In addition, pass ns to check_user_ns().

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/include/namespaces.h |    1 -
 criu/namespaces.c         |   14 +++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 69df0313b..1b5409aef 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -157,7 +157,6 @@  extern int stop_usernsd(void);
 extern uid_t userns_uid(uid_t uid);
 extern gid_t userns_gid(gid_t gid);
 
-extern int dump_user_ns(pid_t pid, int ns_id);
 extern void free_userns_maps(void);
 extern int join_ns_add(const char *type, char *ns_file, char *extra_opts);
 extern int check_namespace_opts(void);
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 340c2fa73..216fc079d 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -876,6 +876,8 @@  static int parse_id_map(pid_t pid, char *name, UidGidExtent ***pb_exts)
 	return -1;
 }
 
+static int dump_user_ns(struct ns_id *ns);
+
 int collect_user_ns(struct ns_id *ns, void *oarg)
 {
 	/*
@@ -883,7 +885,7 @@  int collect_user_ns(struct ns_id *ns, void *oarg)
 	 * mappings, which are used for convirting local id-s to
 	 * userns id-s (userns_uid(), userns_gid())
 	 */
-	if (dump_user_ns(root_item->pid->real, root_item->ids->user_ns_id))
+	if (dump_user_ns(ns))
 		return -1;
 
 	return 0;
@@ -916,8 +918,9 @@  static int collect_ns_hierarhy(bool for_dump)
 	return 0;
 }
 
-static int check_user_ns(int pid)
+static int check_user_ns(struct ns_id *ns)
 {
+	pid_t pid = ns->ns_pid;
 	int status;
 	pid_t chld;
 
@@ -1016,9 +1019,10 @@  static int check_user_ns(int pid)
 	return 0;
 }
 
-int dump_user_ns(pid_t pid, int ns_id)
+static int dump_user_ns(struct ns_id *ns)
 {
 	int ret, exit_code = -1;
+	pid_t pid = ns->ns_pid;
 	UsernsEntry *e = &userns_entry;
 	struct cr_img *img;
 
@@ -1032,10 +1036,10 @@  int dump_user_ns(pid_t pid, int ns_id)
 		goto err;
 	e->n_gid_map = ret;
 
-	if (check_user_ns(pid))
+	if (check_user_ns(ns))
 		return -1;
 
-	img = open_image(CR_FD_USERNS, O_DUMP, ns_id);
+	img = open_image(CR_FD_USERNS, O_DUMP, ns->id);
 	if (!img)
 		goto err;
 	ret = pb_write_one(img, e, PB_USERNS);