drivers/scsi/hosts.c
Source file repositories/reference/linux-study-clean/drivers/scsi/hosts.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/hosts.c- Extension
.c- Size
- 19891 bytes
- Lines
- 770
- Domain
- Driver Families
- Bucket
- drivers/scsi
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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.
- 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/module.hlinux/blkdev.hlinux/kernel.hlinux/slab.hlinux/kthread.hlinux/string.hlinux/mm.hlinux/init.hlinux/completion.hlinux/transport_class.hlinux/platform_device.hlinux/pm_runtime.hlinux/idr.hscsi/scsi_device.hscsi/scsi_host.hscsi/scsi_transport.hscsi/scsi_cmnd.hscsi_priv.hscsi_logging.h
Detected Declarations
struct scsi_host_busy_iter_datafunction scsi_host_cls_releasefunction scsi_host_set_statefunction scsi_remove_hostfunction scsi_add_host_with_dmafunction scsi_host_dev_releasefunction __scsi_host_matchfunction scsi_host_putfunction scsi_host_check_in_flightfunction scsi_host_busyfunction scsi_host_putfunction scsi_init_hostsfunction scsi_exit_hostsfunction scsi_is_host_devicefunction scsi_queue_workfunction scsi_flush_workfunction complete_all_cmds_iterfunction scsi_host_complete_all_commandsfunction __scsi_host_busy_iter_fnfunction scsi_host_busy_iterexport scsi_remove_hostexport scsi_add_host_with_dmaexport scsi_host_allocexport scsi_host_lookupexport scsi_host_getexport scsi_host_busyexport scsi_host_putexport scsi_is_host_deviceexport scsi_queue_workexport scsi_flush_workexport scsi_host_complete_all_commandsexport scsi_host_busy_iter
Annotated Snippet
error = device_add(&shost->shost_gendev);
if (error)
goto out_disable_runtime_pm;
scsi_host_set_state(shost, SHOST_RUNNING);
get_device(shost->shost_gendev.parent);
device_enable_async_suspend(&shost->shost_dev);
get_device(&shost->shost_gendev);
error = device_add(&shost->shost_dev);
if (error)
goto out_del_gendev;
if (shost->transportt->host_size) {
shost->shost_data = kzalloc(shost->transportt->host_size,
GFP_KERNEL);
if (shost->shost_data == NULL) {
error = -ENOMEM;
goto out_del_dev;
}
}
if (shost->transportt->create_work_queue) {
shost->work_q = alloc_workqueue(
"scsi_wq_%d",
WQ_SYSFS | __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_UNBOUND, 1,
shost->host_no);
if (!shost->work_q) {
error = -EINVAL;
goto out_del_dev;
}
}
error = scsi_sysfs_add_host(shost);
if (error)
goto out_del_dev;
if (shost->nr_reserved_cmds) {
shost->pseudo_sdev = scsi_get_pseudo_sdev(shost);
if (!shost->pseudo_sdev) {
error = -ENOMEM;
goto out_del_dev;
}
}
scsi_proc_host_add(shost);
scsi_autopm_put_host(shost);
return error;
/*
* Any host allocation in this function will be freed in
* scsi_host_dev_release().
*/
out_del_dev:
device_del(&shost->shost_dev);
out_del_gendev:
/*
* Host state is SHOST_RUNNING so we have to explicitly release
* ->shost_dev.
*/
put_device(&shost->shost_dev);
device_del(&shost->shost_gendev);
out_disable_runtime_pm:
device_disable_async_suspend(&shost->shost_gendev);
pm_runtime_disable(&shost->shost_gendev);
pm_runtime_set_suspended(&shost->shost_gendev);
pm_runtime_put_noidle(&shost->shost_gendev);
kref_put(&shost->tagset_refcnt, scsi_mq_free_tags);
fail:
return error;
}
EXPORT_SYMBOL(scsi_add_host_with_dma);
static void scsi_host_dev_release(struct device *dev)
{
struct Scsi_Host *shost = dev_to_shost(dev);
struct device *parent = dev->parent;
/* Wait for functions invoked through call_rcu(&scmd->rcu, ...) */
rcu_barrier();
if (shost->tmf_work_q)
destroy_workqueue(shost->tmf_work_q);
if (shost->ehandler)
kthread_stop(shost->ehandler);
if (shost->work_q)
destroy_workqueue(shost->work_q);
Annotation
- Immediate include surface: `linux/module.h`, `linux/blkdev.h`, `linux/kernel.h`, `linux/slab.h`, `linux/kthread.h`, `linux/string.h`, `linux/mm.h`, `linux/init.h`.
- Detected declarations: `struct scsi_host_busy_iter_data`, `function scsi_host_cls_release`, `function scsi_host_set_state`, `function scsi_remove_host`, `function scsi_add_host_with_dma`, `function scsi_host_dev_release`, `function __scsi_host_match`, `function scsi_host_put`, `function scsi_host_check_in_flight`, `function scsi_host_busy`.
- Atlas domain: Driver Families / drivers/scsi.
- 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.