[CRIU] [PATCH 04/11] netns: don't use global fdset for dumping namespace

Andrey Vagin avagin at openvz.org
Mon Sep 30 06:16:46 PDT 2013


We are going to replace pid on id in names of image files. The id is
uniq for each namespace, so it's more convient, if image files are
opened per namespace.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/net.h | 2 +-
 namespaces.c  | 3 ++-
 net.c         | 8 +++++++-
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/include/net.h b/include/net.h
index 7792ba2..26d098b 100644
--- a/include/net.h
+++ b/include/net.h
@@ -4,7 +4,7 @@
 #include "list.h"
 
 struct cr_fdset;
-int dump_net_ns(int pid, struct cr_fdset *);
+int dump_net_ns(int pid, int id);
 int prepare_net_ns(int pid);
 int netns_pre_create(void);
 
diff --git a/namespaces.c b/namespaces.c
index 7996db8..84a6153 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -351,6 +351,7 @@ int dump_task_ns_ids(struct pstree_item *item)
 static int do_dump_namespaces(struct pid *ns_pid, unsigned int ns_flags)
 {
 	struct cr_fdset *fdset;
+	pid_t pid = ns_pid->virt;
 	int ret = 0;
 
 	fdset = cr_ns_fdset_open(ns_pid->virt, O_DUMP);
@@ -377,7 +378,7 @@ static int do_dump_namespaces(struct pid *ns_pid, unsigned int ns_flags)
 	}
 	if (ns_flags & CLONE_NEWNET) {
 		pr_info("Dump NET namespace info\n");
-		ret = dump_net_ns(ns_pid->real, fdset);
+		ret = dump_net_ns(ns_pid->real, pid);
 		if (ret < 0)
 			goto err;
 	}
diff --git a/net.c b/net.c
index b872a1b..c794304 100644
--- a/net.c
+++ b/net.c
@@ -463,10 +463,15 @@ static int mount_ns_sysfs(void)
 	return ns_sysfs_fd >= 0 ? 0 : -1;
 }
 
-int dump_net_ns(int pid, struct cr_fdset *fds)
+int dump_net_ns(int pid, int id)
 {
+	struct cr_fdset *fds;
 	int ret;
 
+	fds = cr_fdset_open(id, _CR_FD_NETNS_FROM, _CR_FD_NETNS_TO, O_DUMP);
+	if (fds == NULL)
+		return -1;
+
 	ret = switch_ns(pid, &net_ns_desc, NULL);
 	if (!ret)
 		ret = mount_ns_sysfs();
@@ -480,6 +485,7 @@ int dump_net_ns(int pid, struct cr_fdset *fds)
 	close(ns_sysfs_fd);
 	ns_sysfs_fd = -1;
 
+	close_cr_fdset(&fds);
 	return ret;
 }
 
-- 
1.8.3.1



More information about the CRIU mailing list