drivers/nvme/host/multipath.c
Source file repositories/reference/linux-study-clean/drivers/nvme/host/multipath.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvme/host/multipath.c- Extension
.c- Size
- 40480 bytes
- Lines
- 1495
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/backing-dev.hlinux/moduleparam.hlinux/vmalloc.htrace/events/block.hnvme.h
Detected Declarations
function multipath_param_setfunction multipath_always_on_setfunction nvme_iopolicy_parsefunction nvme_set_iopolicyfunction nvme_get_iopolicyfunction nvme_mpath_default_iopolicyfunction nvme_mpath_unfreezefunction nvme_mpath_wait_freezefunction nvme_mpath_start_freezefunction nvme_failover_reqfunction nvme_mpath_start_requestfunction nvme_mpath_end_requestfunction nvme_kick_requeue_listsfunction srcu_read_lock_heldfunction nvme_mpath_clear_current_pathfunction for_each_nodefunction nvme_mpath_clear_ctrl_pathsfunction srcu_read_lock_heldfunction nvme_mpath_revalidate_pathsfunction srcu_read_lock_heldfunction nvme_path_is_disabledfunction list_for_each_entry_srcufunction list_for_each_entry_srcufunction nvme_path_is_optimizedfunction nvme_available_pathfunction list_for_each_entry_srcufunction nvme_ns_head_submit_biofunction nvme_ns_head_openfunction nvme_ns_head_releasefunction nvme_ns_head_get_unique_idfunction nvme_ns_head_report_zonesfunction nvme_ns_head_chr_openfunction nvme_ns_head_chr_releasefunction nvme_add_ns_head_cdevfunction nvme_partition_scan_workfunction nvme_requeue_workfunction nvme_remove_headfunction nvme_remove_head_workfunction nvme_mpath_alloc_diskfunction nvme_mpath_set_livefunction test_and_set_bitfunction nvme_parse_ana_logfunction nvme_state_is_livefunction nvme_update_ns_ana_statefunction nvme_update_ana_statefunction srcu_read_lock_heldfunction nvme_read_ana_logfunction nvme_ana_work
Annotated Snippet
static const struct file_operations nvme_ns_head_chr_fops = {
.owner = THIS_MODULE,
.open = nvme_ns_head_chr_open,
.release = nvme_ns_head_chr_release,
.unlocked_ioctl = nvme_ns_head_chr_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.uring_cmd = nvme_ns_head_chr_uring_cmd,
.uring_cmd_iopoll = nvme_ns_chr_uring_cmd_iopoll,
};
static int nvme_add_ns_head_cdev(struct nvme_ns_head *head)
{
int ret;
head->cdev_device.parent = &head->subsys->dev;
ret = dev_set_name(&head->cdev_device, "ng%dn%d",
head->subsys->instance, head->instance);
if (ret)
return ret;
ret = nvme_cdev_add(&head->cdev, &head->cdev_device,
&nvme_ns_head_chr_fops, THIS_MODULE);
return ret;
}
static void nvme_partition_scan_work(struct work_struct *work)
{
struct nvme_ns_head *head =
container_of(work, struct nvme_ns_head, partition_scan_work);
if (WARN_ON_ONCE(!test_and_clear_bit(GD_SUPPRESS_PART_SCAN,
&head->disk->state)))
return;
mutex_lock(&head->disk->open_mutex);
bdev_disk_changed(head->disk, false);
mutex_unlock(&head->disk->open_mutex);
}
static void nvme_requeue_work(struct work_struct *work)
{
struct nvme_ns_head *head =
container_of(work, struct nvme_ns_head, requeue_work);
struct bio *bio, *next;
spin_lock_irq(&head->requeue_lock);
next = bio_list_get(&head->requeue_list);
spin_unlock_irq(&head->requeue_lock);
while ((bio = next) != NULL) {
next = bio->bi_next;
bio->bi_next = NULL;
submit_bio_noacct(bio);
}
}
static void nvme_remove_head(struct nvme_ns_head *head)
{
if (test_and_clear_bit(NVME_NSHEAD_DISK_LIVE, &head->flags)) {
/*
* requeue I/O after NVME_NSHEAD_DISK_LIVE has been cleared
* to allow multipath to fail all I/O.
*/
kblockd_schedule_work(&head->requeue_work);
nvme_cdev_del(&head->cdev, &head->cdev_device);
synchronize_srcu(&head->srcu);
del_gendisk(head->disk);
}
nvme_put_ns_head(head);
}
static void nvme_remove_head_work(struct work_struct *work)
{
struct nvme_ns_head *head = container_of(to_delayed_work(work),
struct nvme_ns_head, remove_work);
bool remove = false;
mutex_lock(&head->subsys->lock);
if (list_empty(&head->list)) {
list_del_init(&head->entry);
remove = true;
}
mutex_unlock(&head->subsys->lock);
if (remove)
nvme_remove_head(head);
module_put(THIS_MODULE);
}
Annotation
- Immediate include surface: `linux/backing-dev.h`, `linux/moduleparam.h`, `linux/vmalloc.h`, `trace/events/block.h`, `nvme.h`.
- Detected declarations: `function multipath_param_set`, `function multipath_always_on_set`, `function nvme_iopolicy_parse`, `function nvme_set_iopolicy`, `function nvme_get_iopolicy`, `function nvme_mpath_default_iopolicy`, `function nvme_mpath_unfreeze`, `function nvme_mpath_wait_freeze`, `function nvme_mpath_start_freeze`, `function nvme_failover_req`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: pattern 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.