aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorMaxim Patlasov <MPatlasov@parallels.com>2013-09-13 11:19:54 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-10-13 19:08:31 -0400
commiteb12ca30f11b89eab811b23562e976c1c954c7f3 (patch)
tree5b4a8371c54d208ba09ea05e03f188878a8f44e1 /fs
parent17cb5c2fef8f1b1b2f3a4ac10f0801c9ad258cb6 (diff)
fuse: wait for writeback in fuse_file_fallocate()
commit bde52788bdb755b9e4b75db6c434f30e32a0ca0b upstream. The patch fixes a race between mmap-ed write and fallocate(PUNCH_HOLE): 1) An user makes a page dirty via mmap-ed write. 2) The user performs fallocate(2) with mode == PUNCH_HOLE|KEEP_SIZE and <offset, size> covering the page. 3) Before truncate_pagecache_range call from fuse_file_fallocate, the page goes to write-back. The page is fully processed by fuse_writepage (including end_page_writeback on the page), but fuse_flush_writepages did nothing because fi->writectr < 0. 4) truncate_pagecache_range is called and fuse_file_fallocate is finishing by calling fuse_release_nowrite. The latter triggers processing queued write-back request which will write stale data to the hole soon. Changed in v2 (thanks to Brian for suggestion): - Do not truncate page cache until FUSE_FALLOCATE succeeded. Otherwise, we can end up in returning -ENOTSUPP while user data is already punched from page cache. Use filemap_write_and_wait_range() instead. Changed in v3 (thanks to Miklos for suggestion): - fuse_wait_on_writeback() is prone to livelocks; use fuse_set_nowrite() instead. So far as we need a dirty-page barrier only, fuse_sync_writes() should be enough. - rebased to for-linus branch of fuse.git Signed-off-by: Maxim Patlasov <mpatlasov@parallels.com> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/fuse/file.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 473e8453a7df..12ea203d9511 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2485,8 +2485,15 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
2485 2485
2486 if (lock_inode) { 2486 if (lock_inode) {
2487 mutex_lock(&inode->i_mutex); 2487 mutex_lock(&inode->i_mutex);
2488 if (mode & FALLOC_FL_PUNCH_HOLE) 2488 if (mode & FALLOC_FL_PUNCH_HOLE) {
2489 fuse_set_nowrite(inode); 2489 loff_t endbyte = offset + length - 1;
2490 err = filemap_write_and_wait_range(inode->i_mapping,
2491 offset, endbyte);
2492 if (err)
2493 goto out;
2494
2495 fuse_sync_writes(inode);
2496 }
2490 } 2497 }
2491 2498
2492 req = fuse_get_req_nopages(fc); 2499 req = fuse_get_req_nopages(fc);
@@ -2521,11 +2528,8 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset,
2521 fuse_invalidate_attr(inode); 2528 fuse_invalidate_attr(inode);
2522 2529
2523out: 2530out:
2524 if (lock_inode) { 2531 if (lock_inode)
2525 if (mode & FALLOC_FL_PUNCH_HOLE)
2526 fuse_release_nowrite(inode);
2527 mutex_unlock(&inode->i_mutex); 2532 mutex_unlock(&inode->i_mutex);
2528 }
2529 2533
2530 return err; 2534 return err;
2531} 2535}