[CRIU] [PATCH 4/7] mnt_ns: Use fdstore to keep mount namespaces

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jun 28 18:54:25 MSK 2017


This allows to decrese number of file descriptors,
which are passed to children, and that is need to
close in close_old_files().

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>:
---
 criu/include/namespaces.h |    2 +-
 criu/mount.c              |   10 +++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 3cfa9a9bf..44520a81a 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -123,7 +123,7 @@ struct ns_id {
 		struct {
 			struct mount_info *mntinfo_list;
 			struct mount_info *mntinfo_tree;
-			int ns_fd;
+			int nsfd_id;
 			int root_fd_id;
 		} mnt;
 
diff --git a/criu/mount.c b/criu/mount.c
index 4274cbd04..fbc46dc1a 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -2718,7 +2718,7 @@ static int do_restore_task_mnt_ns(struct ns_id *nsid, struct pstree_item *curren
 {
 	int fd;
 
-	fd = open_proc(vpid(root_item), "fd/%d", nsid->mnt.ns_fd);
+	fd = fdstore_get(nsid->mnt.nsfd_id);
 	if (fd < 0)
 		return -1;
 
@@ -2775,7 +2775,6 @@ void fini_restore_mntns(void)
 	for (nsid = ns_ids; nsid != NULL; nsid = nsid->next) {
 		if (nsid->nd != &mnt_ns_desc)
 			continue;
-		close_safe(&nsid->mnt.ns_fd);
 		nsid->ns_populated = true;
 	}
 }
@@ -3044,7 +3043,12 @@ int prepare_mnt_ns(void)
 		}
 
 		/* Pin one with a file descriptor */
-		nsid->mnt.ns_fd = fd;
+		nsid->mnt.nsfd_id = fdstore_add(fd);
+		close(fd);
+		if (nsid->mnt.nsfd_id < 0) {
+			pr_err("Can't add ns fd\n");
+			goto err;
+		}
 
 		/* Set its root */
 		path[0] = '/';



More information about the CRIU mailing list