drivers/target/target_core_device.c
Source file repositories/reference/linux-study-clean/drivers/target/target_core_device.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/target/target_core_device.c- Extension
.c- Size
- 32537 bytes
- Lines
- 1225
- 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/delay.hlinux/timer.hlinux/slab.hlinux/spinlock.hlinux/kthread.hlinux/in.hlinux/export.hlinux/t10-pi.hlinux/unaligned.hnet/sock.hnet/tcp.hscsi/scsi_common.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
struct devices_idr_iterfunction transport_lookup_cmd_lunfunction transport_lookup_tmr_lunfunction target_lun_is_rdonlyfunction core_scsi3_emulate_pro_register_and_movefunction core_free_device_list_for_nodefunction core_update_device_list_accessfunction target_pr_kref_releasefunction target_dev_ua_allocatefunction target_luns_data_has_changedfunction core_enable_device_list_for_nodefunction target_free_dev_entryfunction core_disable_device_list_for_nodefunction core_clear_lun_from_tpgfunction hlist_for_each_entry_rcufunction se_release_vpd_for_devfunction se_dev_align_max_sectorsfunction core_dev_add_lunfunction list_for_each_entryfunction core_dev_del_lunfunction core_dev_add_initiator_node_lun_aclfunction core_dev_del_initiator_node_lun_aclfunction core_dev_free_initiator_node_lun_aclfunction scsi_dump_inquiryfunction target_non_ordered_releasefunction target_configure_write_atomic_from_bdevfunction target_configure_unmap_from_bdevfunction target_to_linux_sectorfunction target_devices_idr_iterfunction target_for_each_devicefunction target_configure_devicefunction target_free_devicefunction core_dev_setup_virtual_lun0function core_dev_release_virtual_lun0function passthrough_parse_cdbexport transport_lookup_cmd_lunexport transport_lookup_tmr_lunexport target_lun_is_rdonlyexport target_nacl_find_deveexport target_configure_write_atomic_from_bdevexport target_configure_unmap_from_bdevexport target_to_linux_sectorexport passthrough_parse_cdb
Annotated Snippet
struct devices_idr_iter {
int (*fn)(struct se_device *dev, void *data);
void *data;
};
static int target_devices_idr_iter(int id, void *p, void *data)
__must_hold(&device_mutex)
{
struct devices_idr_iter *iter = data;
struct se_device *dev = p;
struct config_item *item;
int ret;
/*
* We add the device early to the idr, so it can be used
* by backend modules during configuration. We do not want
* to allow other callers to access partially setup devices,
* so we skip them here.
*/
if (!target_dev_configured(dev))
return 0;
item = config_item_get_unless_zero(&dev->dev_group.cg_item);
if (!item)
return 0;
mutex_unlock(&device_mutex);
ret = iter->fn(dev, iter->data);
config_item_put(item);
mutex_lock(&device_mutex);
return ret;
}
/**
* target_for_each_device - iterate over configured devices
* @fn: iterator function
* @data: pointer to data that will be passed to fn
*
* fn must return 0 to continue looping over devices. non-zero will break
* from the loop and return that value to the caller.
*/
int target_for_each_device(int (*fn)(struct se_device *dev, void *data),
void *data)
{
struct devices_idr_iter iter = { .fn = fn, .data = data };
int ret;
mutex_lock(&device_mutex);
ret = idr_for_each(&devices_idr, target_devices_idr_iter, &iter);
mutex_unlock(&device_mutex);
return ret;
}
int target_configure_device(struct se_device *dev)
{
struct se_hba *hba = dev->se_hba;
int ret, id;
if (target_dev_configured(dev)) {
pr_err("se_dev->se_dev_ptr already set for storage"
" object\n");
return -EEXIST;
}
/*
* Add early so modules like tcmu can use during its
* configuration.
*/
mutex_lock(&device_mutex);
/*
* Use cyclic to try and avoid collisions with devices
* that were recently removed.
*/
id = idr_alloc_cyclic(&devices_idr, dev, 0, INT_MAX, GFP_KERNEL);
mutex_unlock(&device_mutex);
if (id < 0) {
ret = -ENOMEM;
goto out;
}
dev->dev_index = id;
ret = dev->transport->configure_device(dev);
if (ret)
goto out_free_index;
if (dev->transport->configure_unmap &&
dev->transport->configure_unmap(dev)) {
pr_debug("Discard support available, but disabled by default.\n");
}
Annotation
- Immediate include surface: `linux/net.h`, `linux/string.h`, `linux/delay.h`, `linux/timer.h`, `linux/slab.h`, `linux/spinlock.h`, `linux/kthread.h`, `linux/in.h`.
- Detected declarations: `struct devices_idr_iter`, `function transport_lookup_cmd_lun`, `function transport_lookup_tmr_lun`, `function target_lun_is_rdonly`, `function core_scsi3_emulate_pro_register_and_move`, `function core_free_device_list_for_node`, `function core_update_device_list_access`, `function target_pr_kref_release`, `function target_dev_ua_allocate`, `function target_luns_data_has_changed`.
- 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.