[CRIU] [PATCH v2 12/36] ns: Rename and export userns_id() and INVALID_ID

Kirill Tkhai ktkhai at virtuozzo.com
Fri Feb 3 08:13:23 PST 2017


Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/include/namespaces.h |    3 +++
 criu/namespaces.c         |   13 ++++++-------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 36dbfe275..16130f187 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -48,6 +48,8 @@
 #define NS_GET_PARENT   _IO(NSIO, 0x2)
 #endif
 
+#define NS_INVALID_XID (~0U)
+
 struct ns_desc {
 	unsigned int	cflag;
 	char		*str;
@@ -126,6 +128,7 @@ extern struct ns_id *ns_ids;
 	}
 
 extern bool check_ns_proc(struct fd_link *link);
+extern unsigned int child_userns_xid(unsigned int xid, UidGidExtent **map, int n);
 
 extern struct ns_desc pid_ns_desc;
 extern struct ns_desc user_ns_desc;
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 77fd50fed..0004b1e42 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -744,9 +744,8 @@ static int set_ns_hookups(struct ns_id *ns)
 
 /* Mapping NS_ROOT to NS_CRIU */
 static UsernsEntry *userns_entry;
-#define INVALID_ID (~0U)
 
-static unsigned int userns_id(unsigned int id, UidGidExtent **map, int n)
+unsigned int child_userns_xid(unsigned int id, UidGidExtent **map, int n)
 {
 	int i;
 
@@ -756,7 +755,7 @@ static unsigned int userns_id(unsigned int id, UidGidExtent **map, int n)
 			return map[i]->first + (id - map[i]->lower_first);
 	}
 
-	return INVALID_ID;
+	return NS_INVALID_XID;
 }
 
 static unsigned int parent_userns_id(unsigned int id, UidGidExtent **map, int n)
@@ -772,7 +771,7 @@ static unsigned int parent_userns_id(unsigned int id, UidGidExtent **map, int n)
 			return map[i]->lower_first + (id - map[i]->first);
 	}
 
-	return INVALID_ID;
+	return NS_INVALID_XID;
 }
 
 static uid_t parent_userns_uid(UsernsEntry *e, uid_t uid)
@@ -792,7 +791,7 @@ uid_t userns_uid(uid_t uid)
 	if (!(root_ns_mask & CLONE_NEWUSER) || !e)
 		return uid;
 
-	return userns_id(uid, e->uid_map, e->n_uid_map);
+	return child_userns_xid(uid, e->uid_map, e->n_uid_map);
 }
 
 gid_t userns_gid(gid_t gid)
@@ -802,7 +801,7 @@ gid_t userns_gid(gid_t gid)
 	if (!(root_ns_mask & CLONE_NEWUSER) || !e)
 		return gid;
 
-	return userns_id(gid, e->gid_map, e->n_gid_map);
+	return child_userns_xid(gid, e->gid_map, e->n_gid_map);
 }
 
 static int parse_id_map(pid_t pid, char *name, UidGidExtent ***pb_exts)
@@ -942,7 +941,7 @@ static int check_user_ns(struct ns_id *ns)
 
 		uid = parent_userns_uid(e, 0);
 		gid = parent_userns_gid(e, 0);
-		if (uid == INVALID_ID || gid == INVALID_ID) {
+		if (uid == NS_INVALID_XID || gid == NS_INVALID_XID) {
 			pr_err("Unable to convert uid or gid\n");
 			return -1;
 		}



More information about the CRIU mailing list