diff mbox series

[2/2] block: integrity: simplify bio_integrity_prep

Message ID 20190423071550.20806-3-ming.lei@redhat.com (mailing list archive)
State New, archived
Headers show
Series block: enable multi-page bvec for bio integrity | expand

Commit Message

Ming Lei April 23, 2019, 7:15 a.m. UTC
Now bio integrity is capable of dealing with multi-page bvec,
also bio_integrity_add_page() can add physically contiguous pages
into bip once, so avoid to loop over page by page.

Cc: Martin K . Petersen <martin.petersen@oracle.com>,
Cc: Christoph Hellwig <hch@lst.de>,
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/bio-integrity.c | 37 +++++--------------------------------
 1 file changed, 5 insertions(+), 32 deletions(-)

Comments

Christoph Hellwig April 24, 2019, 5:42 a.m. UTC | #1
On Tue, Apr 23, 2019 at 03:15:50PM +0800, Ming Lei wrote:
> Now bio integrity is capable of dealing with multi-page bvec,
> also bio_integrity_add_page() can add physically contiguous pages
> into bip once, so avoid to loop over page by page.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index ba9d145315ed..61edc79737bd 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -223,9 +223,7 @@  bool bio_integrity_prep(struct bio *bio)
 	struct blk_integrity *bi = blk_get_integrity(bio->bi_disk);
 	struct request_queue *q = bio->bi_disk->queue;
 	void *buf;
-	unsigned long start, end;
-	unsigned int len, nr_pages;
-	unsigned int bytes, offset, i;
+	unsigned int len;
 	unsigned int intervals;
 	blk_status_t status;
 
@@ -262,12 +260,8 @@  bool bio_integrity_prep(struct bio *bio)
 		goto err_end_io;
 	}
 
-	end = (((unsigned long) buf) + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
-	start = ((unsigned long) buf) >> PAGE_SHIFT;
-	nr_pages = end - start;
-
 	/* Allocate bio integrity payload and integrity vectors */
-	bip = bio_integrity_alloc(bio, GFP_NOIO, nr_pages);
+	bip = bio_integrity_alloc(bio, GFP_NOIO, 1);
 	if (IS_ERR(bip)) {
 		printk(KERN_ERR "could not allocate data integrity bioset\n");
 		kfree(buf);
@@ -283,30 +277,9 @@  bool bio_integrity_prep(struct bio *bio)
 		bip->bip_flags |= BIP_IP_CHECKSUM;
 
 	/* Map it */
-	offset = offset_in_page(buf);
-	for (i = 0 ; i < nr_pages ; i++) {
-		int ret;
-		bytes = PAGE_SIZE - offset;
-
-		if (len <= 0)
-			break;
-
-		if (bytes > len)
-			bytes = len;
-
-		ret = bio_integrity_add_page(bio, virt_to_page(buf),
-					     bytes, offset);
-
-		if (ret == 0)
-			return false;
-
-		if (ret < bytes)
-			break;
-
-		buf += bytes;
-		len -= bytes;
-		offset = 0;
-	}
+	if (bio_integrity_add_page(bio, virt_to_page(buf), len,
+				   offset_in_page(buf)) != len)
+		return false;
 
 	/* Auto-generate integrity metadata if this is a write */
 	if (bio_data_dir(bio) == WRITE) {