2022-04-27 16:34:51

by Pankaj Raghav

[permalink] [raw]
Subject: [PATCH 03/16] block: add bdev_zone_no helper

Many places in the filesystem for zoned devices open code this function
to find the zone number for a given sector with power of 2 assumption.
This generic helper can be used to calculate zone number for a given
sector in a block device

This helper internally uses blk_queue_zone_no to find the zone number.

Reviewed-by: Luis Chamberlain <[email protected]>
Signed-off-by: Pankaj Raghav <[email protected]>
---
include/linux/blkdev.h | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index f8f2d2998afb..55293e0a8702 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1392,6 +1392,15 @@ static inline bool bdev_zone_aligned(struct block_device *bdev, sector_t sec)
return false;
}

+static inline unsigned int bdev_zone_no(struct block_device *bdev, sector_t sec)
+{
+ struct request_queue *q = bdev_get_queue(bdev);
+
+ if (q)
+ return blk_queue_zone_no(q, sec);
+ return 0;
+}
+
static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
{
struct request_queue *q = bdev_get_queue(bdev);
--
2.25.1


2022-04-28 02:10:45

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH 03/16] block: add bdev_zone_no helper

On 4/27/22 09:02, Pankaj Raghav wrote:
> +static inline unsigned int bdev_zone_no(struct block_device *bdev, sector_t sec)
> +{
> + struct request_queue *q = bdev_get_queue(bdev);
> +
> + if (q)
> + return blk_queue_zone_no(q, sec);
> + return 0;
> +}

This patch series has been split incorrectly: the same patch that
introduces a new function should also introduce a caller to that function.

Thanks,

Bart.

2022-04-28 09:46:58

by Damien Le Moal

[permalink] [raw]
Subject: Re: [PATCH 03/16] block: add bdev_zone_no helper

On 4/28/22 01:02, Pankaj Raghav wrote:
> Many places in the filesystem for zoned devices open code this function
> to find the zone number for a given sector with power of 2 assumption.
> This generic helper can be used to calculate zone number for a given
> sector in a block device
>
> This helper internally uses blk_queue_zone_no to find the zone number.
>
> Reviewed-by: Luis Chamberlain <[email protected]>
> Signed-off-by: Pankaj Raghav <[email protected]>
> ---
> include/linux/blkdev.h | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index f8f2d2998afb..55293e0a8702 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -1392,6 +1392,15 @@ static inline bool bdev_zone_aligned(struct block_device *bdev, sector_t sec)
> return false;
> }
>
> +static inline unsigned int bdev_zone_no(struct block_device *bdev, sector_t sec)
> +{
> + struct request_queue *q = bdev_get_queue(bdev);
> +
> + if (q)

q is never NULL. So this can be simplified to:

return blk_queue_zone_no(bdev_get_queue(bdev), sector);

> + return blk_queue_zone_no(q, sec);
> + return 0;
> +}
> +
> static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
> {
> struct request_queue *q = bdev_get_queue(bdev);


--
Damien Le Moal
Western Digital Research

2022-04-28 23:10:36

by Pankaj Raghav

[permalink] [raw]
Subject: Re: [PATCH 03/16] block: add bdev_zone_no helper

On 2022-04-28 01:53, Bart Van Assche wrote:
> On 4/27/22 09:02, Pankaj Raghav wrote:
>> +static inline unsigned int bdev_zone_no(struct block_device *bdev,
>> sector_t sec)
>> +{
>> +    struct request_queue *q = bdev_get_queue(bdev);
>> +
>> +    if (q)
>> +        return blk_queue_zone_no(q, sec);
>> +    return 0;
>> +}
>
> This patch series has been split incorrectly: the same patch that
> introduces a new function should also introduce a caller to that function.
>
Acked. I will make sure this happens in the next revision. Thanks.
> Thanks,
>
> Bart.

2022-04-29 10:43:25

by Pankaj Raghav

[permalink] [raw]
Subject: Re: [PATCH 03/16] block: add bdev_zone_no helper


On 2022-04-28 01:31, Damien Le Moal wrote:

>> +static inline unsigned int bdev_zone_no(struct block_device *bdev, sector_t sec)
>> +{
>> + struct request_queue *q = bdev_get_queue(bdev);
>> +
>> + if (q)
>
> q is never NULL. So this can be simplified to:
>
That is a good point. I just noticed it in the bdev_get_queue() function
that q can never be NULL. I will fix it up.

All the functions `bdev*` have this pattern, so probably they could be
simplified as well in the future.
> return blk_queue_zone_no(bdev_get_queue(bdev), sector);
>
>> + return blk_queue_zone_no(q, sec);
>> + return 0;
>> +}
>> +
>> static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
>> {
>> struct request_queue *q = bdev_get_queue(bdev);
>
>

2022-05-05 12:14:02

by Hannes Reinecke

[permalink] [raw]
Subject: Re: [PATCH 03/16] block: add bdev_zone_no helper

On 4/27/22 09:02, Pankaj Raghav wrote:
> Many places in the filesystem for zoned devices open code this function
> to find the zone number for a given sector with power of 2 assumption.
> This generic helper can be used to calculate zone number for a given
> sector in a block device
>
> This helper internally uses blk_queue_zone_no to find the zone number.
>
> Reviewed-by: Luis Chamberlain <[email protected]>
> Signed-off-by: Pankaj Raghav <[email protected]>
> ---
> include/linux/blkdev.h | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
Reviewed-by: Hannes Reinecke <[email protected]>

Cheers,

Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
[email protected] +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer