[PATCH 2/6] block: Introduce bio_add_zero_pages()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Move the code for adding one or more zero pages into a new function.

Signed-off-by: Bart Van Assche <bart.vanassche@xxxxxxxxxxx>
Cc: Jan Kara <jack@xxxxxxx>
Cc: Christoph Hellwig <hch@xxxxxx>
Cc: Mike Snitzer <snitzer@xxxxxxxxxx>
Cc: Martin K. Petersen <martin.petersen@xxxxxxxxxx>
Cc: Dmitry Monakhov <dmonakhov@xxxxxxxxxx>
---
 block/blk-lib.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 2f4c6b2..f44ec95 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -219,6 +219,22 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
 }
 EXPORT_SYMBOL(blkdev_issue_write_same);
 
+static void bio_add_zero_pages(struct bio *bio, sector_t nr_sects)
+{
+	unsigned sz;
+	int ret;
+
+	/* Avoid that bi_size overflows */
+	nr_sects = min_t(sector_t, nr_sects, UINT_MAX >> 9);
+
+	for (; nr_sects != 0; nr_sects -= ret >> 9) {
+		sz = min_t(unsigned, PAGE_SIZE >> 9, nr_sects) << 9;
+		ret = bio_add_page(bio, ZERO_PAGE(0), sz, 0);
+		if (ret < sz)
+			break;
+	}
+}
+
 /**
  * blkdev_issue_zeroout - generate number of zero filed write bios
  * @bdev:	blockdev to issue
@@ -236,7 +252,6 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
 	int ret;
 	struct bio *bio;
 	struct bio_batch bb;
-	unsigned int sz;
 	DECLARE_COMPLETION_ONSTACK(wait);
 
 	atomic_set(&bb.done, 1);
@@ -256,16 +271,9 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
 		bio->bi_bdev   = bdev;
 		bio->bi_end_io = bio_batch_end_io;
 		bio->bi_private = &bb;
-
-		while (nr_sects != 0) {
-			sz = min((sector_t) PAGE_SIZE >> 9 , nr_sects);
-			ret = bio_add_page(bio, ZERO_PAGE(0), sz << 9, 0);
-			nr_sects -= ret >> 9;
-			sector += ret >> 9;
-			if (ret < (sz << 9))
-				break;
-		}
-		ret = 0;
+		bio_add_zero_pages(bio, nr_sects);
+		nr_sects -= bio->bi_iter.bi_size >> 9;
+		sector += bio->bi_iter.bi_size >> 9;
 		atomic_inc(&bb.done);
 		submit_bio(WRITE, bio);
 	}
-- 
2.1.4

--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/dm-devel



[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux