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

Andrey Vagin avagin at openvz.org
Mon Sep 30 06:16:49 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/ipc_ns.h |  2 +-
 ipc_ns.c         | 16 ++++++++++++----
 namespaces.c     |  2 +-
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/include/ipc_ns.h b/include/ipc_ns.h
index 0942f30..855936f 100644
--- a/include/ipc_ns.h
+++ b/include/ipc_ns.h
@@ -3,7 +3,7 @@
 
 #include "crtools.h"
 
-extern int dump_ipc_ns(int ns_pid, const struct cr_fdset *fdset);
+extern int dump_ipc_ns(int ns_pid, int id);
 extern int prepare_ipc_ns(int pid);
 
 extern struct ns_desc ipc_ns_desc;
diff --git a/ipc_ns.c b/ipc_ns.c
index b9144f7..7a9ca52 100644
--- a/ipc_ns.c
+++ b/ipc_ns.c
@@ -455,20 +455,28 @@ static int dump_ipc_data(const struct cr_fdset *fdset)
 	return 0;
 }
 
-int dump_ipc_ns(int ns_pid, const struct cr_fdset *fdset)
+int dump_ipc_ns(int ns_pid, int id)
 {
 	int ret;
+	struct cr_fdset *fdset;
+
+	fdset = cr_fdset_open(id, _CR_FD_IPCNS_FROM, _CR_FD_IPCNS_TO, O_DUMP);
+	if (fdset == NULL)
+		return -1;
 
 	ret = switch_ns(ns_pid, &ipc_ns_desc, NULL);
 	if (ret < 0)
-		return ret;
+		goto err;
 
 	ret = dump_ipc_data(fdset);
 	if (ret < 0) {
 		pr_err("Failed to write IPC namespace data\n");
-		return ret;
+		goto err;
 	}
-	return 0;
+
+err:
+	close_cr_fdset(&fdset);
+	return ret < 0 ? -1 : 0;
 }
 
 void ipc_sem_handler(int fd, void *obj)
diff --git a/namespaces.c b/namespaces.c
index 04d8d4e..fefce19 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -366,7 +366,7 @@ static int do_dump_namespaces(struct pid *ns_pid, unsigned int ns_flags)
 	}
 	if (ns_flags & CLONE_NEWIPC) {
 		pr_info("Dump IPC namespace\n");
-		ret = dump_ipc_ns(ns_pid->real, fdset);
+		ret = dump_ipc_ns(ns_pid->real, pid);
 		if (ret < 0)
 			goto err;
 	}
-- 
1.8.3.1



More information about the CRIU mailing list