drivers/target/target_core_alua.c
Source file repositories/reference/linux-study-clean/drivers/target/target_core_alua.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/target/target_core_alua.c- Extension
.c- Size
- 60811 bytes
- Lines
- 2279
- Domain
- Driver Families
- Bucket
- drivers/target
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/configfs.hlinux/delay.hlinux/export.hlinux/fcntl.hlinux/file.hlinux/fs.hscsi/scsi_proto.hlinux/unaligned.htarget/target_core_base.htarget/target_core_backend.htarget/target_core_fabric.htarget_core_internal.htarget_core_alua.htarget_core_ua.h
Detected Declarations
function target_emulate_report_referralsfunction list_for_each_entryfunction list_for_each_entryfunction target_emulate_report_target_port_groupsfunction list_for_each_entryfunction target_emulate_set_target_port_groupsfunction fieldfunction list_for_each_entryfunction list_for_each_entryfunction core_alua_state_nonoptimizedfunction core_alua_state_lba_dependentfunction list_for_each_entryfunction list_for_each_entryfunction core_alua_state_standbyfunction core_alua_state_unavailablefunction core_alua_state_transitionfunction target_alua_state_checkfunction core_alua_check_transitionfunction core_alua_check_nonop_delayfunction core_alua_write_tpg_metadatafunction core_alua_update_tpg_primary_metadatafunction core_alua_queue_state_change_uafunction list_for_each_entryfunction core_alua_do_transition_tg_ptfunction core_alua_do_port_transitionfunction core_alua_do_port_transitionfunction list_for_each_entryfunction core_alua_update_tpg_secondary_metadatafunction core_alua_set_tg_pt_secondary_statefunction core_alua_allocate_lba_mapfunction core_alua_allocate_lba_map_memfunction list_for_each_entryfunction core_alua_free_lba_mapfunction list_for_each_entry_safefunction core_alua_set_lba_mapfunction core_alua_allocate_lu_gpfunction core_alua_set_lu_gp_idfunction list_for_each_entryfunction core_alua_allocate_lu_gp_memfunction core_alua_free_lu_gpfunction core_alua_free_lu_gp_memfunction core_alua_put_lu_gp_from_namefunction __core_alua_attach_lu_gp_memfunction __core_alua_drop_lu_gp_memfunction core_alua_set_tg_pt_gp_idfunction list_for_each_entryfunction core_alua_free_tg_pt_gpfunction core_alua_put_tg_pt_gp_from_name
Annotated Snippet
if (rc) {
/*
* If the SET TARGET PORT GROUPS attempts to establish
* an invalid combination of target port asymmetric
* access states or attempts to establish an
* unsupported target port asymmetric access state,
* then the command shall be terminated with CHECK
* CONDITION status, with the sense key set to ILLEGAL
* REQUEST, and the additional sense code set to INVALID
* FIELD IN PARAMETER LIST.
*/
goto out;
}
/*
* If the ASYMMETRIC ACCESS STATE field (see table 267)
* specifies a primary target port asymmetric access state,
* then the TARGET PORT GROUP OR TARGET PORT field specifies
* a primary target port group for which the primary target
* port asymmetric access state shall be changed. If the
* ASYMMETRIC ACCESS STATE field specifies a secondary target
* port asymmetric access state, then the TARGET PORT GROUP OR
* TARGET PORT field specifies the relative target port
* identifier (see 3.1.120) of the target port for which the
* secondary target port asymmetric access state shall be
* changed.
*/
if (primary) {
tg_pt_id = get_unaligned_be16(ptr + 2);
/*
* Locate the matching target port group ID from
* the global tg_pt_gp list
*/
spin_lock(&dev->t10_alua.tg_pt_gps_lock);
list_for_each_entry(tg_pt_gp,
&dev->t10_alua.tg_pt_gps_list,
tg_pt_gp_list) {
if (!tg_pt_gp->tg_pt_gp_valid_id)
continue;
if (tg_pt_id != tg_pt_gp->tg_pt_gp_id)
continue;
atomic_inc_mb(&tg_pt_gp->tg_pt_gp_ref_cnt);
spin_unlock(&dev->t10_alua.tg_pt_gps_lock);
if (!core_alua_do_port_transition(tg_pt_gp,
dev, l_lun, nacl,
alua_access_state, 1))
found = true;
spin_lock(&dev->t10_alua.tg_pt_gps_lock);
atomic_dec_mb(&tg_pt_gp->tg_pt_gp_ref_cnt);
break;
}
spin_unlock(&dev->t10_alua.tg_pt_gps_lock);
} else {
struct se_lun *lun;
/*
* Extract the RELATIVE TARGET PORT IDENTIFIER to identify
* the Target Port in question for the incoming
* SET_TARGET_PORT_GROUPS op.
*/
rtpi = get_unaligned_be16(ptr + 2);
/*
* Locate the matching relative target port identifier
* for the struct se_device storage object.
*/
spin_lock(&dev->se_port_lock);
list_for_each_entry(lun, &dev->dev_sep_list,
lun_dev_link) {
if (lun->lun_tpg->tpg_rtpi != rtpi)
continue;
// XXX: racy unlock
spin_unlock(&dev->se_port_lock);
if (!core_alua_set_tg_pt_secondary_state(
lun, 1, 1))
found = true;
spin_lock(&dev->se_port_lock);
break;
}
spin_unlock(&dev->se_port_lock);
}
if (!found) {
Annotation
- Immediate include surface: `linux/slab.h`, `linux/spinlock.h`, `linux/configfs.h`, `linux/delay.h`, `linux/export.h`, `linux/fcntl.h`, `linux/file.h`, `linux/fs.h`.
- Detected declarations: `function target_emulate_report_referrals`, `function list_for_each_entry`, `function list_for_each_entry`, `function target_emulate_report_target_port_groups`, `function list_for_each_entry`, `function target_emulate_set_target_port_groups`, `function field`, `function list_for_each_entry`, `function list_for_each_entry`, `function core_alua_state_nonoptimized`.
- Atlas domain: Driver Families / drivers/target.
- Implementation status: source 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.