diff mbox series

[2/8] block: Simplify REQ_OP_ZONE_RESET_ALL handling

Message ID 20191027140549.26272-3-damien.lemoal@wdc.com (mailing list archive)
State New, archived
Headers show
Series Zone management commands support | expand

Commit Message

Damien Le Moal Oct. 27, 2019, 2:05 p.m. UTC
There is no need for the function __blkdev_reset_all_zones() as
REQ_OP_ZONE_RESET_ALL can be handled directly in blkdev_reset_zones()
bio loop with an early break from the loop. This patch removes this
function and modifies blkdev_reset_zones(), simplifying the code.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 block/blk-zoned.c | 40 +++++++++++++---------------------------
 1 file changed, 13 insertions(+), 27 deletions(-)

Comments

Chaitanya Kulkarni Oct. 28, 2019, 7:49 a.m. UTC | #1
The reason code for REQ_OP_RESET_ALL is kept in a different function so
we can clearly differentiate between REQ_OP_RESET and REQ_OP_RESET_ALL
when we add new tracepoints with blktrace framework.

But if that is acceptable, then,

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

On 10/27/19 7:06 AM, Damien Le Moal wrote:
> There is no need for the function __blkdev_reset_all_zones() as
> REQ_OP_ZONE_RESET_ALL can be handled directly in blkdev_reset_zones()
> bio loop with an early break from the loop. This patch removes this
> function and modifies blkdev_reset_zones(), simplifying the code.
> 
> Signed-off-by: Damien Le Moal<damien.lemoal@wdc.com>
Damien Le Moal Oct. 28, 2019, 7:54 a.m. UTC | #2
On 2019/10/28 8:49, Chaitanya Kulkarni wrote:
> The reason code for REQ_OP_RESET_ALL is kept in a different function so
> we can clearly differentiate between REQ_OP_RESET and REQ_OP_RESET_ALL
> when we add new tracepoints with blktrace framework.

Isn't the trace point under submit_bio() in
generic_make_request_checks() ? So removing the function is not a
problem for tracing as far as I can tell. Am I missing something ?

> 
> But if that is acceptable, then,
> 
> Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> 
> On 10/27/19 7:06 AM, Damien Le Moal wrote:
>> There is no need for the function __blkdev_reset_all_zones() as
>> REQ_OP_ZONE_RESET_ALL can be handled directly in blkdev_reset_zones()
>> bio loop with an early break from the loop. This patch removes this
>> function and modifies blkdev_reset_zones(), simplifying the code.
>>
>> Signed-off-by: Damien Le Moal<damien.lemoal@wdc.com>
> 
>
Chaitanya Kulkarni Oct. 28, 2019, 8:37 a.m. UTC | #3
On 10/28/19 12:54 AM, Damien Le Moal wrote:
> Isn't the trace point under submit_bio() in
> generic_make_request_checks() ? So removing the function is not a
> problem for tracing as far as I can tell. Am I missing something ?

Yes you are right, I completely missed that.

Sorry I've created confusion with block_dump and tracepoint.

Block trace code is fine.

The block_dump code under the submit_bio() is only dumps the bios with
the data:-


1171                 if (unlikely(block_dump)) {
1172                         char b[BDEVNAME_SIZE];
1173                         printk(KERN_DEBUG "%s(%d): %s block %Lu on 
%s (%u sectors)\n",
1174                         current->comm, task_pid_nr(current),
1175                                 op_is_write(bio_op(bio)) ? "WRITE" 
: "READ",
1176                                 (unsigned long 
long)bio->bi_iter.bi_sector,
1177                                 bio_devname(bio, b), count);
1178                 }


I've posted patch-series [1] in the past to move that code out but it 
didn't go anywhere in anticipation of more data less requests.

Since it is taking longer to have blktrace extensions RFC to move 
forward and [1] didn't go anywhere I wanted to use block_dump
parameter in the blk-zoned.c (not an ideal situation) so that we can 
have atleast minimal debug support for the new REQ_OP_ZONE_XXX 
operations until we get block trace extensions in the kernel.

Nonetheless, I'll just a send a patch on the top of this which will
make discussion much easier.


[1] :- 
https://lore.kernel.org/linux-block/DM6PR04MB57546ECC4CFDDB5535E3382586FB0@DM6PR04MB5754.namprd04.prod.outlook.com/T/
Christoph Hellwig Nov. 7, 2019, 9:51 a.m. UTC | #4
Looks good,

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

Patch

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 7fe376eede86..14785011e798 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -202,32 +202,14 @@  int blkdev_report_zones(struct block_device *bdev, sector_t sector,
 }
 EXPORT_SYMBOL_GPL(blkdev_report_zones);
 
-/*
- * Special case of zone reset operation to reset all zones in one command,
- * useful for applications like mkfs.
- */
-static int __blkdev_reset_all_zones(struct block_device *bdev, gfp_t gfp_mask)
-{
-	struct bio *bio = bio_alloc(gfp_mask, 0);
-	int ret;
-
-	/* across the zones operations, don't need any sectors */
-	bio_set_dev(bio, bdev);
-	bio_set_op_attrs(bio, REQ_OP_ZONE_RESET_ALL, 0);
-
-	ret = submit_bio_wait(bio);
-	bio_put(bio);
-
-	return ret;
-}
-
 static inline bool blkdev_allow_reset_all_zones(struct block_device *bdev,
+						sector_t sector,
 						sector_t nr_sectors)
 {
 	if (!blk_queue_zone_resetall(bdev_get_queue(bdev)))
 		return false;
 
-	if (nr_sectors != part_nr_sects_read(bdev->bd_part))
+	if (sector || nr_sectors != part_nr_sects_read(bdev->bd_part))
 		return false;
 	/*
 	 * REQ_OP_ZONE_RESET_ALL can be executed only if the block device is
@@ -270,9 +252,6 @@  int blkdev_reset_zones(struct block_device *bdev,
 		/* Out of range */
 		return -EINVAL;
 
-	if (blkdev_allow_reset_all_zones(bdev, nr_sectors))
-		return  __blkdev_reset_all_zones(bdev, gfp_mask);
-
 	/* Check alignment (handle eventual smaller last zone) */
 	zone_sectors = blk_queue_zone_sectors(q);
 	if (sector & (zone_sectors - 1))
@@ -283,17 +262,24 @@  int blkdev_reset_zones(struct block_device *bdev,
 		return -EINVAL;
 
 	while (sector < end_sector) {
-
 		bio = blk_next_bio(bio, 0, gfp_mask);
-		bio->bi_iter.bi_sector = sector;
 		bio_set_dev(bio, bdev);
-		bio_set_op_attrs(bio, REQ_OP_ZONE_RESET, 0);
 
+		/*
+		 * Special case for the zone reset operation that reset all
+		 * zones, this is useful for applications like mkfs.
+		 */
+		if (blkdev_allow_reset_all_zones(bdev, sector, nr_sectors)) {
+			bio->bi_opf = REQ_OP_ZONE_RESET_ALL;
+			break;
+		}
+
+		bio->bi_opf = REQ_OP_ZONE_RESET;
+		bio->bi_iter.bi_sector = sector;
 		sector += zone_sectors;
 
 		/* This may take a while, so be nice to others */
 		cond_resched();
-
 	}
 
 	ret = submit_bio_wait(bio);