xfs: don't be so eager to clear the cowblocks tag on truncate
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 14 Dec 2017 23:42:59 +0000 (15:42 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Thu, 21 Dec 2017 16:47:28 +0000 (08:47 -0800)
commit363e59baa4f76d3f97c0133ff7014cba3d90a7c3
treefee3a061d7ab180e6637399edd30377f5ad3efdd
parent91aae6be4139b9e3902656d819e6af66e051bd7a
xfs: don't be so eager to clear the cowblocks tag on truncate

Currently, xfs_itruncate_extents clears the cowblocks tag if i_cnextents
is zero.  This is wrong, since i_cnextents only tracks real extents in
the CoW fork, which means that we could have some delayed CoW
reservations still in there that will now never get cleaned.

Fix a further bug where we /don't/ clear the reflink iflag if there are
any attribute blocks -- really, it's only safe to clear the reflink flag
if there are no data fork extents and no cow fork extents.

Found by adding clonerange to fsstress in xfs/017.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_inode.c