drivers/scsi/scsi_scan.c
Source file repositories/reference/linux-study-clean/drivers/scsi/scsi_scan.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/scsi_scan.c- Extension
.c- Size
- 61861 bytes
- Lines
- 2163
- 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/moduleparam.hlinux/init.hlinux/blkdev.hlinux/delay.hlinux/kthread.hlinux/spinlock.hlinux/async.hlinux/slab.hlinux/unaligned.hscsi/scsi.hscsi/scsi_cmnd.hscsi/scsi_device.hscsi/scsi_driver.hscsi/scsi_devinfo.hscsi/scsi_host.hscsi/scsi_transport.hscsi/scsi_dh.hscsi/scsi_eh.hscsi_priv.hscsi_logging.h
Detected Declarations
struct async_scan_datafunction scsi_enable_async_suspendfunction scsi_complete_async_scansfunction SENSEfunction scsi_realloc_sdev_budget_mapfunction scsi_target_destroyfunction scsi_target_dev_releasefunction scsi_is_target_devicefunction scsi_target_reap_ref_releasefunction visiblefunction scsi_target_reap_ref_putfunction scsi_target_reapfunction scsi_sanitize_inquiry_stringfunction scsi_probe_lunfunction readyfunction scsi_add_lunfunction scsi_probe_and_add_lunfunction SCSI_LOG_SCAN_BUSfunction scsi_sequential_lun_scanfunction modernfunction addedfunction scsi_resume_devicefunction blk_queue_pm_onlyfunction scsi_rescan_devicefunction blk_queue_pm_onlyfunction __scsi_scan_targetfunction scsi_scan_targetfunction scsi_scan_channelfunction scsi_scan_host_selectedfunction scsi_sysfs_add_devicesfunction scsi_finish_async_scanfunction do_scsi_scan_hostfunction do_scan_asyncfunction scsi_scan_hostfunction scsi_forget_hostfunction scsi_get_pseudo_sdevexport scsi_is_target_deviceexport scsi_sanitize_inquiry_stringexport __scsi_add_deviceexport scsi_add_deviceexport scsi_resume_deviceexport scsi_rescan_deviceexport scsi_scan_targetexport scsi_scan_host
Annotated Snippet
struct async_scan_data {
struct list_head list;
struct Scsi_Host *shost;
struct completion prev_finished;
};
/*
* scsi_enable_async_suspend - Enable async suspend and resume
*/
void scsi_enable_async_suspend(struct device *dev)
{
/*
* If a user has disabled async probing a likely reason is due to a
* storage enclosure that does not inject staggered spin-ups. For
* safety, make resume synchronous as well in that case.
*/
if (strncmp(scsi_scan_type, "async", 5) != 0)
return;
/* Enable asynchronous suspend and resume. */
device_enable_async_suspend(dev);
}
/**
* scsi_complete_async_scans - Wait for asynchronous scans to complete
*
* When this function returns, any host which started scanning before
* this function was called will have finished its scan. Hosts which
* started scanning after this function was called may or may not have
* finished.
*/
int scsi_complete_async_scans(void)
{
struct async_scan_data *data;
do {
scoped_guard(spinlock, &async_scan_lock)
if (list_empty(&scanning_hosts))
return 0;
/* If we can't get memory immediately, that's OK. Just
* sleep a little. Even if we never get memory, the async
* scans will finish eventually.
*/
data = kmalloc(sizeof(*data), GFP_KERNEL);
if (!data)
msleep(1);
} while (!data);
data->shost = NULL;
init_completion(&data->prev_finished);
spin_lock(&async_scan_lock);
/* Check that there's still somebody else on the list */
if (list_empty(&scanning_hosts))
goto done;
list_add_tail(&data->list, &scanning_hosts);
spin_unlock(&async_scan_lock);
printk(KERN_INFO "scsi: waiting for bus probes to complete ...\n");
wait_for_completion(&data->prev_finished);
spin_lock(&async_scan_lock);
list_del(&data->list);
if (!list_empty(&scanning_hosts)) {
struct async_scan_data *next = list_entry(scanning_hosts.next,
struct async_scan_data, list);
complete(&next->prev_finished);
}
done:
spin_unlock(&async_scan_lock);
kfree(data);
return 0;
}
/**
* scsi_unlock_floptical - unlock device via a special MODE SENSE command
* @sdev: scsi device to send command to
* @result: area to store the result of the MODE SENSE
*
* Description:
* Send a vendor specific MODE SENSE (not a MODE SELECT) command.
* Called for BLIST_KEY devices.
**/
static void scsi_unlock_floptical(struct scsi_device *sdev,
unsigned char *result)
{
unsigned char scsi_cmd[MAX_COMMAND_SIZE];
sdev_printk(KERN_NOTICE, sdev, "unlocking floptical drive\n");
scsi_cmd[0] = MODE_SENSE;
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `linux/init.h`, `linux/blkdev.h`, `linux/delay.h`, `linux/kthread.h`, `linux/spinlock.h`, `linux/async.h`.
- Detected declarations: `struct async_scan_data`, `function scsi_enable_async_suspend`, `function scsi_complete_async_scans`, `function SENSE`, `function scsi_realloc_sdev_budget_map`, `function scsi_target_destroy`, `function scsi_target_dev_release`, `function scsi_is_target_device`, `function scsi_target_reap_ref_release`, `function visible`.
- 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.