drivers/scsi/scsi_netlink.c
Source file repositories/reference/linux-study-clean/drivers/scsi/scsi_netlink.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/scsi_netlink.c- Extension
.c- Size
- 2924 bytes
- Lines
- 145
- Domain
- Driver Families
- Bucket
- drivers/scsi
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/time.hlinux/jiffies.hlinux/security.hlinux/delay.hlinux/slab.hlinux/export.hnet/sock.hnet/netlink.hscsi/scsi_netlink.hscsi_priv.h
Detected Declarations
function scsi_nl_rcv_msgfunction scsi_netlink_initfunction scsi_netlink_exitexport scsi_nl_sock
Annotated Snippet
if (nlh->nlmsg_type != SCSI_TRANSPORT_MSG) {
err = -EBADMSG;
goto next_msg;
}
hdr = nlmsg_data(nlh);
if ((hdr->version != SCSI_NL_VERSION) ||
(hdr->magic != SCSI_NL_MAGIC)) {
err = -EPROTOTYPE;
goto next_msg;
}
if (!netlink_capable(skb, CAP_SYS_ADMIN)) {
err = -EPERM;
goto next_msg;
}
if (nlh->nlmsg_len < (sizeof(*nlh) + hdr->msglen)) {
printk(KERN_WARNING "%s: discarding partial message\n",
__func__);
goto next_msg;
}
/*
* Deliver message to the appropriate transport
*/
tport = hdr->transport;
if (tport == SCSI_NL_TRANSPORT) {
switch (hdr->msgtype) {
case SCSI_NL_SHOST_VENDOR:
/* Locate the driver that corresponds to the message */
err = -ESRCH;
break;
default:
err = -EBADR;
break;
}
if (err)
printk(KERN_WARNING "%s: Msgtype %d failed - err %d\n",
__func__, hdr->msgtype, err);
}
else
err = -ENOENT;
next_msg:
if ((err) || (nlh->nlmsg_flags & NLM_F_ACK))
netlink_ack(skb, nlh, err, NULL);
skb_pull(skb, rlen);
}
}
/**
* scsi_netlink_init - Called by SCSI subsystem to initialize
* the SCSI transport netlink interface
*
**/
void
scsi_netlink_init(void)
{
struct netlink_kernel_cfg cfg = {
.input = scsi_nl_rcv_msg,
.groups = SCSI_NL_GRP_CNT,
};
scsi_nl_sock = netlink_kernel_create(&init_net, NETLINK_SCSITRANSPORT,
&cfg);
if (!scsi_nl_sock) {
printk(KERN_ERR "%s: register of receive handler failed\n",
__func__);
return;
}
return;
}
/**
* scsi_netlink_exit - Called by SCSI subsystem to disable the SCSI transport netlink interface
*
**/
void
scsi_netlink_exit(void)
{
if (scsi_nl_sock) {
netlink_kernel_release(scsi_nl_sock);
}
return;
}
Annotation
- Immediate include surface: `linux/time.h`, `linux/jiffies.h`, `linux/security.h`, `linux/delay.h`, `linux/slab.h`, `linux/export.h`, `net/sock.h`, `net/netlink.h`.
- Detected declarations: `function scsi_nl_rcv_msg`, `function scsi_netlink_init`, `function scsi_netlink_exit`, `export scsi_nl_sock`.
- Atlas domain: Driver Families / drivers/scsi.
- 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.