Skip to content

Commit 52bfcdd

Browse files
committed
xfs: always swap the cow forks when swapping extents
Since the CoW fork exists as a secondary data structure to the data fork, we must always swap cow forks during swapext. We also need to swap the extent counts and reset the cowblocks tags. Reviewed-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1 parent 5e5c943 commit 52bfcdd

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

fs/xfs/xfs_bmap_util.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,11 +2122,31 @@ xfs_swap_extents(
21222122
ip->i_d.di_flags2 |= tip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK;
21232123
tip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK;
21242124
tip->i_d.di_flags2 |= f & XFS_DIFLAG2_REFLINK;
2125+
}
2126+
2127+
/* Swap the cow forks. */
2128+
if (xfs_sb_version_hasreflink(&mp->m_sb)) {
2129+
xfs_extnum_t extnum;
2130+
2131+
ASSERT(ip->i_cformat == XFS_DINODE_FMT_EXTENTS);
2132+
ASSERT(tip->i_cformat == XFS_DINODE_FMT_EXTENTS);
2133+
2134+
extnum = ip->i_cnextents;
2135+
ip->i_cnextents = tip->i_cnextents;
2136+
tip->i_cnextents = extnum;
2137+
21252138
cowfp = ip->i_cowfp;
21262139
ip->i_cowfp = tip->i_cowfp;
21272140
tip->i_cowfp = cowfp;
2128-
xfs_inode_set_cowblocks_tag(ip);
2129-
xfs_inode_set_cowblocks_tag(tip);
2141+
2142+
if (ip->i_cowfp && ip->i_cnextents)
2143+
xfs_inode_set_cowblocks_tag(ip);
2144+
else
2145+
xfs_inode_clear_cowblocks_tag(ip);
2146+
if (tip->i_cowfp && tip->i_cnextents)
2147+
xfs_inode_set_cowblocks_tag(tip);
2148+
else
2149+
xfs_inode_clear_cowblocks_tag(tip);
21302150
}
21312151

21322152
xfs_trans_log_inode(tp, ip, src_log_flags);

0 commit comments

Comments
 (0)