[CRIU] [PATCH 03/14] mount: rework perparation for pivot_root (v3)
Andrey Vagin
avagin at openvz.org
Tue Oct 14 04:38:17 PDT 2014
We can't bind-mount the required root into itself instead of
resolving a parent mount.
This patch is required to support userns, because if we want to make
pivot_root, the parent mount can't be locked. When we create userns
and mntns, all inherited mounts are marked as locked.
This patch doesn't change properties of the root mount or any other
mounts of the restored namespace. It is needed to satisfy pivot_root().
v2: don't change properties of the given root
v3: bind-mount root into itself recursevly
Cc: Tycho Andersen <tycho.andersen at canonical.com>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
mount.c | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/mount.c b/mount.c
index d8b6beb..bc1d1e6 100644
--- a/mount.c
+++ b/mount.c
@@ -1940,27 +1940,24 @@ int prepare_mnt_ns(void)
if (clean_mnt_ns(ns.mnt.mntinfo_tree))
return -1;
} else {
- struct mount_info *mi;
-
- /* moving a mount residing under a shared mount is invalid. */
- mi = mount_resolve_path(ns.mnt.mntinfo_tree, opts.root);
- if (mi == NULL) {
- pr_err("Unable to find mount point for %s\n", opts.root);
+ char buf[] = "/proc/self/fd/XXXXXXXXXX";
+ int fd;
+ fd = open(opts.root, O_DIRECTORY | O_PATH);
+ if (fd < 0) {
+ pr_perror("Unable to open %s", opts.root);
return -1;
}
- if (mi->parent == NULL) {
- pr_err("New root and old root are the same\n");
+ if (mount(opts.root, opts.root, NULL, MS_BIND | MS_REC, NULL)) {
+ pr_perror("Unable to bind-mount %s", opts.root);
return -1;
}
-
- /* Our root is mounted over the parent (in the same directory) */
- if (!strcmp(mi->parent->mountpoint, mi->mountpoint)) {
- pr_err("The parent of the new root is unreachable\n");
+ snprintf(buf, sizeof(buf), "/proc/self/fd/%d", fd);
+ if (mount("none", buf, "none", MS_SLAVE, NULL)) {
+ pr_perror("Can't remount the parent of the new root with MS_SLAVE");
return -1;
}
-
- if (mount("none", mi->parent->mountpoint + 1, "none", MS_SLAVE, NULL)) {
- pr_perror("Can't remount the parent of the new root with MS_SLAVE");
+ if (chdir(opts.root)) {
+ pr_perror("chdir(%s) failed", opts.root);
return -1;
}
}
--
1.9.3
More information about the CRIU
mailing list