xfs: ensure truncate forces zeroed blocks to disk
authorDave Chinner <dchinner@redhat.com>
Mon, 23 Feb 2015 11:37:08 +0000 (22:37 +1100)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 9 May 2015 22:16:20 +0000 (23:16 +0100)
commit508489491f1dc63de67634a73ac255bb03204c25
tree2e8450c0a851f965ea1b5c46ccf0249302af9c55
parent17f606d841fbc7e0331af2f0cab2af801f18ed46
xfs: ensure truncate forces zeroed blocks to disk

commit 5885ebda878b47c4b4602d4b0410cb4b282af024 upstream.

A new fsync vs power fail test in xfstests indicated that XFS can
have unreliable data consistency when doing extending truncates that
require block zeroing. The blocks beyond EOF get zeroed in memory,
but we never force those changes to disk before we run the
transaction that extends the file size and exposes those blocks to
userspace. This can result in the blocks not being correctly zeroed
after a crash.

Because in-memory behaviour is correct, tools like fsx don't pick up
any coherency problems - it's not until the filesystem is shutdown
or the system crashes after writing the truncate transaction to the
journal but before the zeroed data in the page cache is flushed that
the issue is exposed.

Fix this by also flushing the dirty data in memory region between
the old size and new size when we've found blocks that need zeroing
in the truncate process.

Reported-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
[bwh: Backported to 3.2: adjust filename, context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/xfs/xfs_file.c
fs/xfs/xfs_iops.c
fs/xfs/xfs_vnodeops.h