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 <[email protected]>,
Cc: Christoph Hellwig <[email protected]>,
Signed-off-by: Ming Lei <[email protected]>
---
 block/bio-integrity.c | 37 +++++--------------------------------
 1 file changed, 5 insertions(+), 32 deletions(-)

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) {
-- 
2.9.5

Reply via email to