bio-integrity: add "bip_max_vcnt" into struct bio_integrity_payload
authorGu Zheng <guz.fnst@cn.fujitsu.com>
Tue, 1 Jul 2014 16:36:47 +0000 (10:36 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 1 Jul 2014 16:36:47 +0000 (10:36 -0600)
Commit 08778795 ("block: Fix nr_vecs for inline integrity vectors") from
Martin introduces the function bip_integrity_vecs(get the useful vectors)
to fix the issue about nr_vecs for inline integrity vectors that reported
by David Milburn.

But it seems that bip_integrity_vecs() will return the wrong number if the
bio is not based on any bio_set for some reason(bio->bi_pool == NULL),
because in that case, the bip_inline_vecs[0] is malloced directly.  So
here we add the bip_max_vcnt to record the count of vector slots, and
cleanup the function bip_integrity_vecs().

Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Kent Overstreet <kmo@daterainc.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
block/bio-integrity.c
include/linux/bio.h

index 9e241063a616f2c4ad023a08c8b6b06d676adb56..bc423f7b02da856a6987089b6750322c9b7cbfe4 100644 (file)
@@ -70,8 +70,10 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
                                          bs->bvec_integrity_pool);
                if (!bip->bip_vec)
                        goto err;
+               bip->bip_max_vcnt = bvec_nr_vecs(idx);
        } else {
                bip->bip_vec = bip->bip_inline_vecs;
+               bip->bip_max_vcnt = inline_vecs;
        }
 
        bip->bip_slab = idx;
@@ -114,14 +116,6 @@ void bio_integrity_free(struct bio *bio)
 }
 EXPORT_SYMBOL(bio_integrity_free);
 
-static inline unsigned int bip_integrity_vecs(struct bio_integrity_payload *bip)
-{
-       if (bip->bip_slab == BIO_POOL_NONE)
-               return BIP_INLINE_VECS;
-
-       return bvec_nr_vecs(bip->bip_slab);
-}
-
 /**
  * bio_integrity_add_page - Attach integrity metadata
  * @bio:       bio to update
@@ -137,7 +131,7 @@ int bio_integrity_add_page(struct bio *bio, struct page *page,
        struct bio_integrity_payload *bip = bio->bi_integrity;
        struct bio_vec *iv;
 
-       if (bip->bip_vcnt >= bip_integrity_vecs(bip)) {
+       if (bip->bip_vcnt >= bip->bip_max_vcnt) {
                printk(KERN_ERR "%s: bip_vec full\n", __func__);
                return 0;
        }
index d2633ee099d975836b1fc457cd58e323bfcc8784..b39e5000ff589e6dfdc556c0b80390005fc5718b 100644 (file)
@@ -308,6 +308,7 @@ struct bio_integrity_payload {
 
        unsigned short          bip_slab;       /* slab the bip came from */
        unsigned short          bip_vcnt;       /* # of integrity bio_vecs */
+       unsigned short          bip_max_vcnt;   /* integrity bio_vec slots */
        unsigned                bip_owns_buf:1; /* should free bip_buf */
 
        struct work_struct      bip_work;       /* I/O completion */