Skip to content

Commit 7ba1ba1

Browse files
martinkpetersenJens Axboe
authored andcommitted
block: Block layer data integrity support
Some block devices support verifying the integrity of requests by way of checksums or other protection information that is submitted along with the I/O. This patch implements support for generating and verifying integrity metadata, as well as correctly merging, splitting and cloning bios and requests that have this extra information attached. See Documentation/block/data-integrity.txt for more information. Signed-off-by: Martin K. Petersen <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 51d654e commit 7ba1ba1

File tree

13 files changed

+1355
-7
lines changed

13 files changed

+1355
-7
lines changed

block/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ config BLK_DEV_BSG
8181

8282
If unsure, say N.
8383

84+
config BLK_DEV_INTEGRITY
85+
bool "Block layer data integrity support"
86+
---help---
87+
Some storage devices allow extra information to be
88+
stored/retrieved to help protect the data. The block layer
89+
data integrity option provides hooks which can be used by
90+
filesystems to ensure better data integrity.
91+
92+
Say yes here if you have a storage device that provides the
93+
T10/SCSI Data Integrity Field or the T13/ATA External Path
94+
Protection. If in doubt, say N.
95+
8496
endif # BLOCK
8597

8698
config BLOCK_COMPAT

block/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o
1414

1515
obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o
1616
obj-$(CONFIG_BLOCK_COMPAT) += compat_ioctl.o
17+
obj-$(CONFIG_BLK_DEV_INTEGRITY) += blk-integrity.o

block/blk-core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ static void req_bio_endio(struct request *rq, struct bio *bio,
143143

144144
bio->bi_size -= nbytes;
145145
bio->bi_sector += (nbytes >> 9);
146+
147+
if (bio_integrity(bio))
148+
bio_integrity_advance(bio, nbytes);
149+
146150
if (bio->bi_size == 0)
147151
bio_endio(bio, error);
148152
} else {
@@ -1381,6 +1385,9 @@ static inline void __generic_make_request(struct bio *bio)
13811385
*/
13821386
blk_partition_remap(bio);
13831387

1388+
if (bio_integrity_enabled(bio) && bio_integrity_prep(bio))
1389+
goto end_io;
1390+
13841391
if (old_sector != -1)
13851392
blk_add_trace_remap(q, bio, old_dev, bio->bi_sector,
13861393
old_sector);

0 commit comments

Comments
 (0)