]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
block: factor out a bio_integrity_setup_default helper
authorChristoph Hellwig <hch@lst.de>
Mon, 23 Feb 2026 13:20:02 +0000 (05:20 -0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 9 Mar 2026 13:47:02 +0000 (07:47 -0600)
Add a helper to set the seed and check flag based on useful defaults
from the profile.

Note that this includes a small behavior change, as we now only set the
seed if any action is set, which is fine as nothing will look at it
otherwise.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Tested-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio-integrity-auto.c
block/bio-integrity.c
include/linux/bio-integrity.h

index e16f669dbf1ef8a97ea426bf9c690bc14d32529e..b64c71a7fc8232976991003f248924d4c4d6ae84 100644 (file)
@@ -88,7 +88,6 @@ bool __bio_integrity_endio(struct bio *bio)
  */
 void bio_integrity_prep(struct bio *bio, unsigned int action)
 {
-       struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
        struct bio_integrity_data *bid;
 
        bid = mempool_alloc(&bid_pool, GFP_NOIO);
@@ -96,17 +95,8 @@ void bio_integrity_prep(struct bio *bio, unsigned int action)
        bid->bio = bio;
        bid->bip.bip_flags |= BIP_BLOCK_INTEGRITY;
        bio_integrity_alloc_buf(bio, action & BI_ACT_ZERO);
-
-       bip_set_seed(&bid->bip, bio->bi_iter.bi_sector);
-
-       if (action & BI_ACT_CHECK) {
-               if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
-                       bid->bip.bip_flags |= BIP_IP_CHECKSUM;
-               if (bi->csum_type)
-                       bid->bip.bip_flags |= BIP_CHECK_GUARD;
-               if (bi->flags & BLK_INTEGRITY_REF_TAG)
-                       bid->bip.bip_flags |= BIP_CHECK_REFTAG;
-       }
+       if (action & BI_ACT_CHECK)
+               bio_integrity_setup_default(bio);
 
        /* Auto-generate integrity metadata if this is a write */
        if (bio_data_dir(bio) == WRITE && bip_should_check(&bid->bip))
index 0955be90038beb7e188ab75d8c92b1d491eef1ec..e79eaf04779430465b033981c2451a1da6efc84b 100644 (file)
@@ -101,6 +101,22 @@ void bio_integrity_free_buf(struct bio_integrity_payload *bip)
                kfree(bvec_virt(bv));
 }
 
+void bio_integrity_setup_default(struct bio *bio)
+{
+       struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
+       struct bio_integrity_payload *bip = bio_integrity(bio);
+
+       bip_set_seed(bip, bio->bi_iter.bi_sector);
+
+       if (bi->csum_type) {
+               bip->bip_flags |= BIP_CHECK_GUARD;
+               if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
+                       bip->bip_flags |= BIP_IP_CHECKSUM;
+       }
+       if (bi->flags & BLK_INTEGRITY_REF_TAG)
+               bip->bip_flags |= BIP_CHECK_REFTAG;
+}
+
 /**
  * bio_integrity_free - Free bio integrity payload
  * @bio:       bio containing bip to be freed
index 276cbbdd2c9d69da1c4b8d7496b492115e6b289f..232b86b9bbcb59247ac2c6c33db5aec93998e5e6 100644 (file)
@@ -143,5 +143,6 @@ static inline int bio_integrity_add_page(struct bio *bio, struct page *page,
 
 void bio_integrity_alloc_buf(struct bio *bio, bool zero_buffer);
 void bio_integrity_free_buf(struct bio_integrity_payload *bip);
+void bio_integrity_setup_default(struct bio *bio);
 
 #endif /* _LINUX_BIO_INTEGRITY_H */