Skip to content

Commit 3756587

Browse files
damien-lemoalzandrey
authored andcommitted
block: Simplify REQ_OP_ZONE_RESET_ALL handling
[ Upstream commit c7a1d92 ] 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. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 94ae9b7 commit 3756587

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

block/blk-zoned.c

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -202,32 +202,14 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector,
202202
}
203203
EXPORT_SYMBOL_GPL(blkdev_report_zones);
204204

205-
/*
206-
* Special case of zone reset operation to reset all zones in one command,
207-
* useful for applications like mkfs.
208-
*/
209-
static int __blkdev_reset_all_zones(struct block_device *bdev, gfp_t gfp_mask)
210-
{
211-
struct bio *bio = bio_alloc(gfp_mask, 0);
212-
int ret;
213-
214-
/* across the zones operations, don't need any sectors */
215-
bio_set_dev(bio, bdev);
216-
bio_set_op_attrs(bio, REQ_OP_ZONE_RESET_ALL, 0);
217-
218-
ret = submit_bio_wait(bio);
219-
bio_put(bio);
220-
221-
return ret;
222-
}
223-
224205
static inline bool blkdev_allow_reset_all_zones(struct block_device *bdev,
206+
sector_t sector,
225207
sector_t nr_sectors)
226208
{
227209
if (!blk_queue_zone_resetall(bdev_get_queue(bdev)))
228210
return false;
229211

230-
if (nr_sectors != part_nr_sects_read(bdev->bd_part))
212+
if (sector || nr_sectors != part_nr_sects_read(bdev->bd_part))
231213
return false;
232214
/*
233215
* REQ_OP_ZONE_RESET_ALL can be executed only if the block device is
@@ -271,9 +253,6 @@ int blkdev_reset_zones(struct block_device *bdev,
271253
/* Out of range */
272254
return -EINVAL;
273255

274-
if (blkdev_allow_reset_all_zones(bdev, nr_sectors))
275-
return __blkdev_reset_all_zones(bdev, gfp_mask);
276-
277256
/* Check alignment (handle eventual smaller last zone) */
278257
zone_sectors = blk_queue_zone_sectors(q);
279258
if (sector & (zone_sectors - 1))
@@ -285,17 +264,24 @@ int blkdev_reset_zones(struct block_device *bdev,
285264

286265
blk_start_plug(&plug);
287266
while (sector < end_sector) {
288-
289267
bio = blk_next_bio(bio, 0, gfp_mask);
290-
bio->bi_iter.bi_sector = sector;
291268
bio_set_dev(bio, bdev);
292-
bio_set_op_attrs(bio, REQ_OP_ZONE_RESET, 0);
293269

270+
/*
271+
* Special case for the zone reset operation that reset all
272+
* zones, this is useful for applications like mkfs.
273+
*/
274+
if (blkdev_allow_reset_all_zones(bdev, sector, nr_sectors)) {
275+
bio->bi_opf = REQ_OP_ZONE_RESET_ALL;
276+
break;
277+
}
278+
279+
bio->bi_opf = REQ_OP_ZONE_RESET;
280+
bio->bi_iter.bi_sector = sector;
294281
sector += zone_sectors;
295282

296283
/* This may take a while, so be nice to others */
297284
cond_resched();
298-
299285
}
300286

301287
ret = submit_bio_wait(bio);

0 commit comments

Comments
 (0)