From b895c73c8206568ed3da2f585df8ca94a84be7d5 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Mon, 30 Sep 2013 17:16:48 +0400 Subject: [PATCH] mntns: don't use global fdset for dumping namespace 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 Signed-off-by: Pavel Emelyanov --- 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 b86114c10..9de9b51f2 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 ns_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 5902dc42c..efec0f882 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 ns_id) { struct mount_info *pm; - int img_fd; + int img_fd, ret = -1; + + img_fd = open_image(CR_FD_MNTS, O_DUMP, ns_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 961d694d8..37593a31b 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, ns_id); if (ret < 0) goto err; }