net/sunrpc/xdr.c
Source file repositories/reference/linux-study-clean/net/sunrpc/xdr.c
File Facts
- System
- Linux kernel
- Corpus path
net/sunrpc/xdr.c- Extension
.c- Size
- 63834 bytes
- Lines
- 2445
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration 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.
- 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/module.hlinux/slab.hlinux/types.hlinux/string.hlinux/kernel.hlinux/pagemap.hlinux/errno.hlinux/sunrpc/xdr.hlinux/sunrpc/msg_prot.hlinux/bvec.htrace/events/sunrpc.h
Detected Declarations
function xdr_encode_netobjfunction bytesfunction xdr_encode_stringfunction xdr_terminate_stringfunction xdr_buf_pagecountfunction xdr_alloc_bvecfunction xdr_free_bvecfunction xdr_buf_to_bvecfunction sg_mark_endfunction xdr_buf_sg_nentsfunction sg_nextfunction xdr_inline_pagesfunction asfunction asfunction _copy_to_pagesfunction _copy_from_pagesfunction xdr_buf_iov_zerofunction xdr_buf_pages_zerofunction xdr_buf_pages_fill_sparsefunction xdr_buf_try_expandfunction xdr_buf_tail_copy_rightfunction xdr_buf_pages_copy_rightfunction xdr_buf_head_copy_rightfunction xdr_buf_tail_shift_rightfunction xdr_buf_pages_shift_rightfunction xdr_buf_head_shift_rightfunction xdr_buf_tail_copy_leftfunction xdr_buf_pages_copy_leftfunction xdr_buf_tail_shift_leftfunction xdr_buf_pages_shift_leftfunction xdr_buf_head_shift_leftfunction xdr_shrink_bufheadfunction xdr_shrink_pagelenfunction xdr_stream_posfunction xdr_stream_set_posfunction xdr_stream_page_set_posfunction xdr_page_posfunction xdr_adjust_iovecfunction xdr_init_encode_pagesfunction __xdr_commit_encodefunction xdr_reserve_spacefunction xdr_reserve_spacefunction pagesfunction xdr_truncate_decodefunction xdr_restrict_buflenfunction xdr_write_pagesfunction xdr_set_iovfunction xdr_set_tail_base
Annotated Snippet
while (remaining > 0) {
len = min_t(unsigned int, remaining,
PAGE_SIZE - offset);
if (unlikely(count >= bvec_size))
goto bvec_overflow;
bvec_set_page(bvec++, *pages++, len, offset);
remaining -= len;
offset = 0;
++count;
}
}
if (tail->iov_len) {
if (unlikely(count >= bvec_size))
goto bvec_overflow;
bvec_set_virt(bvec, tail->iov_base, tail->iov_len);
++count;
}
return count;
bvec_overflow:
pr_warn_once("%s: bio_vec array overflow\n", __func__);
return -ESERVERFAULT;
}
EXPORT_SYMBOL_GPL(xdr_buf_to_bvec);
/**
* xdr_buf_to_sg - Populate a scatterlist from an xdr_buf range
* @buf: xdr_buf to map
* @offset: starting byte offset within @buf
* @len: number of bytes to cover
* @sg: scatterlist array initialized with sg_init_table()
* @nsg: number of entries available in @sg
*
* @sg is traversed with sg_next(), so callers may pass a list
* assembled with sg_chain().
*
* Return: on success, the number of scatterlist entries used; the
* last used entry is marked with sg_mark_end(). On failure, a
* negative errno.
*/
int xdr_buf_to_sg(const struct xdr_buf *buf, unsigned int offset,
unsigned int len, struct scatterlist *sg, unsigned int nsg)
{
unsigned int page_len, thislen, page_offset;
struct scatterlist *cur = sg, *prev = NULL;
int nents = 0;
int i;
if (len == 0)
return 0;
if (offset >= buf->head[0].iov_len) {
offset -= buf->head[0].iov_len;
} else {
thislen = min_t(unsigned int,
buf->head[0].iov_len - offset, len);
if (nents >= nsg)
return -ENOSPC;
sg_set_buf(cur, buf->head[0].iov_base + offset,
thislen);
prev = cur;
cur = sg_next(cur);
nents++;
len -= thislen;
offset = 0;
}
if (len == 0)
goto done;
if (offset >= buf->page_len) {
offset -= buf->page_len;
} else {
page_len = min(buf->page_len - offset, len);
len -= page_len;
page_offset = (offset + buf->page_base) & (PAGE_SIZE - 1);
i = (offset + buf->page_base) >> PAGE_SHIFT;
thislen = PAGE_SIZE - page_offset;
do {
if (thislen > page_len)
thislen = page_len;
if (nents >= nsg)
return -ENOSPC;
sg_set_page(cur, buf->pages[i],
thislen, page_offset);
prev = cur;
cur = sg_next(cur);
nents++;
page_len -= thislen;
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/types.h`, `linux/string.h`, `linux/kernel.h`, `linux/pagemap.h`, `linux/errno.h`, `linux/sunrpc/xdr.h`.
- Detected declarations: `function xdr_encode_netobj`, `function bytes`, `function xdr_encode_string`, `function xdr_terminate_string`, `function xdr_buf_pagecount`, `function xdr_alloc_bvec`, `function xdr_free_bvec`, `function xdr_buf_to_bvec`, `function sg_mark_end`, `function xdr_buf_sg_nents`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- 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.