drivers/target/target_core_rd.c
Source file repositories/reference/linux-study-clean/drivers/target/target_core_rd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/target/target_core_rd.c- Extension
.c- Size
- 16509 bytes
- Lines
- 684
- 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.
- 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/string.hlinux/parser.hlinux/highmem.hlinux/timer.hlinux/scatterlist.hlinux/slab.hlinux/spinlock.hscsi/scsi_proto.htarget/target_core_base.htarget/target_core_backend.htarget_core_rd.h
Detected Declarations
function rd_attach_hbafunction rd_detach_hbafunction rd_release_sgl_tablefunction rd_release_device_spacefunction rd_allocate_sgl_tablefunction rd_build_device_spacefunction rd_release_prot_spacefunction rd_build_prot_spacefunction rd_configure_devicefunction rd_dev_call_rcufunction rd_free_devicefunction rd_destroy_devicefunction rd_do_prot_rwfunction rd_execute_rwfunction rd_set_configfs_dev_paramsfunction rd_show_configfs_dev_paramsfunction rd_get_device_typefunction rd_get_blocksfunction rd_init_protfunction rd_free_protfunction rd_parse_cdbfunction rd_module_initfunction rd_module_exit
Annotated Snippet
if (pg) {
__free_page(pg);
page_count++;
}
}
kfree(sg);
}
kfree(sg_table);
return page_count;
}
static void rd_release_device_space(struct rd_dev *rd_dev)
{
u32 page_count;
if (!rd_dev->sg_table_array || !rd_dev->sg_table_count)
return;
page_count = rd_release_sgl_table(rd_dev, rd_dev->sg_table_array,
rd_dev->sg_table_count);
pr_debug("CORE_RD[%u] - Released device space for Ramdisk"
" Device ID: %u, pages %u in %u tables total bytes %lu\n",
rd_dev->rd_host->rd_host_id, rd_dev->rd_dev_id, page_count,
rd_dev->sg_table_count, (unsigned long)page_count * PAGE_SIZE);
rd_dev->sg_table_array = NULL;
rd_dev->sg_table_count = 0;
}
/* rd_build_device_space():
*
*
*/
static int rd_allocate_sgl_table(struct rd_dev *rd_dev, struct rd_dev_sg_table *sg_table,
u32 total_sg_needed, unsigned char init_payload)
{
u32 i = 0, j, page_offset = 0, sg_per_table;
u32 max_sg_per_table = (RD_MAX_ALLOCATION_SIZE /
sizeof(struct scatterlist));
struct page *pg;
struct scatterlist *sg;
unsigned char *p;
while (total_sg_needed) {
unsigned int chain_entry = 0;
sg_per_table = (total_sg_needed > max_sg_per_table) ?
max_sg_per_table : total_sg_needed;
/*
* Reserve extra element for chain entry
*/
if (sg_per_table < total_sg_needed)
chain_entry = 1;
sg = kmalloc_objs(*sg, sg_per_table + chain_entry);
if (!sg)
return -ENOMEM;
sg_init_table(sg, sg_per_table + chain_entry);
if (i > 0) {
sg_chain(sg_table[i - 1].sg_table,
max_sg_per_table + 1, sg);
}
sg_table[i].sg_table = sg;
sg_table[i].rd_sg_count = sg_per_table;
sg_table[i].page_start_offset = page_offset;
sg_table[i++].page_end_offset = (page_offset + sg_per_table)
- 1;
for (j = 0; j < sg_per_table; j++) {
pg = alloc_pages(GFP_KERNEL, 0);
if (!pg) {
pr_err("Unable to allocate scatterlist"
" pages for struct rd_dev_sg_table\n");
return -ENOMEM;
}
sg_assign_page(&sg[j], pg);
sg[j].length = PAGE_SIZE;
p = kmap(pg);
memset(p, init_payload, PAGE_SIZE);
kunmap(pg);
}
Annotation
- Immediate include surface: `linux/string.h`, `linux/parser.h`, `linux/highmem.h`, `linux/timer.h`, `linux/scatterlist.h`, `linux/slab.h`, `linux/spinlock.h`, `scsi/scsi_proto.h`.
- Detected declarations: `function rd_attach_hba`, `function rd_detach_hba`, `function rd_release_sgl_table`, `function rd_release_device_space`, `function rd_allocate_sgl_table`, `function rd_build_device_space`, `function rd_release_prot_space`, `function rd_build_prot_space`, `function rd_configure_device`, `function rd_dev_call_rcu`.
- Atlas domain: Driver Families / drivers/target.
- Implementation status: integration implementation candidate.
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.