drivers/nvme/target/tcp.c
Source file repositories/reference/linux-study-clean/drivers/nvme/target/tcp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvme/target/tcp.c- Extension
.c- Size
- 58009 bytes
- Lines
- 2285
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration 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.
- 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/module.hlinux/init.hlinux/slab.hlinux/crc32c.hlinux/err.hlinux/nvme-tcp.hlinux/nvme-keyring.hnet/sock.hnet/tcp.hnet/tls.hnet/tls_prot.hnet/handshake.hlinux/inet.hlinux/llist.htrace/events/sock.hnvmet.h
Detected Declarations
struct nvmet_tcp_cmdstruct nvmet_tcp_queuestruct nvmet_tcp_portenum nvmet_tcp_send_stateenum nvmet_tcp_recv_stateenum nvmet_tcp_queue_statefunction Copyrightfunction set_paramsfunction nvmet_tcp_cmd_tagfunction nvmet_tcp_has_data_infunction nvmet_tcp_need_data_infunction nvmet_tcp_need_data_outfunction nvmet_tcp_has_inline_datafunction nvmet_tcp_get_cmdfunction nvmet_tcp_put_cmdfunction queue_cpufunction nvmet_tcp_hdgst_lenfunction nvmet_tcp_ddgst_lenfunction nvmet_tcp_hdgstfunction nvmet_tcp_verify_hdgstfunction nvmet_tcp_check_ddgstfunction nvmet_tcp_free_cmd_buffersfunction nvmet_tcp_build_pdu_iovecfunction nvmet_tcp_socket_errorfunction nvmet_tcp_map_datafunction nvmet_tcp_calc_ddgstfunction nvmet_setup_c2h_data_pdufunction nvmet_setup_r2t_pdufunction nvmet_setup_response_pdufunction nvmet_tcp_process_resp_listfunction nvmet_tcp_queue_responsefunction nvmet_tcp_execute_requestfunction nvmet_try_send_data_pdufunction nvmet_try_send_datafunction nvmet_try_send_responsefunction nvmet_try_send_r2tfunction nvmet_try_send_ddgstfunction nvmet_tcp_try_send_onefunction nvmet_tcp_try_sendfunction nvmet_prepare_receive_pdufunction nvmet_tcp_handle_icreqfunction nvmet_tcp_handle_req_failurefunction nvmet_tcp_handle_h2c_data_pdufunction nvmet_tcp_done_recv_pdufunction nvmet_tcp_pdu_sizefunction nvmet_tcp_pdu_validfunction nvmet_tcp_tls_record_okfunction nvmet_tcp_try_recv_pdu
Annotated Snippet
ret = sock_create(port->addr.ss_family, SOCK_STREAM,
IPPROTO_TCP, &port->sock);
if (ret) {
pr_err("failed to create a socket\n");
goto err_port;
}
port->sock->sk->sk_user_data = port;
port->data_ready = port->sock->sk->sk_data_ready;
port->sock->sk->sk_data_ready = nvmet_tcp_listen_data_ready;
sock_set_reuseaddr(port->sock->sk);
tcp_sock_set_nodelay(port->sock->sk);
if (so_priority > 0)
sock_set_priority(port->sock->sk, so_priority);
ret = kernel_bind(port->sock, (struct sockaddr_unsized *)&port->addr,
sizeof(port->addr));
if (ret) {
pr_err("failed to bind port socket %d\n", ret);
goto err_sock;
}
ret = kernel_listen(port->sock, NVMET_TCP_BACKLOG);
if (ret) {
pr_err("failed to listen %d on port sock\n", ret);
goto err_sock;
}
nport->priv = port;
pr_info("enabling port %d (%pISpc)\n",
le16_to_cpu(nport->disc_addr.portid), &port->addr);
return 0;
err_sock:
sock_release(port->sock);
err_port:
kfree(port);
return ret;
}
static void nvmet_tcp_destroy_port_queues(struct nvmet_tcp_port *port)
{
struct nvmet_tcp_queue *queue;
mutex_lock(&nvmet_tcp_queue_mutex);
list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list)
if (queue->port == port)
kernel_sock_shutdown(queue->sock, SHUT_RDWR);
mutex_unlock(&nvmet_tcp_queue_mutex);
}
static void nvmet_tcp_remove_port(struct nvmet_port *nport)
{
struct nvmet_tcp_port *port = nport->priv;
write_lock_bh(&port->sock->sk->sk_callback_lock);
port->sock->sk->sk_data_ready = port->data_ready;
port->sock->sk->sk_user_data = NULL;
write_unlock_bh(&port->sock->sk->sk_callback_lock);
cancel_work_sync(&port->accept_work);
/*
* Destroy the remaining queues, which are not belong to any
* controller yet.
*/
nvmet_tcp_destroy_port_queues(port);
sock_release(port->sock);
kfree(port);
}
static void nvmet_tcp_delete_ctrl(struct nvmet_ctrl *ctrl)
{
struct nvmet_tcp_queue *queue;
mutex_lock(&nvmet_tcp_queue_mutex);
list_for_each_entry(queue, &nvmet_tcp_queue_list, queue_list)
if (queue->nvme_sq.ctrl == ctrl)
kernel_sock_shutdown(queue->sock, SHUT_RDWR);
mutex_unlock(&nvmet_tcp_queue_mutex);
}
static u16 nvmet_tcp_install_queue(struct nvmet_sq *sq)
{
struct nvmet_tcp_queue *queue =
container_of(sq, struct nvmet_tcp_queue, nvme_sq);
if (sq->qid == 0) {
struct nvmet_tcp_queue *q;
int pending = 0;
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/slab.h`, `linux/crc32c.h`, `linux/err.h`, `linux/nvme-tcp.h`, `linux/nvme-keyring.h`, `net/sock.h`.
- Detected declarations: `struct nvmet_tcp_cmd`, `struct nvmet_tcp_queue`, `struct nvmet_tcp_port`, `enum nvmet_tcp_send_state`, `enum nvmet_tcp_recv_state`, `enum nvmet_tcp_queue_state`, `function Copyright`, `function set_params`, `function nvmet_tcp_cmd_tag`, `function nvmet_tcp_has_data_in`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- 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.