提交 3239d834 编写于 作者: M Milosz Tanski 提交者: Al Viro

fs: support IOCB_NOWAIT in generic_file_buffered_read

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: NMilosz Tanski <milosz@adfin.com>
Reviewed-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NJeff Moyer <jmoyer@redhat.com>
Acked-by: NSage Weil <sage@redhat.com>
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
上级 47c27bc4
...@@ -1939,6 +1939,8 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, ...@@ -1939,6 +1939,8 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb,
page = find_get_page(mapping, index); page = find_get_page(mapping, index);
if (!page) { if (!page) {
if (iocb->ki_flags & IOCB_NOWAIT)
goto would_block;
page_cache_sync_readahead(mapping, page_cache_sync_readahead(mapping,
ra, filp, ra, filp,
index, last_index - index); index, last_index - index);
...@@ -1952,6 +1954,11 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, ...@@ -1952,6 +1954,11 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb,
index, last_index - index); index, last_index - index);
} }
if (!PageUptodate(page)) { if (!PageUptodate(page)) {
if (iocb->ki_flags & IOCB_NOWAIT) {
put_page(page);
goto would_block;
}
/* /*
* See comment in do_read_cache_page on why * See comment in do_read_cache_page on why
* wait_on_page_locked is used to avoid unnecessarily * wait_on_page_locked is used to avoid unnecessarily
...@@ -2133,6 +2140,8 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb, ...@@ -2133,6 +2140,8 @@ static ssize_t generic_file_buffered_read(struct kiocb *iocb,
goto readpage; goto readpage;
} }
would_block:
error = -EAGAIN;
out: out:
ra->prev_pos = prev_index; ra->prev_pos = prev_index;
ra->prev_pos <<= PAGE_SHIFT; ra->prev_pos <<= PAGE_SHIFT;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册