Skip to content

Commit

Permalink
fs: support IOCB_NOWAIT in generic_file_buffered_read
Browse files Browse the repository at this point in the history
Allow generic_file_buffered_read to bail out early instead of waiting for
the page lock or reading a page if IOCB_NOWAIT is specified.

Signed-off-by: Milosz Tanski <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Reviewed-by: Jeff Moyer <[email protected]>
Acked-by: Sage Weil <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
mtanski authored and Al Viro committed Sep 4, 2017
1 parent 47c27bc commit 3239d83
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,8 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb,

page = find_get_page(mapping, index);
if (!page) {
if (iocb->ki_flags & IOCB_NOWAIT)
goto would_block;
page_cache_sync_readahead(mapping,
ra, filp,
index, last_index - index);
Expand All @@ -1952,6 +1954,11 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb,
index, last_index - index);
}
if (!PageUptodate(page)) {
if (iocb->ki_flags & IOCB_NOWAIT) {
put_page(page);
goto would_block;
}

/*
* See comment in do_read_cache_page on why
* wait_on_page_locked is used to avoid unnecessarily
Expand Down Expand Up @@ -2133,6 +2140,8 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb,
goto readpage;
}

would_block:
error = -EAGAIN;
out:
ra->prev_pos = prev_index;
ra->prev_pos <<= PAGE_SHIFT;
Expand Down

0 comments on commit 3239d83

Please sign in to comment.