drivers/target/target_core_tpg.c
Source file repositories/reference/linux-study-clean/drivers/target/target_core_tpg.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/target/target_core_tpg.c- Extension
.c- Size
- 19087 bytes
- Lines
- 731
- 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/net.hlinux/string.hlinux/timer.hlinux/slab.hlinux/spinlock.hlinux/in.hlinux/export.hnet/sock.hnet/tcp.hscsi/scsi_proto.htarget/target_core_base.htarget/target_core_backend.htarget/target_core_fabric.htarget_core_internal.htarget_core_alua.htarget_core_pr.htarget_core_ua.h
Detected Declarations
function list_for_each_entryfunction core_allocate_nexus_loss_uafunction core_tpg_add_node_to_devsfunction target_set_nacl_queue_depthfunction target_add_node_aclfunction target_tpg_has_node_aclfunction core_tpg_wait_for_nacl_pr_reffunction target_shutdown_sessionsfunction core_tpg_del_initiator_node_aclfunction core_tpg_set_initiator_node_queue_depthfunction core_tpg_set_initiator_node_tagfunction core_tpg_lun_ref_releasefunction target_tpg_register_rtpifunction target_tpg_deregister_rtpifunction target_tpg_enablefunction target_tpg_disablefunction core_tpg_registerfunction core_tpg_deregisterfunction transport_deregister_sessionfunction target_tpg_free_lunfunction core_tpg_add_lunfunction core_tpg_remove_lunexport core_tpg_get_initiator_node_aclexport core_allocate_nexus_loss_uaexport target_tpg_has_node_aclexport core_tpg_check_initiator_node_aclexport core_tpg_set_initiator_node_queue_depthexport core_tpg_set_initiator_node_tagexport core_tpg_registerexport core_tpg_deregister
Annotated Snippet
if (!tpg->se_tpg_tfo->tpg_check_demo_mode_write_protect(tpg)) {
lun_access_ro = false;
} else {
/*
* Allow only optical drives to issue R/W in default RO
* demo mode.
*/
if (dev->transport->get_device_type(dev) == TYPE_DISK)
lun_access_ro = true;
else
lun_access_ro = false;
}
pr_debug("TARGET_CORE[%s]->TPG[%u]_LUN[%llu] - Adding %s"
" access for LUN in Demo Mode\n",
tpg->se_tpg_tfo->fabric_name,
tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun,
lun_access_ro ? "READ-ONLY" : "READ-WRITE");
core_enable_device_list_for_node(lun, NULL, lun->unpacked_lun,
lun_access_ro, acl, tpg);
/*
* Check to see if there are any existing persistent reservation
* APTPL pre-registrations that need to be enabled for this dynamic
* LUN ACL now..
*/
core_scsi3_check_aptpl_registration(dev, tpg, lun, acl,
lun->unpacked_lun);
}
mutex_unlock(&tpg->tpg_lun_mutex);
}
static void
target_set_nacl_queue_depth(struct se_portal_group *tpg,
struct se_node_acl *acl, u32 queue_depth)
{
acl->queue_depth = queue_depth;
if (!acl->queue_depth) {
pr_warn("Queue depth for %s Initiator Node: %s is 0,"
"defaulting to 1.\n", tpg->se_tpg_tfo->fabric_name,
acl->initiatorname);
acl->queue_depth = 1;
}
}
static struct se_node_acl *target_alloc_node_acl(struct se_portal_group *tpg,
const unsigned char *initiatorname)
{
struct se_node_acl *acl;
u32 queue_depth;
acl = kzalloc(max(sizeof(*acl), tpg->se_tpg_tfo->node_acl_size),
GFP_KERNEL);
if (!acl)
return NULL;
INIT_LIST_HEAD(&acl->acl_list);
INIT_LIST_HEAD(&acl->acl_sess_list);
INIT_HLIST_HEAD(&acl->lun_entry_hlist);
kref_init(&acl->acl_kref);
init_completion(&acl->acl_free_comp);
spin_lock_init(&acl->nacl_sess_lock);
mutex_init(&acl->lun_entry_mutex);
atomic_set(&acl->acl_pr_ref_count, 0);
if (tpg->se_tpg_tfo->tpg_get_default_depth)
queue_depth = tpg->se_tpg_tfo->tpg_get_default_depth(tpg);
else
queue_depth = 1;
target_set_nacl_queue_depth(tpg, acl, queue_depth);
snprintf(acl->initiatorname, TRANSPORT_IQN_LEN, "%s", initiatorname);
acl->se_tpg = tpg;
acl->acl_index = scsi_get_new_index(SCSI_AUTH_INTR_INDEX);
tpg->se_tpg_tfo->set_default_node_attributes(acl);
return acl;
}
static void target_add_node_acl(struct se_node_acl *acl)
{
struct se_portal_group *tpg = acl->se_tpg;
mutex_lock(&tpg->acl_node_mutex);
list_add_tail(&acl->acl_list, &tpg->acl_node_list);
mutex_unlock(&tpg->acl_node_mutex);
pr_debug("%s_TPG[%hu] - Added %s ACL with TCQ Depth: %d for %s"
Annotation
- Immediate include surface: `linux/net.h`, `linux/string.h`, `linux/timer.h`, `linux/slab.h`, `linux/spinlock.h`, `linux/in.h`, `linux/export.h`, `net/sock.h`.
- Detected declarations: `function list_for_each_entry`, `function core_allocate_nexus_loss_ua`, `function core_tpg_add_node_to_devs`, `function target_set_nacl_queue_depth`, `function target_add_node_acl`, `function target_tpg_has_node_acl`, `function core_tpg_wait_for_nacl_pr_ref`, `function target_shutdown_sessions`, `function core_tpg_del_initiator_node_acl`, `function core_tpg_set_initiator_node_queue_depth`.
- 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.