Commit aad3f375 authored by Dave Chinner's avatar Dave Chinner Committed by Dave Chinner

xfs: xfs_vm_write_end truncates too much on failure

Similar to the write_begin problem, xfs-vm_write_end will truncate
back to the old EOF, potentially removing page cache from over the
top of delalloc blocks with valid data in them. Fix this by
truncating back to just the start of the failed write.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Tested-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
parent 72ab70a1
...@@ -1634,9 +1634,12 @@ xfs_vm_write_begin( ...@@ -1634,9 +1634,12 @@ xfs_vm_write_begin(
} }
/* /*
* On failure, we only need to kill delalloc blocks beyond EOF because they * On failure, we only need to kill delalloc blocks beyond EOF in the range of
* will never be written. For blocks within EOF, generic_write_end() zeros them * this specific write because they will never be written. Previous writes
* so they are safe to leave alone and be written with all the other valid data. * beyond EOF where block allocation succeeded do not need to be trashed, so
* only new blocks from this write should be trashed. For blocks within
* EOF, generic_write_end() zeros them so they are safe to leave alone and be
* written with all the other valid data.
*/ */
STATIC int STATIC int
xfs_vm_write_end( xfs_vm_write_end(
...@@ -1659,8 +1662,11 @@ xfs_vm_write_end( ...@@ -1659,8 +1662,11 @@ xfs_vm_write_end(
loff_t to = pos + len; loff_t to = pos + len;
if (to > isize) { if (to > isize) {
truncate_pagecache(inode, isize); /* only kill blocks in this write beyond EOF */
if (pos > isize)
isize = pos;
xfs_vm_kill_delalloc_range(inode, isize, to); xfs_vm_kill_delalloc_range(inode, isize, to);
truncate_pagecache_range(inode, isize, to);
} }
} }
return ret; return ret;
......
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