diff mbox series

[PATCHv3,2/4] block: __blkdev_issue_write_zeroes cleanup

Message ID 20240222191922.2130580-3-kbusch@meta.com (mailing list archive)
State New, archived
Headers show
Series block: make long runnint operations killable | expand

Commit Message

Keith Busch Feb. 22, 2024, 7:19 p.m. UTC
From: Keith Busch <kbusch@kernel.org>

Use min to calculate the next number of sectors like everyone else.

Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 block/blk-lib.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Comments

Ming Lei Feb. 23, 2024, 3:29 a.m. UTC | #1
On Fri, Feb 23, 2024 at 3:20 AM Keith Busch <kbusch@meta.com> wrote:
>
> From: Keith Busch <kbusch@kernel.org>
>
> Use min to calculate the next number of sectors like everyone else.
>
> Signed-off-by: Keith Busch <kbusch@kernel.org>

On Fri, Feb 23, 2024 at 3:21 AM Keith Busch <kbusch@meta.com> wrote:
>
> From: Keith Busch <kbusch@kernel.org>
>
> Use consistent coding style in this file. All the other loops for the
> same purpose use "while (nr_sects)", so they win.
>
> Signed-off-by: Keith Busch <kbusch@kernel.org>

Reviewed-by: Ming Lei <ming.lei@redhat.com>
Christoph Hellwig Feb. 23, 2024, 6:42 a.m. UTC | #2
On Thu, Feb 22, 2024 at 11:19:20AM -0800, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
> 
> Use min to calculate the next number of sectors like everyone else.
> 
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
>  block/blk-lib.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/block/blk-lib.c b/block/blk-lib.c
> index 91770da2239f2..d4c476cf3784a 100644
> --- a/block/blk-lib.c
> +++ b/block/blk-lib.c
> @@ -132,19 +132,16 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
>  		return -EOPNOTSUPP;
>  
>  	while (nr_sects) {
> +		unsigned int len = min_t(sector_t, nr_sects, max_write_zeroes_sectors);

Please avoid the overly long line.

> +		bio->bi_iter.bi_size = len << 9;

And if you touch this anyway use SECTOR_SHIFT here.

Otherwise this looks good.
diff mbox series

Patch

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 91770da2239f2..d4c476cf3784a 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -132,19 +132,16 @@  static int __blkdev_issue_write_zeroes(struct block_device *bdev,
 		return -EOPNOTSUPP;
 
 	while (nr_sects) {
+		unsigned int len = min_t(sector_t, nr_sects, max_write_zeroes_sectors);
+
 		bio = blk_next_bio(bio, bdev, 0, REQ_OP_WRITE_ZEROES, gfp_mask);
 		bio->bi_iter.bi_sector = sector;
 		if (flags & BLKDEV_ZERO_NOUNMAP)
 			bio->bi_opf |= REQ_NOUNMAP;
 
-		if (nr_sects > max_write_zeroes_sectors) {
-			bio->bi_iter.bi_size = max_write_zeroes_sectors << 9;
-			nr_sects -= max_write_zeroes_sectors;
-			sector += max_write_zeroes_sectors;
-		} else {
-			bio->bi_iter.bi_size = nr_sects << 9;
-			nr_sects = 0;
-		}
+		bio->bi_iter.bi_size = len << 9;
+		nr_sects -= len;
+		sector += len;
 		cond_resched();
 	}