Skip to content

Commit

Permalink
xfs: don't unconditionally clear the reflink flag on zero-block files
Browse files Browse the repository at this point in the history
If we have speculative cow preallocations hanging around in the cow
fork, don't let a truncate operation clear the reflink flag because if
we do then there's a chance we'll forget to free those extents when we
destroy the incore inode.

Reported-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
  • Loading branch information
Darrick J. Wong committed Sep 26, 2017
1 parent 2bd6bf0 commit cc6f777
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions fs/xfs/xfs_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1624,10 +1624,12 @@ xfs_itruncate_extents(
goto out;

/*
* Clear the reflink flag if we truncated everything.
* Clear the reflink flag if there are no data fork blocks and
* there are no extents staged in the cow fork.
*/
if (ip->i_d.di_nblocks == 0 && xfs_is_reflink_inode(ip)) {
ip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK;
if (xfs_is_reflink_inode(ip) && ip->i_cnextents == 0) {
if (ip->i_d.di_nblocks == 0)
ip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK;
xfs_inode_clear_cowblocks_tag(ip);
}

Expand Down

0 comments on commit cc6f777

Please sign in to comment.