fs/netfs/iterator.c
Source file repositories/reference/linux-study-clean/fs/netfs/iterator.c
File Facts
- System
- Linux kernel
- Corpus path
fs/netfs/iterator.c- Extension
.c- Size
- 8139 bytes
- Lines
- 309
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- 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/export.hlinux/slab.hlinux/mm.hlinux/uio.hlinux/scatterlist.hlinux/netfs.hinternal.h
Detected Declarations
function Copyrightfunction netfs_limit_bvecfunction netfs_limit_kvecfunction netfs_limit_xarrayfunction netfs_limit_folioqfunction netfs_limit_iterexport netfs_extract_user_iterexport netfs_limit_iter
Annotated Snippet
if (unlikely(ret <= 0)) {
ret = ret ?: -EIO;
break;
}
if (WARN(ret > count,
"%s: extract_pages overrun %zd > %zu bytes\n",
__func__, ret, count)) {
ret = -EIO;
break;
}
cur_npages = DIV_ROUND_UP(offset + ret, PAGE_SIZE);
if (WARN(cur_npages > max_pages - npages,
"%s: extract_pages overrun %u > %u pages\n",
__func__, npages + cur_npages, max_pages)) {
ret = -EIO;
break;
}
count -= ret;
ret += offset;
for (i = 0; i < cur_npages; i++) {
len = ret > PAGE_SIZE ? PAGE_SIZE : ret;
bvec_set_page(bv + npages + i, *pages++, len - offset, offset);
ret -= len;
offset = 0;
}
npages += cur_npages;
}
/* Note: Don't try to clean up after EIO. Either we got no pages, so
* nothing to clean up, or we got a buffer overrun, memory corruption
* and can't trust the stuff in the buffer (a WARN was emitted).
*/
if (ret < 0 && (ret == -ENOMEM || npages == 0)) {
for (i = 0; i < npages; i++)
unpin_user_page(bv[i].bv_page);
kvfree(bv);
return ret;
}
iov_iter_bvec(new, orig->data_source, bv, npages, orig_len - count);
return npages;
}
EXPORT_SYMBOL_GPL(netfs_extract_user_iter);
/*
* Select the span of a bvec iterator we're going to use. Limit it by both maximum
* size and maximum number of segments. Returns the size of the span in bytes.
*/
static size_t netfs_limit_bvec(const struct iov_iter *iter, size_t start_offset,
size_t max_size, size_t max_segs)
{
const struct bio_vec *bvecs = iter->bvec;
unsigned int nbv = iter->nr_segs, ix = 0, nsegs = 0;
size_t len, span = 0, n = iter->count;
size_t skip = iter->iov_offset + start_offset;
if (WARN_ON(!iov_iter_is_bvec(iter)) ||
WARN_ON(start_offset > n) ||
n == 0)
return 0;
while (n && ix < nbv && skip) {
len = bvecs[ix].bv_len;
if (skip < len)
break;
skip -= len;
n -= len;
ix++;
}
while (n && ix < nbv) {
len = min3(n, bvecs[ix].bv_len - skip, max_size);
span += len;
nsegs++;
ix++;
if (span >= max_size || nsegs >= max_segs)
break;
skip = 0;
n -= len;
}
return min(span, max_size);
}
Annotation
- Immediate include surface: `linux/export.h`, `linux/slab.h`, `linux/mm.h`, `linux/uio.h`, `linux/scatterlist.h`, `linux/netfs.h`, `internal.h`.
- Detected declarations: `function Copyright`, `function netfs_limit_bvec`, `function netfs_limit_kvec`, `function netfs_limit_xarray`, `function netfs_limit_folioq`, `function netfs_limit_iter`, `export netfs_extract_user_iter`, `export netfs_limit_iter`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- 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.