[lxc-devel] possible lxc-attach problem

Serge Hallyn serge.hallyn at ubuntu.com
Fri Feb 28 17:20:33 UTC 2014


Quoting Serge Hallyn (serge.hallyn at ubuntu.com):
> It seems to me these are the right things to do, but they'll take
> some experimentation with the many possible hosts:
> 
> 1. If / is not shared, do nothing
> 2. if / is shared, and is not the ramfs, then remount MS_SLAVE|MS_REC
> 3. if / is ramfs, then do the chroot_into_slave

The following patch seems to work for me on arch.  It should
also work on ubuntu as it makes no changes in the !shared
path.  In order to fill in the ramfs root detection, could
someone (Stéphane?) send the output of /proc/self/mountinfo
on an android system?

Subject: [PATCH 1/1] simpler shared rootfs handling

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 src/lxc/conf.c  | 9 ++++++++-
 src/lxc/utils.c | 6 ++++++
 src/lxc/utils.h | 1 +
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index fc39897..1f186c7 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -1506,11 +1506,18 @@ static int setup_rootfs(struct lxc_conf *conf)
                return -1;
        }
 
-       if (detect_shared_rootfs()) {
+       if (detect_ramfs_rootfs()) {
+ERROR("detected ramfs");
                if (chroot_into_slave(conf)) {
                        ERROR("Failed to chroot into slave /");
                        return -1;
                }
+       } else if (detect_shared_rootfs()) {
+ERROR("detected shared rootfs");
+               if (mount("", "/", NULL, MS_SLAVE|MS_REC, 0)) {
+                       SYSERROR("Failed to make / rslave");
+                       return -1;
+               }
        }
 
        // First try mounting rootfs using a bdev
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index da7c3b4..72064cc 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -1234,3 +1234,9 @@ int detect_shared_rootfs(void)
        fclose(f);
        return 0;
 }
+
+int detect_ramfs_rootfs(void)
+{
+       /* TODO - we need to figure out how to detect this */
+       return 0;
+}
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index dcf0e34..b0c9bc1 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -278,3 +278,4 @@ uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval);
 #endif
 
 int detect_shared_rootfs(void);
+int detect_ramfs_rootfs(void);
-- 
1.9.0


More information about the lxc-devel mailing list