Skip to content

Commit a936655

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: factor out a bio_integrity_setup_default helper
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>
1 parent 7ea25ea commit a936655

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

block/bio-integrity-auto.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,15 @@ bool __bio_integrity_endio(struct bio *bio)
8888
*/
8989
void bio_integrity_prep(struct bio *bio, unsigned int action)
9090
{
91-
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
9291
struct bio_integrity_data *bid;
9392

9493
bid = mempool_alloc(&bid_pool, GFP_NOIO);
9594
bio_integrity_init(bio, &bid->bip, &bid->bvec, 1);
9695
bid->bio = bio;
9796
bid->bip.bip_flags |= BIP_BLOCK_INTEGRITY;
9897
bio_integrity_alloc_buf(bio, action & BI_ACT_ZERO);
99-
100-
bip_set_seed(&bid->bip, bio->bi_iter.bi_sector);
101-
102-
if (action & BI_ACT_CHECK) {
103-
if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
104-
bid->bip.bip_flags |= BIP_IP_CHECKSUM;
105-
if (bi->csum_type)
106-
bid->bip.bip_flags |= BIP_CHECK_GUARD;
107-
if (bi->flags & BLK_INTEGRITY_REF_TAG)
108-
bid->bip.bip_flags |= BIP_CHECK_REFTAG;
109-
}
98+
if (action & BI_ACT_CHECK)
99+
bio_integrity_setup_default(bio);
110100

111101
/* Auto-generate integrity metadata if this is a write */
112102
if (bio_data_dir(bio) == WRITE && bip_should_check(&bid->bip))

block/bio-integrity.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ void bio_integrity_free_buf(struct bio_integrity_payload *bip)
101101
kfree(bvec_virt(bv));
102102
}
103103

104+
void bio_integrity_setup_default(struct bio *bio)
105+
{
106+
struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
107+
struct bio_integrity_payload *bip = bio_integrity(bio);
108+
109+
bip_set_seed(bip, bio->bi_iter.bi_sector);
110+
111+
if (bi->csum_type) {
112+
bip->bip_flags |= BIP_CHECK_GUARD;
113+
if (bi->csum_type == BLK_INTEGRITY_CSUM_IP)
114+
bip->bip_flags |= BIP_IP_CHECKSUM;
115+
}
116+
if (bi->flags & BLK_INTEGRITY_REF_TAG)
117+
bip->bip_flags |= BIP_CHECK_REFTAG;
118+
}
119+
104120
/**
105121
* bio_integrity_free - Free bio integrity payload
106122
* @bio: bio containing bip to be freed

include/linux/bio-integrity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,6 @@ static inline int bio_integrity_add_page(struct bio *bio, struct page *page,
143143

144144
void bio_integrity_alloc_buf(struct bio *bio, bool zero_buffer);
145145
void bio_integrity_free_buf(struct bio_integrity_payload *bip);
146+
void bio_integrity_setup_default(struct bio *bio);
146147

147148
#endif /* _LINUX_BIO_INTEGRITY_H */

0 commit comments

Comments
 (0)