block/blk-zoned.c
Source file repositories/reference/linux-study-clean/block/blk-zoned.c
File Facts
- System
- Linux kernel
- Corpus path
block/blk-zoned.c- Extension
.c- Size
- 72358 bytes
- Lines
- 2498
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/blkdev.hlinux/blk-mq.hlinux/spinlock.hlinux/refcount.hlinux/mempool.hlinux/kthread.hlinux/freezer.htrace/events/block.hblk.hblk-mq-sched.hblk-mq-debugfs.h
Detected Declarations
struct blk_zone_wplugstruct blk_report_zones_argsstruct zone_report_argsstruct blk_revalidate_zone_argsfunction disk_need_zone_resourcesfunction disk_zone_wplugs_hash_sizefunction usersfunction blk_zone_set_condfunction disk_zone_set_condfunction bdev_zone_is_seqfunction blkdev_do_report_zonesfunction blkdev_report_zonesfunction blkdev_zone_reset_allfunction blkdev_zone_mgmtfunction blkdev_copy_zone_to_userfunction blkdev_report_zones_ioctlfunction blkdev_reset_zonefunction blkdev_zone_mgmt_ioctlfunction disk_zone_is_lastfunction disk_zone_wplug_is_fullfunction disk_insert_zone_wplugfunction hlist_for_each_entry_rcufunction disk_free_zone_wplug_rcufunction disk_free_zone_wplugfunction disk_put_zone_wplugfunction disk_mark_zone_wplug_deadfunction disk_check_zone_wplug_deadfunction disk_zone_wplugs_workerfunction blk_zone_wplug_bio_workfunction blk_zone_wplug_bio_io_errorfunction Abortfunction disk_zone_wplug_update_condfunction disk_zone_wplug_set_wp_offsetfunction blk_zone_wp_offsetfunction disk_zone_wplug_sync_wp_offsetfunction blkdev_report_zonesfunction blkdev_report_zone_cbfunction blkdev_report_zone_fallbackfunction blkdev_has_cached_report_zonesfunction blkdev_get_zone_infofunction blkdev_report_zonesfunction blk_zone_reset_bio_endiofunction blk_zone_reset_all_bio_endiofunction hlist_for_each_entry_rcufunction blk_zone_finish_bio_endiofunction blk_zone_mgmt_bio_endiofunction disk_zone_wplug_schedule_workfunction disk_zone_wplug_add_bio
Annotated Snippet
blk_mq_submit_bio(bio);
}
return true;
}
static struct blk_zone_wplug *disk_get_zone_wplugs_work(struct gendisk *disk)
{
struct blk_zone_wplug *zwplug;
spin_lock_irq(&disk->zone_wplugs_list_lock);
zwplug = list_first_entry_or_null(&disk->zone_wplugs_list,
struct blk_zone_wplug, entry);
if (zwplug)
list_del_init(&zwplug->entry);
spin_unlock_irq(&disk->zone_wplugs_list_lock);
return zwplug;
}
static int disk_zone_wplugs_worker(void *data)
{
struct gendisk *disk = data;
struct blk_zone_wplug *zwplug;
unsigned int noio_flag;
noio_flag = memalloc_noio_save();
set_user_nice(current, MIN_NICE);
set_freezable();
for (;;) {
set_current_state(TASK_INTERRUPTIBLE | TASK_FREEZABLE);
zwplug = disk_get_zone_wplugs_work(disk);
if (zwplug) {
/*
* Process all BIOs of this zone write plug and then
* drop the reference we took when adding the zone write
* plug to the active list.
*/
set_current_state(TASK_RUNNING);
while (disk_zone_wplug_submit_bio(disk, zwplug))
blk_wait_io(&disk->zone_wplugs_worker_bio_done);
disk_put_zone_wplug(zwplug);
continue;
}
/*
* Only sleep if nothing sets the state to running. Else check
* for zone write plugs work again as a newly submitted BIO
* might have added a zone write plug to the work list.
*/
if (get_current_state() == TASK_RUNNING) {
try_to_freeze();
} else {
if (kthread_should_stop()) {
set_current_state(TASK_RUNNING);
break;
}
schedule();
}
}
WARN_ON_ONCE(!list_empty(&disk->zone_wplugs_list));
memalloc_noio_restore(noio_flag);
return 0;
}
void disk_init_zone_resources(struct gendisk *disk)
{
spin_lock_init(&disk->zone_wplugs_hash_lock);
spin_lock_init(&disk->zone_wplugs_list_lock);
INIT_LIST_HEAD(&disk->zone_wplugs_list);
init_completion(&disk->zone_wplugs_worker_bio_done);
}
/*
* For the size of a disk zone write plug hash table, use the size of the
* zone write plug mempool, which is the maximum of the disk open zones and
* active zones limits. But do not exceed 4KB (512 hlist head entries), that is,
* 9 bits. For a disk that has no limits, mempool size defaults to 128.
*/
#define BLK_ZONE_WPLUG_MAX_HASH_BITS 9
#define BLK_ZONE_WPLUG_DEFAULT_POOL_SIZE 128
static int disk_alloc_zone_resources(struct gendisk *disk,
unsigned int pool_size)
{
unsigned int i;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/blkdev.h`, `linux/blk-mq.h`, `linux/spinlock.h`, `linux/refcount.h`, `linux/mempool.h`, `linux/kthread.h`, `linux/freezer.h`.
- Detected declarations: `struct blk_zone_wplug`, `struct blk_report_zones_args`, `struct zone_report_args`, `struct blk_revalidate_zone_args`, `function disk_need_zone_resources`, `function disk_zone_wplugs_hash_size`, `function users`, `function blk_zone_set_cond`, `function disk_zone_set_cond`, `function bdev_zone_is_seq`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.