[lxc-devel] [PATCH 1/1] Use 'overlay' as fs name when needed

KATOH Yasufumi karma at jazz.email.ne.jp
Mon Jan 26 08:46:43 UTC 2015


Hi,

I applied your patch and tested on:
* 3.18.3 kernel (module name is 'overlay' and needs 'workdir' option)
* 3.17.6 kernel with overlayfs.v24 (module name is 'overlayfs' and
  needs 'workdir' option)
* 3.13.8 kernel with overlayfs.v21 (module name is 'overlayfs' and
  do not need 'workdir' option)

It works fine on those.

>>> On Mon, 26 Jan 2015 05:58:50 +0000
    in message   "[lxc-devel] [PATCH 1/1] Use 'overlay' as fs name when needed"
                  Serge Hallyn-san wrote:

> This addresses https://github.com/lxc/lxc/issues/389

> We will probably also want to switch the order of the mount attempts, as
> the new overlay fs should quickly become the more common scenario.

> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>

Acked-by: KATOH Yasufumi <karma at jazz.email.ne.jp>

> ---
>  src/lxc/bdev.c | 29 +++++++++++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)

> diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
> index ac387b1..721a72b 100644
> --- a/src/lxc/bdev.c
> +++ b/src/lxc/bdev.c
> @@ -2138,6 +2138,28 @@ static int overlayfs_detect(const char *path)
>  	return 0;
>  }
 
> +static char *overlayfs_name;
> +static char *detect_overlayfs_name(void)
> +{
> +	char *v = "overlayfs";
> +	char *line = NULL;
> +	size_t len = 0;
> +	FILE *f = fopen("/proc/filesystems", "r");
> +	if (!f)
> +		return v;
> +
> +	while (getline(&line, &len, f) != -1) {
> +		if (strcmp(line, "nodev\toverlay\n") == 0) {
> +			v = "overlay";
> +			break;
> +		}
> +	}
> +
> +	fclose(f);
> +	free(line);
> +	return v;
> +}
> +
>  //
>  // XXXXXXX plain directory bind mount ops
>  //
> @@ -2156,6 +2178,9 @@ static int overlayfs_mount(struct bdev *bdev)
>  	if (!bdev->src || !bdev->dest)
>  		return -22;
 
> +	if (!overlayfs_name)
> +		overlayfs_name = detect_overlayfs_name();
> +
>  	//  separately mount it first
>  	//  mount -t overlayfs -oupperdir=${upper},lowerdir=${lower} lower dest
>  	dup = alloca(strlen(bdev->src)+1);
> @@ -2216,13 +2241,13 @@ static int overlayfs_mount(struct bdev *bdev)
>  	}
 
>  	// mount without workdir option for overlayfs before v21
> -	ret = mount(lower, bdev->dest, "overlayfs", MS_MGC_VAL | mntflags, options);
> +	ret = mount(lower, bdev->dest, overlayfs_name, MS_MGC_VAL | mntflags, options);
>  	if (ret < 0) {
>  		INFO("overlayfs: error mounting %s onto %s options %s. retry with workdir",
>  			lower, bdev->dest, options);
 
>  		// retry with workdir option for overlayfs v22 and higher
> -		ret = mount(lower, bdev->dest, "overlayfs", MS_MGC_VAL | mntflags, options_work);
> +		ret = mount(lower, bdev->dest, overlayfs_name, MS_MGC_VAL | mntflags, options_work);
>  		if (ret < 0)
>  			SYSERROR("overlayfs: error mounting %s onto %s options %s",
>  				lower, bdev->dest, options_work);
> -- 
> 2.1.0

> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list