[CRIU] [PATCH v3 07/33] ns: Change arguments of dump_user_ns()

Kirill Tkhai ktkhai at virtuozzo.com
Thu Feb 16 04:07:37 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 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 a95774fc8..697f8de02 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -871,6 +871,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)
 {
 	/*
@@ -878,7 +880,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;
@@ -911,8 +913,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;
 
@@ -1011,9 +1014,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;
 
@@ -1027,10 +1031,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