All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Nikolay Borisov <nborisov@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/3] btrfs: Make btrfs_find_device_by_path return struct btrfs_device
Date: Mon, 3 Sep 2018 20:13:57 +0800	[thread overview]
Message-ID: <3da90587-21bf-2e83-a86a-db96df3fc15f@gmx.com> (raw)
In-Reply-To: <20180903094614.2667-2-nborisov@suse.com>



On 2018/9/3 下午5:46, Nikolay Borisov wrote:
> Currently this function returns an error code as well as uses one of
> its arguments as a return value for struct btrfs_device. Change the
> function so that it returns btrfs_device directly and use the usual
> "encode error in pointer" mechanics if something goes wrong. No
> functional changes.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>  fs/btrfs/volumes.c | 26 ++++++++++++++------------
>  1 file changed, 14 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index da86706123ff..715ea45c6c28 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -2096,9 +2096,9 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)
>  	call_rcu(&tgtdev->rcu, free_device_rcu);
>  }
>  
> -static int btrfs_find_device_by_path(struct btrfs_fs_info *fs_info,
> -				     const char *device_path,
> -				     struct btrfs_device **device)
> +static struct btrfs_device *
> +btrfs_find_device_by_path(struct btrfs_fs_info *fs_info,
> +			  const char *device_path)
>  {
>  	int ret = 0;
>  	struct btrfs_super_block *disk_super;
> @@ -2106,21 +2106,21 @@ static int btrfs_find_device_by_path(struct btrfs_fs_info *fs_info,
>  	u8 *dev_uuid;
>  	struct block_device *bdev;
>  	struct buffer_head *bh;
> +	struct btrfs_device *device;
>  
> -	*device = NULL;
>  	ret = btrfs_get_bdev_and_sb(device_path, FMODE_READ,
>  				    fs_info->bdev_holder, 0, &bdev, &bh);
>  	if (ret)
> -		return ret;
> +		return ERR_PTR(ret);
>  	disk_super = (struct btrfs_super_block *)bh->b_data;
>  	devid = btrfs_stack_device_id(&disk_super->dev_item);
>  	dev_uuid = disk_super->dev_item.uuid;
> -	*device = btrfs_find_device(fs_info, devid, dev_uuid, disk_super->fsid);
> +	device = btrfs_find_device(fs_info, devid, dev_uuid, disk_super->fsid);
>  	brelse(bh);
> -	if (!*device)
> -		ret = -ENOENT;
> +	if (!device)
> +		device = ERR_PTR(-ENOENT);
>  	blkdev_put(bdev, FMODE_READ);
> -	return ret;
> +	return device;
>  }
>  
>  int btrfs_find_device_missing_or_by_path(struct btrfs_fs_info *fs_info,
> @@ -2143,11 +2143,13 @@ int btrfs_find_device_missing_or_by_path(struct btrfs_fs_info *fs_info,
>  
>  		if (!*device)
>  			return BTRFS_ERROR_DEV_MISSING_NOT_FOUND;
> -
> -		return 0;
>  	} else {
> -		return btrfs_find_device_by_path(fs_info, device_path, device);
> +		*device = btrfs_find_device_by_path(fs_info, device_path);
> +		if (IS_ERR(*device))
> +			return PTR_ERR(*device);
>  	}
> +
> +	return 0;
>  }
>  
>  /*
> 

  reply	other threads:[~2018-09-03 16:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-03  9:46 [PATCH 0/3] cleanup couple of device-related functions' retval Nikolay Borisov
2018-09-03  9:46 ` [PATCH 1/3] btrfs: Make btrfs_find_device_by_path return struct btrfs_device Nikolay Borisov
2018-09-03 12:13   ` Qu Wenruo [this message]
2018-09-10 18:02   ` David Sterba
2018-09-03  9:46 ` [PATCH 2/3] btrfs: Make btrfs_find_device_missing_or_by_path return directly a device Nikolay Borisov
2018-09-03 12:23   ` Qu Wenruo
2018-09-03  9:46 ` [PATCH 3/3] btrfs: Make btrfs_find_device_by_devspec return btrfs_device directly Nikolay Borisov
2018-09-03 12:27   ` Qu Wenruo
2018-09-03 10:02 ` [PATCH] btrfs-progs: tests: Add test for missing device delete error value Nikolay Borisov
2018-09-10 17:57   ` David Sterba
2018-09-11 14:31     ` David Sterba
2018-09-10 18:07 ` [PATCH 0/3] cleanup couple of device-related functions' retval David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3da90587-21bf-2e83-a86a-db96df3fc15f@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.