[lxc-devel] [PATCH 23/24] create rslave chroot any time pivot_root fails with -EINVAL
Stéphane Graber
stgraber at ubuntu.com
Tue Jan 8 17:03:13 UTC 2013
From: Serge Hallyn <serge.hallyn at ubuntu.com>
Note we still need the function to detect a MS_SHARED /, bc
if we detect that then we need to umount the chroot tmpfs
mount which lxc-start created, whose mount was forwarded to
the host mounts namespace.
Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
---
src/lxc/conf.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 945c3b8..09cfa9f 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -1163,13 +1163,6 @@ static int setup_rootfs(struct lxc_conf *conf)
return -1;
}
- if (detect_shared_rootfs()) {
- if (chroot_into_slave(conf)) {
- ERROR("Failed to chroot into slave /");
- return -1;
- }
- }
-
if (mount_rootfs(rootfs->path, rootfs->mount)) {
ERROR("failed to mount rootfs");
return -1;
@@ -1180,17 +1173,33 @@ static int setup_rootfs(struct lxc_conf *conf)
return 0;
}
-int setup_pivot_root(const struct lxc_rootfs *rootfs)
+static int setup_pivot_root(struct lxc_conf *conf)
{
+ const struct lxc_rootfs *rootfs = &conf->rootfs;
+
if (!rootfs->path)
return 0;
- if (setup_rootfs_pivot_root(rootfs->mount, rootfs->pivot)) {
+ if (setup_rootfs_pivot_root(rootfs->mount, rootfs->pivot) == 0)
+ return 0;
+
+ if (errno != EINVAL) {
ERROR("failed to setup pivot root");
return -1;
}
- return 0;
+ INFO("pivot_root failed. Trying pivot_root under custom chroot.");
+
+ if (chroot_into_slave(conf)) {
+ ERROR("Failed to chroot into slave /");
+ return -1;
+ }
+
+ if (setup_rootfs_pivot_root(rootfs->mount, rootfs->pivot) == 0)
+ return 0;
+
+ ERROR("failed to setup pivot root");
+ return -1;
}
static int setup_pts(int pts)
@@ -2649,7 +2658,7 @@ int lxc_setup(const char *name, struct lxc_conf *lxc_conf)
}
#endif
- if (setup_pivot_root(&lxc_conf->rootfs)) {
+ if (setup_pivot_root(lxc_conf)) {
ERROR("failed to set rootfs for '%s'", name);
return -1;
}
--
1.8.0
More information about the lxc-devel
mailing list