fs/netfs/direct_write.c
Source file repositories/reference/linux-study-clean/fs/netfs/direct_write.c
File Facts
- System
- Linux kernel
- Corpus path
fs/netfs/direct_write.c- Extension
.c- Size
- 11714 bytes
- Lines
- 392
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/uio.hinternal.h
Detected Declarations
function Copyrightfunction netfs_unbuffered_write_collectfunction netfs_unbuffered_writefunction netfs_unbuffered_write_asyncfunction netfs_unbuffered_write_iter_lockedfunction vfs_fsync_rangeexport netfs_unbuffered_write_iter_lockedexport netfs_unbuffered_write_iter
Annotated Snippet
if (wreq->iocb->ki_complete) {
trace_netfs_rreq(wreq, netfs_rreq_trace_ki_complete);
wreq->iocb->ki_complete(wreq->iocb, wreq->error ?: written);
}
wreq->iocb = VFS_PTR_POISON;
}
netfs_clear_subrequests(wreq);
}
/*
* Collect the subrequest results of unbuffered write subrequests.
*/
static void netfs_unbuffered_write_collect(struct netfs_io_request *wreq,
struct netfs_io_stream *stream,
struct netfs_io_subrequest *subreq)
{
trace_netfs_collect_sreq(wreq, subreq);
spin_lock(&wreq->lock);
list_del_init(&subreq->rreq_link);
spin_unlock(&wreq->lock);
wreq->transferred += subreq->transferred;
iov_iter_advance(&wreq->buffer.iter, subreq->transferred);
stream->collected_to = subreq->start + subreq->transferred;
wreq->collected_to = stream->collected_to;
netfs_put_subrequest(subreq, netfs_sreq_trace_put_done);
trace_netfs_collect_stream(wreq, stream);
trace_netfs_collect_state(wreq, wreq->collected_to, 0);
}
/*
* Write data to the server without going through the pagecache and without
* writing it to the local cache. We dispatch the subrequests serially and
* wait for each to complete before dispatching the next, lest we leave a gap
* in the data written due to a failure such as ENOSPC. We could, however
* attempt to do preparation such as content encryption for the next subreq
* whilst the current is in progress.
*/
static int netfs_unbuffered_write(struct netfs_io_request *wreq)
{
struct netfs_io_subrequest *subreq = NULL;
struct netfs_io_stream *stream = &wreq->io_streams[0];
int ret;
_enter("%llx", wreq->len);
if (wreq->origin == NETFS_DIO_WRITE)
inode_dio_begin(wreq->inode);
stream->collected_to = wreq->start;
for (;;) {
bool retry = false;
if (!subreq) {
netfs_prepare_write(wreq, stream, wreq->start + wreq->transferred);
subreq = stream->construct;
stream->construct = NULL;
}
/* Check if (re-)preparation failed. */
if (unlikely(test_bit(NETFS_SREQ_FAILED, &subreq->flags))) {
netfs_write_subrequest_terminated(subreq, subreq->error);
wreq->error = subreq->error;
break;
}
iov_iter_truncate(&subreq->io_iter, wreq->len - wreq->transferred);
if (!iov_iter_count(&subreq->io_iter))
break;
subreq->len = netfs_limit_iter(&subreq->io_iter, 0,
stream->sreq_max_len,
stream->sreq_max_segs);
iov_iter_truncate(&subreq->io_iter, subreq->len);
stream->submit_extendable_to = subreq->len;
trace_netfs_sreq(subreq, netfs_sreq_trace_submit);
stream->issue_write(subreq);
/* Async, need to wait. */
netfs_wait_for_in_progress_stream(wreq, stream);
if (test_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags)) {
retry = true;
} else if (test_bit(NETFS_SREQ_FAILED, &subreq->flags)) {
Annotation
- Immediate include surface: `linux/export.h`, `linux/uio.h`, `internal.h`.
- Detected declarations: `function Copyright`, `function netfs_unbuffered_write_collect`, `function netfs_unbuffered_write`, `function netfs_unbuffered_write_async`, `function netfs_unbuffered_write_iter_locked`, `function vfs_fsync_range`, `export netfs_unbuffered_write_iter_locked`, `export netfs_unbuffered_write_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.