[CRIU] [PATCH] btrfs: Don't fail if we meet non-subvolume mountpoint

Pavel Emelyanov xemul at parallels.com
Thu Dec 5 03:10:01 PST 2013


On 12/05/2013 02:10 PM, Cyrill Gorcunov wrote:
> If mount point is not a subvolume we need more complex logic
> to figure out which subvolumes it might have. It'll be addressed
> later, at moment simply don't fail in such case: for worst
> scenarion we will fail later in CRIU code when devs are not
> matching, in best case if application is not using notify,
> sockets or deleted files -- we should continue without errors.
> 
> Reported-by: Andrew Vagin <avagin at parallels.com>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  mount-btrfs.c | 27 +++++++++++++++++++--------
>  1 file changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/mount-btrfs.c b/mount-btrfs.c
> index 90383dc3bd4a..a693e3c55f3a 100644
> --- a/mount-btrfs.c
> +++ b/mount-btrfs.c
> @@ -397,7 +397,7 @@ static void btrfs_show_subvolumes(struct btrfs_subvol_root *r)
>  	}
>  }
>  
> -static void *btrfs_parse_volume(struct mount_info *m)
> +static struct btrfs_subvol_root *btrfs_parse_volume(struct mount_info *m)
>  {
>  	struct btrfs_ioctl_search_args tree_args;
>  	struct btrfs_ioctl_search_header sh;
> @@ -420,14 +420,17 @@ static void *btrfs_parse_volume(struct mount_info *m)
>  	sk->max_transid		= (u64)-1;
>  	sk->nr_items		= 4096;
>  
> -	fd = open(m->mountpoint, O_RDONLY);
> -	if (fd < 0) {
> -		pr_perror("Can't open %s", m->mountpoint);
> +	if (stat(m->mountpoint, &st)) {
> +		pr_perror("Can't get stat on %s", m->mountpoint);
>  		goto err;
>  	}
>  
> -	if (stat(m->mountpoint, &st)) {
> -		pr_perror("Can't get stat on %s", m->mountpoint);
> +	if (st.st_ino != BTRFS_FIRST_FREE_OBJECTID)
> +		return ERR_PTR(-ENOENT);
> +
> +	fd = open(m->mountpoint, O_RDONLY);
> +	if (fd < 0) {
> +		pr_perror("Can't open %s", m->mountpoint);

Don't do start + open. Do open + fstat.

>  		goto err;
>  	}
>  
> @@ -490,12 +493,20 @@ static void *btrfs_parse_volume(struct mount_info *m)
>  	result = r;
>  err:
>  	close_safe(&fd);
> -	return (void *)result;
> +	return result;
>  }
>  
>  int btrfs_parse_mountinfo(struct mount_info *m)
>  {
> -	return btrfs_parse_volume(m) ? 0 : -1;
> +	struct btrfs_subvol_root *r;
> +
> +	r = btrfs_parse_volume(m);
> +	if (IS_ERR(r)) {
> +		if (PTR_ERR(r) == -ENOENT)
> +			return 0;
> +		return -1;
> +	}
> +	return r ? 0 : -1;

This looks tricky. Why not make btrfs_parse_volume() return int and
decide when to report error and when not itself?

>  }
>  
>  bool is_btrfs_subvol(dev_t vol_id, dev_t dev_id)
> 




More information about the CRIU mailing list