drivers/scsi/scsi_error.c
Source file repositories/reference/linux-study-clean/drivers/scsi/scsi_error.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/scsi_error.c- Extension
.c- Size
- 75242 bytes
- Lines
- 2636
- 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.
- 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/module.hlinux/sched.hlinux/gfp.hlinux/timer.hlinux/string.hlinux/kernel.hlinux/freezer.hlinux/kthread.hlinux/interrupt.hlinux/blkdev.hlinux/delay.hlinux/jiffies.hscsi/scsi.hscsi/scsi_cmnd.hscsi/scsi_dbg.hscsi/scsi_device.hscsi/scsi_driver.hscsi/scsi_eh.hscsi/scsi_common.hscsi/scsi_transport.hscsi/scsi_host.hscsi/scsi_ioctl.hscsi/scsi_dh.hscsi/scsi_devinfo.hscsi/sg.hscsi_priv.hscsi_logging.hscsi_transport_api.htrace/events/scsi.hlinux/unaligned.h
Detected Declarations
function scsi_eh_wakeupfunction scsi_schedule_ehfunction scsi_host_eh_past_deadlinefunction scsi_cmd_retry_allowedfunction scsi_eh_should_retry_cmdfunction scsi_timeoutfunction scsi_abort_commandfunction scsi_eh_resetfunction scsi_eh_inc_host_failedfunction scsi_eh_scmd_addfunction scsi_timeoutfunction scsi_block_when_processing_errorsfunction scsi_eh_prt_fail_statsfunction shost_for_each_devicefunction scsi_report_lun_changefunction scsi_report_sensefunction set_scsi_ml_bytefunction scsi_check_sensefunction limitsfunction scsi_handle_queue_ramp_upfunction scsi_handle_queue_fullfunction shost_for_each_devicefunction scsi_eh_completed_normallyfunction scsi_eh_donefunction scsi_try_host_resetfunction scsi_try_bus_resetfunction __scsi_report_device_resetfunction scsi_try_target_resetfunction scsi_try_bus_device_resetfunction unavailablefunction scsi_abort_eh_cmndfunction scsi_eh_prep_cmndfunction scsi_eh_prep_cmndfunction scsi_send_eh_cmndfunction abovefunction scsi_request_sensefunction scsi_eh_actionfunction scsi_eh_finish_cmdfunction scsi_eh_get_sensefunction scsi_eh_turfunction scsi_eh_test_devicesfunction list_for_each_entry_safefunction scsi_eh_try_stufunction scsi_eh_stufunction shost_for_each_devicefunction list_for_each_entryfunction scsi_eh_bus_device_resetfunction shost_for_each_device
Annotated Snippet
scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY) == 0) {
shost->host_eh_scheduled++;
scsi_eh_wakeup(shost, scsi_host_busy(shost));
}
spin_unlock_irqrestore(shost->host_lock, flags);
}
EXPORT_SYMBOL_GPL(scsi_schedule_eh);
static int scsi_host_eh_past_deadline(struct Scsi_Host *shost)
{
if (!shost->last_reset || shost->eh_deadline == -1)
return 0;
/*
* 32bit accesses are guaranteed to be atomic
* (on all supported architectures), so instead
* of using a spinlock we can as well double check
* if eh_deadline has been set to 'off' during the
* time_before call.
*/
if (time_before(jiffies, shost->last_reset + shost->eh_deadline) &&
shost->eh_deadline > -1)
return 0;
return 1;
}
static bool scsi_cmd_retry_allowed(struct scsi_cmnd *cmd)
{
if (cmd->allowed == SCSI_CMD_RETRIES_NO_LIMIT)
return true;
return ++cmd->retries <= cmd->allowed;
}
static bool scsi_eh_should_retry_cmd(struct scsi_cmnd *cmd)
{
struct scsi_device *sdev = cmd->device;
struct Scsi_Host *host = sdev->host;
if (host->hostt->eh_should_retry_cmd)
return host->hostt->eh_should_retry_cmd(cmd);
return true;
}
/**
* scmd_eh_abort_handler - Handle command aborts
* @work: command to be aborted.
*
* Note: this function must be called only for a command that has timed out.
* Because the block layer marks a request as complete before it calls
* scsi_timeout(), a .scsi_done() call from the LLD for a command that has
* timed out do not have any effect. Hence it is safe to call
* scsi_finish_command() from this function.
*/
void
scmd_eh_abort_handler(struct work_struct *work)
{
struct scsi_cmnd *scmd =
container_of(work, struct scsi_cmnd, abort_work.work);
struct scsi_device *sdev = scmd->device;
struct Scsi_Host *shost = sdev->host;
enum scsi_disposition rtn;
unsigned long flags;
if (scsi_host_eh_past_deadline(shost)) {
SCSI_LOG_ERROR_RECOVERY(3,
scmd_printk(KERN_INFO, scmd,
"eh timeout, not aborting\n"));
goto out;
}
SCSI_LOG_ERROR_RECOVERY(3,
scmd_printk(KERN_INFO, scmd,
"aborting command\n"));
rtn = scsi_try_to_abort_cmd(shost->hostt, scmd);
if (rtn != SUCCESS) {
SCSI_LOG_ERROR_RECOVERY(3,
scmd_printk(KERN_INFO, scmd,
"cmd abort %s\n",
(rtn == FAST_IO_FAIL) ?
"not send" : "failed"));
goto out;
}
set_host_byte(scmd, DID_TIME_OUT);
if (scsi_host_eh_past_deadline(shost)) {
SCSI_LOG_ERROR_RECOVERY(3,
scmd_printk(KERN_INFO, scmd,
Annotation
- Immediate include surface: `linux/module.h`, `linux/sched.h`, `linux/gfp.h`, `linux/timer.h`, `linux/string.h`, `linux/kernel.h`, `linux/freezer.h`, `linux/kthread.h`.
- Detected declarations: `function scsi_eh_wakeup`, `function scsi_schedule_eh`, `function scsi_host_eh_past_deadline`, `function scsi_cmd_retry_allowed`, `function scsi_eh_should_retry_cmd`, `function scsi_timeout`, `function scsi_abort_command`, `function scsi_eh_reset`, `function scsi_eh_inc_host_failed`, `function scsi_eh_scmd_add`.
- Atlas domain: Driver Families / drivers/scsi.
- 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.