Commit 76a27e1b authored by Keith Busch's avatar Keith Busch Committed by Jens Axboe

block: cleanup __blkdev_issue_write_zeroes

Use min to calculate the next number of sectors like everyone else.
Reviewed-by: default avatarMing Lei <ming.lei@redhat.com>
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
Link: https://lore.kernel.org/r/20240223155910.3622666-3-kbusch@meta.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 5affe497
...@@ -120,31 +120,28 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, ...@@ -120,31 +120,28 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
struct bio **biop, unsigned flags) struct bio **biop, unsigned flags)
{ {
struct bio *bio = *biop; struct bio *bio = *biop;
unsigned int max_write_zeroes_sectors; unsigned int max_sectors;
if (bdev_read_only(bdev)) if (bdev_read_only(bdev))
return -EPERM; return -EPERM;
/* Ensure that max_write_zeroes_sectors doesn't overflow bi_size */ /* Ensure that max_sectors doesn't overflow bi_size */
max_write_zeroes_sectors = bdev_write_zeroes_sectors(bdev); max_sectors = bdev_write_zeroes_sectors(bdev);
if (max_write_zeroes_sectors == 0) if (max_sectors == 0)
return -EOPNOTSUPP; return -EOPNOTSUPP;
while (nr_sects) { while (nr_sects) {
unsigned int len = min_t(sector_t, nr_sects, max_sectors);
bio = blk_next_bio(bio, bdev, 0, REQ_OP_WRITE_ZEROES, gfp_mask); bio = blk_next_bio(bio, bdev, 0, REQ_OP_WRITE_ZEROES, gfp_mask);
bio->bi_iter.bi_sector = sector; bio->bi_iter.bi_sector = sector;
if (flags & BLKDEV_ZERO_NOUNMAP) if (flags & BLKDEV_ZERO_NOUNMAP)
bio->bi_opf |= REQ_NOUNMAP; bio->bi_opf |= REQ_NOUNMAP;
if (nr_sects > max_write_zeroes_sectors) { bio->bi_iter.bi_size = len << SECTOR_SHIFT;
bio->bi_iter.bi_size = max_write_zeroes_sectors << 9; nr_sects -= len;
nr_sects -= max_write_zeroes_sectors; sector += len;
sector += max_write_zeroes_sectors;
} else {
bio->bi_iter.bi_size = nr_sects << 9;
nr_sects = 0;
}
cond_resched(); cond_resched();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment