Commit 32502b84 authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Jens Axboe

splice: fix generic_file_splice_read() race with page invalidation

If a page was invalidated during splicing from file to a pipe, then
generic_file_splice_read() could return a short or zero count.

This manifested itself in rare I/O errors seen on nfs exported fuse
filesystems.  This is because nfsd uses splice_direct_to_actor() to read
files, and fuse uses invalidate_inode_pages2() to invalidate stale data on
open.

Fix by redoing the page find/create if it was found to be truncated
(invalidated).
Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 8b3d3567
...@@ -379,13 +379,22 @@ __generic_file_splice_read(struct file *in, loff_t *ppos, ...@@ -379,13 +379,22 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
lock_page(page); lock_page(page);
/* /*
* page was truncated, stop here. if this isn't the * Page was truncated, or invalidated by the
* first page, we'll just complete what we already * filesystem. Redo the find/create, but this time the
* added * page is kept locked, so there's no chance of another
* race with truncate/invalidate.
*/ */
if (!page->mapping) { if (!page->mapping) {
unlock_page(page); unlock_page(page);
break; page = find_or_create_page(mapping, index,
mapping_gfp_mask(mapping));
if (!page) {
error = -ENOMEM;
break;
}
page_cache_release(pages[page_nr]);
pages[page_nr] = page;
} }
/* /*
* page was already under io and is now done, great * page was already under io and is now done, great
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment