From: Carlos Maiolino Currently when swapping inodes with shared extents in a rmap enabled FS, we enforce the rmap updates to use the rmap_shared path only when the target inode has shared extents, but we should also be using the rmap_shared path for the case when only the source inode's extent is shared. Reported-by: Lauri Gates Fixes: 1f08af52e7c9 ("xfs: implement swapext for rmap filesystems") Cc: stable@vger.kernel.org Signed-off-by: Carlos Maiolino Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_bmap_util.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 73e7db3203c0..4704222d9544 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1302,17 +1302,6 @@ xfs_swap_extent_rmap( xfs_filblks_t ilen; xfs_filblks_t rlen; int nimaps; - uint64_t tip_flags2; - - /* - * If the source file has shared blocks, we must flag the donor - * file as having shared blocks so that we get the shared-block - * rmap functions when we go to fix up the rmaps. The flags - * will be switch for reals later. - */ - tip_flags2 = tip->i_diflags2; - if (ip->i_diflags2 & XFS_DIFLAG2_REFLINK) - tip->i_diflags2 |= XFS_DIFLAG2_REFLINK; offset_fsb = 0; end_fsb = XFS_B_TO_FSB(ip->i_mount, i_size_read(VFS_I(ip))); @@ -1399,12 +1388,10 @@ xfs_swap_extent_rmap( offset_fsb += ilen; } - tip->i_diflags2 = tip_flags2; return 0; out: trace_xfs_swap_extent_rmap_error(ip, error, _RET_IP_); - tip->i_diflags2 = tip_flags2; return error; } @@ -1705,14 +1692,6 @@ xfs_swap_extents( src_log_flags = XFS_ILOG_CORE; target_log_flags = XFS_ILOG_CORE; - if (xfs_has_rmapbt(mp)) - error = xfs_swap_extent_rmap(&tp, ip, tip); - else - error = xfs_swap_extent_forks(tp, ip, tip, &src_log_flags, - &target_log_flags); - if (error) - goto out_trans_cancel; - /* Either inode may now own shared blocks; flag both, with CoW forks. */ if ((ip->i_diflags2 | tip->i_diflags2) & XFS_DIFLAG2_REFLINK) { ip->i_diflags2 |= XFS_DIFLAG2_REFLINK; @@ -1721,6 +1700,14 @@ xfs_swap_extents( xfs_ifork_init_cow(tip); } + if (xfs_has_rmapbt(mp)) + error = xfs_swap_extent_rmap(&tp, ip, tip); + else + error = xfs_swap_extent_forks(tp, ip, tip, &src_log_flags, + &target_log_flags); + if (error) + goto out_trans_cancel; + /* Swap the cow forks. */ if (xfs_has_reflink(mp)) { ASSERT(!ip->i_cowfp || -- 2.56.1