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

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

diff --git a/include/mount.h b/include/mount.h
index b86114c..9da3222 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -11,7 +11,7 @@ extern int collect_mount_info(pid_t pid);
 extern struct fstype *find_fstype_by_name(char *fst);
 
 struct cr_fdset;
-extern int dump_mnt_ns(int pid, struct cr_fdset *);
+extern int dump_mnt_ns(int pid, int id);
 int prepare_mnt_ns(int pid);
 
 extern int pivot_root(const char *new_root, const char *put_old);
diff --git a/mount.c b/mount.c
index 44e33bd..8d0d0bb 100644
--- a/mount.c
+++ b/mount.c
@@ -641,37 +641,43 @@ static int dump_one_mountpoint(struct mount_info *pm, int fd)
 	return 0;
 }
 
-int dump_mnt_ns(int ns_pid, struct cr_fdset *fdset)
+int dump_mnt_ns(int ns_pid, int id)
 {
 	struct mount_info *pm;
-	int img_fd;
+	int img_fd, ret = -1;
+
+	img_fd = open_image(CR_FD_MNTS, O_DUMP, id);
+	if (img_fd < 0)
+		return -1;
 
 	pm = parse_mountinfo(ns_pid);
 	if (!pm) {
 		pr_err("Can't parse %d's mountinfo\n", ns_pid);
-		return -1;
+		goto err;
 	}
 
 	if (mnt_build_tree(pm) == NULL)
-		return -1;
+		goto err;
 
 	if (validate_mounts(pm))
-		return -1;
+		goto err;
 
 	pr_info("Dumping mountpoints\n");
 
-	img_fd = fdset_fd(fdset, CR_FD_MNTS);
 	do {
 		struct mount_info *n = pm->next;
 
 		if (dump_one_mountpoint(pm, img_fd))
-			return -1;
+			goto err;
 
 		xfree(pm);
 		pm = n;
 	} while (pm);
 
-	return 0;
+	ret = 0;
+err:
+	close(img_fd);
+	return ret;
 }
 
 /*
diff --git a/namespaces.c b/namespaces.c
index 53029e4..04d8d4e 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -372,7 +372,7 @@ static int do_dump_namespaces(struct pid *ns_pid, unsigned int ns_flags)
 	}
 	if (ns_flags & CLONE_NEWNS) {
 		pr_info("Dump MNT namespace (mountpoints)\n");
-		ret = dump_mnt_ns(ns_pid->real, fdset);
+		ret = dump_mnt_ns(ns_pid->real, pid);
 		if (ret < 0)
 			goto err;
 	}
-- 
1.8.3.1



More information about the CRIU mailing list