drivers/target/target_core_tmr.c
Source file repositories/reference/linux-study-clean/drivers/target/target_core_tmr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/target/target_core_tmr.c- Extension
.c- Size
- 12504 bytes
- Lines
- 431
- Domain
- Driver Families
- Bucket
- drivers/target
- 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/slab.hlinux/spinlock.hlinux/list.hlinux/export.htarget/target_core_base.htarget/target_core_backend.htarget/target_core_fabric.htarget_core_internal.htarget_core_alua.htarget_core_pr.h
Detected Declarations
function core_tmr_alloc_reqfunction core_tmr_release_reqfunction target_check_cdb_and_preemptfunction __target_check_io_statefunction core_tmr_abort_taskfunction list_for_each_entry_safefunction core_tmr_drain_tmr_listfunction list_for_each_entry_safefunction core_tmr_drain_state_listfunction list_for_each_entry_safefunction core_tmr_lun_resetexport core_tmr_alloc_req
Annotated Snippet
if (!cmd) {
pr_err("Unable to locate struct se_cmd for TMR\n");
continue;
}
/*
* We only execute one LUN_RESET at a time so we can't wait
* on them below.
*/
if (tmr_p->function == TMR_LUN_RESET)
continue;
/*
* If this function was called with a valid pr_res_key
* parameter (eg: for PROUT PREEMPT_AND_ABORT service action
* skip non registration key matching TMRs.
*/
if (target_check_cdb_and_preempt(preempt_and_abort_list, cmd))
continue;
sess = cmd->se_sess;
if (WARN_ON_ONCE(!sess))
continue;
spin_lock(&sess->sess_cmd_lock);
rc = __target_check_io_state(cmd, sess, 0);
spin_unlock(&sess->sess_cmd_lock);
if (!rc) {
printk("LUN_RESET TMR: non-zero kref_get_unless_zero\n");
continue;
}
list_move_tail(&tmr_p->tmr_list, &drain_tmr_list);
tmr_p->tmr_dev = NULL;
}
spin_unlock_irqrestore(&dev->se_tmr_lock, flags);
list_for_each_entry_safe(tmr_p, tmr_pp, &drain_tmr_list, tmr_list) {
list_del_init(&tmr_p->tmr_list);
cmd = tmr_p->task_cmd;
pr_debug("LUN_RESET: %s releasing TMR %p Function: 0x%02x,"
" Response: 0x%02x, t_state: %d\n",
(preempt_and_abort_list) ? "Preempt" : "", tmr_p,
tmr_p->function, tmr_p->response, cmd->t_state);
target_put_cmd_and_wait(cmd);
}
}
/**
* core_tmr_drain_state_list() - abort SCSI commands associated with a device
*
* @dev: Device for which to abort outstanding SCSI commands.
* @prout_cmd: Pointer to the SCSI PREEMPT AND ABORT if this function is called
* to realize the PREEMPT AND ABORT functionality.
* @tmr_sess: Session through which the LUN RESET has been received.
* @tas: Task Aborted Status (TAS) bit from the SCSI control mode page.
* A quote from SPC-4, paragraph "7.5.10 Control mode page":
* "A task aborted status (TAS) bit set to zero specifies that
* aborted commands shall be terminated by the device server
* without any response to the application client. A TAS bit set
* to one specifies that commands aborted by the actions of an I_T
* nexus other than the I_T nexus on which the command was
* received shall be completed with TASK ABORTED status."
* @preempt_and_abort_list: For the PREEMPT AND ABORT functionality, a list
* with registrations that will be preempted.
*/
static void core_tmr_drain_state_list(
struct se_device *dev,
struct se_cmd *prout_cmd,
struct se_session *tmr_sess,
bool tas,
struct list_head *preempt_and_abort_list)
{
LIST_HEAD(drain_task_list);
struct se_session *sess;
struct se_cmd *cmd, *next;
unsigned long flags;
int rc, i;
/*
* Complete outstanding commands with TASK_ABORTED SAM status.
*
* This is following sam4r17, section 5.6 Aborting commands, Table 38
* for TMR LUN_RESET:
*
* a) "Yes" indicates that each command that is aborted on an I_T nexus
* other than the one that caused the SCSI device condition is
Annotation
- Immediate include surface: `linux/slab.h`, `linux/spinlock.h`, `linux/list.h`, `linux/export.h`, `target/target_core_base.h`, `target/target_core_backend.h`, `target/target_core_fabric.h`, `target_core_internal.h`.
- Detected declarations: `function core_tmr_alloc_req`, `function core_tmr_release_req`, `function target_check_cdb_and_preempt`, `function __target_check_io_state`, `function core_tmr_abort_task`, `function list_for_each_entry_safe`, `function core_tmr_drain_tmr_list`, `function list_for_each_entry_safe`, `function core_tmr_drain_state_list`, `function list_for_each_entry_safe`.
- Atlas domain: Driver Families / drivers/target.
- 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.