block/t10-pi.c
Source file repositories/reference/linux-study-clean/block/t10-pi.c
File Facts
- System
- Linux kernel
- Corpus path
block/t10-pi.c- Extension
.c- Size
- 14771 bytes
- Lines
- 568
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: implementation source
- Status
- source implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/t10-pi.hlinux/blk-integrity.hlinux/crc-t10dif.hlinux/crc64.hnet/checksum.hlinux/unaligned.hblk.h
Detected Declarations
struct blk_integrity_iterfunction blk_calculate_guardfunction blk_integrity_csum_finishfunction blk_integrity_csum_offsetfunction blk_integrity_copy_from_tuplefunction blk_integrity_copy_to_tuplefunction ext_pi_ref_escapefunction blk_verify_ext_pifunction blk_verify_pifunction blk_verify_t10_pifunction blk_verify_ip_pifunction blk_integrity_verifyfunction blk_set_ext_pifunction blk_set_pifunction blk_set_t10_pifunction blk_set_ip_pifunction blk_integrity_setfunction blk_integrity_intervalfunction blk_integrity_iteratefunction bio_integrity_generatefunction bio_integrity_verifyfunction blk_pi_advance_offsetfunction blk_tuple_remap_endfunction blk_set_ext_unmap_reffunction blk_set_t10_unmap_reffunction blk_reftag_remap_completefunction blk_set_ext_map_reffunction blk_set_t10_map_reffunction blk_reftag_remap_preparefunction __blk_reftag_remapfunction blk_integrity_remapfunction __rq_for_each_biofunction blk_integrity_preparefunction blk_integrity_complete
Annotated Snippet
struct blk_integrity_iter {
struct bio *bio;
struct bio_integrity_payload *bip;
struct blk_integrity *bi;
struct bvec_iter data_iter;
struct bvec_iter prot_iter;
unsigned int interval_remaining;
u64 seed;
u64 csum;
};
static void blk_calculate_guard(struct blk_integrity_iter *iter, void *data,
unsigned int len)
{
switch (iter->bi->csum_type) {
case BLK_INTEGRITY_CSUM_CRC64:
iter->csum = crc64_nvme(iter->csum, data, len);
break;
case BLK_INTEGRITY_CSUM_CRC:
iter->csum = crc_t10dif_update(iter->csum, data, len);
break;
case BLK_INTEGRITY_CSUM_IP:
iter->csum = (__force u32)csum_partial(data, len,
(__force __wsum)iter->csum);
break;
default:
WARN_ON_ONCE(1);
iter->csum = U64_MAX;
break;
}
}
static void blk_integrity_csum_finish(struct blk_integrity_iter *iter)
{
switch (iter->bi->csum_type) {
case BLK_INTEGRITY_CSUM_IP:
iter->csum = (__force u16)csum_fold((__force __wsum)iter->csum);
break;
default:
break;
}
}
/*
* Update the csum for formats that have metadata padding in front of the data
* integrity field
*/
static void blk_integrity_csum_offset(struct blk_integrity_iter *iter)
{
unsigned int offset = iter->bi->pi_offset;
struct bio_vec *bvec = iter->bip->bip_vec;
while (offset > 0) {
struct bio_vec pbv = bvec_iter_bvec(bvec, iter->prot_iter);
unsigned int len = min(pbv.bv_len, offset);
void *prot_buf = bvec_kmap_local(&pbv);
blk_calculate_guard(iter, prot_buf, len);
kunmap_local(prot_buf);
offset -= len;
bvec_iter_advance_single(bvec, &iter->prot_iter, len);
}
blk_integrity_csum_finish(iter);
}
static void blk_integrity_copy_from_tuple(struct bio_integrity_payload *bip,
struct bvec_iter *iter, void *tuple,
unsigned int tuple_size)
{
while (tuple_size) {
struct bio_vec pbv = bvec_iter_bvec(bip->bip_vec, *iter);
unsigned int len = min(tuple_size, pbv.bv_len);
void *prot_buf = bvec_kmap_local(&pbv);
memcpy(prot_buf, tuple, len);
kunmap_local(prot_buf);
bvec_iter_advance_single(bip->bip_vec, iter, len);
tuple_size -= len;
tuple += len;
}
}
static void blk_integrity_copy_to_tuple(struct bio_integrity_payload *bip,
struct bvec_iter *iter, void *tuple,
unsigned int tuple_size)
{
while (tuple_size) {
struct bio_vec pbv = bvec_iter_bvec(bip->bip_vec, *iter);
unsigned int len = min(tuple_size, pbv.bv_len);
void *prot_buf = bvec_kmap_local(&pbv);
Annotation
- Immediate include surface: `linux/t10-pi.h`, `linux/blk-integrity.h`, `linux/crc-t10dif.h`, `linux/crc64.h`, `net/checksum.h`, `linux/unaligned.h`, `blk.h`.
- Detected declarations: `struct blk_integrity_iter`, `function blk_calculate_guard`, `function blk_integrity_csum_finish`, `function blk_integrity_csum_offset`, `function blk_integrity_copy_from_tuple`, `function blk_integrity_copy_to_tuple`, `function ext_pi_ref_escape`, `function blk_verify_ext_pi`, `function blk_verify_pi`, `function blk_verify_t10_pi`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.