[lxc-devel] possible lxc-attach problem

S.Çağlar Onur caglar at 10ur.org
Sat Mar 1 00:08:17 UTC 2014


On Fri, Feb 28, 2014 at 12:20 PM, Serge Hallyn <serge.hallyn at ubuntu.com> wrote:
> 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?

Yep, it looks much better on Fedora 20 as well
(http://paste.ubuntu.com/7013380/)

> 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
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel



-- 
S.Çağlar Onur <caglar at 10ur.org>


More information about the lxc-devel mailing list