Skip to content

Commit

Permalink
splice: fix generic_file_splice_read() race with page invalidation
Browse files Browse the repository at this point in the history
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: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
  • Loading branch information
Miklos Szeredi authored and Jens Axboe committed Jul 4, 2008
1 parent 8b3d356 commit 32502b8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions fs/splice.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,22 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
lock_page(page);

/*
* page was truncated, stop here. if this isn't the
* first page, we'll just complete what we already
* added
* Page was truncated, or invalidated by the
* filesystem. Redo the find/create, but this time the
* page is kept locked, so there's no chance of another
* race with truncate/invalidate.
*/
if (!page->mapping) {
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
Expand Down

0 comments on commit 32502b8

Please sign in to comment.