Skip to contentSkip to conversation

Cleanup blkdev zone helpers

PATCH Applied Damien Le Moal 5 participants 12 messages Jun 21, 2024

Subsystems (2)
lore
Share & tools
lore

Damien Le Moal

author maintainer
#0 lore raw

cover Cleanup blkdev zone helpers

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(-)
Signature · 1 line
2.45.2
author maintainer
#1 lore raw

PATCH 1/3 null_blk: Do not set disk->nr_zones

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().

---
 drivers/block/null_blk/zoned.c | 2 --
 1 file changed, 2 deletions(-)
drivers/block/null_blk/zoned.c +0 -2
index b42c00f13132..9f7151ad93cf 100644
@@ -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");
Signature · 1 line
2.45.2
author maintainer
#4 lore raw

PATCH 2/3 block: Define bdev_nr_zones() as an inline function

In reply to Damien Le Moal

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.

---
 block/blk-zoned.c      | 18 ------------------
 include/linux/blkdev.h |  6 +++++-
 2 files changed, 5 insertions(+), 19 deletions(-)
block/blk-zoned.c +0 -18
index 137842dbb59a..07831fb67201 100644
@@ -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
include/linux/blkdev.h +5 -1
index 2800231046a9..1078a7d51295 100644
@@ -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;
Signature · 1 line
2.45.2
author maintainer
#7 lore raw

PATCH 3/3 block: Cleanup block device zone helpers

In reply to Damien Le Moal

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.

---
 include/linux/blkdev.h | 44 ++++++++++++------------------------------
 1 file changed, 12 insertions(+), 32 deletions(-)
include/linux/blkdev.h +12 -32
index 1078a7d51295..e89003360c17 100644
@@ -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)
Signature · 1 line
2.45.2
Reviewed-by on v1 3/3
#9 lore raw

Re: [PATCH 3/3] block: Cleanup block device zone helpers

In reply to Damien Le Moal
Quoted 4 lines · Damien Le Moal

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,

#10 lore raw

Re: [PATCH 1/3] null_blk: Do not set disk->nr_zones

In reply to Damien Le Moal
Quoted 4 lines · 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

Quoted 74 lines

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.

---
  include/linux/blkdev.h | 44 ++++++++++++------------------------------
  1 file changed, 12 insertions(+), 32 deletions(-)
include/linux/blkdev.h +12 -32
index 1078a7d51295..e89003360c17 100644
@@ -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)
maintainer Applied
#11 lore raw
In reply to Damien Le Moal
Quoted 11 lines · Damien Le Moal

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,

Signature · 1 line
Jens Axboe