net/sunrpc/xprtrdma/svc_rdma_rw.c
Source file repositories/reference/linux-study-clean/net/sunrpc/xprtrdma/svc_rdma_rw.c
File Facts
- System
- Linux kernel
- Corpus path
net/sunrpc/xprtrdma/svc_rdma_rw.c- Extension
.c- Size
- 33456 bytes
- Lines
- 1177
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/bvec.hlinux/overflow.hrdma/rw.hlinux/sunrpc/xdr.hlinux/sunrpc/rpc_rdma.hlinux/sunrpc/svc_rdma.hxprt_rdma.htrace/events/rpcrdma.h
Detected Declarations
struct svc_rdma_rw_ctxtfunction svc_rdma_next_ctxtfunction svc_rdma_get_rw_ctxtfunction __svc_rdma_put_rw_ctxtfunction svc_rdma_put_rw_ctxtfunction svc_rdma_destroy_rw_ctxtsfunction svc_rdma_rw_ctx_initfunction svc_rdma_cc_initfunction svc_rdma_cc_releasefunction svc_rdma_write_info_allocfunction svc_rdma_write_info_freefunction svc_rdma_write_chunk_releasefunction svc_rdma_reply_chunk_releasefunction svc_rdma_reply_donefunction svc_rdma_write_donefunction svc_rdma_wc_read_donefunction svc_rdma_post_chunk_ctxtfunction svc_rdma_vec_to_bvecfunction svc_rdma_pagelist_to_bvecfunction svc_rdma_build_writesfunction svc_rdma_iov_writefunction svc_rdma_pages_writefunction svc_rdma_xb_writefunction svc_rdma_cc_link_wrsfunction svc_rdma_prepare_write_chunkfunction svc_rdma_prepare_write_listfunction pcl_for_each_chunkfunction svc_rdma_prepare_reply_chunkfunction svc_rdma_build_read_segmentfunction svc_rdma_build_read_chunkfunction svc_rdma_copy_inline_rangefunction svc_rdma_read_multiple_chunksfunction pcl_for_each_chunkfunction svc_rdma_read_data_itemfunction svc_rdma_read_chunk_rangefunction svc_rdma_read_call_chunkfunction pcl_for_each_chunkfunction svc_rdma_read_specialfunction svc_xprt_releasefunction svc_rdma_process_read_list
Annotated Snippet
struct svc_rdma_rw_ctxt {
struct llist_node rw_node;
struct list_head rw_list;
struct rdma_rw_ctx rw_ctx;
unsigned int rw_nents;
unsigned int rw_first_bvec_nents;
struct bio_vec *rw_bvec;
struct bio_vec rw_first_bvec[];
};
static void svc_rdma_put_rw_ctxt(struct svcxprt_rdma *rdma,
struct svc_rdma_rw_ctxt *ctxt);
static inline struct svc_rdma_rw_ctxt *
svc_rdma_next_ctxt(struct list_head *list)
{
return list_first_entry_or_null(list, struct svc_rdma_rw_ctxt,
rw_list);
}
static struct svc_rdma_rw_ctxt *
svc_rdma_get_rw_ctxt(struct svcxprt_rdma *rdma, unsigned int nr_bvec)
{
struct ib_device *dev = rdma->sc_cm_id->device;
unsigned int first_bvec_nents = dev->attrs.max_send_sge;
struct svc_rdma_rw_ctxt *ctxt;
struct llist_node *node;
spin_lock(&rdma->sc_rw_ctxt_lock);
node = llist_del_first(&rdma->sc_rw_ctxts);
spin_unlock(&rdma->sc_rw_ctxt_lock);
if (node) {
ctxt = llist_entry(node, struct svc_rdma_rw_ctxt, rw_node);
} else {
ctxt = kmalloc_node(struct_size(ctxt, rw_first_bvec,
first_bvec_nents),
GFP_KERNEL, ibdev_to_node(dev));
if (!ctxt)
goto out_noctx;
INIT_LIST_HEAD(&ctxt->rw_list);
ctxt->rw_first_bvec_nents = first_bvec_nents;
}
if (nr_bvec <= ctxt->rw_first_bvec_nents) {
ctxt->rw_bvec = ctxt->rw_first_bvec;
} else {
ctxt->rw_bvec = kmalloc_array_node(nr_bvec,
sizeof(*ctxt->rw_bvec),
GFP_KERNEL,
ibdev_to_node(dev));
if (!ctxt->rw_bvec)
goto out_free;
}
return ctxt;
out_free:
/* Return cached contexts to cache; free freshly allocated ones */
if (node)
svc_rdma_put_rw_ctxt(rdma, ctxt);
else
kfree(ctxt);
out_noctx:
trace_svcrdma_rwctx_empty(rdma, nr_bvec);
return NULL;
}
static void __svc_rdma_put_rw_ctxt(struct svc_rdma_rw_ctxt *ctxt,
struct llist_head *list)
{
if (ctxt->rw_bvec != ctxt->rw_first_bvec)
kfree(ctxt->rw_bvec);
llist_add(&ctxt->rw_node, list);
}
static void svc_rdma_put_rw_ctxt(struct svcxprt_rdma *rdma,
struct svc_rdma_rw_ctxt *ctxt)
{
__svc_rdma_put_rw_ctxt(ctxt, &rdma->sc_rw_ctxts);
}
/**
* svc_rdma_destroy_rw_ctxts - Free accumulated R/W contexts
* @rdma: transport about to be destroyed
*
*/
void svc_rdma_destroy_rw_ctxts(struct svcxprt_rdma *rdma)
{
struct svc_rdma_rw_ctxt *ctxt;
struct llist_node *node;
Annotation
- Immediate include surface: `linux/bvec.h`, `linux/overflow.h`, `rdma/rw.h`, `linux/sunrpc/xdr.h`, `linux/sunrpc/rpc_rdma.h`, `linux/sunrpc/svc_rdma.h`, `xprt_rdma.h`, `trace/events/rpcrdma.h`.
- Detected declarations: `struct svc_rdma_rw_ctxt`, `function svc_rdma_next_ctxt`, `function svc_rdma_get_rw_ctxt`, `function __svc_rdma_put_rw_ctxt`, `function svc_rdma_put_rw_ctxt`, `function svc_rdma_destroy_rw_ctxts`, `function svc_rdma_rw_ctx_init`, `function svc_rdma_cc_init`, `function svc_rdma_cc_release`, `function svc_rdma_write_info_alloc`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.