[lxc-devel] [PATCH] utils: remove unnecessary check of mystat.st_dev

Serge Hallyn serge.hallyn at ubuntu.com
Wed Oct 29 20:30:16 UTC 2014


Quoting Luka Perkov (luka.perkov at sartura.hr):
> The check is not needed and it breaks lxc-destroy when container is installed
> on top of overlayfs. More information why this is a problem on overlayfs can be
> found here:
> 
> https://kernel.googlesource.com/pub/scm/linux/kernel/git/mszeredi/vfs/+/overlayfs.current/Documentation/filesystems/overlayfs.txt

Hm, not sure how I feel about this.  You say "it's not needed",
but removing it invalidates the "_onedev" part of the function
name.

I realize that in most cases the is-one-device part isn't
needed.  But in those rare cases where admin has messed up and
left a pointer to host's / or /etc in the container
somehow, it'll be missed.

Really I don't know that I'd recommend running containers on top
of overlayfs.  This is not the usual overlayfs-container use-case,
and it overlayfs has enough niggles that it'd worry me.  Still,
if we can fix this in a safe way then I'm open to it.

Maybe we should detect whether the underlying fs is overlayfs,
and ignore the device if it is?

> Signed-off-by: Luka Perkov <luka.perkov at sartura.hr>
> ---
>  src/lxc/utils.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/src/lxc/utils.c b/src/lxc/utils.c
> index 34743dd..1551154 100644
> --- a/src/lxc/utils.c
> +++ b/src/lxc/utils.c
> @@ -47,8 +47,8 @@
>  
>  lxc_log_define(lxc_utils, lxc);
>  
> -static int _recursive_rmdir_onedev(char *dirname, dev_t pdev,
> -				   const char *exclude, int level)
> +static int _recursive_rmdir_onedev(char *dirname, const char *exclude,
> +				   int level)
>  {
>  	struct dirent dirent, *direntp;
>  	DIR *dir;
> @@ -108,10 +108,8 @@ static int _recursive_rmdir_onedev(char *dirname, dev_t pdev,
>  			failed=1;
>  			continue;
>  		}
> -		if (mystat.st_dev != pdev)
> -			continue;
>  		if (S_ISDIR(mystat.st_mode)) {
> -			if (_recursive_rmdir_onedev(pathname, pdev, exclude, level+1) < 0)
> +			if (_recursive_rmdir_onedev(pathname, exclude, level+1) < 0)
>  				failed=1;
>  		} else {
>  			if (unlink(pathname) < 0) {
> @@ -147,7 +145,7 @@ extern int lxc_rmdir_onedev(char *path, const char *exclude)
>  		return -1;
>  	}
>  
> -	return _recursive_rmdir_onedev(path, mystat.st_dev, exclude, 0);
> +	return _recursive_rmdir_onedev(path, exclude, 0);
>  }
>  
>  static int mount_fs(const char *source, const char *target, const char *type)
> -- 
> 2.1.2
> 
> _______________________________________________
> 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