xfs: fix failed write truncation handling.
authorDave Chinner <dchinner@redhat.com>
Tue, 30 Nov 2010 04:14:39 +0000 (15:14 +1100)
committerAlex Elder <aelder@sgi.com>
Wed, 1 Dec 2010 13:40:19 +0000 (07:40 -0600)
commitc726de4409a8d3a03877b1ef4342bfe8a15f5e5e
treef1212b8f61f6dcdb52206842e8436a45f878a9e9
parente8a7e48bb248a1196484d3f8afa53bded2b24e71
xfs: fix failed write truncation handling.

Since the move to the new truncate sequence we call xfs_setattr to
truncate down excessively instanciated blocks.  As shown by the testcase
in kernel.org BZ #22452 that doesn't work too well.  Due to the confusion
of the internal inode size, and the VFS inode i_size it zeroes data that
it shouldn't.

But full blown truncate seems like overkill here.  We only instanciate
delayed allocations in the write path, and given that we never released
the iolock we can't have converted them to real allocations yet either.

The only nasty case is pre-existing preallocation which we need to skip.
We already do this for page discard during writeback, so make the delayed
allocation block punching a generic function and call it from the failed
write path as well as xfs_aops_discard_page. The callers are
responsible for ensuring that partial blocks are not truncated away,
and that they hold the ilock.

Based on a fix originally from Christoph Hellwig. This version used
filesystem blocks as the range unit.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/linux-2.6/xfs_aops.c
fs/xfs/xfs_bmap.c
fs/xfs/xfs_bmap.h