[CRIU] [PATCH v1 04/17] ns: Change arguments of dump_user_ns()

Kirill Tkhai ktkhai at virtuozzo.com
Thu Jan 12 09:52:39 PST 2017


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 at virtuozzo.com>
---
 criu/include/namespaces.h |    1 -
 criu/namespaces.c         |   14 +++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 558050783..29f9039de 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -155,7 +155,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 148b54a00..c976787d7 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -849,6 +849,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)
 {
 	/*
@@ -856,7 +858,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;
@@ -873,8 +875,9 @@ int collect_user_namespaces(bool for_dump)
 	return walk_namespaces(&user_ns_desc, collect_user_ns, NULL);
 }
 
-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;
 
@@ -973,9 +976,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;
 
@@ -989,10 +993,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);



More information about the CRIU mailing list