[PATCH 3/6] block: Optimize __blkdev_issue_zeroout()

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

 



Avoid to confuse SCSI target software by ensuring that the WRITE SAME
data buffer length matches the block size.

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 | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index f44ec95..1a60b3f 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -249,7 +249,9 @@ static void bio_add_zero_pages(struct bio *bio, sector_t nr_sects)
 static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
 				  sector_t nr_sects, gfp_t gfp_mask)
 {
-	int ret;
+	int ret = 0;
+	struct request_queue *q = bdev_get_queue(bdev);
+	unsigned req_sects;
 	struct bio *bio;
 	struct bio_batch bb;
 	DECLARE_COMPLETION_ONSTACK(wait);
@@ -258,7 +260,6 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
 	bb.error = 0;
 	bb.wait = &wait;
 
-	ret = 0;
 	while (nr_sects != 0) {
 		bio = bio_alloc(gfp_mask,
 				min(nr_sects, (sector_t)BIO_MAX_PAGES));
@@ -271,9 +272,11 @@ 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;
-		bio_add_zero_pages(bio, nr_sects);
-		nr_sects -= bio->bi_iter.bi_size >> 9;
-		sector += bio->bi_iter.bi_size >> 9;
+		bio_add_zero_pages(bio, q->limits.logical_block_size);
+		req_sects = min_t(sector_t, nr_sects, UINT_MAX >> 9);
+		bio->bi_iter.bi_size = req_sects << 9;
+		nr_sects -= req_sects;
+		sector += req_sects;
 		atomic_inc(&bb.done);
 		submit_bio(WRITE, bio);
 	}
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-block" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux