From: Darrick J. Wong Date: Tue, 25 Oct 2016 01:26:48 +0000 (+1100) Subject: xfs: adjust refcount when unmapping file blocks X-Git-Tag: v4.9.0-rc1~102 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cfe32f0db83c38696cf1a820ddc93444f33ddf97;p=thirdparty%2Fxfsprogs-dev.git xfs: adjust refcount when unmapping file blocks Source kernel commit: 62aab20f08758b1b171a73a54e0c72dd12beb980 When we're unmapping blocks from a reflinked file, decrease the refcount of the affected blocks and free the extents that are no longer in use. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- diff --git a/include/xfs_inode.h b/include/xfs_inode.h index 0a8edeb4b..a97024d64 100644 --- a/include/xfs_inode.h +++ b/include/xfs_inode.h @@ -122,6 +122,11 @@ xfs_set_projid(struct xfs_icdinode *id, prid_t projid) id->di_projid_lo = (__uint16_t) (projid & 0xffff); } +static inline bool xfs_is_reflink_inode(struct xfs_inode *ip) +{ + return ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK; +} + typedef struct cred { uid_t cr_uid; gid_t cr_gid; diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index bd1d2d9d8..9a911e848 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -40,6 +40,7 @@ #include "xfs_quota_defs.h" #include "xfs_rmap.h" #include "xfs_ag_resv.h" +#include "xfs_refcount.h" kmem_zone_t *xfs_bmap_free_item_zone; @@ -4980,9 +4981,16 @@ xfs_bmap_del_extent( /* * If we need to, add to list of extents to delete. */ - if (do_fx) - xfs_bmap_add_free(mp, dfops, del->br_startblock, - del->br_blockcount, NULL); + if (do_fx) { + if (xfs_is_reflink_inode(ip) && whichfork == XFS_DATA_FORK) { + error = xfs_refcount_decrease_extent(mp, dfops, del); + if (error) + goto done; + } else + xfs_bmap_add_free(mp, dfops, del->br_startblock, + del->br_blockcount, NULL); + } + /* * Adjust inode # blocks in the file. */