[CRIU] [PATCH 10/21] ns: Add possibility to read a ns by alternative name in __get_ns_id()

Kirill Tkhai ktkhai at virtuozzo.com
Tue May 23 05:39:46 PDT 2017


This is need for "/proc/[pid]/ns/pid_for_children_ns",
which is a pid namespace with not standard file name.
Also pass "alternative" parameter to generate_ns_id().

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

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 5e7cbc2e6..e9f09d1e3 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -56,6 +56,7 @@
 struct ns_desc {
 	unsigned int	cflag;
 	char		*str;
+	char		*alt_str;
 	size_t		len;
 };
 
diff --git a/criu/namespaces.c b/criu/namespaces.c
index fb6c77552..c6e47bb8c 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -410,7 +410,7 @@ int walk_namespaces(struct ns_desc *nd, int (*cb)(struct ns_id *, void *), void
 }
 
 static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd,
-		struct ns_id **ns_ret)
+		struct ns_id **ns_ret, bool alternative)
 {
 	struct ns_id *nsid;
 	enum ns_type type;
@@ -456,7 +456,8 @@ static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd
 	return nsid->id;
 }
 
-static unsigned int __get_ns_id(int pid, struct ns_desc *nd, protobuf_c_boolean *supported, struct ns_id **ns)
+static unsigned int __get_ns_id(int pid, struct ns_desc *nd, bool alternative,
+				protobuf_c_boolean *supported, struct ns_id **ns)
 {
 	int proc_dir;
 	unsigned int kid;
@@ -467,7 +468,7 @@ static unsigned int __get_ns_id(int pid, struct ns_desc *nd, protobuf_c_boolean
 	if (proc_dir < 0)
 		return 0;
 
-	sprintf(ns_path, "ns/%s", nd->str);
+	sprintf(ns_path, "ns/%s", !alternative ? nd->str : nd->alt_str);
 
 	if (fstatat(proc_dir, ns_path, &st, 0)) {
 		if (errno == ENOENT) {
@@ -484,12 +485,12 @@ static unsigned int __get_ns_id(int pid, struct ns_desc *nd, protobuf_c_boolean
 out:
 	if (supported)
 		*supported = kid != 0;
-	return generate_ns_id(pid, kid, nd, ns);
+	return generate_ns_id(pid, kid, nd, ns, alternative);
 }
 
 static unsigned int get_ns_id(int pid, struct ns_desc *nd, protobuf_c_boolean *supported)
 {
-	return __get_ns_id(pid, nd, supported, NULL);
+	return __get_ns_id(pid, nd, false, supported, NULL);
 }
 
 int dump_one_ns_file(int lfd, u32 id, const struct fd_parms *p)
@@ -693,7 +694,8 @@ int predump_task_ns_ids(struct pstree_item *item)
 {
 	int pid = item->pid->real;
 
-	if (!__get_ns_id(pid, &net_ns_desc, NULL, &dmpi(item)->netns))
+	if (!__get_ns_id(pid, &net_ns_desc, false,
+			 NULL, &dmpi(item)->netns))
 		return -1;
 
 	if (!get_ns_id(pid, &mnt_ns_desc, NULL))
@@ -729,7 +731,8 @@ int dump_task_ns_ids(struct pstree_item *item)
 		return 0;
 
 	ids->has_net_ns_id = true;
-	ids->net_ns_id = __get_ns_id(pid, &net_ns_desc, NULL, &dmpi(item)->netns);
+	ids->net_ns_id = __get_ns_id(pid, &net_ns_desc, false,
+				     NULL, &dmpi(item)->netns);
 	if (!ids->net_ns_id) {
 		pr_err("Can't make netns id\n");
 		return -1;



More information about the CRIU mailing list