block/blk-settings.c
Source file repositories/reference/linux-study-clean/block/blk-settings.c
File Facts
- System
- Linux kernel
- Corpus path
block/blk-settings.c- Extension
.c- Size
- 33724 bytes
- Lines
- 1056
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/init.hlinux/bio.hlinux/blk-integrity.hlinux/pagemap.hlinux/backing-dev-defs.hlinux/gcd.hlinux/lcm.hlinux/jiffies.hlinux/gfp.hlinux/dma-mapping.hlinux/t10-pi.hlinux/crc64.hblk.hblk-rq-qos.hblk-wbt.h
Detected Declarations
function blk_queue_rq_timeoutfunction blk_stack_limitsfunction blk_apply_bdi_limitsfunction blk_validate_zoned_limitsfunction blk_validate_integrity_limitsfunction iov_iterfunction blk_atomic_writes_update_limitsfunction blk_valid_atomic_writes_boundaryfunction blk_validate_atomic_write_limitsfunction blk_validate_limitsfunction blk_set_default_limitsfunction queue_limits_commit_updatefunction queue_limits_commit_update_frozenfunction queue_limits_start_updatefunction queue_limit_alignment_offsetfunction queue_limit_discard_alignmentfunction blk_round_down_sectorsfunction blk_stack_atomic_writes_tailfunction blk_stack_atomic_writes_chunk_sectorsfunction blk_stack_atomic_writes_headfunction blk_stack_atomic_writes_limitsfunction structfunction structfunction queue_limits_stack_integrityfunction blk_set_queue_depthfunction bdev_alignment_offsetfunction bdev_discard_alignmentexport blk_queue_rq_timeoutexport blk_set_stacking_limitsexport blk_validate_limitsexport queue_limits_commit_updateexport queue_limits_commit_update_frozenexport queue_limits_setexport blk_stack_limitsexport queue_limits_stack_bdevexport queue_limits_stack_integrityexport blk_set_queue_depthexport bdev_alignment_offsetexport bdev_discard_alignment
Annotated Snippet
if (bi->pi_tuple_size) {
pr_warn("pi_tuple_size must be 0 when checksum type is none\n");
return -EINVAL;
}
break;
case BLK_INTEGRITY_CSUM_CRC:
case BLK_INTEGRITY_CSUM_IP:
if (bi->pi_tuple_size != sizeof(struct t10_pi_tuple)) {
pr_warn("pi_tuple_size mismatch for T10 PI: expected %zu, got %u\n",
sizeof(struct t10_pi_tuple),
bi->pi_tuple_size);
return -EINVAL;
}
break;
case BLK_INTEGRITY_CSUM_CRC64:
if (bi->pi_tuple_size != sizeof(struct crc64_pi_tuple)) {
pr_warn("pi_tuple_size mismatch for CRC64 PI: expected %zu, got %u\n",
sizeof(struct crc64_pi_tuple),
bi->pi_tuple_size);
return -EINVAL;
}
break;
}
if (!bi->interval_exp) {
bi->interval_exp = ilog2(lim->logical_block_size);
} else if (bi->interval_exp < SECTOR_SHIFT ||
bi->interval_exp > ilog2(lim->logical_block_size)) {
pr_warn("invalid interval_exp %u\n", bi->interval_exp);
return -EINVAL;
}
/*
* Some IO controllers can not handle data intervals straddling
* multiple bio_vecs. For those, enforce alignment so that those are
* never generated, and that each buffer is aligned as expected.
*/
if (!(bi->flags & BLK_SPLIT_INTERVAL_CAPABLE) && bi->csum_type) {
lim->dma_alignment = max(lim->dma_alignment,
(1U << bi->interval_exp) - 1);
}
/*
* The block layer automatically adds integrity data for bios that don't
* already have it. Limit the I/O size so that a single maximum size
* metadata segment can cover the integrity data for the entire I/O.
*/
lim->max_sectors = min(lim->max_sectors,
max_integrity_io_size(lim) >> SECTOR_SHIFT);
return 0;
}
/*
* Returns max guaranteed bytes which we can fit in a bio.
*
* We request that an atomic_write is ITER_UBUF iov_iter (so a single vector),
* so we assume that we can fit in at least PAGE_SIZE in a segment, apart from
* the first and last segments.
*/
static unsigned int blk_queue_max_guaranteed_bio(struct queue_limits *lim)
{
unsigned int max_segments = min(BIO_MAX_VECS, lim->max_segments);
unsigned int length;
length = min(max_segments, 2) * lim->logical_block_size;
if (max_segments > 2)
length += (max_segments - 2) * PAGE_SIZE;
return length;
}
static void blk_atomic_writes_update_limits(struct queue_limits *lim)
{
unsigned int unit_limit = min(lim->max_hw_sectors << SECTOR_SHIFT,
blk_queue_max_guaranteed_bio(lim));
unit_limit = rounddown_pow_of_two(unit_limit);
lim->atomic_write_max_sectors =
min(lim->atomic_write_hw_max >> SECTOR_SHIFT,
lim->max_hw_sectors);
lim->atomic_write_unit_min =
min(lim->atomic_write_hw_unit_min, unit_limit);
lim->atomic_write_unit_max =
min(lim->atomic_write_hw_unit_max, unit_limit);
lim->atomic_write_boundary_sectors =
lim->atomic_write_hw_boundary >> SECTOR_SHIFT;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/init.h`, `linux/bio.h`, `linux/blk-integrity.h`, `linux/pagemap.h`, `linux/backing-dev-defs.h`, `linux/gcd.h`.
- Detected declarations: `function blk_queue_rq_timeout`, `function blk_stack_limits`, `function blk_apply_bdi_limits`, `function blk_validate_zoned_limits`, `function blk_validate_integrity_limits`, `function iov_iter`, `function blk_atomic_writes_update_limits`, `function blk_valid_atomic_writes_boundary`, `function blk_validate_atomic_write_limits`, `function blk_validate_limits`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.