drivers/nvme/target/discovery.c
Source file repositories/reference/linux-study-clean/drivers/nvme/target/discovery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvme/target/discovery.c- Extension
.c- Size
- 11996 bytes
- Lines
- 443
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: implementation source
- Status
- source implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- 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.hgenerated/utsrelease.hnvmet.h
Detected Declarations
function __nvmet_disc_changedfunction nvmet_port_disc_changedfunction __nvmet_subsys_disc_changedfunction nvmet_subsys_disc_changedfunction list_for_each_entryfunction nvmet_referral_enablefunction nvmet_referral_disablefunction nvmet_format_discovery_entryfunction transportsfunction discovery_log_entriesfunction list_for_each_entryfunction nvmet_execute_disc_get_log_pagefunction list_for_each_entryfunction list_for_each_entryfunction nvmet_execute_disc_identifyfunction nvmet_execute_disc_set_featuresfunction nvmet_execute_disc_get_featuresfunction nvmet_discovery_cmd_data_lenfunction nvmet_parse_discovery_cmdfunction nvmet_init_discoveryfunction nvmet_exit_discovery
Annotated Snippet
list_for_each_entry(s, &port->subsystems, entry) {
if (s->subsys != subsys)
continue;
__nvmet_subsys_disc_changed(port, subsys, host);
}
}
void nvmet_referral_enable(struct nvmet_port *parent, struct nvmet_port *port)
{
down_write(&nvmet_config_sem);
if (list_empty(&port->entry)) {
list_add_tail(&port->entry, &parent->referrals);
port->enabled = true;
nvmet_port_disc_changed(parent, NULL);
}
up_write(&nvmet_config_sem);
}
void nvmet_referral_disable(struct nvmet_port *parent, struct nvmet_port *port)
{
down_write(&nvmet_config_sem);
if (!list_empty(&port->entry)) {
port->enabled = false;
list_del_init(&port->entry);
nvmet_port_disc_changed(parent, NULL);
}
up_write(&nvmet_config_sem);
}
static void nvmet_format_discovery_entry(struct nvmf_disc_rsp_page_hdr *hdr,
struct nvmet_port *port, char *subsys_nqn, char *traddr,
u8 type, u32 numrec)
{
struct nvmf_disc_rsp_page_entry *e = &hdr->entries[numrec];
e->trtype = port->disc_addr.trtype;
e->adrfam = port->disc_addr.adrfam;
e->treq = port->disc_addr.treq;
e->portid = port->disc_addr.portid;
/* we support only dynamic controllers */
e->cntlid = cpu_to_le16(NVME_CNTLID_DYNAMIC);
e->asqsz = cpu_to_le16(NVME_AQ_DEPTH);
e->subtype = type;
memcpy(e->trsvcid, port->disc_addr.trsvcid, NVMF_TRSVCID_SIZE);
memcpy(e->traddr, traddr, NVMF_TRADDR_SIZE);
memcpy(e->tsas.common, port->disc_addr.tsas.common, NVMF_TSAS_SIZE);
strscpy(e->subnqn, subsys_nqn, NVMF_NQN_SIZE);
}
/*
* nvmet_set_disc_traddr - set a correct discovery log entry traddr
*
* IP based transports (e.g RDMA) can listen on "any" ipv4/ipv6 addresses
* (INADDR_ANY or IN6ADDR_ANY_INIT). The discovery log page traddr reply
* must not contain that "any" IP address. If the transport implements
* .disc_traddr, use it. this callback will set the discovery traddr
* from the req->port address in case the port in question listens
* "any" IP address.
*/
static void nvmet_set_disc_traddr(struct nvmet_req *req, struct nvmet_port *port,
char *traddr)
{
if (req->ops->disc_traddr)
req->ops->disc_traddr(req, port, traddr);
else
memcpy(traddr, port->disc_addr.traddr, NVMF_TRADDR_SIZE);
}
static size_t discovery_log_entries(struct nvmet_req *req)
{
struct nvmet_ctrl *ctrl = req->sq->ctrl;
struct nvmet_subsys_link *p;
struct nvmet_port *r;
size_t entries = 1;
list_for_each_entry(p, &req->port->subsystems, entry) {
if (!nvmet_host_allowed(p->subsys, ctrl->hostnqn))
continue;
entries++;
}
list_for_each_entry(r, &req->port->referrals, entry)
entries++;
return entries;
}
static void nvmet_execute_disc_get_log_page(struct nvmet_req *req)
{
const int entry_size = sizeof(struct nvmf_disc_rsp_page_entry);
struct nvmet_ctrl *ctrl = req->sq->ctrl;
struct nvmf_disc_rsp_page_hdr *hdr;
Annotation
- Immediate include surface: `linux/slab.h`, `generated/utsrelease.h`, `nvmet.h`.
- Detected declarations: `function __nvmet_disc_changed`, `function nvmet_port_disc_changed`, `function __nvmet_subsys_disc_changed`, `function nvmet_subsys_disc_changed`, `function list_for_each_entry`, `function nvmet_referral_enable`, `function nvmet_referral_disable`, `function nvmet_format_discovery_entry`, `function transports`, `function discovery_log_entries`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- 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.