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.

Dependency Surface

Detected Declarations

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

Implementation Notes