From ae98ef6ae01cb0e5126208e07f6ed1a6b39ed48f Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 12 Dec 2013 16:19:48 +0400 Subject: [PATCH] mount: Factor out mount tree build for NEWNS and non-NS cases We anyway build the tree, in the NS case -- few calls later. Signed-off-by: Pavel Emelyanov --- cr-dump.c | 2 +- cr-restore.c | 9 +-------- include/mount.h | 2 +- mount.c | 27 ++++++++++----------------- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/cr-dump.c b/cr-dump.c index 98fdddd09..ffae7ffa0 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -1703,7 +1703,7 @@ int cr_dump_tasks(pid_t pid) if (collect_file_locks()) goto err; - if (collect_mount_info(pid, true)) + if (collect_mount_info(pid)) goto err; if (mntns_collect_root(root_item->pid.real)) diff --git a/cr-restore.c b/cr-restore.c index 4d6312ac2..6a0637eb2 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -1260,14 +1260,7 @@ static int restore_task_with_children(void *_arg) /* Restore root task */ if (current->parent == NULL) { - /* - * For ghost file path resolving on BTRFS we will need - * parsed mount tree, but IIF we're not restoring task - * with mount namespace cloned, in this case we don't parse - * mount tree early because we will be reading mount points - * from image later and generate new mount tree. - */ - if (collect_mount_info(getpid(), !(ca->clone_flags & CLONE_NEWNS))) + if (collect_mount_info(getpid())) exit(1); if (prepare_namespace(current, ca->clone_flags)) diff --git a/include/mount.h b/include/mount.h index dade585c7..a76c027d1 100644 --- a/include/mount.h +++ b/include/mount.h @@ -7,7 +7,7 @@ extern int mntns_collect_root(pid_t pid); struct proc_mountinfo; extern int open_mount(unsigned int s_dev); -extern int collect_mount_info(pid_t pid, bool parse); +extern int collect_mount_info(pid_t pid); extern struct fstype *find_fstype_by_name(char *fst); struct cr_fdset; diff --git a/mount.c b/mount.c index a7fd1814b..f943cf7f8 100644 --- a/mount.c +++ b/mount.c @@ -70,7 +70,7 @@ int open_mount(unsigned int s_dev) return -ENOENT; } -int collect_mount_info(pid_t pid, bool parse) +int collect_mount_info(pid_t pid) { pr_info("Collecting mountinfo\n"); @@ -81,16 +81,15 @@ int collect_mount_info(pid_t pid, bool parse) } /* - * WARN: Don't ever parse already parsed mount tree, - * this will corrupt mount lists leading to weird - * errors. + * Build proper tree in any case -- for NEWNS one we'll use + * it for old NS clean, otherwise we'll use the tree for + * path resolution (btrfs stat workaround). */ - if (parse) { - mntinfo_tree = mnt_build_tree(mntinfo); - if (!mntinfo_tree) { - pr_err("Building mount tree %d failed\n", getpid()); - return -1; - } + + mntinfo_tree = mnt_build_tree(mntinfo); + if (!mntinfo_tree) { + pr_err("Building mount tree %d failed\n", getpid()); + return -1; } return 0; @@ -1117,8 +1116,6 @@ static int do_umount_one(struct mount_info *mi) static int clean_mnt_ns(void) { - struct mount_info *pm; - pr_info("Cleaning mount namespace\n"); /* @@ -1130,11 +1127,7 @@ static int clean_mnt_ns(void) return -1; } - pm = mnt_build_tree(mntinfo); - if (!pm) - return -1; - - return mnt_tree_for_each_reverse(pm, do_umount_one); + return mnt_tree_for_each_reverse(mntinfo_tree, do_umount_one); } static int cr_pivot_root()