Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: add fs_bio_integrity helpers

Add a set of helpers for file system initiated integrity information.
These include mempool backed allocations and verifying based on a passed
in sector and size which is often available from file system completion
routines.

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>

authored by

Christoph Hellwig and committed by
Jens Axboe
0bde8a12 8c56ef10

+88 -1
+1 -1
block/Makefile
··· 26 26 obj-$(CONFIG_IOSCHED_BFQ) += bfq.o 27 27 28 28 obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o blk-integrity.o t10-pi.o \ 29 - bio-integrity-auto.o 29 + bio-integrity-auto.o bio-integrity-fs.o 30 30 obj-$(CONFIG_BLK_DEV_ZONED) += blk-zoned.o 31 31 obj-$(CONFIG_BLK_WBT) += blk-wbt.o 32 32 obj-$(CONFIG_BLK_DEBUG_FS) += blk-mq-debugfs.o
+81
block/bio-integrity-fs.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2025 Christoph Hellwig. 4 + */ 5 + #include <linux/blk-integrity.h> 6 + #include <linux/bio-integrity.h> 7 + #include "blk.h" 8 + 9 + struct fs_bio_integrity_buf { 10 + struct bio_integrity_payload bip; 11 + struct bio_vec bvec; 12 + }; 13 + 14 + static struct kmem_cache *fs_bio_integrity_cache; 15 + static mempool_t fs_bio_integrity_pool; 16 + 17 + unsigned int fs_bio_integrity_alloc(struct bio *bio) 18 + { 19 + struct fs_bio_integrity_buf *iib; 20 + unsigned int action; 21 + 22 + action = bio_integrity_action(bio); 23 + if (!action) 24 + return 0; 25 + 26 + iib = mempool_alloc(&fs_bio_integrity_pool, GFP_NOIO); 27 + bio_integrity_init(bio, &iib->bip, &iib->bvec, 1); 28 + 29 + bio_integrity_alloc_buf(bio, action & BI_ACT_ZERO); 30 + if (action & BI_ACT_CHECK) 31 + bio_integrity_setup_default(bio); 32 + return action; 33 + } 34 + 35 + void fs_bio_integrity_free(struct bio *bio) 36 + { 37 + struct bio_integrity_payload *bip = bio_integrity(bio); 38 + 39 + bio_integrity_free_buf(bip); 40 + mempool_free(container_of(bip, struct fs_bio_integrity_buf, bip), 41 + &fs_bio_integrity_pool); 42 + 43 + bio->bi_integrity = NULL; 44 + bio->bi_opf &= ~REQ_INTEGRITY; 45 + } 46 + 47 + void fs_bio_integrity_generate(struct bio *bio) 48 + { 49 + if (fs_bio_integrity_alloc(bio)) 50 + bio_integrity_generate(bio); 51 + } 52 + EXPORT_SYMBOL_GPL(fs_bio_integrity_generate); 53 + 54 + int fs_bio_integrity_verify(struct bio *bio, sector_t sector, unsigned int size) 55 + { 56 + struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk); 57 + struct bio_integrity_payload *bip = bio_integrity(bio); 58 + 59 + /* 60 + * Reinitialize bip->bip_iter. 61 + * 62 + * This is for use in the submitter after the driver is done with the 63 + * bio. Requires the submitter to remember the sector and the size. 64 + */ 65 + memset(&bip->bip_iter, 0, sizeof(bip->bip_iter)); 66 + bip->bip_iter.bi_sector = sector; 67 + bip->bip_iter.bi_size = bio_integrity_bytes(bi, size >> SECTOR_SHIFT); 68 + return blk_status_to_errno(bio_integrity_verify(bio, &bip->bip_iter)); 69 + } 70 + 71 + static int __init fs_bio_integrity_init(void) 72 + { 73 + fs_bio_integrity_cache = kmem_cache_create("fs_bio_integrity", 74 + sizeof(struct fs_bio_integrity_buf), 0, 75 + SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL); 76 + if (mempool_init_slab_pool(&fs_bio_integrity_pool, BIO_POOL_SIZE, 77 + fs_bio_integrity_cache)) 78 + panic("fs_bio_integrity: can't create pool\n"); 79 + return 0; 80 + } 81 + fs_initcall(fs_bio_integrity_init);
+6
include/linux/bio-integrity.h
··· 145 145 void bio_integrity_free_buf(struct bio_integrity_payload *bip); 146 146 void bio_integrity_setup_default(struct bio *bio); 147 147 148 + unsigned int fs_bio_integrity_alloc(struct bio *bio); 149 + void fs_bio_integrity_free(struct bio *bio); 150 + void fs_bio_integrity_generate(struct bio *bio); 151 + int fs_bio_integrity_verify(struct bio *bio, sector_t sector, 152 + unsigned int size); 153 + 148 154 #endif /* _LINUX_BIO_INTEGRITY_H */