All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Cleanup blkdev zone helpers
@ 2024-06-21  3:15 Damien Le Moal
  2024-06-21  3:15 ` [PATCH 1/3] null_blk: Do not set disk->nr_zones Damien Le Moal
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Damien Le Moal @ 2024-06-21  3:15 UTC (permalink / raw)
  To: Jens Axboe, linux-block

The first patch removes a useless initialization of the number of zones
of a zoned null_blk device. The following 2 patches rework the zone
related inline helper functions in blkdev.h to simplify their
definition, removing uneeded code.

Damien Le Moal (3):
  null_blk: Do not set disk->nr_zones
  block: Define bdev_nr_zones() as an inline function
  block: Cleanup block device zone helpers

 block/blk-zoned.c              | 18 -------------
 drivers/block/null_blk/zoned.c |  2 --
 include/linux/blkdev.h         | 46 +++++++++++-----------------------
 3 files changed, 15 insertions(+), 51 deletions(-)

-- 
2.45.2


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/3] null_blk: Do not set disk->nr_zones
  2024-06-21  3:15 [PATCH 0/3] Cleanup blkdev zone helpers Damien Le Moal
@ 2024-06-21  3:15 ` Damien Le Moal
  2024-06-21  5:14   ` Christoph Hellwig
  2024-06-21 10:41   ` Johannes Thumshirn
  2024-06-21  3:15 ` [PATCH 2/3] block: Define bdev_nr_zones() as an inline function Damien Le Moal
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 12+ messages in thread
From: Damien Le Moal @ 2024-06-21  3:15 UTC (permalink / raw)
  To: Jens Axboe, linux-block

In null_register_zoned_dev(), there is no need to set disk->nr_zones as
the now uncoditional call to blk_revalidate_disk_zones() will do that.
So remove the assignment using bdev_nr_zones().

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 drivers/block/null_blk/zoned.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
index b42c00f13132..9f7151ad93cf 100644
--- a/drivers/block/null_blk/zoned.c
+++ b/drivers/block/null_blk/zoned.c
@@ -171,8 +171,6 @@ int null_register_zoned_dev(struct nullb *nullb)
 	struct request_queue *q = nullb->q;
 	struct gendisk *disk = nullb->disk;
 
-	disk->nr_zones = bdev_nr_zones(disk->part0);
-
 	pr_info("%s: using %s zone append\n",
 		disk->disk_name,
 		queue_emulates_zone_append(q) ? "emulated" : "native");
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/3] block: Define bdev_nr_zones() as an inline function
  2024-06-21  3:15 [PATCH 0/3] Cleanup blkdev zone helpers Damien Le Moal
  2024-06-21  3:15 ` [PATCH 1/3] null_blk: Do not set disk->nr_zones Damien Le Moal
@ 2024-06-21  3:15 ` Damien Le Moal
  2024-06-21  5:14   ` Christoph Hellwig
  2024-06-21 10:42   ` Johannes Thumshirn
  2024-06-21  3:15 ` [PATCH 3/3] block: Cleanup block device zone helpers Damien Le Moal
  2024-06-21 18:32 ` [PATCH 0/3] Cleanup blkdev zone helpers Jens Axboe
  3 siblings, 2 replies; 12+ messages in thread
From: Damien Le Moal @ 2024-06-21  3:15 UTC (permalink / raw)
  To: Jens Axboe, linux-block

There is no need for bdev_nr_zones() to be an exported function
calculating the number of zones of a block device. Instead, given that
all callers use this helper with a fully initialized block device that
has a gendisk, we can redefine this function as an inline helper in
blkdev.h.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 block/blk-zoned.c      | 18 ------------------
 include/linux/blkdev.h |  6 +++++-
 2 files changed, 5 insertions(+), 19 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 137842dbb59a..07831fb67201 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -115,24 +115,6 @@ const char *blk_zone_cond_str(enum blk_zone_cond zone_cond)
 }
 EXPORT_SYMBOL_GPL(blk_zone_cond_str);
 
-/**
- * bdev_nr_zones - Get number of zones
- * @bdev:	Target device
- *
- * Return the total number of zones of a zoned block device.  For a block
- * device without zone capabilities, the number of zones is always 0.
- */
-unsigned int bdev_nr_zones(struct block_device *bdev)
-{
-	sector_t zone_sectors = bdev_zone_sectors(bdev);
-
-	if (!bdev_is_zoned(bdev))
-		return 0;
-	return (bdev_nr_sectors(bdev) + zone_sectors - 1) >>
-		ilog2(zone_sectors);
-}
-EXPORT_SYMBOL_GPL(bdev_nr_zones);
-
 /**
  * blkdev_report_zones - Get zones information
  * @bdev:	Target block device
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 2800231046a9..1078a7d51295 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -673,7 +673,6 @@ static inline bool blk_queue_is_zoned(struct request_queue *q)
 }
 
 #ifdef CONFIG_BLK_DEV_ZONED
-unsigned int bdev_nr_zones(struct block_device *bdev);
 
 static inline unsigned int disk_nr_zones(struct gendisk *disk)
 {
@@ -687,6 +686,11 @@ static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
 	return sector >> ilog2(disk->queue->limits.chunk_sectors);
 }
 
+static inline unsigned int bdev_nr_zones(struct block_device *bdev)
+{
+	return disk_nr_zones(bdev->bd_disk);
+}
+
 static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
 {
 	return bdev->bd_disk->queue->limits.max_open_zones;
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/3] block: Cleanup block device zone helpers
  2024-06-21  3:15 [PATCH 0/3] Cleanup blkdev zone helpers Damien Le Moal
  2024-06-21  3:15 ` [PATCH 1/3] null_blk: Do not set disk->nr_zones Damien Le Moal
  2024-06-21  3:15 ` [PATCH 2/3] block: Define bdev_nr_zones() as an inline function Damien Le Moal
@ 2024-06-21  3:15 ` Damien Le Moal
  2024-06-21  5:15   ` Christoph Hellwig
                     ` (2 more replies)
  2024-06-21 18:32 ` [PATCH 0/3] Cleanup blkdev zone helpers Jens Axboe
  3 siblings, 3 replies; 12+ messages in thread
From: Damien Le Moal @ 2024-06-21  3:15 UTC (permalink / raw)
  To: Jens Axboe, linux-block

There is no need to conditionally define on CONFIG_BLK_DEV_ZONED the
inline helper functions bdev_nr_zones(), bdev_max_open_zones(),
bdev_max_active_zones() and disk_zone_no() as these function will return
the correct valu in all cases (zoned device or not, including when
CONFIG_BLK_DEV_ZONED is not set). Furthermore, disk_nr_zones()
definition can be simplified as disk->nr_zones is always 0 for regular
block devices.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
 include/linux/blkdev.h | 44 ++++++++++++------------------------------
 1 file changed, 12 insertions(+), 32 deletions(-)

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 1078a7d51295..e89003360c17 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -673,11 +673,21 @@ static inline bool blk_queue_is_zoned(struct request_queue *q)
 }
 
 #ifdef CONFIG_BLK_DEV_ZONED
-
 static inline unsigned int disk_nr_zones(struct gendisk *disk)
 {
-	return blk_queue_is_zoned(disk->queue) ? disk->nr_zones : 0;
+	return disk->nr_zones;
+}
+bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs);
+#else /* CONFIG_BLK_DEV_ZONED */
+static inline unsigned int disk_nr_zones(struct gendisk *disk)
+{
+	return 0;
+}
+static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)
+{
+	return false;
 }
+#endif /* CONFIG_BLK_DEV_ZONED */
 
 static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
 {
@@ -701,36 +711,6 @@ static inline unsigned int bdev_max_active_zones(struct block_device *bdev)
 	return bdev->bd_disk->queue->limits.max_active_zones;
 }
 
-bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs);
-#else /* CONFIG_BLK_DEV_ZONED */
-static inline unsigned int bdev_nr_zones(struct block_device *bdev)
-{
-	return 0;
-}
-
-static inline unsigned int disk_nr_zones(struct gendisk *disk)
-{
-	return 0;
-}
-static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
-{
-	return 0;
-}
-static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
-{
-	return 0;
-}
-
-static inline unsigned int bdev_max_active_zones(struct block_device *bdev)
-{
-	return 0;
-}
-static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)
-{
-	return false;
-}
-#endif /* CONFIG_BLK_DEV_ZONED */
-
 static inline unsigned int blk_queue_depth(struct request_queue *q)
 {
 	if (q->queue_depth)
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/3] null_blk: Do not set disk->nr_zones
  2024-06-21  3:15 ` [PATCH 1/3] null_blk: Do not set disk->nr_zones Damien Le Moal
@ 2024-06-21  5:14   ` Christoph Hellwig
  2024-06-21 10:41   ` Johannes Thumshirn
  1 sibling, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2024-06-21  5:14 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: Jens Axboe, linux-block

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/3] block: Define bdev_nr_zones() as an inline function
  2024-06-21  3:15 ` [PATCH 2/3] block: Define bdev_nr_zones() as an inline function Damien Le Moal
@ 2024-06-21  5:14   ` Christoph Hellwig
  2024-06-21 10:42   ` Johannes Thumshirn
  1 sibling, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2024-06-21  5:14 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: Jens Axboe, linux-block

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/3] block: Cleanup block device zone helpers
  2024-06-21  3:15 ` [PATCH 3/3] block: Cleanup block device zone helpers Damien Le Moal
@ 2024-06-21  5:15   ` Christoph Hellwig
  2024-06-21 10:44   ` Johannes Thumshirn
  2024-06-21 10:57   ` [PATCH 1/3] null_blk: Do not set disk->nr_zones Zhu Yanjun
  2 siblings, 0 replies; 12+ messages in thread
From: Christoph Hellwig @ 2024-06-21  5:15 UTC (permalink / raw)
  To: Damien Le Moal; +Cc: Jens Axboe, linux-block

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/3] null_blk: Do not set disk->nr_zones
  2024-06-21  3:15 ` [PATCH 1/3] null_blk: Do not set disk->nr_zones Damien Le Moal
  2024-06-21  5:14   ` Christoph Hellwig
@ 2024-06-21 10:41   ` Johannes Thumshirn
  1 sibling, 0 replies; 12+ messages in thread
From: Johannes Thumshirn @ 2024-06-21 10:41 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block@vger.kernel.org

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/3] block: Define bdev_nr_zones() as an inline function
  2024-06-21  3:15 ` [PATCH 2/3] block: Define bdev_nr_zones() as an inline function Damien Le Moal
  2024-06-21  5:14   ` Christoph Hellwig
@ 2024-06-21 10:42   ` Johannes Thumshirn
  1 sibling, 0 replies; 12+ messages in thread
From: Johannes Thumshirn @ 2024-06-21 10:42 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block@vger.kernel.org

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/3] block: Cleanup block device zone helpers
  2024-06-21  3:15 ` [PATCH 3/3] block: Cleanup block device zone helpers Damien Le Moal
  2024-06-21  5:15   ` Christoph Hellwig
@ 2024-06-21 10:44   ` Johannes Thumshirn
  2024-06-21 10:57   ` [PATCH 1/3] null_blk: Do not set disk->nr_zones Zhu Yanjun
  2 siblings, 0 replies; 12+ messages in thread
From: Johannes Thumshirn @ 2024-06-21 10:44 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block@vger.kernel.org

On 21.06.24 05:15, Damien Le Moal wrote:
> There is no need to conditionally define on CONFIG_BLK_DEV_ZONED the
> inline helper functions bdev_nr_zones(), bdev_max_open_zones(),
> bdev_max_active_zones() and disk_zone_no() as these function will return
> the correct valu in all cases (zoned device or not, including when  
	value ~^

Otherwise,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/3] null_blk: Do not set disk->nr_zones
  2024-06-21  3:15 ` [PATCH 3/3] block: Cleanup block device zone helpers Damien Le Moal
  2024-06-21  5:15   ` Christoph Hellwig
  2024-06-21 10:44   ` Johannes Thumshirn
@ 2024-06-21 10:57   ` Zhu Yanjun
  2 siblings, 0 replies; 12+ messages in thread
From: Zhu Yanjun @ 2024-06-21 10:57 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block

在 2024/6/21 13:14, Christoph Hellwig 写道:
> There is no need to conditionally define on CONFIG_BLK_DEV_ZONED the
> inline helper functions bdev_nr_zones(), bdev_max_open_zones(),
> bdev_max_active_zones() and disk_zone_no() as these function will return
> the correct valu in all cases (zoned device or not, including when

s/valu/value ?

Zhu Yanjun

> CONFIG_BLK_DEV_ZONED is not set). Furthermore, disk_nr_zones()
> definition can be simplified as disk->nr_zones is always 0 for regular
> block devices.
> 
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
> ---
>   include/linux/blkdev.h | 44 ++++++++++++------------------------------
>   1 file changed, 12 insertions(+), 32 deletions(-)
> 
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 1078a7d51295..e89003360c17 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -673,11 +673,21 @@ static inline bool blk_queue_is_zoned(struct request_queue *q)
>   }
>   
>   #ifdef CONFIG_BLK_DEV_ZONED
> -
>   static inline unsigned int disk_nr_zones(struct gendisk *disk)
>   {
> -	return blk_queue_is_zoned(disk->queue) ? disk->nr_zones : 0;
> +	return disk->nr_zones;
> +}
> +bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs);
> +#else /* CONFIG_BLK_DEV_ZONED */
> +static inline unsigned int disk_nr_zones(struct gendisk *disk)
> +{
> +	return 0;
> +}
> +static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)
> +{
> +	return false;
>   }
> +#endif /* CONFIG_BLK_DEV_ZONED */
>   
>   static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
>   {
> @@ -701,36 +711,6 @@ static inline unsigned int bdev_max_active_zones(struct block_device *bdev)
>   	return bdev->bd_disk->queue->limits.max_active_zones;
>   }
>   
> -bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs);
> -#else /* CONFIG_BLK_DEV_ZONED */
> -static inline unsigned int bdev_nr_zones(struct block_device *bdev)
> -{
> -	return 0;
> -}
> -
> -static inline unsigned int disk_nr_zones(struct gendisk *disk)
> -{
> -	return 0;
> -}
> -static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
> -{
> -	return 0;
> -}
> -static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
> -{
> -	return 0;
> -}
> -
> -static inline unsigned int bdev_max_active_zones(struct block_device *bdev)
> -{
> -	return 0;
> -}
> -static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)
> -{
> -	return false;
> -}
> -#endif /* CONFIG_BLK_DEV_ZONED */
> -
>   static inline unsigned int blk_queue_depth(struct request_queue *q)
>   {
>   	if (q->queue_depth)


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/3] Cleanup blkdev zone helpers
  2024-06-21  3:15 [PATCH 0/3] Cleanup blkdev zone helpers Damien Le Moal
                   ` (2 preceding siblings ...)
  2024-06-21  3:15 ` [PATCH 3/3] block: Cleanup block device zone helpers Damien Le Moal
@ 2024-06-21 18:32 ` Jens Axboe
  3 siblings, 0 replies; 12+ messages in thread
From: Jens Axboe @ 2024-06-21 18:32 UTC (permalink / raw)
  To: linux-block, Damien Le Moal


On Fri, 21 Jun 2024 12:15:03 +0900, Damien Le Moal wrote:
> The first patch removes a useless initialization of the number of zones
> of a zoned null_blk device. The following 2 patches rework the zone
> related inline helper functions in blkdev.h to simplify their
> definition, removing uneeded code.
> 
> Damien Le Moal (3):
>   null_blk: Do not set disk->nr_zones
>   block: Define bdev_nr_zones() as an inline function
>   block: Cleanup block device zone helpers
> 
> [...]

Applied, thanks!

[1/3] null_blk: Do not set disk->nr_zones
      commit: 4ac9056e4bd787f1ba2001167c5acc2b5a75ddf9
[2/3] block: Define bdev_nr_zones() as an inline function
      commit: b6cfe2287df6e26d685af8a8a96ed1bf87bdde28
[3/3] block: Cleanup block device zone helpers
      commit: caaf7101c01a91a882d3da2f566579dda692367d

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-06-21 18:32 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-21  3:15 [PATCH 0/3] Cleanup blkdev zone helpers Damien Le Moal
2024-06-21  3:15 ` [PATCH 1/3] null_blk: Do not set disk->nr_zones Damien Le Moal
2024-06-21  5:14   ` Christoph Hellwig
2024-06-21 10:41   ` Johannes Thumshirn
2024-06-21  3:15 ` [PATCH 2/3] block: Define bdev_nr_zones() as an inline function Damien Le Moal
2024-06-21  5:14   ` Christoph Hellwig
2024-06-21 10:42   ` Johannes Thumshirn
2024-06-21  3:15 ` [PATCH 3/3] block: Cleanup block device zone helpers Damien Le Moal
2024-06-21  5:15   ` Christoph Hellwig
2024-06-21 10:44   ` Johannes Thumshirn
2024-06-21 10:57   ` [PATCH 1/3] null_blk: Do not set disk->nr_zones Zhu Yanjun
2024-06-21 18:32 ` [PATCH 0/3] Cleanup blkdev zone helpers Jens Axboe

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.