drivers/scsi/scsi_debug.c
Source file repositories/reference/linux-study-clean/drivers/scsi/scsi_debug.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/scsi_debug.c- Extension
.c- Size
- 281582 bytes
- Lines
- 9691
- Domain
- Driver Families
- Bucket
- drivers/scsi
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- 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/module.hlinux/align.hlinux/kernel.hlinux/errno.hlinux/jiffies.hlinux/slab.hlinux/types.hlinux/string.hlinux/fs.hlinux/init.hlinux/proc_fs.hlinux/vmalloc.hlinux/moduleparam.hlinux/scatterlist.hlinux/blkdev.hlinux/crc-t10dif.hlinux/spinlock.hlinux/interrupt.hlinux/atomic.hlinux/hrtimer.hlinux/uuid.hlinux/t10-pi.hlinux/msdos_partition.hlinux/random.hlinux/xarray.hlinux/prefetch.hlinux/debugfs.hlinux/async.hlinux/cleanup.hnet/checksum.hlinux/unaligned.hscsi/scsi.h
Detected Declarations
struct tape_blockstruct sdeb_zone_statestruct sdebug_err_injectstruct sdebug_dev_infostruct sdebug_target_infostruct sdebug_host_infostruct sdeb_store_infostruct sdebug_deferstruct sdebug_scsi_cmdstruct opcode_info_tstruct grouping_m_pgstruct unmap_block_descstruct sdebug_abort_cmdstruct sdebug_internal_cmdstruct sdebug_submit_queue_datastruct sdebug_blk_mq_poll_dataenum sdebug_z_typeenum sdebug_z_condenum sdebug_err_typeenum sdeb_defer_typeenum sdeb_opcode_indexenum sam_lun_addr_methodenum sdeb_cmd_dataenum sdebug_internal_cmd_typefunction sdebug_get_devselfunction sdebug_err_freefunction sdebug_err_addfunction sdebug_err_removefunction sdebug_error_showfunction sdebug_error_openfunction sdebug_error_writefunction sdebug_target_reset_fail_showfunction sdebug_target_reset_fail_openfunction sdebug_target_reset_fail_writefunction sdebug_target_allocfunction sdebug_tartget_cleanup_asyncfunction sdebug_target_destroyfunction writesfunction scsi_debug_atomic_writefunction sdebug_max_tgts_lunsfunction mk_sense_invalid_fldfunction mk_sense_bufferfunction mk_sense_info_tapefunction mk_sense_invalid_opcodefunction scsi_debug_ioctlfunction config_cdb_lenfunction all_config_cdb_lenfunction shost_for_each_device
Annotated Snippet
static const struct bus_type pseudo_lld_bus;
static struct device_driver sdebug_driverfs_driver = {
.name = sdebug_proc_name,
.bus = &pseudo_lld_bus,
};
static const int check_condition_result =
SAM_STAT_CHECK_CONDITION;
static const int illegal_condition_result =
(DID_ABORT << 16) | SAM_STAT_CHECK_CONDITION;
static const int device_qfull_result =
(DID_ABORT << 16) | SAM_STAT_TASK_SET_FULL;
static const int condition_met_result = SAM_STAT_CONDITION_MET;
static struct dentry *sdebug_debugfs_root;
static ASYNC_DOMAIN_EXCLUSIVE(sdebug_async_domain);
static u32 sdebug_get_devsel(struct scsi_device *sdp)
{
unsigned char devtype = sdp->type;
u32 devsel;
if (devtype < 32)
devsel = (1 << devtype);
else
devsel = DS_ALL;
return devsel;
}
static void sdebug_err_free(struct rcu_head *head)
{
struct sdebug_err_inject *inject =
container_of(head, typeof(*inject), rcu);
kfree(inject);
}
static void sdebug_err_add(struct scsi_device *sdev, struct sdebug_err_inject *new)
{
struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdev->hostdata;
struct sdebug_err_inject *err;
spin_lock(&devip->list_lock);
list_for_each_entry_rcu(err, &devip->inject_err_list, list) {
if (err->type == new->type && err->cmd == new->cmd) {
list_del_rcu(&err->list);
call_rcu(&err->rcu, sdebug_err_free);
}
}
list_add_tail_rcu(&new->list, &devip->inject_err_list);
spin_unlock(&devip->list_lock);
}
static int sdebug_err_remove(struct scsi_device *sdev, const char *buf, size_t count)
{
struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdev->hostdata;
struct sdebug_err_inject *err;
int type;
unsigned char cmd;
if (sscanf(buf, "- %d %hhx", &type, &cmd) != 2) {
kfree(buf);
return -EINVAL;
}
spin_lock(&devip->list_lock);
list_for_each_entry_rcu(err, &devip->inject_err_list, list) {
if (err->type == type && err->cmd == cmd) {
list_del_rcu(&err->list);
call_rcu(&err->rcu, sdebug_err_free);
spin_unlock(&devip->list_lock);
kfree(buf);
return count;
}
}
spin_unlock(&devip->list_lock);
kfree(buf);
return -EINVAL;
}
static int sdebug_error_show(struct seq_file *m, void *p)
{
struct scsi_device *sdev = (struct scsi_device *)m->private;
Annotation
- Immediate include surface: `linux/module.h`, `linux/align.h`, `linux/kernel.h`, `linux/errno.h`, `linux/jiffies.h`, `linux/slab.h`, `linux/types.h`, `linux/string.h`.
- Detected declarations: `struct tape_block`, `struct sdeb_zone_state`, `struct sdebug_err_inject`, `struct sdebug_dev_info`, `struct sdebug_target_info`, `struct sdebug_host_info`, `struct sdeb_store_info`, `struct sdebug_defer`, `struct sdebug_scsi_cmd`, `struct opcode_info_t`.
- Atlas domain: Driver Families / drivers/scsi.
- 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.