diff mbox series

[2/4] block: Simplify report zones execution

Message ID 20191024065006.8684-3-damien.lemoal@wdc.com (mailing list archive)
State New, archived
Headers show
Series zoned block device report zones enhancements | expand

Commit Message

Damien Le Moal Oct. 24, 2019, 6:50 a.m. UTC
All kernel users of blkdev_report_zones() as well as applications use
through ioctl(BLKZONEREPORT) expect to potentially get less zone
descriptors than requested. As such, the use of the internal report
zones command execution loop implemented by blk_report_zones() is
not necessary and can even be harmful to performance by causing the
execution of inefficient small zones report command to service the
reminder of a requested zone array.

This patch removes blk_report_zones(), simplifying the code. Also
remove a now incorrect comment in dm_blk_report_zones().

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 block/blk-zoned.c | 34 +++++-----------------------------
 drivers/md/dm.c   |  6 ------
 2 files changed, 5 insertions(+), 35 deletions(-)

Comments

Christoph Hellwig Oct. 24, 2019, 7:10 a.m. UTC | #1
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Javier González Oct. 25, 2019, 5:17 a.m. UTC | #2
On 24.10.2019 15:50, Damien Le Moal wrote:
>All kernel users of blkdev_report_zones() as well as applications use
>through ioctl(BLKZONEREPORT) expect to potentially get less zone
>descriptors than requested. As such, the use of the internal report
>zones command execution loop implemented by blk_report_zones() is
>not necessary and can even be harmful to performance by causing the
>execution of inefficient small zones report command to service the
>reminder of a requested zone array.
>
>This patch removes blk_report_zones(), simplifying the code. Also
>remove a now incorrect comment in dm_blk_report_zones().
>
>Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
>---
> block/blk-zoned.c | 34 +++++-----------------------------
> drivers/md/dm.c   |  6 ------
> 2 files changed, 5 insertions(+), 35 deletions(-)
>
>diff --git a/block/blk-zoned.c b/block/blk-zoned.c
>index 293891b7068a..43bfd1be0985 100644
>--- a/block/blk-zoned.c
>+++ b/block/blk-zoned.c
>@@ -119,31 +119,6 @@ static bool blkdev_report_zone(struct block_device *bdev, struct blk_zone *rep)
> 	return true;
> }
>
>-static int blk_report_zones(struct gendisk *disk, sector_t sector,
>-			    struct blk_zone *zones, unsigned int *nr_zones)
>-{
>-	struct request_queue *q = disk->queue;
>-	unsigned int z = 0, n, nrz = *nr_zones;
>-	sector_t capacity = get_capacity(disk);
>-	int ret;
>-
>-	while (z < nrz && sector < capacity) {
>-		n = nrz - z;
>-		ret = disk->fops->report_zones(disk, sector, &zones[z], &n);
>-		if (ret)
>-			return ret;
>-		if (!n)
>-			break;
>-		sector += blk_queue_zone_sectors(q) * n;
>-		z += n;
>-	}
>-
>-	WARN_ON(z > *nr_zones);
>-	*nr_zones = z;
>-
>-	return 0;
>-}
>-
> /**
>  * blkdev_report_zones - Get zones information
>  * @bdev:	Target block device
>@@ -164,6 +139,7 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector,
> 			struct blk_zone *zones, unsigned int *nr_zones)
> {
> 	struct request_queue *q = bdev_get_queue(bdev);
>+	struct gendisk *disk = bdev->bd_disk;
> 	unsigned int i, nrz;
> 	int ret;
>
>@@ -175,7 +151,7 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector,
> 	 * report_zones method. If it does not have one defined, the device
> 	 * driver has a bug. So warn about that.
> 	 */
>-	if (WARN_ON_ONCE(!bdev->bd_disk->fops->report_zones))
>+	if (WARN_ON_ONCE(!disk->fops->report_zones))
> 		return -EOPNOTSUPP;
>
> 	if (!*nr_zones || sector >= bdev->bd_part->nr_sects) {
>@@ -185,8 +161,8 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector,
>
> 	nrz = min(*nr_zones,
> 		  __blkdev_nr_zones(q, bdev->bd_part->nr_sects - sector));
>-	ret = blk_report_zones(bdev->bd_disk, get_start_sect(bdev) + sector,
>-			       zones, &nrz);
>+	ret = disk->fops->report_zones(disk, get_start_sect(bdev) + sector,
>+				       zones, &nrz);
> 	if (ret)
> 		return ret;
>
>@@ -552,7 +528,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
>
> 	while (z < nr_zones) {
> 		nrz = min(nr_zones - z, rep_nr_zones);
>-		ret = blk_report_zones(disk, sector, zones, &nrz);
>+		ret = disk->fops->report_zones(disk, sector, zones, &nrz);
> 		if (ret)
> 			goto out;
> 		if (!nrz)
>diff --git a/drivers/md/dm.c b/drivers/md/dm.c
>index 1a5e328c443a..647aa5b0233b 100644
>--- a/drivers/md/dm.c
>+++ b/drivers/md/dm.c
>@@ -473,12 +473,6 @@ static int dm_blk_report_zones(struct gendisk *disk, sector_t sector,
> 		goto out;
> 	}
>
>-	/*
>-	 * blkdev_report_zones() will loop and call this again to cover all the
>-	 * zones of the target, eventually moving on to the next target.
>-	 * So there is no need to loop here trying to fill the entire array
>-	 * of zones.
>-	 */
> 	ret = tgt->type->report_zones(tgt, sector, zones, nr_zones);
>
> out:
>-- 
>2.21.0
>

Looks good to me.

Reviewed-by: Javier González <javier@javigon.com>
diff mbox series

Patch

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 293891b7068a..43bfd1be0985 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -119,31 +119,6 @@  static bool blkdev_report_zone(struct block_device *bdev, struct blk_zone *rep)
 	return true;
 }
 
-static int blk_report_zones(struct gendisk *disk, sector_t sector,
-			    struct blk_zone *zones, unsigned int *nr_zones)
-{
-	struct request_queue *q = disk->queue;
-	unsigned int z = 0, n, nrz = *nr_zones;
-	sector_t capacity = get_capacity(disk);
-	int ret;
-
-	while (z < nrz && sector < capacity) {
-		n = nrz - z;
-		ret = disk->fops->report_zones(disk, sector, &zones[z], &n);
-		if (ret)
-			return ret;
-		if (!n)
-			break;
-		sector += blk_queue_zone_sectors(q) * n;
-		z += n;
-	}
-
-	WARN_ON(z > *nr_zones);
-	*nr_zones = z;
-
-	return 0;
-}
-
 /**
  * blkdev_report_zones - Get zones information
  * @bdev:	Target block device
@@ -164,6 +139,7 @@  int blkdev_report_zones(struct block_device *bdev, sector_t sector,
 			struct blk_zone *zones, unsigned int *nr_zones)
 {
 	struct request_queue *q = bdev_get_queue(bdev);
+	struct gendisk *disk = bdev->bd_disk;
 	unsigned int i, nrz;
 	int ret;
 
@@ -175,7 +151,7 @@  int blkdev_report_zones(struct block_device *bdev, sector_t sector,
 	 * report_zones method. If it does not have one defined, the device
 	 * driver has a bug. So warn about that.
 	 */
-	if (WARN_ON_ONCE(!bdev->bd_disk->fops->report_zones))
+	if (WARN_ON_ONCE(!disk->fops->report_zones))
 		return -EOPNOTSUPP;
 
 	if (!*nr_zones || sector >= bdev->bd_part->nr_sects) {
@@ -185,8 +161,8 @@  int blkdev_report_zones(struct block_device *bdev, sector_t sector,
 
 	nrz = min(*nr_zones,
 		  __blkdev_nr_zones(q, bdev->bd_part->nr_sects - sector));
-	ret = blk_report_zones(bdev->bd_disk, get_start_sect(bdev) + sector,
-			       zones, &nrz);
+	ret = disk->fops->report_zones(disk, get_start_sect(bdev) + sector,
+				       zones, &nrz);
 	if (ret)
 		return ret;
 
@@ -552,7 +528,7 @@  int blk_revalidate_disk_zones(struct gendisk *disk)
 
 	while (z < nr_zones) {
 		nrz = min(nr_zones - z, rep_nr_zones);
-		ret = blk_report_zones(disk, sector, zones, &nrz);
+		ret = disk->fops->report_zones(disk, sector, zones, &nrz);
 		if (ret)
 			goto out;
 		if (!nrz)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 1a5e328c443a..647aa5b0233b 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -473,12 +473,6 @@  static int dm_blk_report_zones(struct gendisk *disk, sector_t sector,
 		goto out;
 	}
 
-	/*
-	 * blkdev_report_zones() will loop and call this again to cover all the
-	 * zones of the target, eventually moving on to the next target.
-	 * So there is no need to loop here trying to fill the entire array
-	 * of zones.
-	 */
 	ret = tgt->type->report_zones(tgt, sector, zones, nr_zones);
 
 out: