xfs: force all shared extent swap to use rmap shared path
Subsystems (2)
[email protected]
maintainerv2 cover xfs: force all shared extent swap to use rmap shared path
From: Carlos Maiolino <[email protected]>
This is a new version of this series which takes a different approach by forcing a log transaction if we need to set reflink flags to inodes. This should close any possible gap left by setting the flags in-memory only. Will see what Sashiko finds next...
Carlos Maiolino (2):
xfs: move _right_neighbor_result trace before erroring out
xfs: force all shared extent swap to use rmap shared path
fs/xfs/libxfs/xfs_rmap.c | 14 ++++++----- fs/xfs/xfs_bmap_util.c | 52 ++++++++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 19 deletions(-)
Signature · 1 line
2.56.1
[email protected]
maintainerPATCH v2 1/2 xfs: move _right_neighbor_result trace before erroring out
From: Carlos Maiolino <[email protected]>
The tracepoint doesn't help much if we find an invalid right record. Move it before we check the record so it can still be printed even if we end up jumping to the error label.
---
V2: Initialize rmap records during definition so we can safely use them
in the tracepoints
Christoph, I left your RwB because I think the change is small enough to keep the RwB, please let me know if you're not ok with it and I'll avoid that in the future.
fs/xfs/libxfs/xfs_rmap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_rmap.c +8 -6
@@ -1024,8 +1024,8 @@ xfs_rmap_map( const struct xfs_owner_info *oinfo) {struct xfs_mount *mp = cur->bc_mp; -struct xfs_rmap_irec ltrec; -struct xfs_rmap_irec gtrec; +struct xfs_rmap_irec ltrec = {0 }; +struct xfs_rmap_irec gtrec = {0 };int have_gt;int have_lt;int error =0 ;
@@ -1082,6 +1082,12 @@ xfs_rmap_map( error =xfs_rmap_get_rec (cur, >rec, &have_gt);if (error) goto out_error; + +trace_xfs_rmap_find_right_neighbor_result (cur, + gtrec.rm_startblock, gtrec.rm_blockcount, + gtrec.rm_owner, gtrec.rm_offset, + gtrec.rm_flags); +if (XFS_IS_CORRUPT (mp, have_gt !=1 )) {xfs_btree_mark_sick (cur); error = -EFSCORRUPTED ;
@@ -1092,10 +1098,6 @@ xfs_rmap_map( error = -EFSCORRUPTED ; goto out_error; } -trace_xfs_rmap_find_right_neighbor_result (cur, - gtrec.rm_startblock, gtrec.rm_blockcount, - gtrec.rm_owner, gtrec.rm_offset, - gtrec.rm_flags);if (!xfs_rmap_is_mergeable (>rec, owner, flags)) have_gt =0 ; }
Signature · 1 line
2.56.1
[email protected]
maintainerPATCH v2 2/2 xfs: force all shared extent swap to use rmap shared path
In reply to [email protected]From: Carlos Maiolino <[email protected]>
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.
---
V2: Use a transaction roll when setting reflink flag to the inodes if we need to do update flags. I was initially avoiding doing so but seems like any attempt to fix it without logging the change always risks to leave a timebomb behind.
fs/xfs/xfs_bmap_util.c | 52 +++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 13 deletions(-)
fs/xfs/xfs_bmap_util.c +39 -13
@@ -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; }
@@ -1547,6 +1534,41 @@ xfs_swap_change_owner(return error; } +/* +* If either file has shared blocks, both may own shared blocks once the extents +* are exchanged, so set reflink flag on both and init the CoW fork. +* +* rmap code chooses how to process each extent based on the reflink flag on the +* inode being remapped. Both at runtime and when log recovery attempts to +* replay deferred bmap intents. +*/ +static int +xfs_extents_set_reflink ( +struct xfs_trans **tpp, +struct xfs_inode *ip, +struct xfs_inode *tip) +{ +int error; + +if (xfs_is_reflink_inode (ip) ==xfs_is_reflink_inode (tip)) +return 0 ; + + ip->i_diflags2 |=XFS_DIFLAG2_REFLINK ; + tip->i_diflags2 |=XFS_DIFLAG2_REFLINK ; +xfs_ifork_init_cow (ip); +xfs_ifork_init_cow (tip); +xfs_trans_log_inode (*tpp, ip,XFS_ILOG_CORE ); +xfs_trans_log_inode (*tpp, tip,XFS_ILOG_CORE ); + + error =xfs_trans_roll (tpp); +if (error) +return error; + +xfs_trans_ijoin (*tpp, ip,0 ); +xfs_trans_ijoin (*tpp, tip,0 ); +return 0 ; +} + int xfs_swap_extents( struct xfs_inode *ip, /* target inode */
@@ -1705,6 +1727,10 @@ xfs_swap_extents( src_log_flags =XFS_ILOG_CORE ; target_log_flags =XFS_ILOG_CORE ; + error =xfs_extents_set_reflink (&tp, ip, tip); +if (error) + goto out_trans_cancel; +if (xfs_has_rmapbt (mp)) error =xfs_swap_extent_rmap (&tp, ip, tip);else
Signature · 1 line
2.56.1