[lxc-devel] [PATCH 1/1] setup_rootfs: always mount / slave

Serge Hallyn serge.hallyn at ubuntu.com
Thu Feb 27 01:24:29 UTC 2014


When the host root is rshared, this appears to fix both the extra mounts
in the container's /proc/self/mounts, and the lxc-attach ending up in
the host rootfs.

chroot_into_slave is careful to turn mounts into slave mounts
as quickly as possible, but for reasons I haven't wrapped my
head around, not quickly enough.  Mounting / ms_slave first
appears to do the trick.

It's possible that in cases (like android) where / is a chroot
and not a bind mount, this will fail, in which case we'll need
to first do a bind mount of / onto itself.  Let's not do that
until we're sure we need it.

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 src/lxc/conf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index fc39897..2b1ba20 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -1500,6 +1500,11 @@ static int setup_rootfs(struct lxc_conf *conf)
 		return 0;
 	}
 
+	if (mount("", "/", NULL, MS_SLAVE, 0)) {
+		SYSERROR("Failed to make / rslave");
+		return -1;
+	}
+
 	if (access(rootfs->mount, F_OK)) {
 		SYSERROR("failed to access to '%s', check it is present",
 			 rootfs->mount);
-- 
1.9.0



More information about the lxc-devel mailing list