1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Network filesystem high-level read support.
4 * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
8 #include <linux/module.h>
9 #include <linux/export.h>
12 #include <linux/pagemap.h>
13 #include <linux/slab.h>
14 #include <linux/uio.h>
15 #include <linux/sched/mm.h>
16 #include <linux/task_io_accounting_ops.h>
20 * Clear the unread part of an I/O request.
22 static void netfs_clear_unread(struct netfs_io_subrequest *subreq)
24 iov_iter_zero(iov_iter_count(&subreq->io_iter), &subreq->io_iter);
27 static void netfs_cache_read_terminated(void *priv, ssize_t transferred_or_error,
30 struct netfs_io_subrequest *subreq = priv;
32 netfs_subreq_terminated(subreq, transferred_or_error, was_async);
36 * Issue a read against the cache.
37 * - Eats the caller's ref on subreq.
39 static void netfs_read_from_cache(struct netfs_io_request *rreq,
40 struct netfs_io_subrequest *subreq,
41 enum netfs_read_from_hole read_hole)
43 struct netfs_cache_resources *cres = &rreq->cache_resources;
45 netfs_stat(&netfs_n_rh_read);
46 cres->ops->read(cres, subreq->start, &subreq->io_iter, read_hole,
47 netfs_cache_read_terminated, subreq);
51 * Fill a subrequest region with zeroes.
53 static void netfs_fill_with_zeroes(struct netfs_io_request *rreq,
54 struct netfs_io_subrequest *subreq)
56 netfs_stat(&netfs_n_rh_zero);
57 __set_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags);
58 netfs_subreq_terminated(subreq, 0, false);
62 * Ask the netfs to issue a read request to the server for us.
64 * The netfs is expected to read from subreq->pos + subreq->transferred to
65 * subreq->pos + subreq->len - 1. It may not backtrack and write data into the
66 * buffer prior to the transferred point as it might clobber dirty data
67 * obtained from the cache.
69 * Alternatively, the netfs is allowed to indicate one of two things:
71 * - NETFS_SREQ_SHORT_READ: A short read - it will get called again to try and
74 * - NETFS_SREQ_CLEAR_TAIL: A short read - the rest of the buffer will be
77 static void netfs_read_from_server(struct netfs_io_request *rreq,
78 struct netfs_io_subrequest *subreq)
80 netfs_stat(&netfs_n_rh_download);
82 if (rreq->origin != NETFS_DIO_READ &&
83 iov_iter_count(&subreq->io_iter) != subreq->len - subreq->transferred)
84 pr_warn("R=%08x[%u] ITER PRE-MISMATCH %zx != %zx-%zx %lx\n",
85 rreq->debug_id, subreq->debug_index,
86 iov_iter_count(&subreq->io_iter), subreq->len,
87 subreq->transferred, subreq->flags);
88 rreq->netfs_ops->issue_read(subreq);
92 * Release those waiting.
94 static void netfs_rreq_completed(struct netfs_io_request *rreq, bool was_async)
96 trace_netfs_rreq(rreq, netfs_rreq_trace_done);
97 netfs_clear_subrequests(rreq, was_async);
98 netfs_put_request(rreq, was_async, netfs_rreq_trace_put_complete);
102 * [DEPRECATED] Deal with the completion of writing the data to the cache. We
103 * have to clear the PG_fscache bits on the folios involved and release the
106 * May be called in softirq mode and we inherit a ref from the caller.
108 static void netfs_rreq_unmark_after_write(struct netfs_io_request *rreq,
111 struct netfs_io_subrequest *subreq;
113 pgoff_t unlocked = 0;
114 bool have_unlocked = false;
118 list_for_each_entry(subreq, &rreq->subrequests, rreq_link) {
119 XA_STATE(xas, &rreq->mapping->i_pages, subreq->start / PAGE_SIZE);
121 xas_for_each(&xas, folio, (subreq->start + subreq->len - 1) / PAGE_SIZE) {
122 if (xas_retry(&xas, folio))
125 /* We might have multiple writes from the same huge
126 * folio, but we mustn't unlock a folio more than once.
128 if (have_unlocked && folio->index <= unlocked)
130 unlocked = folio_next_index(folio) - 1;
131 trace_netfs_folio(folio, netfs_folio_trace_end_copy);
132 folio_end_private_2(folio);
133 have_unlocked = true;
138 netfs_rreq_completed(rreq, was_async);
141 static void netfs_rreq_copy_terminated(void *priv, ssize_t transferred_or_error,
142 bool was_async) /* [DEPRECATED] */
144 struct netfs_io_subrequest *subreq = priv;
145 struct netfs_io_request *rreq = subreq->rreq;
147 if (IS_ERR_VALUE(transferred_or_error)) {
148 netfs_stat(&netfs_n_rh_write_failed);
149 trace_netfs_failure(rreq, subreq, transferred_or_error,
150 netfs_fail_copy_to_cache);
152 netfs_stat(&netfs_n_rh_write_done);
155 trace_netfs_sreq(subreq, netfs_sreq_trace_write_term);
157 /* If we decrement nr_copy_ops to 0, the ref belongs to us. */
158 if (atomic_dec_and_test(&rreq->nr_copy_ops))
159 netfs_rreq_unmark_after_write(rreq, was_async);
161 netfs_put_subrequest(subreq, was_async, netfs_sreq_trace_put_terminated);
165 * [DEPRECATED] Perform any outstanding writes to the cache. We inherit a ref
168 static void netfs_rreq_do_write_to_cache(struct netfs_io_request *rreq)
170 struct netfs_cache_resources *cres = &rreq->cache_resources;
171 struct netfs_io_subrequest *subreq, *next, *p;
172 struct iov_iter iter;
175 trace_netfs_rreq(rreq, netfs_rreq_trace_copy);
177 /* We don't want terminating writes trying to wake us up whilst we're
178 * still going through the list.
180 atomic_inc(&rreq->nr_copy_ops);
182 list_for_each_entry_safe(subreq, p, &rreq->subrequests, rreq_link) {
183 if (!test_bit(NETFS_SREQ_COPY_TO_CACHE, &subreq->flags)) {
184 list_del_init(&subreq->rreq_link);
185 netfs_put_subrequest(subreq, false,
186 netfs_sreq_trace_put_no_copy);
190 list_for_each_entry(subreq, &rreq->subrequests, rreq_link) {
191 /* Amalgamate adjacent writes */
192 while (!list_is_last(&subreq->rreq_link, &rreq->subrequests)) {
193 next = list_next_entry(subreq, rreq_link);
194 if (next->start != subreq->start + subreq->len)
196 subreq->len += next->len;
197 list_del_init(&next->rreq_link);
198 netfs_put_subrequest(next, false,
199 netfs_sreq_trace_put_merged);
202 ret = cres->ops->prepare_write(cres, &subreq->start, &subreq->len,
203 subreq->len, rreq->i_size, true);
205 trace_netfs_failure(rreq, subreq, ret, netfs_fail_prepare_write);
206 trace_netfs_sreq(subreq, netfs_sreq_trace_write_skip);
210 iov_iter_xarray(&iter, ITER_SOURCE, &rreq->mapping->i_pages,
211 subreq->start, subreq->len);
213 atomic_inc(&rreq->nr_copy_ops);
214 netfs_stat(&netfs_n_rh_write);
215 netfs_get_subrequest(subreq, netfs_sreq_trace_get_copy_to_cache);
216 trace_netfs_sreq(subreq, netfs_sreq_trace_write);
217 cres->ops->write(cres, subreq->start, &iter,
218 netfs_rreq_copy_terminated, subreq);
221 /* If we decrement nr_copy_ops to 0, the usage ref belongs to us. */
222 if (atomic_dec_and_test(&rreq->nr_copy_ops))
223 netfs_rreq_unmark_after_write(rreq, false);
226 static void netfs_rreq_write_to_cache_work(struct work_struct *work) /* [DEPRECATED] */
228 struct netfs_io_request *rreq =
229 container_of(work, struct netfs_io_request, work);
231 netfs_rreq_do_write_to_cache(rreq);
234 static void netfs_rreq_write_to_cache(struct netfs_io_request *rreq) /* [DEPRECATED] */
236 rreq->work.func = netfs_rreq_write_to_cache_work;
237 if (!queue_work(system_unbound_wq, &rreq->work))
242 * Handle a short read.
244 static void netfs_rreq_short_read(struct netfs_io_request *rreq,
245 struct netfs_io_subrequest *subreq)
247 __clear_bit(NETFS_SREQ_SHORT_IO, &subreq->flags);
248 __set_bit(NETFS_SREQ_SEEK_DATA_READ, &subreq->flags);
250 netfs_stat(&netfs_n_rh_short_read);
251 trace_netfs_sreq(subreq, netfs_sreq_trace_resubmit_short);
253 netfs_get_subrequest(subreq, netfs_sreq_trace_get_short_read);
254 atomic_inc(&rreq->nr_outstanding);
255 if (subreq->source == NETFS_READ_FROM_CACHE)
256 netfs_read_from_cache(rreq, subreq, NETFS_READ_HOLE_CLEAR);
258 netfs_read_from_server(rreq, subreq);
262 * Reset the subrequest iterator prior to resubmission.
264 static void netfs_reset_subreq_iter(struct netfs_io_request *rreq,
265 struct netfs_io_subrequest *subreq)
267 size_t remaining = subreq->len - subreq->transferred;
268 size_t count = iov_iter_count(&subreq->io_iter);
270 if (count == remaining)
273 _debug("R=%08x[%u] ITER RESUB-MISMATCH %zx != %zx-%zx-%llx %x\n",
274 rreq->debug_id, subreq->debug_index,
275 iov_iter_count(&subreq->io_iter), subreq->transferred,
276 subreq->len, rreq->i_size,
277 subreq->io_iter.iter_type);
279 if (count < remaining)
280 iov_iter_revert(&subreq->io_iter, remaining - count);
282 iov_iter_advance(&subreq->io_iter, count - remaining);
286 * Resubmit any short or failed operations. Returns true if we got the rreq
289 static bool netfs_rreq_perform_resubmissions(struct netfs_io_request *rreq)
291 struct netfs_io_subrequest *subreq;
293 WARN_ON(in_interrupt());
295 trace_netfs_rreq(rreq, netfs_rreq_trace_resubmit);
297 /* We don't want terminating submissions trying to wake us up whilst
298 * we're still going through the list.
300 atomic_inc(&rreq->nr_outstanding);
302 __clear_bit(NETFS_RREQ_INCOMPLETE_IO, &rreq->flags);
303 list_for_each_entry(subreq, &rreq->subrequests, rreq_link) {
305 if (subreq->source != NETFS_READ_FROM_CACHE)
307 subreq->source = NETFS_DOWNLOAD_FROM_SERVER;
309 netfs_stat(&netfs_n_rh_download_instead);
310 trace_netfs_sreq(subreq, netfs_sreq_trace_download_instead);
311 netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit);
312 atomic_inc(&rreq->nr_outstanding);
313 netfs_reset_subreq_iter(rreq, subreq);
314 netfs_read_from_server(rreq, subreq);
315 } else if (test_bit(NETFS_SREQ_SHORT_IO, &subreq->flags)) {
316 netfs_reset_subreq_iter(rreq, subreq);
317 netfs_rreq_short_read(rreq, subreq);
321 /* If we decrement nr_outstanding to 0, the usage ref belongs to us. */
322 if (atomic_dec_and_test(&rreq->nr_outstanding))
325 wake_up_var(&rreq->nr_outstanding);
330 * Check to see if the data read is still valid.
332 static void netfs_rreq_is_still_valid(struct netfs_io_request *rreq)
334 struct netfs_io_subrequest *subreq;
336 if (!rreq->netfs_ops->is_still_valid ||
337 rreq->netfs_ops->is_still_valid(rreq))
340 list_for_each_entry(subreq, &rreq->subrequests, rreq_link) {
341 if (subreq->source == NETFS_READ_FROM_CACHE) {
342 subreq->error = -ESTALE;
343 __set_bit(NETFS_RREQ_INCOMPLETE_IO, &rreq->flags);
349 * Determine how much we can admit to having read from a DIO read.
351 static void netfs_rreq_assess_dio(struct netfs_io_request *rreq)
353 struct netfs_io_subrequest *subreq;
355 size_t transferred = 0;
357 for (i = 0; i < rreq->direct_bv_count; i++) {
358 flush_dcache_page(rreq->direct_bv[i].bv_page);
359 // TODO: cifs marks pages in the destination buffer
360 // dirty under some circumstances after a read. Do we
361 // need to do that too?
362 set_page_dirty(rreq->direct_bv[i].bv_page);
365 list_for_each_entry(subreq, &rreq->subrequests, rreq_link) {
366 if (subreq->error || subreq->transferred == 0)
368 transferred += subreq->transferred;
369 if (subreq->transferred < subreq->len)
373 for (i = 0; i < rreq->direct_bv_count; i++)
374 flush_dcache_page(rreq->direct_bv[i].bv_page);
376 rreq->transferred = transferred;
377 task_io_account_read(transferred);
380 rreq->iocb->ki_pos += transferred;
381 if (rreq->iocb->ki_complete)
382 rreq->iocb->ki_complete(
383 rreq->iocb, rreq->error ? rreq->error : transferred);
385 if (rreq->netfs_ops->done)
386 rreq->netfs_ops->done(rreq);
387 inode_dio_end(rreq->inode);
391 * Assess the state of a read request and decide what to do next.
393 * Note that we could be in an ordinary kernel thread, on a workqueue or in
394 * softirq context at this point. We inherit a ref from the caller.
396 static void netfs_rreq_assess(struct netfs_io_request *rreq, bool was_async)
398 trace_netfs_rreq(rreq, netfs_rreq_trace_assess);
401 netfs_rreq_is_still_valid(rreq);
403 if (!test_bit(NETFS_RREQ_FAILED, &rreq->flags) &&
404 test_bit(NETFS_RREQ_INCOMPLETE_IO, &rreq->flags)) {
405 if (netfs_rreq_perform_resubmissions(rreq))
410 if (rreq->origin != NETFS_DIO_READ)
411 netfs_rreq_unlock_folios(rreq);
413 netfs_rreq_assess_dio(rreq);
415 trace_netfs_rreq(rreq, netfs_rreq_trace_wake_ip);
416 clear_bit_unlock(NETFS_RREQ_IN_PROGRESS, &rreq->flags);
417 wake_up_bit(&rreq->flags, NETFS_RREQ_IN_PROGRESS);
419 if (test_bit(NETFS_RREQ_COPY_TO_CACHE, &rreq->flags) &&
420 test_bit(NETFS_RREQ_USE_PGPRIV2, &rreq->flags))
421 return netfs_rreq_write_to_cache(rreq);
423 netfs_rreq_completed(rreq, was_async);
426 static void netfs_rreq_work(struct work_struct *work)
428 struct netfs_io_request *rreq =
429 container_of(work, struct netfs_io_request, work);
430 netfs_rreq_assess(rreq, false);
434 * Handle the completion of all outstanding I/O operations on a read request.
435 * We inherit a ref from the caller.
437 static void netfs_rreq_terminated(struct netfs_io_request *rreq,
440 if (test_bit(NETFS_RREQ_INCOMPLETE_IO, &rreq->flags) &&
442 if (!queue_work(system_unbound_wq, &rreq->work))
445 netfs_rreq_assess(rreq, was_async);
450 * netfs_subreq_terminated - Note the termination of an I/O operation.
451 * @subreq: The I/O request that has terminated.
452 * @transferred_or_error: The amount of data transferred or an error code.
453 * @was_async: The termination was asynchronous
455 * This tells the read helper that a contributory I/O operation has terminated,
456 * one way or another, and that it should integrate the results.
458 * The caller indicates in @transferred_or_error the outcome of the operation,
459 * supplying a positive value to indicate the number of bytes transferred, 0 to
460 * indicate a failure to transfer anything that should be retried or a negative
461 * error code. The helper will look after reissuing I/O operations as
462 * appropriate and writing downloaded data to the cache.
464 * If @was_async is true, the caller might be running in softirq or interrupt
465 * context and we can't sleep.
467 void netfs_subreq_terminated(struct netfs_io_subrequest *subreq,
468 ssize_t transferred_or_error,
471 struct netfs_io_request *rreq = subreq->rreq;
474 _enter("R=%x[%x]{%llx,%lx},%zd",
475 rreq->debug_id, subreq->debug_index,
476 subreq->start, subreq->flags, transferred_or_error);
478 switch (subreq->source) {
479 case NETFS_READ_FROM_CACHE:
480 netfs_stat(&netfs_n_rh_read_done);
482 case NETFS_DOWNLOAD_FROM_SERVER:
483 netfs_stat(&netfs_n_rh_download_done);
489 if (IS_ERR_VALUE(transferred_or_error)) {
490 subreq->error = transferred_or_error;
491 trace_netfs_failure(rreq, subreq, transferred_or_error,
496 if (WARN(transferred_or_error > subreq->len - subreq->transferred,
497 "Subreq overread: R%x[%x] %zd > %zu - %zu",
498 rreq->debug_id, subreq->debug_index,
499 transferred_or_error, subreq->len, subreq->transferred))
500 transferred_or_error = subreq->len - subreq->transferred;
503 subreq->transferred += transferred_or_error;
504 if (subreq->transferred < subreq->len)
508 __clear_bit(NETFS_SREQ_NO_PROGRESS, &subreq->flags);
509 if (test_bit(NETFS_SREQ_COPY_TO_CACHE, &subreq->flags))
510 set_bit(NETFS_RREQ_COPY_TO_CACHE, &rreq->flags);
513 trace_netfs_sreq(subreq, netfs_sreq_trace_terminated);
515 /* If we decrement nr_outstanding to 0, the ref belongs to us. */
516 u = atomic_dec_return(&rreq->nr_outstanding);
518 netfs_rreq_terminated(rreq, was_async);
520 wake_up_var(&rreq->nr_outstanding);
522 netfs_put_subrequest(subreq, was_async, netfs_sreq_trace_put_terminated);
526 if (test_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags)) {
527 netfs_clear_unread(subreq);
528 subreq->transferred = subreq->len;
532 if (transferred_or_error == 0) {
533 if (__test_and_set_bit(NETFS_SREQ_NO_PROGRESS, &subreq->flags)) {
534 if (rreq->origin != NETFS_DIO_READ)
535 subreq->error = -ENODATA;
539 __clear_bit(NETFS_SREQ_NO_PROGRESS, &subreq->flags);
542 __set_bit(NETFS_SREQ_SHORT_IO, &subreq->flags);
543 set_bit(NETFS_RREQ_INCOMPLETE_IO, &rreq->flags);
547 if (subreq->source == NETFS_READ_FROM_CACHE) {
548 netfs_stat(&netfs_n_rh_read_failed);
549 set_bit(NETFS_RREQ_INCOMPLETE_IO, &rreq->flags);
551 netfs_stat(&netfs_n_rh_download_failed);
552 set_bit(NETFS_RREQ_FAILED, &rreq->flags);
553 rreq->error = subreq->error;
557 EXPORT_SYMBOL(netfs_subreq_terminated);
559 static enum netfs_io_source netfs_cache_prepare_read(struct netfs_io_subrequest *subreq,
562 struct netfs_io_request *rreq = subreq->rreq;
563 struct netfs_cache_resources *cres = &rreq->cache_resources;
566 return cres->ops->prepare_read(subreq, i_size);
567 if (subreq->start >= rreq->i_size)
568 return NETFS_FILL_WITH_ZEROES;
569 return NETFS_DOWNLOAD_FROM_SERVER;
573 * Work out what sort of subrequest the next one will be.
575 static enum netfs_io_source
576 netfs_rreq_prepare_read(struct netfs_io_request *rreq,
577 struct netfs_io_subrequest *subreq,
578 struct iov_iter *io_iter)
580 enum netfs_io_source source = NETFS_DOWNLOAD_FROM_SERVER;
581 struct netfs_inode *ictx = netfs_inode(rreq->inode);
584 _enter("%llx-%llx,%llx", subreq->start, subreq->start + subreq->len, rreq->i_size);
586 if (rreq->origin != NETFS_DIO_READ) {
587 source = netfs_cache_prepare_read(subreq, rreq->i_size);
588 if (source == NETFS_INVALID_READ)
592 if (source == NETFS_DOWNLOAD_FROM_SERVER) {
593 /* Call out to the netfs to let it shrink the request to fit
594 * its own I/O sizes and boundaries. If it shinks it here, it
595 * will be called again to make simultaneous calls; if it wants
596 * to make serial calls, it can indicate a short read and then
597 * we will call it again.
599 if (rreq->origin != NETFS_DIO_READ) {
600 if (subreq->start >= ictx->zero_point) {
601 source = NETFS_FILL_WITH_ZEROES;
604 if (subreq->len > ictx->zero_point - subreq->start)
605 subreq->len = ictx->zero_point - subreq->start;
607 /* We limit buffered reads to the EOF, but let the
608 * server deal with larger-than-EOF DIO/unbuffered
611 if (subreq->len > rreq->i_size - subreq->start)
612 subreq->len = rreq->i_size - subreq->start;
614 if (rreq->rsize && subreq->len > rreq->rsize)
615 subreq->len = rreq->rsize;
617 if (rreq->netfs_ops->clamp_length &&
618 !rreq->netfs_ops->clamp_length(subreq)) {
619 source = NETFS_INVALID_READ;
623 if (subreq->max_nr_segs) {
624 lsize = netfs_limit_iter(io_iter, 0, subreq->len,
625 subreq->max_nr_segs);
626 if (subreq->len > lsize) {
628 trace_netfs_sreq(subreq, netfs_sreq_trace_limited);
634 if (subreq->len > rreq->len)
635 pr_warn("R=%08x[%u] SREQ>RREQ %zx > %llx\n",
636 rreq->debug_id, subreq->debug_index,
637 subreq->len, rreq->len);
639 if (WARN_ON(subreq->len == 0)) {
640 source = NETFS_INVALID_READ;
644 subreq->source = source;
645 trace_netfs_sreq(subreq, netfs_sreq_trace_prepare);
647 subreq->io_iter = *io_iter;
648 iov_iter_truncate(&subreq->io_iter, subreq->len);
649 iov_iter_advance(io_iter, subreq->len);
651 subreq->source = source;
652 trace_netfs_sreq(subreq, netfs_sreq_trace_prepare);
657 * Slice off a piece of a read request and submit an I/O request for it.
659 static bool netfs_rreq_submit_slice(struct netfs_io_request *rreq,
660 struct iov_iter *io_iter)
662 struct netfs_io_subrequest *subreq;
663 enum netfs_io_source source;
665 subreq = netfs_alloc_subrequest(rreq);
669 subreq->start = rreq->start + rreq->submitted;
670 subreq->len = io_iter->count;
672 _debug("slice %llx,%zx,%llx", subreq->start, subreq->len, rreq->submitted);
673 list_add_tail(&subreq->rreq_link, &rreq->subrequests);
675 /* Call out to the cache to find out what it can do with the remaining
676 * subset. It tells us in subreq->flags what it decided should be done
677 * and adjusts subreq->len down if the subset crosses a cache boundary.
679 * Then when we hand the subset, it can choose to take a subset of that
680 * (the starts must coincide), in which case, we go around the loop
681 * again and ask it to download the next piece.
683 source = netfs_rreq_prepare_read(rreq, subreq, io_iter);
684 if (source == NETFS_INVALID_READ)
687 atomic_inc(&rreq->nr_outstanding);
689 rreq->submitted += subreq->len;
691 trace_netfs_sreq(subreq, netfs_sreq_trace_submit);
693 case NETFS_FILL_WITH_ZEROES:
694 netfs_fill_with_zeroes(rreq, subreq);
696 case NETFS_DOWNLOAD_FROM_SERVER:
697 netfs_read_from_server(rreq, subreq);
699 case NETFS_READ_FROM_CACHE:
700 netfs_read_from_cache(rreq, subreq, NETFS_READ_HOLE_IGNORE);
709 rreq->error = subreq->error;
710 netfs_put_subrequest(subreq, false, netfs_sreq_trace_put_failed);
715 * Begin the process of reading in a chunk of data, where that data may be
716 * stitched together from multiple sources, including multiple servers and the
719 int netfs_begin_read(struct netfs_io_request *rreq, bool sync)
721 struct iov_iter io_iter;
724 _enter("R=%x %llx-%llx",
725 rreq->debug_id, rreq->start, rreq->start + rreq->len - 1);
727 if (rreq->len == 0) {
728 pr_err("Zero-sized read [R=%x]\n", rreq->debug_id);
732 if (rreq->origin == NETFS_DIO_READ)
733 inode_dio_begin(rreq->inode);
735 // TODO: Use bounce buffer if requested
736 rreq->io_iter = rreq->iter;
738 INIT_WORK(&rreq->work, netfs_rreq_work);
740 /* Chop the read into slices according to what the cache and the netfs
741 * want and submit each one.
743 netfs_get_request(rreq, netfs_rreq_trace_get_for_outstanding);
744 atomic_set(&rreq->nr_outstanding, 1);
745 io_iter = rreq->io_iter;
747 _debug("submit %llx + %llx >= %llx",
748 rreq->start, rreq->submitted, rreq->i_size);
749 if (!netfs_rreq_submit_slice(rreq, &io_iter))
751 if (test_bit(NETFS_SREQ_NO_PROGRESS, &rreq->flags))
753 if (test_bit(NETFS_RREQ_BLOCKED, &rreq->flags) &&
754 test_bit(NETFS_RREQ_NONBLOCK, &rreq->flags))
757 } while (rreq->submitted < rreq->len);
759 if (!rreq->submitted) {
760 netfs_put_request(rreq, false, netfs_rreq_trace_put_no_submit);
761 if (rreq->origin == NETFS_DIO_READ)
762 inode_dio_end(rreq->inode);
768 /* Keep nr_outstanding incremented so that the ref always
769 * belongs to us, and the service code isn't punted off to a
770 * random thread pool to process. Note that this might start
771 * further work, such as writing to the cache.
773 wait_var_event(&rreq->nr_outstanding,
774 atomic_read(&rreq->nr_outstanding) == 1);
775 if (atomic_dec_and_test(&rreq->nr_outstanding))
776 netfs_rreq_assess(rreq, false);
778 trace_netfs_rreq(rreq, netfs_rreq_trace_wait_ip);
779 wait_on_bit(&rreq->flags, NETFS_RREQ_IN_PROGRESS,
780 TASK_UNINTERRUPTIBLE);
783 if (ret == 0 && rreq->submitted < rreq->len &&
784 rreq->origin != NETFS_DIO_READ) {
785 trace_netfs_failure(rreq, NULL, ret, netfs_fail_short_read);
789 /* If we decrement nr_outstanding to 0, the ref belongs to us. */
790 if (atomic_dec_and_test(&rreq->nr_outstanding))
791 netfs_rreq_assess(rreq, false);