diff options
author | Miklos Szeredi <mszeredi@suse.cz> | 2008-07-04 03:35:17 -0400 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2008-07-04 03:52:14 -0400 |
commit | 32502b8413a77b54b9e19809404109590c32dfb7 (patch) | |
tree | c84b87396be32d529b9902a7261b772b1d919e8b /fs | |
parent | 8b3d3567f72aa61d5d6f4ce89d289b154e1ea866 (diff) |
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: Miklos Szeredi <mszeredi@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/splice.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/fs/splice.c b/fs/splice.c index aa5f6f60b305..399442179d89 100644 --- a/fs/splice.c +++ b/fs/splice.c | |||
@@ -379,13 +379,22 @@ __generic_file_splice_read(struct file *in, loff_t *ppos, | |||
379 | lock_page(page); | 379 | lock_page(page); |
380 | 380 | ||
381 | /* | 381 | /* |
382 | * page was truncated, stop here. if this isn't the | 382 | * Page was truncated, or invalidated by the |
383 | * first page, we'll just complete what we already | 383 | * filesystem. Redo the find/create, but this time the |
384 | * added | 384 | * page is kept locked, so there's no chance of another |
385 | * race with truncate/invalidate. | ||
385 | */ | 386 | */ |
386 | if (!page->mapping) { | 387 | if (!page->mapping) { |
387 | unlock_page(page); | 388 | unlock_page(page); |
388 | break; | 389 | page = find_or_create_page(mapping, index, |
390 | mapping_gfp_mask(mapping)); | ||
391 | |||
392 | if (!page) { | ||
393 | error = -ENOMEM; | ||
394 | break; | ||
395 | } | ||
396 | page_cache_release(pages[page_nr]); | ||
397 | pages[page_nr] = page; | ||
389 | } | 398 | } |
390 | /* | 399 | /* |
391 | * page was already under io and is now done, great | 400 | * page was already under io and is now done, great |