linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org, dsterba@suse.cz
Subject: Re: [PATCH 5/6 v2] btrfs: merge btrfs_find_device() and find_device()
Date: Wed, 23 Jan 2019 13:28:26 +0800	[thread overview]
Message-ID: <f1554171-01ee-05f2-136a-7732f6ea678a@oracle.com> (raw)
In-Reply-To: <1547880535-29710-1-git-send-email-anand.jain@oracle.com>



On 01/19/2019 02:48 PM, Anand Jain wrote:
> Both btrfs_find_device() and find_device() does the same things expect
> that latter function is not keen in seed device in the scan-context. So
> merge them.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

    A gentle ping.

Thanks, Anand

> ---
> v2: use bool instead of int.
>      use positive meaning instead of negative.
>      conflict fix: due to 1b3922a8bc7 in misc-next.
> 
> 	if (dev->disk_total_bytes == 0) {
> -		dev = find_device(fs_info->fs_devices->seed, devid, NULL);
> +		dev = btrfs_find_device(fs_info->fs_devices->seed, devid, NULL,
> +					NULL, false);
>   fs/btrfs/dev-replace.c |  4 +--
>   fs/btrfs/ioctl.c       |  4 +--
>   fs/btrfs/scrub.c       |  4 +--
>   fs/btrfs/volumes.c     | 73 +++++++++++++++++++++++++-------------------------
>   fs/btrfs/volumes.h     |  3 ++-
>   5 files changed, 44 insertions(+), 44 deletions(-)
> 
> diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
> index 6f0fe3623381..975cbf011593 100644
> --- a/fs/btrfs/dev-replace.c
> +++ b/fs/btrfs/dev-replace.c
> @@ -112,10 +112,10 @@ int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info)
>   	case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
>   	case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
>   		dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices,
> -							src_devid, NULL, NULL);
> +							src_devid, NULL, NULL, true);
>   		dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices,
>   							BTRFS_DEV_REPLACE_DEVID,
> -							NULL, NULL);
> +							NULL, NULL, true);
>   		/*
>   		 * allow 'btrfs dev replace_cancel' if src/tgt device is
>   		 * missing
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index fd5f97aeb35c..3f9d7be30bf4 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1642,7 +1642,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
>   		btrfs_info(fs_info, "resizing devid %llu", devid);
>   	}
>   
> -	device = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
> +	device = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, true);
>   	if (!device) {
>   		btrfs_info(fs_info, "resizer unable to find device %llu",
>   			   devid);
> @@ -3179,7 +3179,7 @@ static long btrfs_ioctl_dev_info(struct btrfs_fs_info *fs_info,
>   
>   	rcu_read_lock();
>   	dev = btrfs_find_device(fs_info->fs_devices, di_args->devid, s_uuid,
> -				NULL);
> +				NULL, true);
>   
>   	if (!dev) {
>   		ret = -ENODEV;
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index 72044efc610a..b320910c6740 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -3835,7 +3835,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
>   		return PTR_ERR(sctx);
>   
>   	mutex_lock(&fs_info->fs_devices->device_list_mutex);
> -	dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
> +	dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, true);
>   	if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
>   		     !is_dev_replace)) {
>   		mutex_unlock(&fs_info->fs_devices->device_list_mutex);
> @@ -4012,7 +4012,7 @@ int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
>   	struct scrub_ctx *sctx = NULL;
>   
>   	mutex_lock(&fs_info->fs_devices->device_list_mutex);
> -	dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
> +	dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, true);
>   	if (dev)
>   		sctx = dev->scrub_ctx;
>   	if (sctx)
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 5b37044503c0..df1a077aeb80 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -415,27 +415,6 @@ static struct btrfs_device *__alloc_device(void)
>   	return dev;
>   }
>   
> -/*
> - * Find a device specified by @devid or @uuid in the list of @fs_devices, or
> - * return NULL.
> - *
> - * If devid and uuid are both specified, the match must be exact, otherwise
> - * only devid is used.
> - */
> -static struct btrfs_device *find_device(struct btrfs_fs_devices *fs_devices,
> -		u64 devid, const u8 *uuid)
> -{
> -	struct btrfs_device *dev;
> -
> -	list_for_each_entry(dev, &fs_devices->devices, dev_list) {
> -		if (dev->devid == devid &&
> -		    (!uuid || !memcmp(dev->uuid, uuid, BTRFS_UUID_SIZE))) {
> -			return dev;
> -		}
> -	}
> -	return NULL;
> -}
> -
>   static noinline struct btrfs_fs_devices *find_fsid(
>   		const u8 *fsid, const u8 *metadata_fsid)
>   {
> @@ -990,8 +969,9 @@ static noinline struct btrfs_device *device_list_add(const char *path,
>   		device = NULL;
>   	} else {
>   		mutex_lock(&fs_devices->device_list_mutex);
> -		device = find_device(fs_devices, devid,
> -				disk_super->dev_item.uuid);
> +		device = btrfs_find_device(fs_devices, devid,
> +					   disk_super->dev_item.uuid, NULL,
> +					   false);
>   
>   		/*
>   		 * If this disk has been pulled into an fs devices created by
> @@ -2419,10 +2399,10 @@ static struct btrfs_device *btrfs_find_device_by_path(
>   	dev_uuid = disk_super->dev_item.uuid;
>   	if (btrfs_fs_incompat(fs_info, METADATA_UUID))
>   		device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
> -					   disk_super->metadata_uuid);
> +					   disk_super->metadata_uuid, true);
>   	else
>   		device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
> -					   disk_super->fsid);
> +					   disk_super->fsid, true);
>   
>   	brelse(bh);
>   	if (!device)
> @@ -2442,7 +2422,7 @@ struct btrfs_device *btrfs_find_device_by_devspec(
>   
>   	if (devid) {
>   		device = btrfs_find_device(fs_info->fs_devices, devid, NULL,
> -					   NULL);
> +					   NULL, true);
>   		if (!device)
>   			return ERR_PTR(-ENOENT);
>   		return device;
> @@ -2584,7 +2564,7 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans,
>   		read_extent_buffer(leaf, fs_uuid, btrfs_device_fsid(dev_item),
>   				   BTRFS_FSID_SIZE);
>   		device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
> -					   fs_uuid);
> +					   fs_uuid, true);
>   		BUG_ON(!device); /* Logic error */
>   
>   		if (device->fs_devices->seeding) {
> @@ -6637,19 +6617,36 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
>   	return BLK_STS_OK;
>   }
>   
> +/*
> + * Find a device specified by @devid or @uuid in the list of @fs_devices, or
> + * return NULL.
> + *
> + * If devid and uuid are both specified, the match must be exact, otherwise
> + * only devid is used.
> + *
> + * If seed is true, traverse through the seed devices.
> + */
>   struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
> -				       u64 devid, u8 *uuid, u8 *fsid)
> +				       u64 devid, u8 *uuid, u8 *fsid,
> +				       bool seed)
>   {
>   	struct btrfs_device *device;
>   
>   	while (fs_devices) {
>   		if (!fsid ||
>   		    !memcmp(fs_devices->metadata_uuid, fsid, BTRFS_FSID_SIZE)) {
> -			device = find_device(fs_devices, devid, uuid);
> -			if (device)
> -				return device;
> +			list_for_each_entry(device, &fs_devices->devices,
> +					    dev_list) {
> +				if (device->devid == devid && (!uuid ||
> +				    !memcmp(device->uuid, uuid,
> +				    BTRFS_UUID_SIZE)))
> +					return device;
> +			}
>   		}
> -		fs_devices = fs_devices->seed;
> +		if (seed)
> +			fs_devices = fs_devices->seed;
> +		else
> +			return NULL;
>   	}
>   	return NULL;
>   }
> @@ -6895,7 +6892,7 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
>   				   btrfs_stripe_dev_uuid_nr(chunk, i),
>   				   BTRFS_UUID_SIZE);
>   		map->stripes[i].dev = btrfs_find_device(fs_info->fs_devices,
> -							devid, uuid, NULL);
> +							devid, uuid, NULL, true);
>   		if (!map->stripes[i].dev &&
>   		    !btrfs_test_opt(fs_info, DEGRADED)) {
>   			free_extent_map(em);
> @@ -7035,7 +7032,7 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
>   	}
>   
>   	device = btrfs_find_device(fs_info->fs_devices, devid, dev_uuid,
> -				   fs_uuid);
> +				   fs_uuid, true);
>   	if (!device) {
>   		if (!btrfs_test_opt(fs_info, DEGRADED)) {
>   			btrfs_report_missing_device(fs_info, devid,
> @@ -7625,7 +7622,8 @@ int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
>   	int i;
>   
>   	mutex_lock(&fs_devices->device_list_mutex);
> -	dev = btrfs_find_device(fs_info->fs_devices, stats->devid, NULL, NULL);
> +	dev = btrfs_find_device(fs_info->fs_devices, stats->devid, NULL, NULL,
> +				true);
>   	mutex_unlock(&fs_devices->device_list_mutex);
>   
>   	if (!dev) {
> @@ -7839,7 +7837,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
>   	}
>   
>   	/* Make sure no dev extent is beyond device bondary */
> -	dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL);
> +	dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, true);
>   	if (!dev) {
>   		btrfs_err(fs_info, "failed to find devid %llu", devid);
>   		ret = -EUCLEAN;
> @@ -7848,7 +7846,8 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
>   
>   	/* It's possible this device is a dummy for seed device */
>   	if (dev->disk_total_bytes == 0) {
> -		dev = find_device(fs_info->fs_devices->seed, devid, NULL);
> +		dev = btrfs_find_device(fs_info->fs_devices->seed, devid, NULL,
> +					NULL, false);
>   		if (!dev) {
>   			btrfs_err(fs_info, "failed to find seed devid %llu",
>   				  devid);
> diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
> index 46ee8eafdc92..c8ddcf4ae1f2 100644
> --- a/fs/btrfs/volumes.h
> +++ b/fs/btrfs/volumes.h
> @@ -435,7 +435,8 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,
>   int btrfs_grow_device(struct btrfs_trans_handle *trans,
>   		      struct btrfs_device *device, u64 new_size);
>   struct btrfs_device *btrfs_find_device(struct btrfs_fs_devices *fs_devices,
> -				       u64 devid, u8 *uuid, u8 *fsid);
> +				       u64 devid, u8 *uuid, u8 *fsid,
> +				       bool seed);
>   int btrfs_shrink_device(struct btrfs_device *device, u64 new_size);
>   int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *path);
>   int btrfs_balance(struct btrfs_fs_info *fs_info,
> 

  reply	other threads:[~2019-01-23  5:28 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-17 15:32 [PATCH 0/6] btrfs: find_device cleanups Anand Jain
2019-01-17 15:32 ` [PATCH 1/6] btrfs: merge btrfs_find_device_missing_or_by_path() into parent Anand Jain
2019-01-17 15:57   ` David Sterba
2019-01-17 15:32 ` [PATCH 2/6] btrfs: cleanup btrfs_find_device_by_devspec() Anand Jain
2019-01-17 15:57   ` David Sterba
2019-01-17 15:32 ` [PATCH 3/6] btrfs: rename btrfs_find_device_by_path() Anand Jain
2019-01-17 15:54   ` David Sterba
2019-01-18  6:13     ` Anand Jain
2019-01-18 17:05       ` David Sterba
2019-01-17 15:32 ` [PATCH 4/6] btrfs: refactor btrfs_find_device() take fs_devices as argument Anand Jain
2019-01-17 15:58   ` David Sterba
2019-01-17 15:32 ` [PATCH 5/6] btrfs: merge btrfs_find_device() and find_device() Anand Jain
2019-01-17 15:51   ` David Sterba
2019-01-19  6:48   ` [PATCH 5/6 v2] " Anand Jain
2019-01-23  5:28     ` Anand Jain [this message]
2019-01-28 18:44     ` David Sterba
2019-01-17 15:32 ` [PATCH 6/6] btrfs: refactor btrfs_find_device() return error code Anand Jain
2019-01-17 15:49   ` David Sterba
2019-01-18  6:13     ` Anand Jain
2019-01-18 17:20       ` David Sterba
2019-01-18 17:33 ` [PATCH 0/6] btrfs: find_device cleanups David Sterba
2019-01-19  6:54   ` Anand Jain

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=f1554171-01ee-05f2-136a-7732f6ea678a@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).