[v2,07/30] ns: Rename root_user_ns to top_user_ns

Submitted by Kirill Tkhai on June 7, 2017, 11:26 a.m.

Details

Message ID 149683478710.4663.12228405724257797941.stgit@localhost.localdomain
State Accepted
Series "Support sockets leaked to child user_ns task"
Commit e50a1100865d1d9008beb567d9eee8b6a606db0e
Headers show

Commit Message

Kirill Tkhai June 7, 2017, 11:26 a.m.
I'm going to use this in !(root_ns_mask & CLONE_NEWUSER) case,
so choose a better name to fit everything.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/cr-restore.c         |    2 +-
 criu/include/namespaces.h |    2 +-
 criu/namespaces.c         |   36 ++++++++++++++++++++----------------
 criu/net.c                |    2 +-
 4 files changed, 23 insertions(+), 19 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index c4146869a..220450b43 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -479,7 +479,7 @@  static int setup_child_task_namespaces(struct pstree_item *item, struct ns_id **
 		else
 			item->user_ns = current->user_ns;
 	} else
-		item->user_ns = root_user_ns;
+		item->user_ns = top_user_ns;
 
 	wait_pid_ns_helper_prepared(pid_ns, item->pid);
 
diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 4e06ebc0f..3cfa9a9bf 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -162,7 +162,7 @@  struct ns_id {
 };
 extern struct ns_id *ns_ids;
 extern struct ns_id *top_pid_ns;
-extern struct ns_id *root_user_ns;
+extern struct ns_id *top_user_ns;
 extern struct ns_id *top_net_ns;
 
 #define NS_DESC_ENTRY(_cflag, _str, _alt_str)		\
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 5ab64ccc6..811e02bb9 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -897,10 +897,14 @@  static int set_ns_hookups(struct ns_id *ns)
  * top_xxx_ns -- top namespaces of the dumped/restored tasks.
  * For not-hierarchical types this means namespace of root_item.
  * For hierarchical types this means the grand parent namespace,
- * which is ancestor of all others.
+ * which is ancestor of all others. That is, root_item may have
+ * a namespace different to top_user_ns, but currently it's not
+ * supported.
+ * top_xxx_ns may differ to NS_ROOT(i.e., to be NS_CRIU on dump),
+ * so the prefix "top" is used.
  */
 struct ns_id *top_pid_ns = NULL;
-struct ns_id *root_user_ns = NULL;
+struct ns_id *top_user_ns = NULL;
 struct ns_id *top_net_ns = NULL;
 /* Mapping NS_ROOT to NS_CRIU */
 UsernsEntry *userns_entry;
@@ -987,7 +991,7 @@  unsigned int target_userns_uid(struct ns_id *ns, unsigned int uid)
 {
 	if (!(root_ns_mask & CLONE_NEWUSER))
 		return uid;
-	if (ns == root_user_ns)
+	if (ns == top_user_ns)
 		return uid;
 	/* User ns max nesting level is only 32 */
 	uid = target_userns_uid(ns->parent, uid);
@@ -999,7 +1003,7 @@  unsigned int target_userns_gid(struct ns_id *ns, unsigned int gid)
 {
 	if (!(root_ns_mask & CLONE_NEWUSER))
 		return gid;
-	if (ns == root_user_ns)
+	if (ns == top_user_ns)
 		return gid;
 	/* User ns max nesting level is only 32 */
 	gid = target_userns_gid(ns->parent, gid);
@@ -1011,7 +1015,7 @@  unsigned int root_userns_uid(struct ns_id *ns, unsigned int uid)
 {
 	if (!(root_ns_mask & CLONE_NEWUSER))
 		return uid;
-	while (ns != root_user_ns) {
+	while (ns != top_user_ns) {
 		uid = parent_userns_uid(ns->user.e, uid);
 		ns = ns->parent;
 	}
@@ -1023,7 +1027,7 @@  unsigned int root_userns_gid(struct ns_id *ns, unsigned int gid)
 {
 	if (!(root_ns_mask & CLONE_NEWUSER))
 		return gid;
-	while (ns != root_user_ns) {
+	while (ns != top_user_ns) {
 		gid = parent_userns_gid(ns->user.e, gid);
 		ns = ns->parent;
 	}
@@ -1122,7 +1126,7 @@  int collect_user_ns(struct ns_id *ns, void *oarg)
 	ns->user.e = e;
 	if (ns->type == NS_ROOT) {
 		userns_entry = e;
-		root_user_ns = ns;
+		top_user_ns = ns;
 	}
 	/*
 	 * User namespace is dumped before files to get uid and gid
@@ -1933,7 +1937,7 @@  static int do_read_old_user_ns_img(struct ns_id *ns, void *arg)
 	ns->user.e = e;
 	userns_entry = e;
 	ns->type = NS_ROOT;
-	root_user_ns = ns;
+	top_user_ns = ns;
 	return 0;
 }
 
@@ -1945,16 +1949,16 @@  static int read_old_user_ns_img(void)
 	if (!(root_ns_mask & CLONE_NEWUSER))
 		return 0;
 	/* If new format img has already been read */
-	if (root_user_ns)
+	if (top_user_ns)
 		return 0;
-	/* Old format img is only for root_user_ns. More or less is error */
+	/* Old format img is only for top_user_ns. More or less is error */
 	ret = walk_namespaces(&user_ns_desc, do_read_old_user_ns_img, &count);
 	if (ret < 0)
 		return -1;
 
 	for (ns = ns_ids; ns != NULL; ns = ns->next)
 		if (ns->nd != &user_ns_desc)
-			ns->user_ns = root_user_ns;
+			ns->user_ns = top_user_ns;
 	return 0;
 }
 
@@ -2093,12 +2097,12 @@  int read_ns_with_hookups(void)
 				list_add(&ns->siblings, &p_ns->children);
 			}
 		} else if (e->ns_cflag == CLONE_NEWUSER) {
-			if (root_user_ns) {
-				pr_err("root_user_ns already set\n");
+			if (top_user_ns) {
+				pr_err("top_user_ns already set\n");
 				goto close;
 			}
 			ns->type = NS_ROOT;
-			root_user_ns = ns;
+			top_user_ns = ns;
 			userns_entry = ns->user.e;
 		} else if (e->ns_cflag == CLONE_NEWPID) {
 			if (top_pid_ns) {
@@ -2391,7 +2395,7 @@  static int create_user_ns_hierarhy_fn(void *in_arg)
 	struct ns_id *me, *child;
 	pid_t pid = -1;
 
-	if (p_arg->me != root_user_ns)
+	if (p_arg->me != top_user_ns)
 		p_futex = &p_arg->futex;
 	me = p_arg->me;
 
@@ -2459,7 +2463,7 @@  static int create_user_ns_hierarhy_fn(void *in_arg)
 
 static int create_user_ns_hierarhy(void)
 {
-	struct ns_arg arg = { .me = root_user_ns };
+	struct ns_arg arg = { .me = top_user_ns };
 	return create_user_ns_hierarhy_fn(&arg);
 }
 
diff --git a/criu/net.c b/criu/net.c
index 6849cd2a7..410a3d2a7 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -2108,7 +2108,7 @@  static int __prepare_net_namespaces(void *unused)
 		if (nsid->nd != &net_ns_desc)
 			continue;
 
-		if (root_user_ns && nsid->user_ns != root_user_ns) {
+		if (top_user_ns && nsid->user_ns != top_user_ns) {
 			if (call_in_child_process(create_net_ns, nsid) < 0)
 				goto err;
 		} else if (nsid->type == NS_ROOT) {