xfs: online repair, part 1
Subsystems (3)
PATCH v25 1/2 xfs: online repair, part 1
Hi everyone,
I've finished merging parent pointers into what is now part 2 of online repair. Part 1 hasn't changed much since the last posting at the end of 2022, aside from various reorganizations of the directory repair, dotdot repair, and the tempfile/orphanage infrastructure to support the bits that part 2 will want. Zorro merged all the pending fstests changes to support and test everything in part 1, so that part is done.
In other words, I'm formally submitting part 1 for inclusion in 6.5.
For this review, I would like people to focus the following:
- Are the major subsystems sufficiently documented that you could figure out what the code does?
- Do you see any problems that are severe enough to cause long term support hassles? (e.g. bad API design, writing weird metadata to disk)
- Can you spot mis-interactions between the subsystems?
- What were my blind spots in devising this feature?
- Are there missing pieces that you'd like to help build?
- Can I just merge all of this?
The one thing that is /not/ in scope for this review are requests for more refactoring of existing subsystems.
I've been running daily online **repairs** of every computer I own for the last 14 months. So far, no damage has resulted from these operations.
Fuzz and stress testing of online repairs have been running well for a year now. As of this writing, online repair can fix slightly more things than offline repair, and the fsstress+repair long soak test has passed 200 million repairs with zero problems observed. All issues observed in that time have been corrected in this submission.
(For comparison, the long soak fsx test recently passed 99 billion file operations, so online fsck has a ways to go...)
This is actually an excerpt of the xfsprogs patches -- I'm only mailing the changes to xfs_scrub; there are substantially more bug fixes and improvements to xfs_{db,repair,spaceman} that I've made along the way.
--D
cover xfs: fix ranged queries and integer overflows in GETFSMAP
Hi all,
As part of merging the parent pointers patchset into my development branch, I noticed a few problems with the GETFSMAP implementation for XFS. The biggest problem is that ranged queries don't work properly if the query interval is exactly within a single record. It turns out that I didn't implement the record filtering quite right -- for the first call into the btree code, we want to find any rmap that overlaps with the range specified, but for subsequent calls, we only want rmaps that come after the low key of the query. This can be fixed by tweaking the filtering logic and pushing the key handling into the individual backend implementations.
The second problem I noticed is that there are integer overflows in the rtbitmap and external log handlers. This is the result of a poor decision on my part to use the incore rmap records for storing the query ranges; this only works for the rmap code, which is smart enough to iterate AGs. This breaks down spectacularly if someone tries to query high block offsets in either the rt volume or the log device. I fixed that by introducing a second filtering implementation based entirely on daddrs.
The third problem was minor by comparison -- the rt volume cannot ever use rtblocks beyond the end of the last rtextent, so it makes no sense for GETFSMAP to try to query those areas.
Having done that, add a few more patches to clean up some messes.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=getfsmap-fixes
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=getfsmap-fixes
--- fs/xfs/libxfs/xfs_alloc.c | 10 -- fs/xfs/libxfs/xfs_refcount.c | 13 +- fs/xfs/libxfs/xfs_rmap.c | 10 -- fs/xfs/xfs_fsmap.c | 261 ++++++++++++++++++++++-------------------- fs/xfs/xfs_trace.h | 25 ++++ 5 files changed, 177 insertions(+), 142 deletions(-)
PATCH 1/7 xfs: fix interval filtering in multi-step fsmap queries
From: Darrick J. Wong <[email protected]>
I noticed a bug in ranged GETFSMAP queries:
# xfs_io -c 'fsmap -vvvv' /opt EXT: DEV BLOCK-RANGE OWNER FILE-OFFSET AG AG-OFFSET TOTAL 0: 8:80 [0..7]: static fs metadata 0 (0..7) 8 <snip> 9: 8:80 [192..223]: 137 0..31 0 (192..223) 32 # xfs_io -c 'fsmap -vvvv -d 208 208' /opt #
That's not right -- we asked what block maps block 208, and we should've received a mapping for inode 137 offset 16. Instead, we get nothing.
The root cause of this problem is a mis-interaction between the fsmap code and how btree ranged queries work. xfs_btree_query_range returns any btree record that overlaps with the query interval, even if the record starts before or ends after the interval. Similarly, GETFSMAP is supposed to return a recordset containing all records that overlap the range queried.
However, it's possible that the recordset is larger than the buffer that the caller provided to convey mappings to userspace. In /that/ case, userspace is supposed to copy the last record returned to fmh_keys[0] and call GETFSMAP again. In this case, we do not want to return mappings that we have already supplied to the caller. The call to xfs_btree_query_range is the same, but now we ignore any records that start before fmh_keys[0].
Unfortunately, we didn't implement the filtering predicate correctly. The predicate should only be called when we're calling back for more records. Accomplish this by setting info->low.rm_blockcount to a nonzero value and ensuring that it is cleared as necessary. As a result, we no longer want to adjust dkeys[0] in the main setup function because that's confusing.
This patch doesn't touch the logdev/rtbitmap backends because they have bigger problems that will be addressed by subsequent patches.
Found via xfs/556 with parent pointers enabled.
--- fs/xfs/xfs_fsmap.c | 67 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 19 deletions(-)
fs/xfs/xfs_fsmap.c +48 -19
@@ -162,7 +162,14 @@ struct xfs_getfsmap_info {xfs_daddr_t next_daddr;/* next daddr we expect */ u64 missing_owner;/* owner of holes */ u32 dev;/* device id */ -struct xfs_rmap_irec low;/* low rmap key */ +/* +* Low rmap key for the query. If low.rm_blockcount is nonzero, this +* is the second (or later) call to retrieve the recordset in pieces. +* xfs_getfsmap_rec_before_start will compare all records retrieved +* by the rmapbt query to filter out any records that start before +* the last record. +*/ +struct xfs_rmap_irec low;struct xfs_rmap_irec high;/* high rmap key */ bool last;/* last extent? */ };
@@ -237,6 +244,17 @@ xfs_getfsmap_format(xfs_fsmap_from_internal (rec, xfm); } +static inline bool +xfs_getfsmap_rec_before_start ( +struct xfs_getfsmap_info *info, +const struct xfs_rmap_irec *rec, +xfs_daddr_t rec_daddr) +{ +if (info->low.rm_blockcount) +return xfs_rmap_compare (rec, &info->low) <0 ; +return false; +} +/* * Format a reverse mapping for getfsmap, having translated rm_startblock * into the appropriate daddr units.
@@ -260,7 +278,7 @@ xfs_getfsmap_helper(* Filter out records that start before our startpoint, if the * caller requested that. */ -if (xfs_rmap_compare (rec, &info->low) <0 ) { +if (xfs_getfsmap_rec_before_start (info, rec, rec_daddr)) { rec_daddr +=XFS_FSB_TO_BB (mp, rec->rm_blockcount);if (info->next_daddr < rec_daddr) info->next_daddr = rec_daddr;
@@ -606,9 +624,27 @@ __xfs_getfsmap_datadev( error =xfs_fsmap_owner_to_rmap (&info->low, &keys[0 ]);if (error)return error; - info->low.rm_blockcount =0 ; + info->low.rm_blockcount =XFS_BB_TO_FSBT (mp, keys[0 ].fmr_length);xfs_getfsmap_set_irec_flags (&info->low, &keys[0 ]); +/* Adjust the low key if we are continuing from where we left off. */ +if (info->low.rm_blockcount ==0 ) { +/* empty */ + }else if (XFS_RMAP_NON_INODE_OWNER (info->low.rm_owner) || + (info->low.rm_flags & (XFS_RMAP_ATTR_FORK | +XFS_RMAP_BMBT_BLOCK | +XFS_RMAP_UNWRITTEN ))) { + info->low.rm_startblock += info->low.rm_blockcount; + info->low.rm_owner =0 ; + info->low.rm_offset =0 ; + + start_fsb += info->low.rm_blockcount; +if (XFS_FSB_TO_DADDR (mp, start_fsb) >= eofs) +return 0 ; + }else { + info->low.rm_offset += info->low.rm_blockcount; + } + info->high.rm_startblock =-1U ; info->high.rm_owner =ULLONG_MAX ; info->high.rm_offset =ULLONG_MAX ;
@@ -659,12 +695,8 @@ __xfs_getfsmap_datadev(* Set the AG low key to the start of the AG prior to * moving on to the next AG. */ -if (pag->pag_agno == start_ag) { - info->low.rm_startblock =0 ; - info->low.rm_owner =0 ; - info->low.rm_offset =0 ; - info->low.rm_flags =0 ; - } +if (pag->pag_agno == start_ag) +memset (&info->low,0 ,sizeof (info->low));/* * If this is the last AG, report any gap at the end of it
@@ -901,21 +933,17 @@ xfs_getfsmap(* blocks could be mapped to several other files/offsets. * According to rmapbt record ordering, the minimal next * possible record for the block range is the next starting -* offset in the same inode. Therefore, bump the file offset to -* continue the search appropriately. For all other low key -* mapping types (attr blocks, metadata), bump the physical -* offset as there can be no other mapping for the same physical -* block range. +* offset in the same inode. Therefore, each fsmap backend bumps +* the file offset to continue the search appropriately. For +* all other low key mapping types (attr blocks, metadata), each +* fsmap backend bumps the physical offset as there can be no +* other mapping for the same physical block range. */ dkeys[0 ] = head->fmh_keys[0 ];if (dkeys[0 ].fmr_flags & (FMR_OF_SPECIAL_OWNER |FMR_OF_EXTENT_MAP )) { - dkeys[0 ].fmr_physical += dkeys[0 ].fmr_length; - dkeys[0 ].fmr_owner =0 ;if (dkeys[0 ].fmr_offset)return -EINVAL ; - }else - dkeys[0 ].fmr_offset += dkeys[0 ].fmr_length; - dkeys[0 ].fmr_length =0 ; + }memset (&dkeys[1 ],0xFF ,sizeof (struct xfs_fsmap ));if (!xfs_getfsmap_check_keys (dkeys, &head->fmh_keys[1 ]))
@@ -960,6 +988,7 @@ xfs_getfsmap( info.dev = handlers[i].dev; info.last = false; info.pag =NULL ; + info.low.rm_blockcount =0 ; error = handlers[i].fn (tp, dkeys, &info);if (error)break ;
PATCH 2/7 xfs: fix integer overflows in the fsmap rtbitmap and logdev backends
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
It's not correct to use the rmap irec structure to hold query key information to query the rtbitmap because the realtime volume can be longer than 2^32 fsblocks in length. Because the rt volume doesn't have allocation groups, introduce a daddr-based record filtering algorithm and compute the rtextent values using 64-bit variables. The same problem exists in the external log device fsmap implementation, so use the same solution to fix it too.
After this patch, all the code that touches info->low and info->high under xfs_getfsmap_logdev and __xfs_getfsmap_rtdev are unnecessary. Cleaning this up will be done in subsequent patches.
--- fs/xfs/xfs_fsmap.c | 90 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 26 deletions(-)
fs/xfs/xfs_fsmap.c +64 -26
@@ -160,6 +160,8 @@ struct xfs_getfsmap_info {struct xfs_buf *agf_bp;/* AGF, for refcount queries */ struct xfs_perag *pag;/* AG info, if applicable */ xfs_daddr_t next_daddr;/* next daddr we expect */ +/* daddr of low fsmap key when we're using the rtbitmap */ +xfs_daddr_t low_daddr;u64 missing_owner;/* owner of holes */ u32 dev;/* device id */ /*
@@ -250,6 +252,8 @@ xfs_getfsmap_rec_before_start( const struct xfs_rmap_irec *rec, xfs_daddr_t rec_daddr) { + if (info->low_daddr != -1ULL) + return rec_daddr < info->low_daddr;if (info->low.rm_blockcount)return xfs_rmap_compare (rec, &info->low) <0 ;return false;
@@ -257,14 +261,16 @@ xfs_getfsmap_rec_before_start(/* * Format a reverse mapping for getfsmap, having translated rm_startblock -* into the appropriate daddr units. +* into the appropriate daddr units. Pass in a nonzero @len_daddr if the +* length could be larger than rm_blockcount in struct xfs_rmap_irec. */ STATIC intxfs_getfsmap_helper (struct xfs_trans *tp,struct xfs_getfsmap_info *info,const struct xfs_rmap_irec *rec, -xfs_daddr_t rec_daddr) +xfs_daddr_t rec_daddr, +xfs_daddr_t len_daddr) {struct xfs_fsmap fmr;struct xfs_mount *mp = tp->t_mountp;
@@ -274,12 +280,15 @@ xfs_getfsmap_helper(if (fatal_signal_pending (current))return -EINTR ; +if (len_daddr ==0 ) + len_daddr =XFS_FSB_TO_BB (mp, rec->rm_blockcount); +/* * Filter out records that start before our startpoint, if the * caller requested that. */ if (xfs_getfsmap_rec_before_start (info, rec, rec_daddr)) { - rec_daddr +=XFS_FSB_TO_BB (mp, rec->rm_blockcount); + rec_daddr += len_daddr;if (info->next_daddr < rec_daddr) info->next_daddr = rec_daddr;return 0 ;
@@ -298,7 +307,7 @@ xfs_getfsmap_helper( info->head->fmh_entries++; - rec_daddr +=XFS_FSB_TO_BB (mp, rec->rm_blockcount); + rec_daddr += len_daddr;if (info->next_daddr < rec_daddr) info->next_daddr = rec_daddr;return 0 ;
@@ -338,7 +347,7 @@ xfs_getfsmap_helper(if (error)return error; fmr.fmr_offset =XFS_FSB_TO_BB (mp, rec->rm_offset); - fmr.fmr_length =XFS_FSB_TO_BB (mp, rec->rm_blockcount); + fmr.fmr_length = len_daddr;if (rec->rm_flags &XFS_RMAP_UNWRITTEN ) fmr.fmr_flags |=FMR_OF_PREALLOC ;if (rec->rm_flags &XFS_RMAP_ATTR_FORK )
@@ -355,7 +364,7 @@ xfs_getfsmap_helper(xfs_getfsmap_format (mp, &fmr, info); out: - rec_daddr +=XFS_FSB_TO_BB (mp, rec->rm_blockcount); + rec_daddr += len_daddr;if (info->next_daddr < rec_daddr) info->next_daddr = rec_daddr;return 0 ;
@@ -376,7 +385,7 @@ xfs_getfsmap_datadev_helper( fsb =XFS_AGB_TO_FSB (mp, cur->bc_ag.pag->pag_agno, rec->rm_startblock); rec_daddr =XFS_FSB_TO_DADDR (mp, fsb); -return xfs_getfsmap_helper (cur->bc_tp, info, rec, rec_daddr); +return xfs_getfsmap_helper (cur->bc_tp, info, rec, rec_daddr,0 ); }/* Transform a bnobt irec into a fsmap */
@@ -400,7 +409,7 @@ xfs_getfsmap_datadev_bnobt_helper( irec.rm_offset =0 ; irec.rm_flags =0 ; -return xfs_getfsmap_helper (cur->bc_tp, info, &irec, rec_daddr); +return xfs_getfsmap_helper (cur->bc_tp, info, &irec, rec_daddr,0 ); }/* Set rmap flags based on the getfsmap flags */
@@ -427,9 +436,13 @@ xfs_getfsmap_logdev( {struct xfs_mount *mp = tp->t_mountp;struct xfs_rmap_irec rmap; +xfs_daddr_t rec_daddr, len_daddr; +xfs_fsblock_t start_fsb;int error;/* Set up search keys */ + start_fsb =XFS_BB_TO_FSBT (mp, + keys[0 ].fmr_physical + keys[0 ].fmr_length); info->low.rm_startblock =XFS_BB_TO_FSBT (mp, keys[0 ].fmr_physical); info->low.rm_offset =XFS_BB_TO_FSBT (mp, keys[0 ].fmr_offset); error =xfs_fsmap_owner_to_rmap (&info->low, keys);
@@ -438,6 +451,10 @@ xfs_getfsmap_logdev( info->low.rm_blockcount =0 ;xfs_getfsmap_set_irec_flags (&info->low, &keys[0 ]); +/* Adjust the low key if we are continuing from where we left off. */ +if (keys[0 ].fmr_length >0 ) + info->low_daddr =XFS_FSB_TO_BB (mp, start_fsb); + error =xfs_fsmap_owner_to_rmap (&info->high, keys +1 );if (error)return error;
@@ -451,7 +468,7 @@ xfs_getfsmap_logdev(trace_xfs_fsmap_low_key (mp, info->dev,NULLAGNUMBER , &info->low);trace_xfs_fsmap_high_key (mp, info->dev,NULLAGNUMBER , &info->high); -if (keys[0 ].fmr_physical >0 ) +if (start_fsb >0 )return 0 ;/* Fabricate an rmap entry for the external log device. */
@@ -461,7 +478,9 @@ xfs_getfsmap_logdev( rmap.rm_offset =0 ; rmap.rm_flags =0 ; -return xfs_getfsmap_helper (tp, info, &rmap,0 ); + rec_daddr =XFS_FSB_TO_BB (mp, rmap.rm_startblock); + len_daddr =XFS_FSB_TO_BB (mp, rmap.rm_blockcount); +return xfs_getfsmap_helper (tp, info, &rmap, rec_daddr, len_daddr); }#ifdef CONFIG_XFS_RT
@@ -475,16 +494,22 @@ xfs_getfsmap_rtdev_rtbitmap_helper( {struct xfs_getfsmap_info *info = priv;struct xfs_rmap_irec irec; -xfs_daddr_t rec_daddr; +xfs_rtblock_t rtbno; +xfs_daddr_t rec_daddr, len_daddr; + + rtbno = rec->ar_startext * mp->m_sb.sb_rextsize; + rec_daddr =XFS_FSB_TO_BB (mp, rtbno); + irec.rm_startblock = rtbno; + + rtbno = rec->ar_extcount * mp->m_sb.sb_rextsize; + len_daddr =XFS_FSB_TO_BB (mp, rtbno); + irec.rm_blockcount = rtbno; - irec.rm_startblock = rec->ar_startext * mp->m_sb.sb_rextsize; - rec_daddr =XFS_FSB_TO_BB (mp, irec.rm_startblock); - irec.rm_blockcount = rec->ar_extcount * mp->m_sb.sb_rextsize; irec.rm_owner =XFS_RMAP_OWN_NULL ;/* "free" */ irec.rm_offset =0 ; irec.rm_flags =0 ; -return xfs_getfsmap_helper (tp, info, &irec, rec_daddr); +return xfs_getfsmap_helper (tp, info, &irec, rec_daddr, len_daddr); }/* Execute a getfsmap query against the realtime device. */
@@ -493,23 +518,26 @@ __xfs_getfsmap_rtdev(struct xfs_trans *tp, const struct xfs_fsmap *keys, int (*query_fn)(struct xfs_trans *, -struct xfs_getfsmap_info *), +struct xfs_getfsmap_info *, +xfs_rtblock_t start_rtb, +xfs_rtblock_t end_rtb), struct xfs_getfsmap_info *info) { struct xfs_mount *mp = tp->t_mountp; -xfs_fsblock_t start_fsb; -xfs_fsblock_t end_fsb; +xfs_rtblock_t start_rtb; +xfs_rtblock_t end_rtb;uint64_t eofs;int error =0 ; eofs =XFS_FSB_TO_BB (mp, mp->m_sb.sb_rblocks);if (keys[0 ].fmr_physical >= eofs)return 0 ; - start_fsb =XFS_BB_TO_FSBT (mp, keys[0 ].fmr_physical); - end_fsb =XFS_BB_TO_FSB (mp,min (eofs -1 , keys[1 ].fmr_physical)); + start_rtb =XFS_BB_TO_FSBT (mp, + keys[0 ].fmr_physical + keys[0 ].fmr_length); + end_rtb =XFS_BB_TO_FSB (mp,min (eofs -1 , keys[1 ].fmr_physical));/* Set up search keys */ - info->low.rm_startblock = start_fsb; + info->low.rm_startblock = start_rtb; error =xfs_fsmap_owner_to_rmap (&info->low, &keys[0 ]);if (error)return error;
@@ -517,7 +545,14 @@ __xfs_getfsmap_rtdev( info->low.rm_blockcount =0 ;xfs_getfsmap_set_irec_flags (&info->low, &keys[0 ]); - info->high.rm_startblock = end_fsb; +/* Adjust the low key if we are continuing from where we left off. */ +if (keys[0 ].fmr_length >0 ) { + info->low_daddr =XFS_FSB_TO_BB (mp, start_rtb); +if (info->low_daddr >= eofs) +return 0 ; + } + + info->high.rm_startblock = end_rtb; error =xfs_fsmap_owner_to_rmap (&info->high, &keys[1 ]);if (error)return error;
@@ -528,14 +563,16 @@ __xfs_getfsmap_rtdev(trace_xfs_fsmap_low_key (mp, info->dev,NULLAGNUMBER , &info->low);trace_xfs_fsmap_high_key (mp, info->dev,NULLAGNUMBER , &info->high); -return query_fn (tp, info); +return query_fn (tp, info, start_rtb, end_rtb); }/* Actually query the realtime bitmap. */ STATIC intxfs_getfsmap_rtdev_rtbitmap_query (struct xfs_trans *tp, -struct xfs_getfsmap_info *info) +struct xfs_getfsmap_info *info, +xfs_rtblock_t start_rtb, +xfs_rtblock_t end_rtb) {struct xfs_rtalloc_rec alow = {0 };struct xfs_rtalloc_rec ahigh = {0 };
@@ -548,8 +585,8 @@ xfs_getfsmap_rtdev_rtbitmap_query(* Set up query parameters to return free rtextents covering the range * we want. */ - alow.ar_startext = info->low.rm_startblock; - ahigh.ar_startext = info->high.rm_startblock; + alow.ar_startext = start_rtb; + ahigh.ar_startext = end_rtb;do_div (alow.ar_startext, mp->m_sb.sb_rextsize);if (do_div (ahigh.ar_startext, mp->m_sb.sb_rextsize)) ahigh.ar_startext++;
@@ -988,6 +1025,7 @@ xfs_getfsmap( info.dev = handlers[i].dev; info.last = false; info.pag =NULL ; + info.low_daddr =-1ULL ; info.low.rm_blockcount =0 ; error = handlers[i].fn (tp, dkeys, &info);if (error)
PATCH 3/7 xfs: fix getfsmap reporting past the last rt extent
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The realtime section ends at the last rt extent. If the user configures the rt geometry with an extent size that is not an integer factor of the number of rt blocks, it's possible for there to be rt blocks past the end of the last rt extent. These tail blocks cannot ever be allocated and will cause corruption reports if the last extent coincides with the end of an rt bitmap block, so do not report consider them for the GETFSMAP output.
--- fs/xfs/xfs_fsmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_fsmap.c +1 -1
@@ -529,7 +529,7 @@ __xfs_getfsmap_rtdev(uint64_t eofs;int error =0 ; - eofs =XFS_FSB_TO_BB (mp, mp->m_sb.sb_rblocks); + eofs =XFS_FSB_TO_BB (mp, mp->m_sb.sb_rextents * mp->m_sb.sb_rextsize);if (keys[0 ].fmr_physical >= eofs)return 0 ; start_rtb = XFS_BB_TO_FSBT(mp,
PATCH 4/7 xfs: clean up the rtbitmap fsmap backend
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The rtbitmap fsmap backend doesn't query the rmapbt, so it's wasteful to spend time initializing the rmap_irec objects. Worse yet, the logic to query the rtbitmap is spread across three separate functions, which is unnecessarily difficult to follow.
Compute the start rtextent that we want from keys[0] directly and combine the functions to avoid passing parameters around everywhere, and consolidate all the logic into a single function. At one point many years ago I intended to use __xfs_getfsmap_rtdev as the launching point for realtime rmapbt queries, but this hasn't been the case for a long time.
--- fs/xfs/xfs_fsmap.c | 62 ++++++++-------------------------------------------- fs/xfs/xfs_trace.h | 25 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 53 deletions(-)
fs/xfs/xfs_fsmap.c +9 -53
@@ -512,22 +512,21 @@ xfs_getfsmap_rtdev_rtbitmap_helper(return xfs_getfsmap_helper (tp, info, &irec, rec_daddr, len_daddr); } -/* Execute a getfsmap query against the realtime device. */ +/* Execute a getfsmap query against the realtime device rtbitmap. */ STATIC int -__xfs_getfsmap_rtdev ( +xfs_getfsmap_rtdev_rtbitmap (struct xfs_trans *tp,const struct xfs_fsmap *keys, -int (*query_fn)(struct xfs_trans *, -struct xfs_getfsmap_info *, -xfs_rtblock_t start_rtb, -xfs_rtblock_t end_rtb),struct xfs_getfsmap_info *info) { + +struct xfs_rtalloc_rec alow = {0 }; +struct xfs_rtalloc_rec ahigh = {0 };struct xfs_mount *mp = tp->t_mountp;xfs_rtblock_t start_rtb;xfs_rtblock_t end_rtb;uint64_t eofs; -int error =0 ; +int error; eofs =XFS_FSB_TO_BB (mp, mp->m_sb.sb_rextents * mp->m_sb.sb_rextsize);if (keys[0 ].fmr_physical >= eofs)
@@ -536,14 +535,7 @@ __xfs_getfsmap_rtdev( keys[0].fmr_physical + keys[0].fmr_length); end_rtb =XFS_BB_TO_FSB (mp,min (eofs -1 , keys[1 ].fmr_physical)); -/* Set up search keys */ - info->low.rm_startblock = start_rtb; - error =xfs_fsmap_owner_to_rmap (&info->low, &keys[0 ]); -if (error) -return error; - info->low.rm_offset =XFS_BB_TO_FSBT (mp, keys[0 ].fmr_offset); - info->low.rm_blockcount =0 ; -xfs_getfsmap_set_irec_flags (&info->low, &keys[0 ]); + info->missing_owner =XFS_FMR_OWN_UNKNOWN ;/* Adjust the low key if we are continuing from where we left off. */ if (keys[0 ].fmr_length >0 ) {
@@ -552,32 +544,8 @@ __xfs_getfsmap_rtdev(return 0 ; } - info->high.rm_startblock = end_rtb; - error =xfs_fsmap_owner_to_rmap (&info->high, &keys[1 ]); -if (error) -return error; - info->high.rm_offset =XFS_BB_TO_FSBT (mp, keys[1 ].fmr_offset); - info->high.rm_blockcount =0 ; -xfs_getfsmap_set_irec_flags (&info->high, &keys[1 ]); - -trace_xfs_fsmap_low_key (mp, info->dev,NULLAGNUMBER , &info->low); -trace_xfs_fsmap_high_key (mp, info->dev,NULLAGNUMBER , &info->high); - -return query_fn (tp, info, start_rtb, end_rtb); -} - -/* Actually query the realtime bitmap. */ -STATIC int -xfs_getfsmap_rtdev_rtbitmap_query ( -struct xfs_trans *tp, -struct xfs_getfsmap_info *info, -xfs_rtblock_t start_rtb, -xfs_rtblock_t end_rtb) -{ -struct xfs_rtalloc_rec alow = {0 }; -struct xfs_rtalloc_rec ahigh = {0 }; -struct xfs_mount *mp = tp->t_mountp; -int error; +trace_xfs_fsmap_low_key_linear (mp, info->dev, start_rtb); +trace_xfs_fsmap_high_key_linear (mp, info->dev, end_rtb);xfs_ilock (mp->m_rbmip,XFS_ILOCK_SHARED |XFS_ILOCK_RTBITMAP );
@@ -609,18 +577,6 @@ xfs_getfsmap_rtdev_rtbitmap_query(xfs_iunlock (mp->m_rbmip,XFS_ILOCK_SHARED |XFS_ILOCK_RTBITMAP ); return error; } - -/* Execute a getfsmap query against the realtime device rtbitmap. */ -STATIC int -xfs_getfsmap_rtdev_rtbitmap ( -struct xfs_trans *tp, -const struct xfs_fsmap *keys, -struct xfs_getfsmap_info *info) -{ - info->missing_owner =XFS_FMR_OWN_UNKNOWN ; -return __xfs_getfsmap_rtdev (tp, keys, xfs_getfsmap_rtdev_rtbitmap_query, - info); -}#endif /* CONFIG_XFS_RT */ /* Execute a getfsmap query against the regular data device. */
fs/xfs/xfs_trace.h +25 -0
@@ -3623,6 +3623,31 @@ DEFINE_FSMAP_EVENT(xfs_fsmap_low_key);DEFINE_FSMAP_EVENT (xfs_fsmap_high_key);DEFINE_FSMAP_EVENT (xfs_fsmap_mapping); +DECLARE_EVENT_CLASS (xfs_fsmap_linear_class, + TP_PROTO(struct xfs_mount *mp, u32 keydev, uint64_t bno), +TP_ARGS (mp, keydev, bno), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(dev_t, keydev) +__field (xfs_fsblock_t, bno) + ), +TP_fast_assign ( + __entry->dev = mp->m_super->s_dev; + __entry->keydev = new_decode_dev(keydev); + __entry->bno = bno; + ), +TP_printk ("dev %d:%d keydev %d:%d bno 0x%llx" , +MAJOR (__entry->dev),MINOR (__entry->dev), +MAJOR (__entry->keydev),MINOR (__entry->keydev), + __entry->bno) +) +#define DEFINE_FSMAP_LINEAR_EVENT (name) \ +DEFINE_EVENT(xfs_fsmap_linear_class, name, \ + TP_PROTO(struct xfs_mount *mp, u32 keydev, uint64_t bno), \ + TP_ARGS(mp, keydev, bno)) +DEFINE_FSMAP_LINEAR_EVENT (xfs_fsmap_low_key_linear); +DEFINE_FSMAP_LINEAR_EVENT (xfs_fsmap_high_key_linear); + DECLARE_EVENT_CLASS(xfs_getfsmap_class, TP_PROTO(struct xfs_mount *mp, struct xfs_fsmap *fsmap), TP_ARGS(mp, fsmap),
PATCH 5/7 xfs: fix logdev fsmap query result filtering
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The external log device fsmap backend doesn't have an rmapbt to query, so it's wasteful to spend time initializing the rmap_irec objects. Worse yet, the log could (someday) be longer than 2^32 fsblocks, so using the rmap irec structure will result in integer overflows.
Fix this mess by computing the start address that we want from keys[0] directly, and use the daddr-based record filtering algorithm that we also use for rtbitmap queries.
--- fs/xfs/xfs_fsmap.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-)
fs/xfs/xfs_fsmap.c +8 -22
@@ -437,36 +437,22 @@ xfs_getfsmap_logdev(struct xfs_mount *mp = tp->t_mountp;struct xfs_rmap_irec rmap;xfs_daddr_t rec_daddr, len_daddr; -xfs_fsblock_t start_fsb; -int error; +xfs_fsblock_t start_fsb, end_fsb; +uint64_t eofs; -/* Set up search keys */ + eofs =XFS_FSB_TO_BB (mp, mp->m_sb.sb_logblocks); +if (keys[0 ].fmr_physical >= eofs) +return 0 ; start_fsb =XFS_BB_TO_FSBT (mp, keys[0 ].fmr_physical + keys[0 ].fmr_length); - info->low.rm_startblock =XFS_BB_TO_FSBT (mp, keys[0 ].fmr_physical); - info->low.rm_offset =XFS_BB_TO_FSBT (mp, keys[0 ].fmr_offset); - error =xfs_fsmap_owner_to_rmap (&info->low, keys); -if (error) -return error; - info->low.rm_blockcount =0 ; -xfs_getfsmap_set_irec_flags (&info->low, &keys[0 ]); + end_fsb =XFS_BB_TO_FSB (mp,min (eofs -1 , keys[1 ].fmr_physical));/* Adjust the low key if we are continuing from where we left off. */ if (keys[0 ].fmr_length >0 ) info->low_daddr =XFS_FSB_TO_BB (mp, start_fsb); - error =xfs_fsmap_owner_to_rmap (&info->high, keys +1 ); -if (error) -return error; - info->high.rm_startblock =-1U ; - info->high.rm_owner =ULLONG_MAX ; - info->high.rm_offset =ULLONG_MAX ; - info->high.rm_blockcount =0 ; - info->high.rm_flags =XFS_RMAP_KEY_FLAGS |XFS_RMAP_REC_FLAGS ; - info->missing_owner =XFS_FMR_OWN_FREE ; - -trace_xfs_fsmap_low_key (mp, info->dev,NULLAGNUMBER , &info->low); -trace_xfs_fsmap_high_key (mp, info->dev,NULLAGNUMBER , &info->high); +trace_xfs_fsmap_low_key_linear (mp, info->dev, start_fsb); +trace_xfs_fsmap_high_key_linear (mp, info->dev, end_fsb);if (start_fsb >0 )return 0 ;
PATCH 6/7 xfs: validate fsmap offsets specified in the query keys
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Improve the validation of the fsmap offset fields in the query keys and move the validation to the top of the function now that we have pushed the low key adjustment code downwards.
Also fix some indenting issues that aren't worth a separate patch.
--- fs/xfs/xfs_fsmap.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
fs/xfs/xfs_fsmap.c +19 -11
@@ -802,6 +802,19 @@ xfs_getfsmap_check_keys( struct xfs_fsmap *low_key, struct xfs_fsmap *high_key) { +if (low_key->fmr_flags & (FMR_OF_SPECIAL_OWNER |FMR_OF_EXTENT_MAP )) { +if (low_key->fmr_offset) +return false; + } +if (high_key->fmr_flags !=-1U && + (high_key->fmr_flags & (FMR_OF_SPECIAL_OWNER | +FMR_OF_EXTENT_MAP ))) { +if (high_key->fmr_offset && high_key->fmr_offset !=-1ULL ) +return false; + } +if (high_key->fmr_length && high_key->fmr_length !=-1ULL ) +return false; +if (low_key->fmr_device > high_key->fmr_device)return false;if (low_key->fmr_device < high_key->fmr_device)
@@ -845,15 +858,15 @@ xfs_getfsmap_check_keys(* ---------------- * There are multiple levels of keys and counters at work here: * xfs_fsmap_head.fmh_keys -- low and high fsmap keys passed in; -* these reflect fs-wide sector addrs. +* these reflect fs-wide sector addrs. * dkeys -- fmh_keys used to query each device; -* these are fmh_keys but w/ the low key -* bumped up by fmr_length. +* these are fmh_keys but w/ the low key +* bumped up by fmr_length. * xfs_getfsmap_info.next_daddr -- next disk addr we expect to see; this * is how we detect gaps in the fsmap records and report them. * xfs_getfsmap_info.low/high -- per-AG low/high keys computed from -* dkeys; used to query the metadata. +* dkeys; used to query the metadata. */ int xfs_getfsmap(
@@ -874,6 +887,8 @@ xfs_getfsmap(if (!xfs_getfsmap_is_valid_device (mp, &head->fmh_keys[0 ]) || !xfs_getfsmap_is_valid_device (mp, &head->fmh_keys[1 ]))return -EINVAL ; +if (!xfs_getfsmap_check_keys (&head->fmh_keys[0 ], &head->fmh_keys[1 ])) +return -EINVAL ; use_rmap =xfs_has_rmapbt (mp) &&has_capability_noaudit (current,CAP_SYS_ADMIN );
@@ -919,15 +934,8 @@ xfs_getfsmap(* other mapping for the same physical block range. */ dkeys[0 ] = head->fmh_keys[0 ]; -if (dkeys[0 ].fmr_flags & (FMR_OF_SPECIAL_OWNER |FMR_OF_EXTENT_MAP )) { -if (dkeys[0 ].fmr_offset) -return -EINVAL ; - }memset (&dkeys[1 ],0xFF ,sizeof (struct xfs_fsmap )); -if (!xfs_getfsmap_check_keys (dkeys, &head->fmh_keys[1 ])) -return -EINVAL ; - info.next_daddr = head->fmh_keys[0 ].fmr_physical + head->fmh_keys[0 ].fmr_length; info.fsmap_recs = fsmap_recs;
PATCH 7/7 xfs: fix xfs_btree_query_range callers to initialize btree rec fully
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Use struct initializers to ensure that the xfs_btree_irecs passed into the query_range function are completely initialized. No functional changes, just closing some sloppy hygiene.
--- fs/xfs/libxfs/xfs_alloc.c | 10 +++------- fs/xfs/libxfs/xfs_refcount.c | 13 +++++++------ fs/xfs/libxfs/xfs_rmap.c | 10 +++------- 3 files changed, 13 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +3 -7
@@ -3717,15 +3717,11 @@ xfs_alloc_query_range(xfs_alloc_query_range_fn fn, void *priv) { - union xfs_btree_irec low_brec; -union xfs_btree_irec high_brec; -struct xfs_alloc_query_range_info query; + union xfs_btree_irec low_brec = { .a = *low_rec }; +union xfs_btree_irec high_brec = { .a = *high_rec }; +struct xfs_alloc_query_range_info query = { .priv = priv, .fn = fn };ASSERT (cur->bc_btnum ==XFS_BTNUM_BNO ); - low_brec.a = *low_rec; - high_brec.a = *high_rec; - query.priv = priv; - query.fn = fn;return xfs_btree_query_range (cur, &low_brec, &high_brec, xfs_alloc_query_range_helper, &query); }
fs/xfs/libxfs/xfs_refcount.c +7 -6
@@ -1915,8 +1915,13 @@ xfs_refcount_recover_cow_leftovers(struct xfs_buf *agbp;struct xfs_refcount_recovery *rr, *n;struct list_head debris; -union xfs_btree_irec low; -union xfs_btree_irec high; +union xfs_btree_irec low = { + .rc.rc_domain =XFS_REFC_DOMAIN_COW , + }; +union xfs_btree_irec high = { + .rc.rc_domain =XFS_REFC_DOMAIN_COW , + .rc.rc_startblock =-1U , + };xfs_fsblock_t fsb;int error;
@@ -1947,10 +1952,6 @@ xfs_refcount_recover_cow_leftovers( cur =xfs_refcountbt_init_cursor (mp, tp, agbp, pag);/* Find all the leftover CoW staging extents. */ -memset (&low,0 ,sizeof (low)); -memset (&high,0 ,sizeof (high)); - low.rc.rc_domain = high.rc.rc_domain =XFS_REFC_DOMAIN_COW ; - high.rc.rc_startblock =-1U ; error =xfs_btree_query_range (cur, &low, &high, xfs_refcount_recover_extent, &debris);xfs_btree_del_cursor (cur, error);
fs/xfs/libxfs/xfs_rmap.c +3 -7
@@ -2389,14 +2389,10 @@ xfs_rmap_query_range(xfs_rmap_query_range_fn fn, void *priv) { - union xfs_btree_irec low_brec; -union xfs_btree_irec high_brec; -struct xfs_rmap_query_range_info query; + union xfs_btree_irec low_brec = { .r = *low_rec }; +union xfs_btree_irec high_brec = { .r = *high_rec }; +struct xfs_rmap_query_range_info query = { .priv = priv, .fn = fn }; - low_brec.r = *low_rec; - high_brec.r = *high_rec; - query.priv = priv; - query.fn = fn;return xfs_btree_query_range (cur, &low_brec, &high_brec, xfs_rmap_query_range_helper, &query); }
Re: [PATCHSET 0/7] xfs: fix ranged queries and integer overflows in GETFSMAP
In reply to Darrick J. WongPing? Even if it's too late for 6.5, can we at least get this bug fix series reviewed?
--D
Quoted 49 lines · Darrick J. Wong
Hi all,
As part of merging the parent pointers patchset into my development branch, I noticed a few problems with the GETFSMAP implementation for XFS. The biggest problem is that ranged queries don't work properly if the query interval is exactly within a single record. It turns out that I didn't implement the record filtering quite right -- for the first call into the btree code, we want to find any rmap that overlaps with the range specified, but for subsequent calls, we only want rmaps that come after the low key of the query. This can be fixed by tweaking the filtering logic and pushing the key handling into the individual backend implementations.
The second problem I noticed is that there are integer overflows in the rtbitmap and external log handlers. This is the result of a poor decision on my part to use the incore rmap records for storing the query ranges; this only works for the rmap code, which is smart enough to iterate AGs. This breaks down spectacularly if someone tries to query high block offsets in either the rt volume or the log device. I fixed that by introducing a second filtering implementation based entirely on daddrs.
The third problem was minor by comparison -- the rt volume cannot ever use rtblocks beyond the end of the last rtextent, so it makes no sense for GETFSMAP to try to query those areas.
Having done that, add a few more patches to clean up some messes.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=getfsmap-fixesxfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=getfsmap-fixes--- fs/xfs/libxfs/xfs_alloc.c | 10 -- fs/xfs/libxfs/xfs_refcount.c | 13 +- fs/xfs/libxfs/xfs_rmap.c | 10 -- fs/xfs/xfs_fsmap.c | 261 ++++++++++++++++++++++-------------------- fs/xfs/xfs_trace.h | 25 ++++ 5 files changed, 177 insertions(+), 142 deletions(-)
Re: [PATCHSET 0/7] xfs: fix ranged queries and integer overflows in GETFSMAP
Quoted 2 lines · Darrick J. Wong
Ping? Even if it's too late for 6.5, can we at least get this bug fix series reviewed?
I haven't even had time to read the description of this mega patchset, so I had no idea there were bug fixes in it. Normally you send them separately, so it's obvious they are bug fixes that need immediate attention.
I'll put it on my list, but I have no idea right now when I'll get to it....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCHSET 0/7] xfs: fix ranged queries and integer overflows in GETFSMAP
In reply to Darrick J. WongQuoted 41 lines · Darrick J. Wong
Hi all,
As part of merging the parent pointers patchset into my development branch, I noticed a few problems with the GETFSMAP implementation for XFS. The biggest problem is that ranged queries don't work properly if the query interval is exactly within a single record. It turns out that I didn't implement the record filtering quite right -- for the first call into the btree code, we want to find any rmap that overlaps with the range specified, but for subsequent calls, we only want rmaps that come after the low key of the query. This can be fixed by tweaking the filtering logic and pushing the key handling into the individual backend implementations.
The second problem I noticed is that there are integer overflows in the rtbitmap and external log handlers. This is the result of a poor decision on my part to use the incore rmap records for storing the query ranges; this only works for the rmap code, which is smart enough to iterate AGs. This breaks down spectacularly if someone tries to query high block offsets in either the rt volume or the log device. I fixed that by introducing a second filtering implementation based entirely on daddrs.
The third problem was minor by comparison -- the rt volume cannot ever use rtblocks beyond the end of the last rtextent, so it makes no sense for GETFSMAP to try to query those areas.
Having done that, add a few more patches to clean up some messes.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=getfsmap-fixesxfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=getfsmap-fixes
Quoted 7 lines
--- fs/xfs/libxfs/xfs_alloc.c | 10 -- fs/xfs/libxfs/xfs_refcount.c | 13 +- fs/xfs/libxfs/xfs_rmap.c | 10 -- fs/xfs/xfs_fsmap.c | 261 ++++++++++++++++++++++-------------------- fs/xfs/xfs_trace.h | 25 ++++ 5 files changed, 177 insertions(+), 142 deletions(-)
Changes look sensible, but I know my limits: I'm not going to find off-by-one problems in this code during review.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCHSET 0/7] xfs: fix ranged queries and integer overflows in GETFSMAP
Quoted 50 lines · Dave Chinner
Quoted 41 lines · Darrick J. Wong
Hi all,
As part of merging the parent pointers patchset into my development branch, I noticed a few problems with the GETFSMAP implementation for XFS. The biggest problem is that ranged queries don't work properly if the query interval is exactly within a single record. It turns out that I didn't implement the record filtering quite right -- for the first call into the btree code, we want to find any rmap that overlaps with the range specified, but for subsequent calls, we only want rmaps that come after the low key of the query. This can be fixed by tweaking the filtering logic and pushing the key handling into the individual backend implementations.
The second problem I noticed is that there are integer overflows in the rtbitmap and external log handlers. This is the result of a poor decision on my part to use the incore rmap records for storing the query ranges; this only works for the rmap code, which is smart enough to iterate AGs. This breaks down spectacularly if someone tries to query high block offsets in either the rt volume or the log device. I fixed that by introducing a second filtering implementation based entirely on daddrs.
The third problem was minor by comparison -- the rt volume cannot ever use rtblocks beyond the end of the last rtextent, so it makes no sense for GETFSMAP to try to query those areas.
Having done that, add a few more patches to clean up some messes.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=getfsmap-fixesxfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=getfsmap-fixesQuoted 7 lines
--- fs/xfs/libxfs/xfs_alloc.c | 10 -- fs/xfs/libxfs/xfs_refcount.c | 13 +- fs/xfs/libxfs/xfs_rmap.c | 10 -- fs/xfs/xfs_fsmap.c | 261 ++++++++++++++++++++++-------------------- fs/xfs/xfs_trace.h | 25 ++++ 5 files changed, 177 insertions(+), 142 deletions(-)
Quoted 4 lines
Changes look sensible, but I know my limits: I'm not going to find off-by-one problems in this code during review.
Reviewed-by Dave Chinner <[email protected]>
Oh, heh, thanks for the review!
I guess I'll go spin the for-next bottle again...
--D
Quoted 3 lines
Signature · 2 lines
Dave Chinner [email protected]
cover xfs: fix online repair block reaping
In reply to Darrick J. WongHi all,
These patches fix a few problems that I noticed in the code that deals with old btree blocks after a successful repair.
First, I observed that it is possible for repair to incorrectly invalidate and delete old btree blocks if they were crosslinked. The solution here is to consult the reverse mappings for each block in the extent -- singly owned blocks are invalidated and freed, whereas for crosslinked blocks, we merely drop the incorrect reverse mapping.
A largeish change in this patchset is moving the reaping code to a separate file, because the code are mostly interrelated static functions. For now this also drops the ability to reap file blocks, which will return when we add the bmbt repair functions.
Second, we convert the reap function to use EFIs so that we can commit to freeing as many blocks in as few transactions as we dare. We would like to free as many old blocks as we can in the same transaction that commits the new structure to the ondisk filesystem to minimize the number of blocks that leak if the system crashes before the repair fully completes.
The third change made in this series is to avoid tripping buffer cache assertions if we're merely scanning the buffer cache for buffers to invalidate, and find a non-stale buffer of the wrong length. This is primarily cosmetic, but makes my life easier.
The fourth change restructures the reaping code to try to process as many blocks in one go as possible, to reduce logging traffic.
The last change switches the reaping mechanism to use per-AG bitmaps defined in a previous patchset. This should reduce type confusion when reading the source code.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-reap-fixes
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-reap-fixes
--- fs/xfs/Makefile | 1 fs/xfs/scrub/agheader_repair.c | 75 +++--- fs/xfs/scrub/bitmap.c | 78 ------ fs/xfs/scrub/bitmap.h | 10 - fs/xfs/scrub/reap.c | 489 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/reap.h | 12 + fs/xfs/scrub/repair.c | 366 ++++-------------------------- fs/xfs/scrub/repair.h | 10 - fs/xfs/scrub/trace.h | 72 +++--- fs/xfs/xfs_buf.c | 5 fs/xfs/xfs_buf.h | 10 + 11 files changed, 649 insertions(+), 479 deletions(-) create mode 100644 fs/xfs/scrub/reap.c create mode 100644 fs/xfs/scrub/reap.h
PATCH 1/9 xfs: cull repair code that will never get used
From: Darrick J. Wong <[email protected]>
These two functions date from the era when I thought that we could rebuild btrees by creating an alternate root and adding records one by one. In other words, they predate the btree bulk loader. They're not necessary now, so remove them.
--- fs/xfs/scrub/repair.c | 83 ------------------------------------------------- fs/xfs/scrub/repair.h | 6 ---- fs/xfs/scrub/trace.h | 22 ------------- 3 files changed, 111 deletions(-)
fs/xfs/scrub/repair.c +0 -83
@@ -297,89 +297,6 @@ xrep_calc_ag_resblks(return max (max (bnobt_sz, inobt_sz),max (rmapbt_sz, refcbt_sz)); } -/* Allocate a block in an AG. */ -int -xrep_alloc_ag_block ( -struct xfs_scrub *sc, -const struct xfs_owner_info *oinfo, -xfs_fsblock_t *fsbno, -enum xfs_ag_resv_type resv) -{ -struct xfs_alloc_arg args = {0 }; -xfs_agblock_t bno; -int error; - -switch (resv) { -case XFS_AG_RESV_AGFL : -case XFS_AG_RESV_RMAPBT : - error =xfs_alloc_get_freelist (sc->sa.pag, sc->tp, - sc->sa.agf_bp, &bno,1 ); -if (error) -return error; -if (bno ==NULLAGBLOCK ) -return -ENOSPC ; -xfs_extent_busy_reuse (sc->mp, sc->sa.pag, bno,1 , false); - *fsbno =XFS_AGB_TO_FSB (sc->mp, sc->sa.pag->pag_agno, bno); -if (resv ==XFS_AG_RESV_RMAPBT ) -xfs_ag_resv_rmapbt_alloc (sc->mp, sc->sa.pag->pag_agno); -return 0 ; -default : -break ; - } - - args.tp = sc->tp; - args.mp = sc->mp; - args.pag = sc->sa.pag; - args.oinfo = *oinfo; - args.minlen =1 ; - args.maxlen =1 ; - args.prod =1 ; - args.resv = resv; - - error =xfs_alloc_vextent_this_ag (&args, sc->sa.pag->pag_agno); -if (error) -return error; -if (args.fsbno ==NULLFSBLOCK ) -return -ENOSPC ; -ASSERT (args.len ==1 ); - *fsbno = args.fsbno; - -return 0 ; -} - -/* Initialize a new AG btree root block with zero entries. */ -int -xrep_init_btblock ( -struct xfs_scrub *sc, -xfs_fsblock_t fsb, -struct xfs_buf **bpp, -xfs_btnum_t btnum, -const struct xfs_buf_ops *ops) -{ -struct xfs_trans *tp = sc->tp; -struct xfs_mount *mp = sc->mp; -struct xfs_buf *bp; -int error; - -trace_xrep_init_btblock (mp,XFS_FSB_TO_AGNO (mp, fsb), -XFS_FSB_TO_AGBNO (mp, fsb), btnum); - -ASSERT (XFS_FSB_TO_AGNO (mp, fsb) == sc->sa.pag->pag_agno); - error =xfs_trans_get_buf (tp, mp->m_ddev_targp, -XFS_FSB_TO_DADDR (mp, fsb),XFS_FSB_TO_BB (mp,1 ),0 , - &bp); -if (error) -return error; -xfs_buf_zero (bp,0 ,BBTOB (bp->b_length)); -xfs_btree_init_block (mp, bp, btnum,0 ,0 , sc->sa.pag->pag_agno); -xfs_trans_buf_set_type (tp, bp,XFS_BLFT_BTREE_BUF ); -xfs_trans_log_buf (tp, bp,0 ,BBTOB (bp->b_length) -1 ); - bp->b_ops = ops; - *bpp = bp; - -return 0 ; -} -/* * Reconstructing per-AG Btrees *
fs/xfs/scrub/repair.h +0 -6
@@ -23,12 +23,6 @@ int xrep_roll_ag_trans(struct xfs_scrub *sc);bool xrep_ag_has_space (struct xfs_perag *pag,xfs_extlen_t nr_blocks,enum xfs_ag_resv_type type);xfs_extlen_t xrep_calc_ag_resblks (struct xfs_scrub *sc); -int xrep_alloc_ag_block (struct xfs_scrub *sc, -const struct xfs_owner_info *oinfo,xfs_fsblock_t *fsbno, -enum xfs_ag_resv_type resv); -int xrep_init_btblock (struct xfs_scrub *sc,xfs_fsblock_t fsb, -struct xfs_buf **bpp,xfs_btnum_t btnum, -const struct xfs_buf_ops *ops);struct xbitmap ;struct xagb_bitmap ;
fs/xfs/scrub/trace.h +0 -22
@@ -827,28 +827,6 @@ TRACE_EVENT(xrep_refcount_extent_fn, __entry->refcount) ) -TRACE_EVENT (xrep_init_btblock, - TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, xfs_agblock_t agbno, - xfs_btnum_t btnum), -TP_ARGS (mp, agno, agbno, btnum), -TP_STRUCT__entry ( - __field(dev_t, dev) - __field(xfs_agnumber_t, agno) - __field(xfs_agblock_t, agbno) -__field (uint32_t, btnum) - ), -TP_fast_assign ( - __entry->dev = mp->m_super->s_dev; - __entry->agno = agno; - __entry->agbno = agbno; - __entry->btnum = btnum; - ), -TP_printk ("dev %d:%d agno 0x%x agbno 0x%x btree %s" , -MAJOR (__entry->dev),MINOR (__entry->dev), - __entry->agno, - __entry->agbno, -__print_symbolic (__entry->btnum,XFS_BTNUM_STRINGS )) -) TRACE_EVENT(xrep_findroot_block, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, xfs_agblock_t agbno, uint32_t magic, uint16_t level),
PATCH 2/9 xfs: move the post-repair block reaping code to a separate file
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Reaping blocks after a repair is a complicated affair involving a lot of rmap btree lookups and figuring out if we're going to unmap or free old metadata blocks that might be crosslinked. Eventually, we will need to be able to reap per-AG metadata blocks, bmbt blocks from inode forks, garbage CoW staging extents, and (even later) blocks from btrees rooted in inodes. This results in a lot of reaping code, so we might as well split that off while it's easy.
--- fs/xfs/Makefile | 1 fs/xfs/scrub/agheader_repair.c | 1 fs/xfs/scrub/reap.c | 268 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/reap.h | 13 ++ fs/xfs/scrub/repair.c | 232 ----------------------------------- fs/xfs/scrub/repair.h | 2 6 files changed, 283 insertions(+), 234 deletions(-) create mode 100644 fs/xfs/scrub/reap.c create mode 100644 fs/xfs/scrub/reap.h
fs/xfs/Makefile +1 -0
@@ -173,6 +173,7 @@ xfs-$(CONFIG_XFS_QUOTA) += scrub/quota.o ifeq ($(CONFIG_XFS_ONLINE_REPAIR),y) xfs-y += $(addprefix scrub/, \ agheader_repair.o \ + reap.o \ repair.o \ ) endif
fs/xfs/scrub/agheader_repair.c +1 -0
@@ -26,6 +26,7 @@#include "scrub/trace.h" #include "scrub/repair.h" #include "scrub/bitmap.h" +#include "scrub/reap.h" /* Superblock */
fs/xfs/scrub/reap.c new file +268 -0
268 lines not on this page · raw message
fs/xfs/scrub/reap.h new file +13 -0
@@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2022-2023 Oracle. All Rights Reserved. +* Author: Darrick J. Wong <[email protected]> +*/ +#ifndef __XFS_SCRUB_REAP_H__ +#define __XFS_SCRUB_REAP_H__ + +int xrep_reap_extents (struct xfs_scrub *sc,struct xbitmap *bitmap, +const struct xfs_owner_info *oinfo, +enum xfs_ag_resv_type type); + +#endif /* __XFS_SCRUB_REAP_H__ */
fs/xfs/scrub/repair.c +0 -232
246 lines not on this page · raw message
fs/xfs/scrub/repair.h +0 -2
@@ -29,8 +29,6 @@ struct xagb_bitmap;int xrep_fix_freelist (struct xfs_scrub *sc,bool can_shrink);int xrep_invalidate_blocks (struct xfs_scrub *sc,struct xbitmap *btlist); -int xrep_reap_extents (struct xfs_scrub *sc,struct xbitmap *exlist, -const struct xfs_owner_info *oinfo,enum xfs_ag_resv_type type);struct xrep_find_ag_btree {/* in: rmap owner of the btree we're looking for */
PATCH 3/9 xfs: only invalidate blocks if we're going to free them
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When we're discarding old btree blocks after a repair, only invalidate the buffers for the ones that we're freeing -- if the metadata was crosslinked with another data structure, we don't want to touch it.
--- fs/xfs/scrub/reap.c | 96 +++++++++++++++++++++---------------------------- fs/xfs/scrub/repair.h | 1 - 2 files changed, 42 insertions(+), 55 deletions(-)
fs/xfs/scrub/reap.c +42 -54
@@ -70,54 +70,10 @@* * The caller is responsible for locking the AG headers for the entire rebuild * operation so that nothing else can sneak in and change the AG state while -* we're not looking. We also assume that the caller already invalidated any -* buffers associated with @bitmap. +* we're not looking. We must also invalidate any buffers associated with +* @bitmap. */ -static int -xrep_invalidate_block ( -uint64_t fsbno, -void *priv) -{ -struct xfs_scrub *sc = priv; -struct xfs_buf *bp; -int error; - -/* Skip AG headers and post-EOFS blocks */ -if (!xfs_verify_fsbno (sc->mp, fsbno)) -return 0 ; - - error =xfs_buf_incore (sc->mp->m_ddev_targp, -XFS_FSB_TO_DADDR (sc->mp, fsbno), -XFS_FSB_TO_BB (sc->mp,1 ),XBF_TRYLOCK , &bp); -if (error) -return 0 ; - -xfs_trans_bjoin (sc->tp, bp); -xfs_trans_binval (sc->tp, bp); -return 0 ; -} - -/* -* Invalidate buffers for per-AG btree blocks we're dumping. This function -* is not intended for use with file data repairs; we have bunmapi for that. -*/ -int -xrep_invalidate_blocks ( -struct xfs_scrub *sc, -struct xbitmap *bitmap) -{ -/* -* For each block in each extent, see if there's an incore buffer for -* exactly that block; if so, invalidate it. The buffer cache only -* lets us look for one buffer at a time, so we have to look one block -* at a time. Avoid invalidating AG headers and post-EOFS blocks -* because we never own those; and if we can't TRYLOCK the buffer we -* assume it's owned by someone else. -*/ -return xbitmap_walk_bits (bitmap, xrep_invalidate_block, sc); -} -/* Information about reaping extents after a repair. */ struct xrep_reap_state {struct xfs_scrub *sc;
@@ -127,9 +83,7 @@ struct xrep_reap_state {enum xfs_ag_resv_type resv; }; -/* -* Put a block back on the AGFL. -*/ +/* Put a block back on the AGFL. */ STATIC int xrep_put_freelist( struct xfs_scrub *sc,
@@ -168,6 +122,37 @@ xrep_put_freelist(return 0 ; } +/* Try to invalidate the incore buffer for a block that we're about to free. */ +STATIC void +xrep_block_reap_binval ( +struct xfs_scrub *sc, +xfs_fsblock_t fsbno) +{ +struct xfs_buf *bp =NULL ; +int error; + +/* +* If there's an incore buffer for exactly this block, invalidate it. +* Avoid invalidating AG headers and post-EOFS blocks because we never +* own those. +*/ +if (!xfs_verify_fsbno (sc->mp, fsbno)) +return ; + +/* +* We assume that the lack of any other known owners means that the +* buffer can be locked without risk of deadlocking. +*/ + error =xfs_buf_incore (sc->mp->m_ddev_targp, +XFS_FSB_TO_DADDR (sc->mp, fsbno), +XFS_FSB_TO_BB (sc->mp,1 ),0 , &bp); +if (error) +return ; + +xfs_trans_bjoin (sc->tp, bp); +xfs_trans_binval (sc->tp, bp); +} +/* Dispose of a single block. */ STATIC int xrep_reap_block(
@@ -225,14 +210,17 @@ xrep_reap_block(* blow on writeout, the filesystem will shut down, and the admin gets * to run xfs_repair. */ -if (has_other_rmap) - error =xfs_rmap_free (sc->tp, agf_bp, sc->sa.pag, agbno, -1 , rs->oinfo); -else if (rs->resv ==XFS_AG_RESV_AGFL ) +if (has_other_rmap) { + error =xfs_rmap_free (sc->tp, agf_bp, sc->sa.pag, agbno,1 , + rs->oinfo); + }else if (rs->resv ==XFS_AG_RESV_AGFL ) { +xrep_block_reap_binval (sc, fsbno); error =xrep_put_freelist (sc, agbno); -else + }else { +xrep_block_reap_binval (sc, fsbno); error =xfs_free_extent (sc->tp, sc->sa.pag, agbno,1 , rs->oinfo, rs->resv); + }if (agf_bp != sc->sa.agf_bp)xfs_trans_brelse (sc->tp, agf_bp);if (error)
fs/xfs/scrub/repair.h +0 -1
@@ -28,7 +28,6 @@ struct xbitmap;struct xagb_bitmap ;int xrep_fix_freelist (struct xfs_scrub *sc,bool can_shrink); -int xrep_invalidate_blocks (struct xfs_scrub *sc,struct xbitmap *btlist);struct xrep_find_ag_btree {/* in: rmap owner of the btree we're looking for */
PATCH 4/9 xfs: only allow reaping of per-AG blocks in xrep_reap_extents
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Now that we've refactored btree cursors to require the caller to pass in a perag structure, there are numerous problems in xrep_reap_extents if it's being called to reap extents for an inode metadata repair. We don't have any repair functions that can do that, so drop the support for now.
--- fs/xfs/scrub/reap.c | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-)
fs/xfs/scrub/reap.c +13 -32
@@ -162,40 +162,30 @@ xrep_reap_block(struct xrep_reap_state *rs = priv;struct xfs_scrub *sc = rs->sc;struct xfs_btree_cur *cur; -struct xfs_buf *agf_bp =NULL ; +xfs_agnumber_t agno;xfs_agblock_t agbno;bool has_other_rmap;int error; -ASSERT (sc->ip !=NULL || -XFS_FSB_TO_AGNO (sc->mp, fsbno) == sc->sa.pag->pag_agno); -trace_xrep_dispose_btree_extent (sc->mp, -XFS_FSB_TO_AGNO (sc->mp, fsbno), -XFS_FSB_TO_AGBNO (sc->mp, fsbno),1 ); - + agno =XFS_FSB_TO_AGNO (sc->mp, fsbno); agbno =XFS_FSB_TO_AGBNO (sc->mp, fsbno); -ASSERT (XFS_FSB_TO_AGNO (sc->mp, fsbno) == sc->sa.pag->pag_agno); -/* -* If we are repairing per-inode metadata, we need to read in the AGF -* buffer. Otherwise, we're repairing a per-AG structure, so reuse -* the AGF buffer that the setup functions already grabbed. -*/ -if (sc->ip) { - error =xfs_alloc_read_agf (sc->sa.pag, sc->tp,0 , &agf_bp); -if (error) -return error; - }else { - agf_bp = sc->sa.agf_bp; +trace_xrep_dispose_btree_extent (sc->mp, agno, agbno,1 ); + +/* We don't support reaping file extents yet. */ +if (sc->ip !=NULL || sc->sa.pag->pag_agno != agno) { +ASSERT (0 ); +return -EFSCORRUPTED ; } - cur =xfs_rmapbt_init_cursor (sc->mp, sc->tp, agf_bp, sc->sa.pag); + + cur =xfs_rmapbt_init_cursor (sc->mp, sc->tp, sc->sa.agf_bp, sc->sa.pag);/* Can we find any other rmappings? */ error =xfs_rmap_has_other_keys (cur, agbno,1 , rs->oinfo, &has_other_rmap);xfs_btree_del_cursor (cur, error);if (error) - goto out_free; +return error;/* * If there are other rmappings, this block is cross linked and must
@@ -211,8 +201,8 @@ xrep_reap_block(* to run xfs_repair. */ if (has_other_rmap) { - error =xfs_rmap_free (sc->tp, agf_bp, sc->sa.pag, agbno,1 , - rs->oinfo); + error =xfs_rmap_free (sc->tp, sc->sa.agf_bp, sc->sa.pag, agbno, +1 , rs->oinfo); }else if (rs->resv ==XFS_AG_RESV_AGFL ) {xrep_block_reap_binval (sc, fsbno); error =xrep_put_freelist (sc, agbno);
@@ -221,19 +211,10 @@ xrep_reap_block( error =xfs_free_extent (sc->tp, sc->sa.pag, agbno,1 , rs->oinfo, rs->resv); } -if (agf_bp != sc->sa.agf_bp) -xfs_trans_brelse (sc->tp, agf_bp);if (error)return error; -if (sc->ip) -return xfs_trans_roll_inode (&sc->tp, sc->ip);return xrep_roll_ag_trans (sc); - -out_free: -if (agf_bp != sc->sa.agf_bp) -xfs_trans_brelse (sc->tp, agf_bp); -return error; }/* Dispose of every block of every extent in the bitmap. */
PATCH 5/9 xfs: use deferred frees to reap old btree blocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Use deferred frees (EFIs) to reap the blocks of a btree that we just replaced. This helps us to shrink the window in which those old blocks could be lost due to a system crash, though we try to flush the EFIs every few hundred blocks so that we don't also overflow the transaction reservations during and after we commit the new btree.
--- fs/xfs/scrub/reap.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
fs/xfs/scrub/reap.c +23 -4
@@ -26,6 +26,7 @@#include "xfs_ag_resv.h" #include "xfs_quota.h" #include "xfs_qm.h" +#include "xfs_bmap.h" #include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/trace.h"
@@ -81,6 +82,9 @@ struct xrep_reap_state {/* Reverse mapping owner and metadata reservation type. */ const struct xfs_owner_info *oinfo;enum xfs_ag_resv_type resv; + +/* Number of deferred reaps attached to the current transaction. */ +unsigned int deferred; };/* Put a block back on the AGFL. */
@@ -165,6 +169,7 @@ xrep_reap_block(xfs_agnumber_t agno;xfs_agblock_t agbno;bool has_other_rmap; +bool need_roll = true;int error; agno =XFS_FSB_TO_AGNO (sc->mp, fsbno);
@@ -207,13 +212,22 @@ xrep_reap_block(xrep_block_reap_binval (sc, fsbno); error =xrep_put_freelist (sc, agbno); }else { +/* +* Use deferred frees to get rid of the old btree blocks to try +* to minimize the window in which we could crash and lose the +* old blocks. However, we still need to roll the transaction +* every 100 or so EFIs so that we don't exceed the log +* reservation. +*/ xrep_block_reap_binval (sc, fsbno); - error =xfs_free_extent (sc->tp, sc->sa.pag, agbno,1 , rs->oinfo, - rs->resv); +__xfs_free_extent_later (sc->tp, fsbno,1 , rs->oinfo, true); + rs->deferred++; + need_roll = rs->deferred >100 ; } -if (error) +if (error || !need_roll)return error; + rs->deferred =0 ;return xrep_roll_ag_trans (sc); }
@@ -230,8 +244,13 @@ xrep_reap_extents( .oinfo = oinfo, .resv = type, }; +int error;ASSERT (xfs_has_rmapbt (sc->mp)); -return xbitmap_walk_bits (bitmap, xrep_reap_block, &rs); + error =xbitmap_walk_bits (bitmap, xrep_reap_block, &rs); +if (error || rs.deferred ==0 ) +return error; + +return xrep_roll_ag_trans (sc); }
Re: [PATCH 5/9] xfs: use deferred frees to reap old btree blocks
Quoted 12 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Use deferred frees (EFIs) to reap the blocks of a btree that we just replaced. This helps us to shrink the window in which those old blocks could be lost due to a system crash, though we try to flush the EFIs every few hundred blocks so that we don't also overflow the transaction reservations during and after we commit the new btree.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/reap.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
.....
Quoted 5 lines
fs/xfs/scrub/reap.c +1
-0@@ -207,13 +212,22 @@ xrep_reap_block(xrep_block_reap_binval (sc, fsbno); error =xrep_put_freelist (sc, agbno); }else { +/*
fs/xfs/scrub/reap.c xrep_reap_block( · line 223
Quoted 10 lines
fs/xfs/scrub/reap.c +7
-2+* Use deferred frees to get rid of the old btree blocks to try +* to minimize the window in which we could crash and lose the +* old blocks. However, we still need to roll the transaction +* every 100 or so EFIs so that we don't exceed the log +* reservation. +*/ xrep_block_reap_binval (sc, fsbno); - error =xfs_free_extent (sc->tp, sc->sa.pag, agbno,1 , rs->oinfo, - rs->resv); +__xfs_free_extent_later (sc->tp, fsbno,1 , rs->oinfo, true);
Need to capture the returned error here.
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 5/9] xfs: use deferred frees to reap old btree blocks
Quoted 24 lines · Dave Chinner
Quoted 12 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Use deferred frees (EFIs) to reap the blocks of a btree that we just replaced. This helps us to shrink the window in which those old blocks could be lost due to a system crash, though we try to flush the EFIs every few hundred blocks so that we don't also overflow the transaction reservations during and after we commit the new btree.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/reap.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-).....
Quoted 9 lines
fs/xfs/scrub/reap.c +5
-0@@ -207,13 +212,22 @@ xrep_reap_block(xrep_block_reap_binval (sc, fsbno); error =xrep_put_freelist (sc, agbno); }else { +/* +* Use deferred frees to get rid of the old btree blocks to try +* to minimize the window in which we could crash and lose the +* old blocks. However, we still need to roll the transaction +* every 100 or so EFIs so that we don't exceed the log
Quoted 8 lines
fs/xfs/scrub/reap.c xrep_reap_block( · line 223
Quoted 6 lines
fs/xfs/scrub/reap.c +3
-2+* reservation. +*/ xrep_block_reap_binval (sc, fsbno); - error =xfs_free_extent (sc->tp, sc->sa.pag, agbno,1 , rs->oinfo, - rs->resv); +__xfs_free_extent_later (sc->tp, fsbno,1 , rs->oinfo, true);Need to capture the returned error here.
Yep, that'll be part of v26.
--D
Quoted 4 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 6/9 xfs: rearrange xrep_reap_block to make future code flow easier
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Rearrange the logic inside xrep_reap_block to make it more obvious that crosslinked metadata blocks are handled differently. Add a couple of tracepoints so that we can tell what's going on at the end of a btree rebuild operation.
--- fs/xfs/scrub/agheader_repair.c | 6 +++--- fs/xfs/scrub/reap.c | 19 ++++++++++++++----- fs/xfs/scrub/trace.h | 17 ++++++++--------- 3 files changed, 25 insertions(+), 17 deletions(-)
fs/xfs/scrub/agheader_repair.c +3 -3
@@ -646,13 +646,13 @@ xrep_agfl_fill(xfs_fsblock_t fsbno = start;int error; +trace_xrep_agfl_insert (sc->sa.pag,XFS_FSB_TO_AGBNO (sc->mp, start), + len); +while (fsbno < start + len && af->fl_off < af->flcount) af->agfl_bno[af->fl_off++] =cpu_to_be32 (XFS_FSB_TO_AGBNO (sc->mp, fsbno++)); -trace_xrep_agfl_insert (sc->mp, sc->sa.pag->pag_agno, -XFS_FSB_TO_AGBNO (sc->mp, start), len); - error =xbitmap_set (&af->used_extents, start, fsbno -1 );if (error)return error;
fs/xfs/scrub/reap.c +14 -5
@@ -175,8 +175,6 @@ xrep_reap_block( agno =XFS_FSB_TO_AGNO (sc->mp, fsbno); agbno =XFS_FSB_TO_AGBNO (sc->mp, fsbno); -trace_xrep_dispose_btree_extent (sc->mp, agno, agbno,1 ); -/* We don't support reaping file extents yet. */ if (sc->ip !=NULL || sc->sa.pag->pag_agno != agno) {ASSERT (0 );
@@ -206,10 +204,21 @@ xrep_reap_block(* to run xfs_repair. */ if (has_other_rmap) { +trace_xrep_dispose_unmap_extent (sc->sa.pag, agbno,1 ); + error =xfs_rmap_free (sc->tp, sc->sa.agf_bp, sc->sa.pag, agbno,1 , rs->oinfo); - }else if (rs->resv ==XFS_AG_RESV_AGFL ) { -xrep_block_reap_binval (sc, fsbno); +if (error) +return error; + + goto roll_out; + } + +trace_xrep_dispose_free_extent (sc->sa.pag, agbno,1 ); + +xrep_block_reap_binval (sc, fsbno); + +if (rs->resv ==XFS_AG_RESV_AGFL ) { error =xrep_put_freelist (sc, agbno); }else {/*
@@ -219,7 +228,6 @@ xrep_reap_block(* every 100 or so EFIs so that we don't exceed the log * reservation. */ -xrep_block_reap_binval (sc, fsbno);__xfs_free_extent_later (sc->tp, fsbno,1 , rs->oinfo, true); rs->deferred++; need_roll = rs->deferred >100 ;
@@ -227,6 +235,7 @@ xrep_reap_block(if (error || !need_roll)return error; +roll_out: rs->deferred =0 ;return xrep_roll_ag_trans (sc); }
fs/xfs/scrub/trace.h +8 -9
@@ -729,9 +729,8 @@ TRACE_EVENT(xchk_refcount_incorrect,#if IS_ENABLED (CONFIG_XFS_ONLINE_REPAIR ) DECLARE_EVENT_CLASS(xrep_extent_class, - TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, - xfs_agblock_t agbno, xfs_extlen_t len), - TP_ARGS(mp, agno, agbno, len), + TP_PROTO(struct xfs_perag *pag, xfs_agblock_t agbno, xfs_extlen_t len), + TP_ARGS(pag, agbno, len), TP_STRUCT__entry( __field(dev_t, dev) __field(xfs_agnumber_t, agno)
@@ -739,8 +738,8 @@ DECLARE_EVENT_CLASS(xrep_extent_class,__field (xfs_extlen_t, len) ),TP_fast_assign ( - __entry->dev = mp->m_super->s_dev; - __entry->agno = agno; + __entry->dev = pag->pag_mount->m_super->s_dev; + __entry->agno = pag->pag_agno; __entry->agbno = agbno; __entry->len = len; ),
@@ -752,10 +751,10 @@ DECLARE_EVENT_CLASS(xrep_extent_class, );#define DEFINE_REPAIR_EXTENT_EVENT (name) \ DEFINE_EVENT(xrep_extent_class, name, \ - TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, \ - xfs_agblock_t agbno, xfs_extlen_t len), \ - TP_ARGS(mp, agno, agbno, len)) -DEFINE_REPAIR_EXTENT_EVENT (xrep_dispose_btree_extent); + TP_PROTO(struct xfs_perag *pag, xfs_agblock_t agbno, xfs_extlen_t len), \ + TP_ARGS(pag, agbno, len)) +DEFINE_REPAIR_EXTENT_EVENT (xrep_dispose_unmap_extent); +DEFINE_REPAIR_EXTENT_EVENT (xrep_dispose_free_extent);DEFINE_REPAIR_EXTENT_EVENT (xrep_agfl_insert); DECLARE_EVENT_CLASS(xrep_rmap_class,
PATCH 7/9 xfs: ignore stale buffers when scanning the buffer cache
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
After an online repair, we need to invalidate buffers representing the blocks from the old metadata that we're replacing. It's possible that parts of a tree that were previously cached in memory are no longer accessible due to media failure or other corruption on interior nodes, so repair figures out the old blocks from the reverse mapping data and scans the buffer cache directly.
Unfortunately, the current buffer cache code triggers asserts if the rhashtable lookup finds a non-stale buffer of a different length than the key we searched for. For regular operation this is desirable, but for this repair procedure, we don't care since we're going to forcibly stale the buffer anyway. Add an internal lookup flag to avoid the assert.
--- fs/xfs/scrub/reap.c | 2 +- fs/xfs/xfs_buf.c | 5 ++++- fs/xfs/xfs_buf.h | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-)
fs/xfs/scrub/reap.c +1 -1
@@ -149,7 +149,7 @@ xrep_block_reap_binval(*/ error =xfs_buf_incore (sc->mp->m_ddev_targp,XFS_FSB_TO_DADDR (sc->mp, fsbno), -XFS_FSB_TO_BB (sc->mp,1 ),0 , &bp); +XFS_FSB_TO_BB (sc->mp,1 ),XBF_BCACHE_SCAN , &bp);if (error)return ;
fs/xfs/xfs_buf.c +4 -1
@@ -481,7 +481,8 @@ _xfs_buf_obj_cmp(* reallocating a busy extent. Skip this buffer and * continue searching for an exact match. */ -ASSERT (bp->b_flags &XBF_STALE ); +if (!(map->bm_flags &XBM_IGNORE_LENGTH_MISMATCH )) +ASSERT (bp->b_flags &XBF_STALE );return 1 ; }return 0 ;
@@ -682,6 +683,8 @@ xfs_buf_get_map(int error;int i; +if (flags &XBF_BCACHE_SCAN ) + cmap.bm_flags |=XBM_IGNORE_LENGTH_MISMATCH ;for (i =0 ; i < nmaps; i++) cmap.bm_len += map[i].bm_len;
fs/xfs/xfs_buf.h +10 -0
@@ -44,6 +44,11 @@ struct xfs_buf;#define _XBF_DELWRI_Q (1u << 22)/* buffer on a delwri queue */ /* flags used only as arguments to access routines */ +/* +* We're scanning the buffer cache; do not warn about lookup mismatches. +* Only online repair should use this. +*/ +#define XBF_BCACHE_SCAN (1u << 28)#define XBF_INCORE (1u << 29)/* lookup only, return if found in cache */ #define XBF_TRYLOCK (1u << 30)/* lock requested, but do not wait */ #define XBF_UNMAPPED (1u << 31)/* do not map the buffer */
@@ -67,6 +72,7 @@ typedef unsigned int xfs_buf_flags_t; { _XBF_KMEM, "KMEM" }, \ { _XBF_DELWRI_Q, "DELWRI_Q" }, \/* The following interface flags should never be set */ \ + { XBF_BCACHE_SCAN, "BCACHE_SCAN" }, \ { XBF_INCORE, "INCORE" }, \ { XBF_TRYLOCK, "TRYLOCK" }, \ { XBF_UNMAPPED, "UNMAPPED" }
@@ -114,8 +120,12 @@ typedef struct xfs_buftarg {struct xfs_buf_map {xfs_daddr_t bm_bn;/* block number for I/O */ int bm_len;/* size of I/O */ +unsigned int bm_flags; }; +/* Don't complain about live buffers with the wrong length during lookup. */ +#define XBM_IGNORE_LENGTH_MISMATCH (1U << 0) +#define DEFINE_SINGLE_BUF_MAP (map, blkno, numblk) \ struct xfs_buf_map (map) = { .bm_bn = (blkno), .bm_len = (numblk) };
Re: [PATCH 7/9] xfs: ignore stale buffers when scanning the buffer cache
Quoted 29 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
After an online repair, we need to invalidate buffers representing the blocks from the old metadata that we're replacing. It's possible that parts of a tree that were previously cached in memory are no longer accessible due to media failure or other corruption on interior nodes, so repair figures out the old blocks from the reverse mapping data and scans the buffer cache directly.
Unfortunately, the current buffer cache code triggers asserts if the rhashtable lookup finds a non-stale buffer of a different length than the key we searched for. For regular operation this is desirable, but for this repair procedure, we don't care since we're going to forcibly stale the buffer anyway. Add an internal lookup flag to avoid the assert.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/reap.c | 2 +- fs/xfs/xfs_buf.c | 5 ++++- fs/xfs/xfs_buf.h | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-)fs/xfs/scrub/reap.c +0
-0
fs/xfs/scrub/reap.c xrep_block_reap_binval( · line 152
Quoted 5 lines
fs/xfs/scrub/reap.c +1
-1@@ -149,7 +149,7 @@ xrep_block_reap_binval(*/ error =xfs_buf_incore (sc->mp->m_ddev_targp,XFS_FSB_TO_DADDR (sc->mp, fsbno), -XFS_FSB_TO_BB (sc->mp,1 ),0 , &bp); +XFS_FSB_TO_BB (sc->mp,1 ),XBF_BCACHE_SCAN , &bp);
Can't say I'm a big fan of XBF_BCACHE_SCAN as a name - it tells me nothing about what the incore lookup is actually doing. The actual lookup action that is being performed is "find any match" rather than "find exact match". XBF_ANY_MATCH would be a better name, IMO.
Quoted 8 lines
fs/xfs/scrub/reap.c +0
-0if (error)return ;fs/xfs/xfs_buf.c +0
-0
fs/xfs/xfs_buf.c _xfs_buf_obj_cmp( · line 485
Quoted 6 lines
fs/xfs/xfs_buf.c +2
-1@@ -481,7 +481,8 @@ _xfs_buf_obj_cmp(* reallocating a busy extent. Skip this buffer and * continue searching for an exact match. */ -ASSERT (bp->b_flags &XBF_STALE ); +if (!(map->bm_flags &XBM_IGNORE_LENGTH_MISMATCH )) +ASSERT (bp->b_flags &XBF_STALE );
And this becomes XBM_ANY_MATCH, too.
Quoted 17 lines
fs/xfs/xfs_buf.c +2
-0return 1 ; }return 0 ;@@ -682,6 +683,8 @@ xfs_buf_get_map(int error;int i; +if (flags &XBF_BCACHE_SCAN ) + cmap.bm_flags |=XBM_IGNORE_LENGTH_MISMATCH ;for (i =0 ; i < nmaps; i++) cmap.bm_len += map[i].bm_len;fs/xfs/xfs_buf.h +0
-0
fs/xfs/xfs_buf.h struct xfs_buf; · line 48
Quoted 5 lines
fs/xfs/xfs_buf.h +2
-0@@ -44,6 +44,11 @@ struct xfs_buf;#define _XBF_DELWRI_Q (1u << 22)/* buffer on a delwri queue */ /* flags used only as arguments to access routines */ +/* +* We're scanning the buffer cache; do not warn about lookup mismatches.
The code using the flag isn't doing this - it's trying to invalidate any existing buffer at the location given. It simply wants any buffer at that address to be returned...
Quoted 15 lines
fs/xfs/xfs_buf.h +4
-0+* Only online repair should use this. +*/ +#define XBF_BCACHE_SCAN (1u << 28)#define XBF_INCORE (1u << 29)/* lookup only, return if found in cache */ #define XBF_TRYLOCK (1u << 30)/* lock requested, but do not wait */ #define XBF_UNMAPPED (1u << 31)/* do not map the buffer */ @@ -67,6 +72,7 @@ typedef unsigned int xfs_buf_flags_t; { _XBF_KMEM, "KMEM" }, \ { _XBF_DELWRI_Q, "DELWRI_Q" }, \/* The following interface flags should never be set */ \ + { XBF_BCACHE_SCAN, "BCACHE_SCAN" }, \ { XBF_INCORE, "INCORE" }, \ { XBF_TRYLOCK, "TRYLOCK" }, \ { XBF_UNMAPPED, "UNMAPPED" }
fs/xfs/xfs_buf.h typedef struct xfs_buftarg { · line 127
Quoted 8 lines
fs/xfs/xfs_buf.h +3
-0@@ -114,8 +120,12 @@ typedef struct xfs_buftarg {struct xfs_buf_map {xfs_daddr_t bm_bn;/* block number for I/O */ int bm_len;/* size of I/O */ +unsigned int bm_flags; }; +/* Don't complain about live buffers with the wrong length during lookup. */ +#define XBM_IGNORE_LENGTH_MISMATCH (1U << 0)
Which makes me wonder now: can we have two cached buffers at the same address with different lengths during a repair?
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 7/9] xfs: ignore stale buffers when scanning the buffer cache
Quoted 44 lines · Dave Chinner
Quoted 29 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
After an online repair, we need to invalidate buffers representing the blocks from the old metadata that we're replacing. It's possible that parts of a tree that were previously cached in memory are no longer accessible due to media failure or other corruption on interior nodes, so repair figures out the old blocks from the reverse mapping data and scans the buffer cache directly.
Unfortunately, the current buffer cache code triggers asserts if the rhashtable lookup finds a non-stale buffer of a different length than the key we searched for. For regular operation this is desirable, but for this repair procedure, we don't care since we're going to forcibly stale the buffer anyway. Add an internal lookup flag to avoid the assert.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/reap.c | 2 +- fs/xfs/xfs_buf.c | 5 ++++- fs/xfs/xfs_buf.h | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-)fs/xfs/scrub/reap.c +0
-0fs/xfs/scrub/reap.c xrep_block_reap_binval( · line 152
Quoted 5 lines
fs/xfs/scrub/reap.c +1
-1@@ -149,7 +149,7 @@ xrep_block_reap_binval(*/ error =xfs_buf_incore (sc->mp->m_ddev_targp,XFS_FSB_TO_DADDR (sc->mp, fsbno), -XFS_FSB_TO_BB (sc->mp,1 ),0 , &bp); +XFS_FSB_TO_BB (sc->mp,1 ),XBF_BCACHE_SCAN , &bp);Can't say I'm a big fan of
XBF_BCACHE_SCANas a name - it tells me nothing about what the incore lookup is actually doing. The actual lookup action that is being performed is "find any match" rather than "find exact match".XBF_ANY_MATCHwould be a better name, IMO.Quoted 3 lines
fs/xfs/scrub/reap.c +0
-0if (error)return ;
Quoted 13 lines
fs/xfs/xfs_buf.c _xfs_buf_obj_cmp( · line 485
Quoted 11 lines
fs/xfs/xfs_buf.c +2
-1@@ -481,7 +481,8 @@ _xfs_buf_obj_cmp(* reallocating a busy extent. Skip this buffer and * continue searching for an exact match. */ -ASSERT (bp->b_flags &XBF_STALE ); +if (!(map->bm_flags &XBM_IGNORE_LENGTH_MISMATCH )) +ASSERT (bp->b_flags &XBF_STALE );And this becomes
XBM_ANY_MATCH, too.
Hmmm. I've never come up with a good name for this flag. The caller actually has a *specific* length in mind; it simply doesn't want to trip the assertions on the cached buffers that have a different length but won't be returned by *this* call.
If the buffer cache has bufs for daddr 24 len 8 and daddr len 120, the scan calls xfs_buf_get as follows:
daddr 24 len 1 (nothing)
daddr 24 len 2 (nothing)
...
daddr 24 len 8 (finds the first buffer)
...
daddr 24 len 120 (finds the second buffer)
...
daddr 24 len 132 (nothing)
I don't want the scan to ASSERT 130 times, because that muddles the output so badly that it becomes impossible to find relevant debugging messages among the crap.
Can I change it to XB[FM]_IGNORE_MISMATCHES?
Quoted 48 lines
Quoted 17 lines
fs/xfs/xfs_buf.c +2
-0return 1 ; }return 0 ;@@ -682,6 +683,8 @@ xfs_buf_get_map(int error;int i; +if (flags &XBF_BCACHE_SCAN ) + cmap.bm_flags |=XBM_IGNORE_LENGTH_MISMATCH ;for (i =0 ; i < nmaps; i++) cmap.bm_len += map[i].bm_len;fs/xfs/xfs_buf.h +0
-0fs/xfs/xfs_buf.h struct xfs_buf; · line 48
Quoted 5 lines
fs/xfs/xfs_buf.h +2
-0@@ -44,6 +44,11 @@ struct xfs_buf;#define _XBF_DELWRI_Q (1u << 22)/* buffer on a delwri queue */ /* flags used only as arguments to access routines */ +/* +* We're scanning the buffer cache; do not warn about lookup mismatches. The code using the flag isn't doing this - it's trying to invalidate any existing buffer at the location given. It simply wants any buffer at that address to be returned...
Quoted 21 lines
fs/xfs/xfs_buf.h +5
-0+* Only online repair should use this. +*/ +#define XBF_BCACHE_SCAN (1u << 28)#define XBF_INCORE (1u << 29)/* lookup only, return if found in cache */ #define XBF_TRYLOCK (1u << 30)/* lock requested, but do not wait */ #define XBF_UNMAPPED (1u << 31)/* do not map the buffer */ @@ -67,6 +72,7 @@ typedef unsigned int xfs_buf_flags_t; { _XBF_KMEM, "KMEM" }, \ { _XBF_DELWRI_Q, "DELWRI_Q" }, \/* The following interface flags should never be set */ \ + { XBF_BCACHE_SCAN, "BCACHE_SCAN" }, \ { XBF_INCORE, "INCORE" }, \ { XBF_TRYLOCK, "TRYLOCK" }, \ { XBF_UNMAPPED, "UNMAPPED" }@@ -114,8 +120,12 @@ typedef struct xfs_buftarg {struct xfs_buf_map {xfs_daddr_t bm_bn;/* block number for I/O */ int bm_len;/* size of I/O */ +unsigned int bm_flags; };
Quoted 5 lines
fs/xfs/xfs_buf.h typedef struct xfs_buftarg { · line 127
Quoted 2 lines
fs/xfs/xfs_buf.h +2
-0+/* Don't complain about live buffers with the wrong length during lookup. */ +#define XBM_IGNORE_LENGTH_MISMATCH (1U << 0)Which makes me wonder now: can we have two cached buffers at the same address with different lengths during a repair?
Let's say there's a filesystem with dirblksize 8k. A directory block gets crosslinked with an xattr block. Running the dir and xattr scrubbers each will create a new cached buffer -- an 8k buffer for the dir, and a 4k buffer for the xattr. Let's say that the dir block overwrote the attr block. Then, the xattr read verifier will fail in xfs_trans_buf_read, but that doesn't remove the buffer from the cache.
I want the xattr repair to be able to scan the buffer cache and examine both buffers without throwing assertions all over the place, because that makes it harder to debug repair.
--D
Quoted 6 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 7/9] xfs: ignore stale buffers when scanning the buffer cache
Quoted 76 lines · Darrick J. Wong
Quoted 44 lines · Dave Chinner
Quoted 29 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
After an online repair, we need to invalidate buffers representing the blocks from the old metadata that we're replacing. It's possible that parts of a tree that were previously cached in memory are no longer accessible due to media failure or other corruption on interior nodes, so repair figures out the old blocks from the reverse mapping data and scans the buffer cache directly.
Unfortunately, the current buffer cache code triggers asserts if the rhashtable lookup finds a non-stale buffer of a different length than the key we searched for. For regular operation this is desirable, but for this repair procedure, we don't care since we're going to forcibly stale the buffer anyway. Add an internal lookup flag to avoid the assert.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/reap.c | 2 +- fs/xfs/xfs_buf.c | 5 ++++- fs/xfs/xfs_buf.h | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-)fs/xfs/scrub/reap.c +0
-0fs/xfs/scrub/reap.c xrep_block_reap_binval( · line 152
Quoted 5 lines
fs/xfs/scrub/reap.c +1
-1@@ -149,7 +149,7 @@ xrep_block_reap_binval(*/ error =xfs_buf_incore (sc->mp->m_ddev_targp,XFS_FSB_TO_DADDR (sc->mp, fsbno), -XFS_FSB_TO_BB (sc->mp,1 ),0 , &bp); +XFS_FSB_TO_BB (sc->mp,1 ),XBF_BCACHE_SCAN , &bp);Can't say I'm a big fan of
XBF_BCACHE_SCANas a name - it tells me nothing about what the incore lookup is actually doing. The actual lookup action that is being performed is "find any match" rather than "find exact match".XBF_ANY_MATCHwould be a better name, IMO.Quoted 3 lines
fs/xfs/scrub/reap.c +0
-0if (error)return ;Quoted 13 lines
fs/xfs/xfs_buf.c _xfs_buf_obj_cmp( · line 485
Quoted 11 lines
fs/xfs/xfs_buf.c +2
-1@@ -481,7 +481,8 @@ _xfs_buf_obj_cmp(* reallocating a busy extent. Skip this buffer and * continue searching for an exact match. */ -ASSERT (bp->b_flags &XBF_STALE ); +if (!(map->bm_flags &XBM_IGNORE_LENGTH_MISMATCH )) +ASSERT (bp->b_flags &XBF_STALE );And this becomes
XBM_ANY_MATCH, too.Hmmm. I've never come up with a good name for this flag. The caller actually has a *specific* length in mind; it simply doesn't want to trip the assertions on the cached buffers that have a different length but won't be returned by *this* call.
If the buffer cache has bufs for daddr 24 len 8 and daddr len 120, the scan calls
xfs_buf_getas follows:daddr 24 len 1 (nothing)
daddr 24 len 2 (nothing)
...
daddr 24 len 8 (finds the first buffer)
...
daddr 24 len 120 (finds the second buffer)
...
daddr 24 len 132 (nothing)
Quoted 3 lines
I don't want the scan to ASSERT 130 times, because that muddles the output so badly that it becomes impossible to find relevant debugging messages among the crap.
As I mentioned in the my response to the next patch, this is an O(N^2) brute force search. But how do you get two buffers at the same address into the cache in the first place?
Quoted 54 lines
Quoted 48 lines
Quoted 17 lines
fs/xfs/xfs_buf.c +2
-0return 1 ; }return 0 ;@@ -682,6 +683,8 @@ xfs_buf_get_map(int error;int i; +if (flags &XBF_BCACHE_SCAN ) + cmap.bm_flags |=XBM_IGNORE_LENGTH_MISMATCH ;for (i =0 ; i < nmaps; i++) cmap.bm_len += map[i].bm_len;fs/xfs/xfs_buf.h +0
-0fs/xfs/xfs_buf.h struct xfs_buf; · line 48
Quoted 5 lines
fs/xfs/xfs_buf.h +2
-0@@ -44,6 +44,11 @@ struct xfs_buf;#define _XBF_DELWRI_Q (1u << 22)/* buffer on a delwri queue */ /* flags used only as arguments to access routines */ +/* +* We're scanning the buffer cache; do not warn about lookup mismatches. The code using the flag isn't doing this - it's trying to invalidate any existing buffer at the location given. It simply wants any buffer at that address to be returned...
Quoted 21 lines
fs/xfs/xfs_buf.h +5
-0+* Only online repair should use this. +*/ +#define XBF_BCACHE_SCAN (1u << 28)#define XBF_INCORE (1u << 29)/* lookup only, return if found in cache */ #define XBF_TRYLOCK (1u << 30)/* lock requested, but do not wait */ #define XBF_UNMAPPED (1u << 31)/* do not map the buffer */ @@ -67,6 +72,7 @@ typedef unsigned int xfs_buf_flags_t; { _XBF_KMEM, "KMEM" }, \ { _XBF_DELWRI_Q, "DELWRI_Q" }, \/* The following interface flags should never be set */ \ + { XBF_BCACHE_SCAN, "BCACHE_SCAN" }, \ { XBF_INCORE, "INCORE" }, \ { XBF_TRYLOCK, "TRYLOCK" }, \ { XBF_UNMAPPED, "UNMAPPED" }@@ -114,8 +120,12 @@ typedef struct xfs_buftarg {struct xfs_buf_map {xfs_daddr_t bm_bn;/* block number for I/O */ int bm_len;/* size of I/O */ +unsigned int bm_flags; };Quoted 5 lines
fs/xfs/xfs_buf.h typedef struct xfs_buftarg { · line 127
Quoted 2 lines
fs/xfs/xfs_buf.h +2
-0+/* Don't complain about live buffers with the wrong length during lookup. */ +#define XBM_IGNORE_LENGTH_MISMATCH (1U << 0)Which makes me wonder now: can we have two cached buffers at the same address with different lengths during a repair?
Quoted 4 lines
Let's say there's a filesystem with dirblksize 8k. A directory block gets crosslinked with an xattr block. Running the dir and xattr scrubbers each will create a new cached buffer -- an 8k buffer for the dir, and a 4k buffer for the xattr.
The second one will trip an assert fail because it found a non-stale block of a different length.
This is fundamental property of the buffer cache - there is only supposed to be a single active buffer for a given daddr in the cache at once. Just because the production code doesn't noisily complain about it, doesn't mean it is valid behaviour.
Quoted 3 lines
Let's say that the dir block
overwrote the attr block. Then, the xattr read verifier will fail inxfs_trans_buf_read, but that doesn't remove the buffer from the cache.
It won't even get to the read verifier on a debug kernel - it should be assert failing in the compare function trying to look up the second buffer as it's asking for a different length.
i.e. I don't see how the above "crosslinked with different lengths instantiates two independent buffers" works at all on a debug kernel. It should fail, it is meant to fail, it is meant to tell us something is breaking the fundamental assumption that there is only one active cached buffer for a given daddr at a given time....
What am I missing?
Quoted 3 lines
I want the xattr repair to be able to scan the buffer cache and examine both buffers without throwing assertions all over the place, because that makes it harder to debug repair.
Right, but I don't see anything in the buffer cache changes so far that allow that or make it in any way safe for it to occur.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 7/9] xfs: ignore stale buffers when scanning the buffer cache
Quoted 77 lines · Dave Chinner
Quoted 76 lines · Darrick J. Wong
Quoted 44 lines · Dave Chinner
Quoted 29 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
After an online repair, we need to invalidate buffers representing the blocks from the old metadata that we're replacing. It's possible that parts of a tree that were previously cached in memory are no longer accessible due to media failure or other corruption on interior nodes, so repair figures out the old blocks from the reverse mapping data and scans the buffer cache directly.
Unfortunately, the current buffer cache code triggers asserts if the rhashtable lookup finds a non-stale buffer of a different length than the key we searched for. For regular operation this is desirable, but for this repair procedure, we don't care since we're going to forcibly stale the buffer anyway. Add an internal lookup flag to avoid the assert.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/reap.c | 2 +- fs/xfs/xfs_buf.c | 5 ++++- fs/xfs/xfs_buf.h | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-)fs/xfs/scrub/reap.c +0
-0fs/xfs/scrub/reap.c xrep_block_reap_binval( · line 152
Quoted 5 lines
fs/xfs/scrub/reap.c +1
-1@@ -149,7 +149,7 @@ xrep_block_reap_binval(*/ error =xfs_buf_incore (sc->mp->m_ddev_targp,XFS_FSB_TO_DADDR (sc->mp, fsbno), -XFS_FSB_TO_BB (sc->mp,1 ),0 , &bp); +XFS_FSB_TO_BB (sc->mp,1 ),XBF_BCACHE_SCAN , &bp);Can't say I'm a big fan of
XBF_BCACHE_SCANas a name - it tells me nothing about what the incore lookup is actually doing. The actual lookup action that is being performed is "find any match" rather than "find exact match".XBF_ANY_MATCHwould be a better name, IMO.Quoted 3 lines
fs/xfs/scrub/reap.c +0
-0if (error)return ;Quoted 13 lines
fs/xfs/xfs_buf.c _xfs_buf_obj_cmp( · line 485
Quoted 11 lines
fs/xfs/xfs_buf.c +2
-1@@ -481,7 +481,8 @@ _xfs_buf_obj_cmp(* reallocating a busy extent. Skip this buffer and * continue searching for an exact match. */ -ASSERT (bp->b_flags &XBF_STALE ); +if (!(map->bm_flags &XBM_IGNORE_LENGTH_MISMATCH )) +ASSERT (bp->b_flags &XBF_STALE );And this becomes
XBM_ANY_MATCH, too.Hmmm. I've never come up with a good name for this flag. The caller actually has a *specific* length in mind; it simply doesn't want to trip the assertions on the cached buffers that have a different length but won't be returned by *this* call.
If the buffer cache has bufs for daddr 24 len 8 and daddr len 120, the scan calls
xfs_buf_getas follows:daddr 24 len 1 (nothing)
daddr 24 len 2 (nothing)
...
daddr 24 len 8 (finds the first buffer)
...
daddr 24 len 120 (finds the second buffer)
...
daddr 24 len 132 (nothing)
Quoted 7 lines
Quoted 3 lines
I don't want the scan to ASSERT 130 times, because that muddles the output so badly that it becomes impossible to find relevant debugging messages among the crap.
As I mentioned in the my response to the next patch, this is an O(N^2) brute force search. But how do you get two buffers at the same address into the cache in the first place?
/me smacks forehead, realizes that I totally lead you astray here. What we're scanning for is the case that the buffer cache has two overlapping buffers with *different* daddrs.
(That teaches me to reply to emails while on vacation...)
xreap_agextent_binval is only called if the extent being freed is completely owned by the data structure and is *not* crosslinked with a different structure. We've just rebuilt a data structure that was corrupt in some manner, but the reaper doesn't know the details of that corruption. Therefore, the reaper should invalidate /all/ buffers that might span the extent being freed, no matter how they ended up in the cache. If a deceased data structure thought it was the sole owner of a single fsblock of space starting at fsblock 16, we ought to look for buffers (daddr 128, length 1) (128, 2), ... (128, 8), (129, 1), (129, 2) ... (129, 7) ... (135, 1) and invalidate all of them.
Concrete example:
So let's pretend that we have an xfs with fs blocksize 4k and dir blocksize 8k. Let's suppose the directory's data fork maps fsblock 16, resulting in a buffer (daddr 128, length 16). Let us further suppose the inobt then allocates fsblock 17, resulting in a buffer (daddr 136, length 8). These are crosslinked.
First, we discover the inobt is crosslinked with a directory and decide to rebuild it. We write out the new inobt and go to reap the old blocks. Since fsblock 17 is crosslinked, we simply remove the OWN_INOBT rmap record and leave the buffer.
Aside: Long ago, I tried to make the reaping code invalidate buffers when the space is crosslinked, but I couldn't figure out how to deal with the situation where (say) the bmap btrees of two separate forks think they own the same block. The b_ops will be the same; the buffer cache doesn't know about the owner field in the block header, and there's no way to distinguish the blocks for a data fork bmbt vs. an attr fork bmbt.
Next we discover that the directory is corrupt and decide to rebuild that. The directory is now the only owner, so it can actually free the two fsb of space at startblock 16fsb. Both buffers (128, 16) and (136,
8) are still in the cache, so it needs to invalidate both.
Does all /that/ make sense?
--D
Quoted 96 lines
Quoted 54 lines
Quoted 48 lines
Quoted 17 lines
fs/xfs/xfs_buf.c +2
-0return 1 ; }return 0 ;@@ -682,6 +683,8 @@ xfs_buf_get_map(int error;int i; +if (flags &XBF_BCACHE_SCAN ) + cmap.bm_flags |=XBM_IGNORE_LENGTH_MISMATCH ;for (i =0 ; i < nmaps; i++) cmap.bm_len += map[i].bm_len;fs/xfs/xfs_buf.h +0
-0fs/xfs/xfs_buf.h struct xfs_buf; · line 48
Quoted 5 lines
fs/xfs/xfs_buf.h +2
-0@@ -44,6 +44,11 @@ struct xfs_buf;#define _XBF_DELWRI_Q (1u << 22)/* buffer on a delwri queue */ /* flags used only as arguments to access routines */ +/* +* We're scanning the buffer cache; do not warn about lookup mismatches. The code using the flag isn't doing this - it's trying to invalidate any existing buffer at the location given. It simply wants any buffer at that address to be returned...
Quoted 21 lines
fs/xfs/xfs_buf.h +5
-0+* Only online repair should use this. +*/ +#define XBF_BCACHE_SCAN (1u << 28)#define XBF_INCORE (1u << 29)/* lookup only, return if found in cache */ #define XBF_TRYLOCK (1u << 30)/* lock requested, but do not wait */ #define XBF_UNMAPPED (1u << 31)/* do not map the buffer */ @@ -67,6 +72,7 @@ typedef unsigned int xfs_buf_flags_t; { _XBF_KMEM, "KMEM" }, \ { _XBF_DELWRI_Q, "DELWRI_Q" }, \/* The following interface flags should never be set */ \ + { XBF_BCACHE_SCAN, "BCACHE_SCAN" }, \ { XBF_INCORE, "INCORE" }, \ { XBF_TRYLOCK, "TRYLOCK" }, \ { XBF_UNMAPPED, "UNMAPPED" }@@ -114,8 +120,12 @@ typedef struct xfs_buftarg {struct xfs_buf_map {xfs_daddr_t bm_bn;/* block number for I/O */ int bm_len;/* size of I/O */ +unsigned int bm_flags; };Quoted 5 lines
fs/xfs/xfs_buf.h typedef struct xfs_buftarg { · line 127
Quoted 2 lines
fs/xfs/xfs_buf.h +2
-0+/* Don't complain about live buffers with the wrong length during lookup. */ +#define XBM_IGNORE_LENGTH_MISMATCH (1U << 0)Which makes me wonder now: can we have two cached buffers at the same address with different lengths during a repair?
Quoted 4 lines
Let's say there's a filesystem with dirblksize 8k. A directory block gets crosslinked with an xattr block. Running the dir and xattr scrubbers each will create a new cached buffer -- an 8k buffer for the dir, and a 4k buffer for the xattr.
The second one will trip an assert fail because it found a non-stale block of a different length.
This is fundamental property of the buffer cache - there is only supposed to be a single active buffer for a given daddr in the cache at once. Just because the production code doesn't noisily complain about it, doesn't mean it is valid behaviour.
Quoted 3 lines
Let's say that the dir block
overwrote the attr block. Then, the xattr read verifier will fail inxfs_trans_buf_read, but that doesn't remove the buffer from the cache.It won't even get to the read verifier on a debug kernel - it should be assert failing in the compare function trying to look up the second buffer as it's asking for a different length.
i.e. I don't see how the above "crosslinked with different lengths instantiates two independent buffers" works at all on a debug kernel. It should fail, it is meant to fail, it is meant to tell us something is breaking the fundamental assumption that there is only one active cached buffer for a given daddr at a given time....
What am I missing?
Quoted 3 lines
I want the xattr repair to be able to scan the buffer cache and examine both buffers without throwing assertions all over the place, because that makes it harder to debug repair.
Right, but I don't see anything in the buffer cache changes so far that allow that or make it in any way safe for it to occur.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 7/9] xfs: ignore stale buffers when scanning the buffer cache
Quoted 92 lines · Darrick J. Wong
Quoted 77 lines · Dave Chinner
Quoted 76 lines · Darrick J. Wong
Quoted 44 lines · Dave Chinner
Quoted 29 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
After an online repair, we need to invalidate buffers representing the blocks from the old metadata that we're replacing. It's possible that parts of a tree that were previously cached in memory are no longer accessible due to media failure or other corruption on interior nodes, so repair figures out the old blocks from the reverse mapping data and scans the buffer cache directly.
Unfortunately, the current buffer cache code triggers asserts if the rhashtable lookup finds a non-stale buffer of a different length than the key we searched for. For regular operation this is desirable, but for this repair procedure, we don't care since we're going to forcibly stale the buffer anyway. Add an internal lookup flag to avoid the assert.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/reap.c | 2 +- fs/xfs/xfs_buf.c | 5 ++++- fs/xfs/xfs_buf.h | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-)fs/xfs/scrub/reap.c +0
-0fs/xfs/scrub/reap.c xrep_block_reap_binval( · line 152
Quoted 5 lines
fs/xfs/scrub/reap.c +1
-1@@ -149,7 +149,7 @@ xrep_block_reap_binval(*/ error =xfs_buf_incore (sc->mp->m_ddev_targp,XFS_FSB_TO_DADDR (sc->mp, fsbno), -XFS_FSB_TO_BB (sc->mp,1 ),0 , &bp); +XFS_FSB_TO_BB (sc->mp,1 ),XBF_BCACHE_SCAN , &bp);Can't say I'm a big fan of
XBF_BCACHE_SCANas a name - it tells me nothing about what the incore lookup is actually doing. The actual lookup action that is being performed is "find any match" rather than "find exact match".XBF_ANY_MATCHwould be a better name, IMO.Quoted 3 lines
fs/xfs/scrub/reap.c +0
-0if (error)return ;Quoted 13 lines
fs/xfs/xfs_buf.c _xfs_buf_obj_cmp( · line 485
Quoted 11 lines
fs/xfs/xfs_buf.c +2
-1@@ -481,7 +481,8 @@ _xfs_buf_obj_cmp(* reallocating a busy extent. Skip this buffer and * continue searching for an exact match. */ -ASSERT (bp->b_flags &XBF_STALE ); +if (!(map->bm_flags &XBM_IGNORE_LENGTH_MISMATCH )) +ASSERT (bp->b_flags &XBF_STALE );And this becomes
XBM_ANY_MATCH, too.Hmmm. I've never come up with a good name for this flag. The caller actually has a *specific* length in mind; it simply doesn't want to trip the assertions on the cached buffers that have a different length but won't be returned by *this* call.
If the buffer cache has bufs for daddr 24 len 8 and daddr len 120, the scan calls
xfs_buf_getas follows:daddr 24 len 1 (nothing)
daddr 24 len 2 (nothing)
...
daddr 24 len 8 (finds the first buffer)
...
daddr 24 len 120 (finds the second buffer)
...
daddr 24 len 132 (nothing)Quoted 7 lines
Quoted 3 lines
I don't want the scan to ASSERT 130 times, because that muddles the output so badly that it becomes impossible to find relevant debugging messages among the crap.
As I mentioned in the my response to the next patch, this is an O(N^2) brute force search. But how do you get two buffers at the same address into the cache in the first place?
/me smacks forehead, realizes that I totally lead you astray here. What we're scanning for is the case that the buffer cache has two overlapping buffers with *different* daddrs.
(That teaches me to reply to emails while on vacation...)
Quoted 10 lines
xreap_agextent_binvalis only called if the extent being freed is completely owned by the data structure and is *not* crosslinked with a different structure. We've just rebuilt a data structure that was corrupt in some manner, but the reaper doesn't know the details of that corruption. Therefore, the reaper should invalidate /all/ buffers that might span the extent being freed, no matter how they ended up in the cache. If a deceased data structure thought it was the sole owner of a single fsblock of space starting at fsblock 16, we ought to look for buffers (daddr 128, length 1) (128, 2), ... (128, 8), (129, 1), (129, 2) ... (129, 7) ... (135, 1) and invalidate all of them.
Ok, but we can't have random metadata buffers at individual daddr offsets - except for the AG headers, every metadata buffer is filesystem block aligned. Hence in the above example, there is no possibility of having a metadata buffer at sectors 129-135 on a 4kB block size filesystem.
Quoted 7 lines
Concrete example:
So let's pretend that we have an xfs with fs blocksize 4k and dir blocksize 8k. Let's suppose the directory's data fork maps fsblock 16, resulting in a buffer (daddr 128, length 16). Let us further suppose the inobt then allocates fsblock 17, resulting in a buffer (daddr 136, length 8). These are crosslinked.
RIght, that's an intersection of {128,16} and {136,8}. The search region for buffer invalidation is {128, 8} {128, 16} and {136, 8}. They are the only possible buffers that can be cached in that region for a 4kB block size filesystem, as there can be no metadata buffers starting at daddrs 129-135 or 137-143...
Quoted 13 lines
First, we discover the inobt is crosslinked with a directory and decide to rebuild it. We write out the new inobt and go to reap the old blocks. Since fsblock 17 is crosslinked, we simply remove the
OWN_INOBTrmap record and leave the buffer.Aside: Long ago, I tried to make the reaping code invalidate buffers when the space is crosslinked, but I couldn't figure out how to deal with the situation where (say) the bmap btrees of two separate forks think they own the same block. The
b_opswill be the same; the buffer cache doesn't know about the owner field in the block header, and there's no way to distinguish the blocks for a data fork bmbt vs. an attr fork bmbt.
Quoted 6 lines
Next we discover that the directory is corrupt and decide to rebuild that. The directory is now the only owner, so it can actually free the two fsb of space at startblock 16fsb. Both buffers (128, 16) and (136,
8) are still in the cache, so it needs to invalidate both.Does all /that/ make sense?
Yes, it does, and I figured that is waht you were trying to detect, it's just the search pattern you described made no sense.
I still think needs cleaning up - it's doing a massive amount of unnecessary work checking for things that cannot exist...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 7/9] xfs: ignore stale buffers when scanning the buffer cache
Quoted 118 lines · Dave Chinner
Quoted 92 lines · Darrick J. Wong
Quoted 77 lines · Dave Chinner
Quoted 76 lines · Darrick J. Wong
Quoted 44 lines · Dave Chinner
Quoted 29 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
After an online repair, we need to invalidate buffers representing the blocks from the old metadata that we're replacing. It's possible that parts of a tree that were previously cached in memory are no longer accessible due to media failure or other corruption on interior nodes, so repair figures out the old blocks from the reverse mapping data and scans the buffer cache directly.
Unfortunately, the current buffer cache code triggers asserts if the rhashtable lookup finds a non-stale buffer of a different length than the key we searched for. For regular operation this is desirable, but for this repair procedure, we don't care since we're going to forcibly stale the buffer anyway. Add an internal lookup flag to avoid the assert.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/reap.c | 2 +- fs/xfs/xfs_buf.c | 5 ++++- fs/xfs/xfs_buf.h | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-)fs/xfs/scrub/reap.c +0
-0fs/xfs/scrub/reap.c xrep_block_reap_binval( · line 152
Quoted 5 lines
fs/xfs/scrub/reap.c +1
-1@@ -149,7 +149,7 @@ xrep_block_reap_binval(*/ error =xfs_buf_incore (sc->mp->m_ddev_targp,XFS_FSB_TO_DADDR (sc->mp, fsbno), -XFS_FSB_TO_BB (sc->mp,1 ),0 , &bp); +XFS_FSB_TO_BB (sc->mp,1 ),XBF_BCACHE_SCAN , &bp);Can't say I'm a big fan of
XBF_BCACHE_SCANas a name - it tells me nothing about what the incore lookup is actually doing. The actual lookup action that is being performed is "find any match" rather than "find exact match".XBF_ANY_MATCHwould be a better name, IMO.Quoted 3 lines
fs/xfs/scrub/reap.c +0
-0if (error)return ;Quoted 13 lines
fs/xfs/xfs_buf.c _xfs_buf_obj_cmp( · line 485
Quoted 11 lines
fs/xfs/xfs_buf.c +2
-1@@ -481,7 +481,8 @@ _xfs_buf_obj_cmp(* reallocating a busy extent. Skip this buffer and * continue searching for an exact match. */ -ASSERT (bp->b_flags &XBF_STALE ); +if (!(map->bm_flags &XBM_IGNORE_LENGTH_MISMATCH )) +ASSERT (bp->b_flags &XBF_STALE );And this becomes
XBM_ANY_MATCH, too.Hmmm. I've never come up with a good name for this flag. The caller actually has a *specific* length in mind; it simply doesn't want to trip the assertions on the cached buffers that have a different length but won't be returned by *this* call.
If the buffer cache has bufs for daddr 24 len 8 and daddr len 120, the scan calls
xfs_buf_getas follows:daddr 24 len 1 (nothing)
daddr 24 len 2 (nothing)
...
daddr 24 len 8 (finds the first buffer)
...
daddr 24 len 120 (finds the second buffer)
...
daddr 24 len 132 (nothing)Quoted 7 lines
Quoted 3 lines
I don't want the scan to ASSERT 130 times, because that muddles the output so badly that it becomes impossible to find relevant debugging messages among the crap.
As I mentioned in the my response to the next patch, this is an O(N^2) brute force search. But how do you get two buffers at the same address into the cache in the first place?
/me smacks forehead, realizes that I totally lead you astray here. What we're scanning for is the case that the buffer cache has two overlapping buffers with *different* daddrs.
(That teaches me to reply to emails while on vacation...)
Quoted 10 lines
xreap_agextent_binvalis only called if the extent being freed is completely owned by the data structure and is *not* crosslinked with a different structure. We've just rebuilt a data structure that was corrupt in some manner, but the reaper doesn't know the details of that corruption. Therefore, the reaper should invalidate /all/ buffers that might span the extent being freed, no matter how they ended up in the cache. If a deceased data structure thought it was the sole owner of a single fsblock of space starting at fsblock 16, we ought to look for buffers (daddr 128, length 1) (128, 2), ... (128, 8), (129, 1), (129, 2) ... (129, 7) ... (135, 1) and invalidate all of them.Ok, but we can't have random metadata buffers at individual daddr offsets - except for the AG headers, every metadata buffer is filesystem block aligned. Hence in the above example, there is no possibility of having a metadata buffer at sectors 129-135 on a 4kB block size filesystem.
Quoted 7 lines
Concrete example:
So let's pretend that we have an xfs with fs blocksize 4k and dir blocksize 8k. Let's suppose the directory's data fork maps fsblock 16, resulting in a buffer (daddr 128, length 16). Let us further suppose the inobt then allocates fsblock 17, resulting in a buffer (daddr 136, length 8). These are crosslinked.
Quoted 5 lines
RIght, that's an intersection of {128,16} and {136,8}. The search region for buffer invalidation is {128, 8} {128, 16} and {136, 8}. They are the only possible buffers that can be cached in that region for a 4kB block size filesystem, as there can be no metadata buffers starting at daddrs 129-135 or 137-143...
<nod> There's nothing in this flag that *prevents* someone from spending a lot of time pounding on the buffer cache with a per-daddr scan. But note that the next patch only ever calls it with fsblock-aligned daddr and length values. So in the end, the only xfs_buf queries will indded be for {128, 8} {128, 16} and {136, 8} like you said.
See the next patch for the actual usage. Sorry that I've been unclear about all this and compounding it with not very good examples. It's been a /very/ long time since I actually touched this code (this rewrite has been waiting for merge since ... 2019?) and I'm basically coming in cold. :(
Ultimately I make invalidation scan code look like this:
/* Buffer cache scan context. */
struct xrep_bufscan {
/* Disk address for the buffers we want to scan. */
xfs_daddr_t daddr;
/* Maximum number of sectors to scan. */
xfs_daddr_t max_sectors;
/* Each round, increment the search length by this number of sectors. */
xfs_daddr_t daddr_step;
/* Internal scan state; initialize to zero. */
xfs_daddr_t __sector_count;
};/*
* Return an incore buffer from a sector scan, or NULL if there are no buffers
* left to return.
*/
struct xfs_buf *
xrep_bufscan_advance(
struct xfs_mount *mp,
struct xrep_bufscan *scan)
{
scan->__sector_count += scan->daddr_step;
while (scan->__sector_count <= scan->max_sectors) {
struct xfs_buf *bp = NULL;
int error;
error = xfs_buf_incore(mp->m_ddev_targp, scan->daddr,
scan->__sector_count, XBF_LIVESCAN, &bp);
if (!error)
return bp;
scan->__sector_count += scan->daddr_step;
}
return NULL;
}/* Try to invalidate the incore buffers for an extent that we're freeing. */ STATIC void
xreap_agextent_binval(
struct xreap_state *rs,
xfs_agblock_t agbno,
xfs_extlen_t *aglenp)
{
struct xfs_scrub *sc = rs->sc;
struct xfs_perag *pag = sc->sa.pag;
struct xfs_mount *mp = sc->mp;
xfs_agnumber_t agno = sc->sa.pag->pag_agno;
xfs_agblock_t agbno_next = agbno + *aglenp;
xfs_agblock_t bno = agbno;
/*
* Avoid invalidating AG headers and post-EOFS blocks because we never
* own those.
*/
if (!xfs_verify_agbno(pag, agbno) ||
!xfs_verify_agbno(pag, agbno_next - 1))
return;
/*
* If there are incore buffers for these blocks, invalidate them. We
* assume that the lack of any other known owners means that the buffer
* can be locked without risk of deadlocking. The buffer cache cannot
* detect aliasing, so employ nested loops to scan for incore buffers
* of any plausible size.
*/
while (bno < agbno_next) {
struct xrep_bufscan scan = {
.daddr = XFS_AGB_TO_DADDR(mp, agno, bno),
.max_sectors = xrep_bufscan_max_sectors(mp,
agbno_next - bno),
.daddr_step = XFS_FSB_TO_BB(mp, 1),
};
struct xfs_buf *bp;
while ((bp = xrep_bufscan_advance(mp, &scan)) != NULL) {
xfs_trans_bjoin(sc->tp, bp);
xfs_trans_binval(sc->tp, bp);
rs->invalidated++;
/*
* Stop invalidating if we've hit the limit; we should
* still have enough reservation left to free however
* far we've gotten.
*/
if (rs->invalidated > XREAP_MAX_BINVAL) {
*aglenp -= agbno_next - bno;
goto out;
}
}
bno++;
}out:
trace_xreap_agextent_binval(sc->sa.pag, agbno, *aglenp); }
I hope that makes it clearer?
--D
Quoted 32 lines
Quoted 13 lines
First, we discover the inobt is crosslinked with a directory and decide to rebuild it. We write out the new inobt and go to reap the old blocks. Since fsblock 17 is crosslinked, we simply remove the
OWN_INOBTrmap record and leave the buffer.Aside: Long ago, I tried to make the reaping code invalidate buffers when the space is crosslinked, but I couldn't figure out how to deal with the situation where (say) the bmap btrees of two separate forks think they own the same block. The
b_opswill be the same; the buffer cache doesn't know about the owner field in the block header, and there's no way to distinguish the blocks for a data fork bmbt vs. an attr fork bmbt.Quoted 6 lines
Next we discover that the directory is corrupt and decide to rebuild that. The directory is now the only owner, so it can actually free the two fsb of space at startblock 16fsb. Both buffers (128, 16) and (136,
8) are still in the cache, so it needs to invalidate both.Does all /that/ make sense?
Yes, it does, and I figured that is waht you were trying to detect, it's just the search pattern you described made no sense.
I still think needs cleaning up - it's doing a massive amount of unnecessary work checking for things that cannot exist...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 7/9] xfs: ignore stale buffers when scanning the buffer cache
Quoted 53 lines · Darrick J. Wong
Quoted 9 lines · Dave Chinner
Quoted 7 lines · Darrick J. Wong
Concrete example:
So let's pretend that we have an xfs with fs blocksize 4k and dir blocksize 8k. Let's suppose the directory's data fork maps fsblock 16, resulting in a buffer (daddr 128, length 16). Let us further suppose the inobt then allocates fsblock 17, resulting in a buffer (daddr 136, length 8). These are crosslinked.
Quoted 5 lines
RIght, that's an intersection of {128,16} and {136,8}. The search region for buffer invalidation is {128, 8} {128, 16} and {136, 8}. They are the only possible buffers that can be cached in that region for a 4kB block size filesystem, as there can be no metadata buffers starting at daddrs 129-135 or 137-143...
<nod> There's nothing in this flag that *prevents* someone from spending a lot of time pounding on the buffer cache with a per-daddr scan. But note that the next patch only ever calls it with fsblock-aligned daddr and length values. So in the end, the only
xfs_bufqueries will indded be for {128, 8} {128, 16} and {136, 8} like you said.See the next patch for the actual usage. Sorry that I've been unclear about all this and compounding it with not very good examples. It's been a /very/ long time since I actually touched this code (this rewrite has been waiting for merge since ... 2019?) and I'm basically coming in cold. :(
Ultimately I make invalidation scan code look like this:
/* Buffer cache scan context. */
struct xrep_bufscan { /* Disk address for the buffers we want to scan. */ xfs_daddr_t daddr; /* Maximum number of sectors to scan. */ xfs_daddr_t max_sectors; /* Each round, increment the search length by this number of sectors. */ xfs_daddr_t daddr_step; /* Internal scan state; initialize to zero. */ xfs_daddr_t __sector_count; };/*
* Return an incore buffer from a sector scan, or NULL if there are no buffers
* left to return.
*/
structxfs_buf*
xrep_bufscan_advance(
structxfs_mount*mp,
structxrep_bufscan*scan)
Quoted 16 lines
{
scan->__sector_count += scan->daddr_step;
while (scan->__sector_count <= scan->max_sectors) {
struct xfs_buf *bp = NULL;
int error;
error = xfs_buf_incore(mp->m_ddev_targp, scan->daddr,
scan->__sector_count, XBF_LIVESCAN, &bp);
if (!error)
return bp;
scan->__sector_count += scan->daddr_step;
}
return NULL;
}.....
Yup, that's much better, will do for now.
I suspect this could be smarter with a custom rhashtable walker; all the buffers at a given daddr should have the same key (i.e. daddr) so should hash to the same list, so we should be able to walk an entire list in one pass doing a bjoin/binval callback on each non-stale buffer that matches the key....
But that can be done later, it's not necessary for correctness and this looks a lot better than the original code.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 8/9 xfs: reap large AG metadata extents when possible
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When we're freeing extents that have been set in a bitmap, break the bitmap extent into multiple sub-extents organized by fate, and reap the extents. This enables us to dispose of old resources more efficiently than doing them block by block.
While we're at it, rename the reaping functions to make it clear that they're reaping per-AG extents.
--- fs/xfs/scrub/agheader_repair.c | 2 fs/xfs/scrub/bitmap.c | 37 ---- fs/xfs/scrub/bitmap.h | 4 fs/xfs/scrub/reap.c | 382 ++++++++++++++++++++++++++++++++-------- fs/xfs/scrub/reap.h | 2 fs/xfs/scrub/repair.c | 51 +++++ fs/xfs/scrub/repair.h | 1 fs/xfs/scrub/trace.h | 37 ++++ 8 files changed, 395 insertions(+), 121 deletions(-)
fs/xfs/scrub/agheader_repair.c +1 -1
@@ -775,7 +775,7 @@ xrep_agfl( goto err;/* Dump any AGFL overflow. */ - error =xrep_reap_extents (sc, &agfl_extents, &XFS_RMAP_OINFO_AG , + error =xrep_reap_ag_metadata (sc, &agfl_extents, &XFS_RMAP_OINFO_AG ,XFS_AG_RESV_AGFL ); err:xbitmap_destroy (&agfl_extents);
fs/xfs/scrub/bitmap.c +0 -37
@@ -385,43 +385,6 @@ xbitmap_walk(return error; } -struct xbitmap_walk_bits { -xbitmap_walk_bits_fn fn; -void *priv; -}; - -/* Walk all the bits in a run. */ -static int -xbitmap_walk_bits_in_run ( -uint64_t start, -uint64_t len, -void *priv) -{ -struct xbitmap_walk_bits *wb = priv; -uint64_t i; -int error =0 ; - -for (i = start; i < start + len; i++) { - error = wb->fn (i, wb->priv); -if (error) -break ; - } - -return error; -} - -/* Call a function for every set bit in this bitmap. */ -int -xbitmap_walk_bits ( -struct xbitmap *bitmap, -xbitmap_walk_bits_fn fn, -void *priv) -{ -struct xbitmap_walk_bits wb = {.fn = fn, .priv = priv}; - -return xbitmap_walk (bitmap, xbitmap_walk_bits_in_run, &wb); -} -/* Does this bitmap have no bits set at all? */ bool xbitmap_empty(
fs/xfs/scrub/bitmap.h +0 -4
@@ -33,10 +33,6 @@ typedef int (*xbitmap_walk_fn)(uint64_t start, uint64_t len, void *priv);int xbitmap_walk (struct xbitmap *bitmap,xbitmap_walk_fn fn,void *priv); -typedef int (*xbitmap_walk_bits_fn )(uint64_t bit,void *priv); -int xbitmap_walk_bits (struct xbitmap *bitmap,xbitmap_walk_bits_fn fn, -void *priv); -bool xbitmap_empty (struct xbitmap *bitmap);bool xbitmap_test (struct xbitmap *bitmap,uint64_t start,uint64_t *len);
fs/xfs/scrub/reap.c +306 -76
463 lines not on this page · raw message
fs/xfs/scrub/reap.h +1 -1
@@ -6,7 +6,7 @@#ifndef __XFS_SCRUB_REAP_H__#define __XFS_SCRUB_REAP_H__ -int xrep_reap_extents (struct xfs_scrub *sc,struct xbitmap *bitmap, +int xrep_reap_ag_metadata (struct xfs_scrub *sc,struct xbitmap *bitmap,const struct xfs_owner_info *oinfo,enum xfs_ag_resv_type type);
fs/xfs/scrub/repair.c +51 -0
63 lines not on this page · raw message
fs/xfs/scrub/repair.h +1 -0
@@ -20,6 +20,7 @@ static inline int xrep_notsupported(struct xfs_scrub *sc)int xrep_attempt (struct xfs_scrub *sc);void xrep_failure (struct xfs_mount *mp);int xrep_roll_ag_trans (struct xfs_scrub *sc); +int xrep_defer_finish (struct xfs_scrub *sc);bool xrep_ag_has_space (struct xfs_perag *pag,xfs_extlen_t nr_blocks,enum xfs_ag_resv_type type);xfs_extlen_t xrep_calc_ag_resblks (struct xfs_scrub *sc);
fs/xfs/scrub/trace.h +35 -2
@@ -753,10 +753,43 @@ DECLARE_EVENT_CLASS(xrep_extent_class,DEFINE_EVENT (xrep_extent_class, name, \ TP_PROTO(struct xfs_perag *pag, xfs_agblock_t agbno, xfs_extlen_t len), \ TP_ARGS(pag, agbno, len)) -DEFINE_REPAIR_EXTENT_EVENT (xrep_dispose_unmap_extent); -DEFINE_REPAIR_EXTENT_EVENT (xrep_dispose_free_extent); +DEFINE_REPAIR_EXTENT_EVENT (xreap_dispose_unmap_extent); +DEFINE_REPAIR_EXTENT_EVENT (xreap_dispose_free_extent); +DEFINE_REPAIR_EXTENT_EVENT (xreap_agextent_binval);DEFINE_REPAIR_EXTENT_EVENT (xrep_agfl_insert); +DECLARE_EVENT_CLASS (xrep_reap_find_class, + TP_PROTO(struct xfs_perag *pag, xfs_agblock_t agbno, xfs_extlen_t len, + bool crosslinked), +TP_ARGS (pag, agbno, len, crosslinked), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(xfs_agnumber_t, agno) + __field(xfs_agblock_t, agbno) + __field(xfs_extlen_t, len) +__field (bool, crosslinked) + ), +TP_fast_assign ( + __entry->dev = pag->pag_mount->m_super->s_dev; + __entry->agno = pag->pag_agno; + __entry->agbno = agbno; + __entry->len = len; + __entry->crosslinked = crosslinked; + ), +TP_printk ("dev %d:%d agno 0x%x agbno 0x%x fsbcount 0x%x crosslinked %d" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->agno, + __entry->agbno, + __entry->len, + __entry->crosslinked ?1 :0 ) +); +#define DEFINE_REPAIR_REAP_FIND_EVENT (name) \ +DEFINE_EVENT(xrep_reap_find_class, name, \ + TP_PROTO(struct xfs_perag *pag, xfs_agblock_t agbno, xfs_extlen_t len, \ + bool crosslinked), \ + TP_ARGS(pag, agbno, len, crosslinked)) +DEFINE_REPAIR_REAP_FIND_EVENT (xreap_agextent_select); + DECLARE_EVENT_CLASS(xrep_rmap_class, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, xfs_agblock_t agbno, xfs_extlen_t len,
Re: [PATCH 8/9] xfs: reap large AG metadata extents when possible
Quoted 12 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
When we're freeing extents that have been set in a bitmap, break the bitmap extent into multiple sub-extents organized by fate, and reap the extents. This enables us to dispose of old resources more efficiently than doing them block by block.
While we're at it, rename the reaping functions to make it clear that they're reaping per-AG extents.
Signed-off-by Darrick J. Wong <[email protected]>---
.....
Quoted 57 lines
fs/xfs/scrub/reap.c +33
-14+xreap_agextent_binval ( + struct xreap_state *rs, + xfs_agblock_t agbno, + xfs_extlen_t *aglenp) { -struct xfs_buf *bp =NULL ; -int error; + struct xfs_scrub *sc = rs->sc; +struct xfs_perag *pag = sc->sa.pag; +struct xfs_mount *mp = sc->mp; +xfs_agnumber_t agno = sc->sa.pag->pag_agno; +xfs_agblock_t agbno_next = agbno + *aglenp; +xfs_agblock_t bno = agbno;/* -* If there's an incore buffer for exactly this block, invalidate it. * Avoid invalidating AG headers and post-EOFS blocks because we never * own those. */ -if (!xfs_verify_fsbno (sc->mp, fsbno)) +if (!xfs_verify_agbno (pag, agbno) || + !xfs_verify_agbno (pag, agbno_next -1 ))return ;/* -* We assume that the lack of any other known owners means that the -* buffer can be locked without risk of deadlocking. +* If there are incore buffers for these blocks, invalidate them. We +* assume that the lack of any other known owners means that the buffer +* can be locked without risk of deadlocking. The buffer cache cannot +* detect aliasing, so employ nested loops to scan for incore buffers +* of any plausible size. */ - error =xfs_buf_incore (sc->mp->m_ddev_targp, -XFS_FSB_TO_DADDR (sc->mp, fsbno), -XFS_FSB_TO_BB (sc->mp,1 ),XBF_BCACHE_SCAN , &bp); -if (error) -return ; - -xfs_trans_bjoin (sc->tp, bp); -xfs_trans_binval (sc->tp, bp); +while (bno < agbno_next) { +xfs_agblock_t fsbcount; +xfs_agblock_t max_fsbs; + +/* +* Max buffer size is the max remote xattr buffer size, which +* is one fs block larger than 64k. +*/ + max_fsbs =min_t (xfs_agblock_t, agbno_next - bno, +xfs_attr3_rmt_blocks (mp,XFS_XATTR_SIZE_MAX )); + +for (fsbcount =1 ; fsbcount < max_fsbs; fsbcount++) { +struct xfs_buf *bp =NULL ; +xfs_daddr_t daddr; +int error; +
fs/xfs/scrub/reap.c xrep_put_freelist( · line 265
Quoted 10 lines
fs/xfs/scrub/reap.c +10
-0+ daddr =XFS_AGB_TO_DADDR (mp, agno, bno); + error =xfs_buf_incore (mp->m_ddev_targp, daddr, +XFS_FSB_TO_BB (mp, fsbcount), +XBF_BCACHE_SCAN , &bp); +if (error) +continue ; + +xfs_trans_bjoin (sc->tp, bp); +xfs_trans_binval (sc->tp, bp); + rs->invalidated++;
Hmmm. O(N^2) brute force lookup walk to find any buffer at that specific daddr? That's going to have an impact on running systems by hammering the perag hash lock.
I didn't know this was being done before I suggested XBF_ANY_MATCH, but now I'm wondering how can we even have multiple buffers in the cache at a given address? The whole point of the ASSERT() in the match function is to indicate this should not ever happen.
i.e. xfs_buf_find_insert() uses rhashtable_lookup_get_insert_fast(), which will return an existing buffer only if it has a match length. The compare function used at insert time will throw an assert fail if any other buffer exists at that address that has a mismatched length that is not stale. There is no way to avoid that ASSERT check on insert.
Hence, AFAICT, the only way we can get multiple buffers into the cache at the same daddr with different lengths is for all the existing buffers at that daddr to all be stale at insert time. In which case, why do we need to invalidate buffers that are already stale (i.e. been invalidated)?
What am I missing here? i.e. this appears to cater for behaviour that doesn't currently exist in the buffer cache, and I'm not sure we even want to allow to occur in the buffer cache given that it generally indicates in-memory metadata corruption.....
Hmmmm. What if the buffer was already stale? The lookup will then clear all the stale state from it, leave it with no valid contents which we then invalidate again and log a new buffer cancel item for it. What are the implications of that? (My brain is too full of stuff trying to understand what this code is doing to be able to think this through right now.)
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 8/9] xfs: reap large AG metadata extents when possible
Quoted 99 lines · Dave Chinner
Quoted 12 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
When we're freeing extents that have been set in a bitmap, break the bitmap extent into multiple sub-extents organized by fate, and reap the extents. This enables us to dispose of old resources more efficiently than doing them block by block.
While we're at it, rename the reaping functions to make it clear that they're reaping per-AG extents.
Signed-off-by Darrick J. Wong <[email protected]>---
.....
Quoted 57 lines
fs/xfs/scrub/reap.c +33
-14+xreap_agextent_binval ( + struct xreap_state *rs, + xfs_agblock_t agbno, + xfs_extlen_t *aglenp) { -struct xfs_buf *bp =NULL ; -int error; + struct xfs_scrub *sc = rs->sc; +struct xfs_perag *pag = sc->sa.pag; +struct xfs_mount *mp = sc->mp; +xfs_agnumber_t agno = sc->sa.pag->pag_agno; +xfs_agblock_t agbno_next = agbno + *aglenp; +xfs_agblock_t bno = agbno;/* -* If there's an incore buffer for exactly this block, invalidate it. * Avoid invalidating AG headers and post-EOFS blocks because we never * own those. */ -if (!xfs_verify_fsbno (sc->mp, fsbno)) +if (!xfs_verify_agbno (pag, agbno) || + !xfs_verify_agbno (pag, agbno_next -1 ))return ;/* -* We assume that the lack of any other known owners means that the -* buffer can be locked without risk of deadlocking. +* If there are incore buffers for these blocks, invalidate them. We +* assume that the lack of any other known owners means that the buffer +* can be locked without risk of deadlocking. The buffer cache cannot +* detect aliasing, so employ nested loops to scan for incore buffers +* of any plausible size. */ - error =xfs_buf_incore (sc->mp->m_ddev_targp, -XFS_FSB_TO_DADDR (sc->mp, fsbno), -XFS_FSB_TO_BB (sc->mp,1 ),XBF_BCACHE_SCAN , &bp); -if (error) -return ; - -xfs_trans_bjoin (sc->tp, bp); -xfs_trans_binval (sc->tp, bp); +while (bno < agbno_next) { +xfs_agblock_t fsbcount; +xfs_agblock_t max_fsbs; + +/* +* Max buffer size is the max remote xattr buffer size, which +* is one fs block larger than 64k. +*/ + max_fsbs =min_t (xfs_agblock_t, agbno_next - bno, +xfs_attr3_rmt_blocks (mp,XFS_XATTR_SIZE_MAX )); + +for (fsbcount =1 ; fsbcount < max_fsbs; fsbcount++) { +struct xfs_buf *bp =NULL ; +xfs_daddr_t daddr; +int error; +fs/xfs/scrub/reap.c xrep_put_freelist( · line 265
Quoted 10 lines
fs/xfs/scrub/reap.c +10
-0+ daddr =XFS_AGB_TO_DADDR (mp, agno, bno); + error =xfs_buf_incore (mp->m_ddev_targp, daddr, +XFS_FSB_TO_BB (mp, fsbcount), +XBF_BCACHE_SCAN , &bp); +if (error) +continue ; + +xfs_trans_bjoin (sc->tp, bp); +xfs_trans_binval (sc->tp, bp); + rs->invalidated++;Hmmm. O(N^2) brute force lookup walk to find any buffer at that specific daddr? That's going to have an impact on running systems by hammering the perag hash lock.
I didn't know this was being done before I suggested
XBF_ANY_MATCH, but now I'm wondering how can we even have multiple buffers in the cache at a given address? The whole point of theASSERT()in the match function is to indicate this should not ever happen.i.e.
xfs_buf_find_insert()usesrhashtable_lookup_get_insert_fast(), which will return an existing buffer only if it has a match length. The compare function used at insert time will throw an assert fail if any other buffer exists at that address that has a mismatched length that is not stale. There is no way to avoid that ASSERT check on insert.
Quoted 7 lines
Hence, AFAICT, the only way we can get multiple buffers into the cache at the same daddr with different lengths is for all the existing buffers at that daddr to all be stale at insert time. In which case, why do we need to invalidate buffers that are already stale (i.e. been invalidated)?
What am I missing here? i.e. this appears to cater for behaviour
The same braino that I mentioned in my previous replies -- I failed to state that we're looking for buffers within a specific range of fsblocks that do /not/ start at the same addr.
Quoted 5 lines
that doesn't currently exist in the buffer cache, and I'm not sure we even want to allow to occur in the buffer cache given that it generally indicates in-memory metadata corruption.....
Hmmmm. What if the buffer was already stale? The lookup will then
Urk. Yes, that results in the buffer's stale state being cleared and then the buffer gets cancelled *again*. It's unnecessary and we can skip the second invalidation.
I think I'll change the name back to its former name XBF_LIVESCAN, which means "only return non-stale buffers, and don't complain about finding something with the same daddr but a different length from what the caller asked for".
--D
Quoted 10 lines
clear all the stale state from it, leave it with no valid contents which we then invalidate again and log a new buffer cancel item for it. What are the implications of that? (My brain is too full of stuff trying to understand what this code is doing to be able to think this through right now.)
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 9/9 xfs: use per-AG bitmaps to reap unused AG metadata blocks during repair
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The AGFL repair code uses a series of bitmaps to figure out where there are OWN_AG blocks that are not claimed by the free space and rmap btrees. These blocks become the new AGFL, and any overflow is reaped. The bitmaps current track xfs_fsblock_t even though we already know the AG number.
In the last patch, we introduced a new bitmap "type" for tracking xfs_agblock_t extents. Port the reaping code and the AGFL repair to use this new type, which makes it very obvious what we're tracking. This also eliminates a bunch of unnecessary agblock <-> fsblock conversions.
--- fs/xfs/scrub/agheader_repair.c | 74 ++++++++++++++++++---------------------- fs/xfs/scrub/bitmap.c | 41 ++-------------------- fs/xfs/scrub/bitmap.h | 6 +-- fs/xfs/scrub/reap.c | 14 ++------ fs/xfs/scrub/reap.h | 5 +-- 5 files changed, 45 insertions(+), 95 deletions(-)
fs/xfs/scrub/agheader_repair.c +34 -40
@@ -445,13 +445,13 @@ xrep_agf(struct xrep_agfl {/* Bitmap of alleged AGFL blocks that we're not going to add. */ -struct xbitmap crossed; +struct xagb_bitmap crossed;/* Bitmap of other OWN_AG metadata blocks. */ -struct xbitmap agmetablocks; +struct xagb_bitmap agmetablocks;/* Bitmap of free space. */ -struct xbitmap *freesp; +struct xagb_bitmap *freesp;/* rmapbt cursor for finding crosslinked blocks */ struct xfs_btree_cur *rmap_cur;
@@ -467,7 +467,6 @@ xrep_agfl_walk_rmap( void *priv) {struct xrep_agfl *ra = priv; -xfs_fsblock_t fsb;int error =0 ;if (xchk_should_terminate (ra->sc, &error))
@@ -475,14 +474,13 @@ xrep_agfl_walk_rmap(/* Record all the OWN_AG blocks. */ if (rec->rm_owner ==XFS_RMAP_OWN_AG ) { - fsb =XFS_AGB_TO_FSB (cur->bc_mp, cur->bc_ag.pag->pag_agno, - rec->rm_startblock); - error =xbitmap_set (ra->freesp, fsb, rec->rm_blockcount); + error =xagb_bitmap_set (ra->freesp, rec->rm_startblock, + rec->rm_blockcount);if (error)return error; } -return xbitmap_set_btcur_path (&ra->agmetablocks, cur); +return xagb_bitmap_set_btcur_path (&ra->agmetablocks, cur); }/* Strike out the blocks that are cross-linked according to the rmapbt. */
@@ -493,12 +491,10 @@ xrep_agfl_check_extent( void *priv) {struct xrep_agfl *ra = priv; -xfs_agblock_t agbno =XFS_FSB_TO_AGBNO (ra->sc->mp, start); +xfs_agblock_t agbno = start;xfs_agblock_t last_agbno = agbno + len -1 ;int error; -ASSERT (XFS_FSB_TO_AGNO (ra->sc->mp, start) == ra->sc->sa.pag->pag_agno); -while (agbno <= last_agbno) {bool other_owners;
@@ -508,7 +504,7 @@ xrep_agfl_check_extent(return error;if (other_owners) { - error =xbitmap_set (&ra->crossed, agbno,1 ); + error =xagb_bitmap_set (&ra->crossed, agbno,1 );if (error)return error; }
@@ -534,7 +530,7 @@ STATIC intxrep_agfl_collect_blocks ( struct xfs_scrub *sc, struct xfs_buf *agf_bp, - struct xbitmap *agfl_extents, + struct xagb_bitmap *agfl_extents, xfs_agblock_t *flcount) { struct xrep_agfl ra;
@@ -544,8 +540,8 @@ xrep_agfl_collect_blocks( ra.sc = sc; ra.freesp = agfl_extents; -xbitmap_init (&ra.agmetablocks); -xbitmap_init (&ra.crossed); +xagb_bitmap_init (&ra.agmetablocks); +xagb_bitmap_init (&ra.crossed);/* Find all space used by the free space btrees & rmapbt. */ cur =xfs_rmapbt_init_cursor (mp, sc->tp, agf_bp, sc->sa.pag);
@@ -557,7 +553,7 @@ xrep_agfl_collect_blocks(/* Find all blocks currently being used by the bnobt. */ cur =xfs_allocbt_init_cursor (mp, sc->tp, agf_bp, sc->sa.pag,XFS_BTNUM_BNO ); - error =xbitmap_set_btblocks (&ra.agmetablocks, cur); + error =xagb_bitmap_set_btblocks (&ra.agmetablocks, cur);xfs_btree_del_cursor (cur, error);if (error) goto out_bmp;
@@ -565,7 +561,7 @@ xrep_agfl_collect_blocks(/* Find all blocks currently being used by the cntbt. */ cur =xfs_allocbt_init_cursor (mp, sc->tp, agf_bp, sc->sa.pag,XFS_BTNUM_CNT ); - error =xbitmap_set_btblocks (&ra.agmetablocks, cur); + error =xagb_bitmap_set_btblocks (&ra.agmetablocks, cur);xfs_btree_del_cursor (cur, error);if (error) goto out_bmp;
@@ -574,17 +570,17 @@ xrep_agfl_collect_blocks(* Drop the freesp meta blocks that are in use by btrees. * The remaining blocks /should/ be AGFL blocks. */ - error =xbitmap_disunion (agfl_extents, &ra.agmetablocks); + error =xagb_bitmap_disunion (agfl_extents, &ra.agmetablocks);if (error) goto out_bmp;/* Strike out the blocks that are cross-linked. */ ra.rmap_cur =xfs_rmapbt_init_cursor (mp, sc->tp, agf_bp, sc->sa.pag); - error =xbitmap_walk (agfl_extents, xrep_agfl_check_extent, &ra); + error =xagb_bitmap_walk (agfl_extents, xrep_agfl_check_extent, &ra);xfs_btree_del_cursor (ra.rmap_cur, error);if (error) goto out_bmp; - error =xbitmap_disunion (agfl_extents, &ra.crossed); + error =xagb_bitmap_disunion (agfl_extents, &ra.crossed);if (error) goto out_bmp;
@@ -592,12 +588,12 @@ xrep_agfl_collect_blocks(* Calculate the new AGFL size. If we found more blocks than fit in * the AGFL we'll free them later. */ - *flcount =min_t (uint64_t,xbitmap_hweight (agfl_extents), + *flcount =min_t (uint64_t,xagb_bitmap_hweight (agfl_extents),xfs_agfl_size (mp)); out_bmp: -xbitmap_destroy (&ra.crossed); -xbitmap_destroy (&ra.agmetablocks); +xagb_bitmap_destroy (&ra.crossed); +xagb_bitmap_destroy (&ra.agmetablocks);return error; }
@@ -627,7 +623,7 @@ xrep_agfl_update_agf( }struct xrep_agfl_fill { -struct xbitmap used_extents; +struct xagb_bitmap used_extents;struct xfs_scrub *sc;__be32 *agfl_bno;xfs_agblock_t flcount;
@@ -643,17 +639,15 @@ xrep_agfl_fill( {struct xrep_agfl_fill *af = priv;struct xfs_scrub *sc = af->sc; -xfs_fsblock_t fsbno = start; +xfs_agblock_t agbno = start;int error; -trace_xrep_agfl_insert (sc->sa.pag,XFS_FSB_TO_AGBNO (sc->mp, start), - len); +trace_xrep_agfl_insert (sc->sa.pag, agbno, len); -while (fsbno < start + len && af->fl_off < af->flcount) - af->agfl_bno[af->fl_off++] = -cpu_to_be32 (XFS_FSB_TO_AGBNO (sc->mp, fsbno++)); +while (agbno < start + len && af->fl_off < af->flcount) + af->agfl_bno[af->fl_off++] =cpu_to_be32 (agbno++); - error =xbitmap_set (&af->used_extents, start, fsbno -1 ); + error =xagb_bitmap_set (&af->used_extents, start, agbno -1 );if (error)return error;
@@ -668,7 +662,7 @@ STATIC int xrep_agfl_init_header( struct xfs_scrub *sc, struct xfs_buf *agfl_bp, - struct xbitmap *agfl_extents, + struct xagb_bitmap *agfl_extents, xfs_agblock_t flcount) { struct xrep_agfl_fill af = {
@@ -696,17 +690,17 @@ xrep_agfl_init_header(* blocks than fit in the AGFL, they will be freed in a subsequent * step. */ -xbitmap_init (&af.used_extents); +xagb_bitmap_init (&af.used_extents); af.agfl_bno =xfs_buf_to_agfl_bno (agfl_bp), -xbitmap_walk (agfl_extents, xrep_agfl_fill, &af); - error =xbitmap_disunion (agfl_extents, &af.used_extents); +xagb_bitmap_walk (agfl_extents, xrep_agfl_fill, &af); + error =xagb_bitmap_disunion (agfl_extents, &af.used_extents);if (error)return error;/* Write new AGFL to disk. */ xfs_trans_buf_set_type (sc->tp, agfl_bp,XFS_BLFT_AGFL_BUF );xfs_trans_log_buf (sc->tp, agfl_bp,0 ,BBTOB (agfl_bp->b_length) -1 ); -xbitmap_destroy (&af.used_extents); +xagb_bitmap_destroy (&af.used_extents);return 0 ; }
@@ -715,7 +709,7 @@ intxrep_agfl ( struct xfs_scrub *sc) { -struct xbitmap agfl_extents; +struct xagb_bitmap agfl_extents;struct xfs_mount *mp = sc->mp;struct xfs_buf *agf_bp;struct xfs_buf *agfl_bp;
@@ -726,7 +720,7 @@ xrep_agfl(if (!xfs_has_rmapbt (mp))return -EOPNOTSUPP ; -xbitmap_init (&agfl_extents); +xagb_bitmap_init (&agfl_extents);/* * Read the AGF so that we can query the rmapbt. We hope that there's
@@ -775,10 +769,10 @@ xrep_agfl( goto err;/* Dump any AGFL overflow. */ - error =xrep_reap_ag_metadata (sc, &agfl_extents, &XFS_RMAP_OINFO_AG , + error =xrep_reap_agblocks (sc, &agfl_extents, &XFS_RMAP_OINFO_AG ,XFS_AG_RESV_AGFL ); err: -xbitmap_destroy (&agfl_extents); +xagb_bitmap_destroy (&agfl_extents);return error; }
fs/xfs/scrub/bitmap.c +3 -38
59 lines not on this page · raw message
fs/xfs/scrub/bitmap.h +2 -4
@@ -16,10 +16,6 @@ void xbitmap_destroy(struct xbitmap *bitmap);int xbitmap_clear (struct xbitmap *bitmap,uint64_t start,uint64_t len);int xbitmap_set (struct xbitmap *bitmap,uint64_t start,uint64_t len);int xbitmap_disunion (struct xbitmap *bitmap,struct xbitmap *sub); -int xbitmap_set_btcur_path (struct xbitmap *bitmap, -struct xfs_btree_cur *cur); -int xbitmap_set_btblocks (struct xbitmap *bitmap, -struct xfs_btree_cur *cur);uint64_t xbitmap_hweight (struct xbitmap *bitmap);/*
@@ -106,5 +102,7 @@ static inline int xagb_bitmap_walk(struct xagb_bitmap *bitmap,int xagb_bitmap_set_btblocks (struct xagb_bitmap *bitmap,struct xfs_btree_cur *cur); +int xagb_bitmap_set_btcur_path (struct xagb_bitmap *bitmap, +struct xfs_btree_cur *cur);#endif /* __XFS_SCRUB_BITMAP_H__ */
fs/xfs/scrub/reap.c +4 -10
@@ -422,19 +422,13 @@ xreap_agmeta_extent( {struct xreap_state *rs = priv;struct xfs_scrub *sc = rs->sc; -xfs_agnumber_t agno =XFS_FSB_TO_AGNO (sc->mp, fsbno); -xfs_agblock_t agbno =XFS_FSB_TO_AGBNO (sc->mp, fsbno); +xfs_agblock_t agbno = fsbno;xfs_agblock_t agbno_next = agbno + len;int error =0 ;ASSERT (len <=XFS_MAX_BMBT_EXTLEN );ASSERT (sc->ip ==NULL ); -if (agno != sc->sa.pag->pag_agno) { -ASSERT (sc->sa.pag->pag_agno == agno); -return -EFSCORRUPTED ; - } -while (agbno < agbno_next) {xfs_extlen_t aglen;bool crosslinked;
@@ -468,9 +462,9 @@ xreap_agmeta_extent(/* Dispose of every block of every AG metadata extent in the bitmap. */ int -xrep_reap_ag_metadata ( +xrep_reap_agblocks (struct xfs_scrub *sc, -struct xbitmap *bitmap, +struct xagb_bitmap *bitmap,const struct xfs_owner_info *oinfo,enum xfs_ag_resv_type type) {
@@ -484,7 +478,7 @@ xrep_reap_ag_metadata(ASSERT (xfs_has_rmapbt (sc->mp));ASSERT (sc->ip ==NULL ); - error =xbitmap_walk (bitmap, xreap_agmeta_extent, &rs); + error =xagb_bitmap_walk (bitmap, xreap_agmeta_extent, &rs);if (error)return error;
fs/xfs/scrub/reap.h +2 -3
@@ -6,8 +6,7 @@#ifndef __XFS_SCRUB_REAP_H__#define __XFS_SCRUB_REAP_H__ -int xrep_reap_ag_metadata (struct xfs_scrub *sc,struct xbitmap *bitmap, -const struct xfs_owner_info *oinfo, -enum xfs_ag_resv_type type); +int xrep_reap_agblocks (struct xfs_scrub *sc,struct xagb_bitmap *bitmap, +const struct xfs_owner_info *oinfo,enum xfs_ag_resv_type type);#endif /* __XFS_SCRUB_REAP_H__ */
cover xfs: prepare repair for bulk loading
In reply to Darrick J. WongHi all,
Before we start merging the online repair functions, let's improve the bulk loading code a bit. First, we need to fix a misinteraction between the AIL and the btree bulkloader wherein the delwri at the end of the bulk load fails to queue a buffer for writeback if it happens to be on the AIL list.
Second, we introduce EFIs in the btree bulkloader block allocator to to guarantee that staging blocks are freed if the filesystem goes down before committing the new btree.
Third, we change the bulkloader itself to copy multiple records into a block if possible, and add some debugging knobs so that developers can control the slack factors, just like they can do for xfs_repair.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-prep-for-bulk-loading
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-prep-for-bulk-loading
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_btree.c | 2 fs/xfs/libxfs/xfs_btree.h | 3 fs/xfs/libxfs/xfs_btree_staging.c | 67 +++- fs/xfs/libxfs/xfs_btree_staging.h | 32 +- fs/xfs/scrub/agheader_repair.c | 1 fs/xfs/scrub/common.c | 1 fs/xfs/scrub/newbt.c | 622 +++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/newbt.h | 66 ++++ fs/xfs/scrub/repair.c | 10 + fs/xfs/scrub/repair.h | 1 fs/xfs/scrub/scrub.c | 2 fs/xfs/scrub/trace.h | 37 ++ fs/xfs/xfs_buf.c | 31 ++ fs/xfs/xfs_buf.h | 1 fs/xfs/xfs_globals.c | 12 + fs/xfs/xfs_sysctl.h | 2 fs/xfs/xfs_sysfs.c | 54 +++ 18 files changed, 912 insertions(+), 33 deletions(-) create mode 100644 fs/xfs/scrub/newbt.c create mode 100644 fs/xfs/scrub/newbt.h
PATCH 1/6 xfs: force all buffers to be written during btree bulk load
From: Darrick J. Wong <[email protected]>
While stress-testing online repair of btrees, I noticed periodic assertion failures from the buffer cache about buffer readers encountering buffers with DELWRI_Q set, even though the btree bulk load had already committed and the buffer itself wasn't on any delwri list.
I traced this to a misunderstanding of how the delwri lists work, particularly with regards to the AIL's buffer list. If a buffer is logged and committed, the buffer can end up on that AIL buffer list. If btree repairs are run twice in rapid succession, it's possible that the first repair will invalidate the buffer and free it before the next time the AIL wakes up. This clears DELWRI_Q from the buffer state.
If the second repair allocates the same block, it will then recycle the buffer to start writing the new btree block. Meanwhile, if the AIL wakes up and walks the buffer list, it will ignore the buffer because it can't lock it, and go back to sleep.
When the second repair calls delwri_queue to put the buffer on the list of buffers to write before committing the new btree, it will set DELWRI_Q again, but since the buffer hasn't been removed from the AIL's buffer list, it won't add it to the bulkload buffer's list.
This is incorrect, because the bulkload caller relies on delwri_submit to ensure that all the buffers have been sent to disk /before/ committing the new btree root pointer. This ordering requirement is required for data consistency.
Worse, the AIL won't clear DELWRI_Q from the buffer when it does finally drop it, so the next thread to walk through the btree will trip over a debug assertion on that flag.
To fix this, create a new function that waits for the buffer to be removed from any other delwri lists before adding the buffer to the caller's delwri list.
--- fs/xfs/libxfs/xfs_btree_staging.c | 4 +--- fs/xfs/xfs_buf.c | 31 +++++++++++++++++++++++++++++++ fs/xfs/xfs_buf.h | 1 + 3 files changed, 33 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_btree_staging.c +1 -3
@@ -342,9 +342,7 @@ xfs_btree_bload_drop_buf(if (*bpp ==NULL )return ; -if (!xfs_buf_delwri_queue (*bpp, buffers_list)) -ASSERT (0 ); - +xfs_buf_delwri_queue_here (*bpp, buffers_list);xfs_buf_relse (*bpp); *bpp =NULL ; }
fs/xfs/xfs_buf.c +31 -0
@@ -2112,6 +2112,37 @@ xfs_buf_delwri_queue(return true; } +/* +* Queue a buffer to this delwri list as part of a data integrity operation. +* If the buffer is on any other delwri list, we'll wait for that to clear +* so that the caller can submit the buffer for IO and wait for the result. +* Callers must ensure the buffer is not already on the list. +*/ +void +xfs_buf_delwri_queue_here ( +struct xfs_buf *bp, +struct list_head *buffer_list) +{ +/* +* We need this buffer to end up on the /caller's/ delwri list, not any +* old list. This can happen if the buffer is marked stale (which +* clears DELWRI_Q) after the AIL queues the buffer to its list but +* before the AIL has a chance to submit the list. +*/ +while (!list_empty (&bp->b_list)) { +xfs_buf_unlock (bp); +delay (1 ); +xfs_buf_lock (bp); + } + +ASSERT (!(bp->b_flags & _XBF_DELWRI_Q)); + +/* This buffer is uptodate; don't let it get reread. */ + bp->b_flags |=XBF_DONE ; + +xfs_buf_delwri_queue (bp, buffer_list); +} +/* * Compare function is more complex than it needs to be because * the return value is only 32 bits and we are doing comparisons
fs/xfs/xfs_buf.h +1 -0
@@ -315,6 +315,7 @@ extern void xfs_buf_stale(struct xfs_buf *bp);/* Delayed Write Buffer Routines */ extern void xfs_buf_delwri_cancel (struct list_head *);extern bool xfs_buf_delwri_queue (struct xfs_buf *,struct list_head *); +void xfs_buf_delwri_queue_here (struct xfs_buf *bp,struct list_head *bl);extern int xfs_buf_delwri_submit (struct list_head *);extern int xfs_buf_delwri_submit_nowait (struct list_head *);extern int xfs_buf_delwri_pushbuf (struct xfs_buf *,struct list_head *);
Re: [PATCH 1/6] xfs: force all buffers to be written during btree bulk load
fs/xfs/xfs_buf.c xfs_buf_delwri_queue( · line 2122
Quoted 12 lines · Darrick J. Wong
fs/xfs/xfs_buf.c +8
-0@@ -2112,6 +2112,37 @@ xfs_buf_delwri_queue(return true; } +/* +* Queue a buffer to this delwri list as part of a data integrity operation. +* If the buffer is on any other delwri list, we'll wait for that to clear +* so that the caller can submit the buffer for IO and wait for the result. +* Callers must ensure the buffer is not already on the list. +*/ +void +xfs_buf_delwri_queue_here(
This is more of an "exclusive" queuing semantic. i.e. queue this buffer exclusively on the list provided, rather than just ensuring it is queued on some delwri list....
Quoted 4 lines
fs/xfs/xfs_buf.c +4
-0+struct xfs_buf *bp, + struct list_head *buffer_list) +{ +/*
fs/xfs/xfs_buf.c xfs_buf_delwri_queue( · line 2136
Quoted 10 lines
fs/xfs/xfs_buf.c +10
-0+* We need this buffer to end up on the /caller's/ delwri list, not any +* old list. This can happen if the buffer is marked stale (which +* clears DELWRI_Q) after the AIL queues the buffer to its list but +* before the AIL has a chance to submit the list. +*/ +while (!list_empty (&bp->b_list)) { +xfs_buf_unlock (bp); +delay (1 ); +xfs_buf_lock (bp); + }
Not a big fan of this as it the buffer can be on the AIL buffer list for some time (e.g. AIL might have a hundred thousand buffers to push).
This seems more like a case for:
while (!list_empty(&bp->b_list)) {
xfs_buf_unlock(bp);
wait_event_var(bp->b_flags, !(bp->b_flags & _XBF_DELWRI_Q));
xfs_buf_lock(bp);
}And a wrapper:
void xfs_buf_remove_delwri(
struct xfs_buf *bp)
{
list_del(&bp->b_list);
bp->b_flags &= ~_XBF_DELWRI_Q;
wake_up_var(bp->b_flags);
}And we replace all the places where the buffer is taken off the delwri list with calls to xfs_buf_remove_delwri()...
This will greatly reduce the number of context switches during a wait cycle, and reduce the latency of waiting for buffers that are queued for delwri...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 1/6] xfs: force all buffers to be written during btree bulk load
Quoted 55 lines · Dave Chinner
fs/xfs/xfs_buf.c xfs_buf_delwri_queue( · line 2122
Quoted 12 lines · Darrick J. Wong
fs/xfs/xfs_buf.c +8
-0@@ -2112,6 +2112,37 @@ xfs_buf_delwri_queue(return true; } +/* +* Queue a buffer to this delwri list as part of a data integrity operation. +* If the buffer is on any other delwri list, we'll wait for that to clear +* so that the caller can submit the buffer for IO and wait for the result. +* Callers must ensure the buffer is not already on the list. +*/ +void +xfs_buf_delwri_queue_here(This is more of an "exclusive" queuing semantic. i.e. queue this buffer exclusively on the list provided, rather than just ensuring it is queued on some delwri list....
Quoted 4 lines
fs/xfs/xfs_buf.c +4
-0+struct xfs_buf *bp, + struct list_head *buffer_list) +{ +/* fs/xfs/xfs_buf.c xfs_buf_delwri_queue( · line 2136
Quoted 10 lines
fs/xfs/xfs_buf.c +10
-0+* We need this buffer to end up on the /caller's/ delwri list, not any +* old list. This can happen if the buffer is marked stale (which +* clears DELWRI_Q) after the AIL queues the buffer to its list but +* before the AIL has a chance to submit the list. +*/ +while (!list_empty (&bp->b_list)) { +xfs_buf_unlock (bp); +delay (1 ); +xfs_buf_lock (bp); + }Not a big fan of this as it the buffer can be on the AIL buffer list for some time (e.g. AIL might have a hundred thousand buffers to push).
This seems more like a case for:
while (!list_empty(&bp->b_list)) { xfs_buf_unlock(bp); wait_event_var(bp->b_flags, !(bp->b_flags & _XBF_DELWRI_Q)); xfs_buf_lock(bp); }And a wrapper:
void xfs_buf_remove_delwri(
structxfs_buf*bp){ list_del(&bp->b_list); bp->b_flags &= ~_XBF_DELWRI_Q; wake_up_var(bp->b_flags); }
Quoted 6 lines
And we replace all the places where the buffer is taken off the delwri list with calls to
xfs_buf_remove_delwri()...This will greatly reduce the number of context switches during a wait cycle, and reduce the latency of waiting for buffers that are queued for delwri...
The thing is, we're really waiting for the buffer to clear /all/ delwri-related lists. This could be the actual buffer list, but it could also be the xfs_buf_delwri_submit's wait_list. It's not sufficient for repair to allow some other (probably the AIL) thread to write the new structure's buffer because that caller could see an EIO/ENOSPC error, and repair needs to return the specific condition to the caller.
That said, I suppose we could spring a wait_var_event on bp->b_list.next to look for list_empty(&bp->b_list). I'll try that out tonight.
--D
Quoted 6 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 2/6 xfs: implement block reservation accounting for btrees we're staging
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a new xrep_newbt structure to encapsulate a fake root for creating a staged btree cursor as well as to track all the blocks that we need to reserve in order to build that btree.
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_btree_staging.h | 7 - fs/xfs/scrub/agheader_repair.c | 1 fs/xfs/scrub/common.c | 1 fs/xfs/scrub/newbt.c | 470 +++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/newbt.h | 62 +++++ fs/xfs/scrub/scrub.c | 2 fs/xfs/scrub/trace.h | 37 +++ 8 files changed, 576 insertions(+), 5 deletions(-) create mode 100644 fs/xfs/scrub/newbt.c create mode 100644 fs/xfs/scrub/newbt.h
fs/xfs/Makefile +1 -0
@@ -173,6 +173,7 @@ xfs-$(CONFIG_XFS_QUOTA) += scrub/quota.o ifeq ($(CONFIG_XFS_ONLINE_REPAIR),y) xfs-y += $(addprefix scrub/, \ agheader_repair.o \ + newbt.o \ reap.o \ repair.o \ )
fs/xfs/libxfs/xfs_btree_staging.h +2 -5
@@ -38,11 +38,8 @@ struct xbtree_ifakeroot {/* Number of bytes available for this fork in the inode. */ unsigned int if_fork_size; -/* Fork format. */ -unsigned int if_format; - -/* Number of records. */ -unsigned int if_extents; +/* Which fork is this btree being built for? */ +int if_whichfork; };/* Cursor interactions with fake roots for inode-rooted btrees. */
fs/xfs/scrub/agheader_repair.c +1 -0
@@ -10,6 +10,7 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_btree.h" +#include "xfs_btree_staging.h" #include "xfs_log_format.h" #include "xfs_trans.h" #include "xfs_sb.h"
fs/xfs/scrub/common.c +1 -0
@@ -10,6 +10,7 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_btree.h" +#include "xfs_btree_staging.h" #include "xfs_log_format.h" #include "xfs_trans.h" #include "xfs_inode.h"
fs/xfs/scrub/newbt.c new file +470 -0
470 lines not on this page · raw message
fs/xfs/scrub/newbt.h new file +62 -0
62 lines not on this page · raw message
fs/xfs/scrub/scrub.c +2 -0
@@ -17,6 +17,8 @@#include "xfs_errortag.h" #include "xfs_error.h" #include "xfs_scrub.h" +#include "xfs_btree.h" +#include "xfs_btree_staging.h" #include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/trace.h"
fs/xfs/scrub/trace.h +37 -0
@@ -988,6 +988,43 @@ TRACE_EVENT(xrep_ialloc_insert, __entry->freemask) ) +DECLARE_EVENT_CLASS (xrep_newbt_extent_class, + TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, + xfs_agblock_t agbno, xfs_extlen_t len, + int64_t owner), +TP_ARGS (mp, agno, agbno, len, owner), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(xfs_agnumber_t, agno) + __field(xfs_agblock_t, agbno) + __field(xfs_extlen_t, len) +__field (int64_t, owner) + ), +TP_fast_assign ( + __entry->dev = mp->m_super->s_dev; + __entry->agno = agno; + __entry->agbno = agbno; + __entry->len = len; + __entry->owner = owner; + ), +TP_printk ("dev %d:%d agno 0x%x agbno 0x%x fsbcount 0x%x owner 0x%llx" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->agno, + __entry->agbno, + __entry->len, + __entry->owner) +); +#define DEFINE_NEWBT_EXTENT_EVENT (name) \ +DEFINE_EVENT(xrep_newbt_extent_class, name, \ + TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, \ + xfs_agblock_t agbno, xfs_extlen_t len, \ + int64_t owner), \ + TP_ARGS(mp, agno, agbno, len, owner)) +DEFINE_NEWBT_EXTENT_EVENT (xrep_newbt_alloc_ag_blocks); +DEFINE_NEWBT_EXTENT_EVENT (xrep_newbt_alloc_file_blocks); +DEFINE_NEWBT_EXTENT_EVENT (xrep_newbt_free_blocks); +DEFINE_NEWBT_EXTENT_EVENT (xrep_newbt_claim_block); +#endif /* IS_ENABLED(CONFIG_XFS_ONLINE_REPAIR) */ #endif /* _TRACE_XFS_SCRUB_TRACE_H */
PATCH 3/6 xfs: log EFIs for all btree blocks being used to stage a btree
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
We need to log EFIs for every extent that we allocate for the purpose of staging a new btree so that if we fail then the blocks will be freed during log recovery. Add a function to relog the EFIs, so that repair can relog them all every time it creates a new btree block, which will help us to avoid pinning the log tail.
--- fs/xfs/scrub/newbt.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/newbt.h | 4 + fs/xfs/scrub/repair.c | 10 +++ fs/xfs/scrub/repair.h | 1 4 files changed, 162 insertions(+)
fs/xfs/scrub/newbt.c +147 -0
@@ -13,12 +13,14 @@#include "xfs_btree_staging.h" #include "xfs_log_format.h" #include "xfs_trans.h" +#include "xfs_log.h" #include "xfs_sb.h" #include "xfs_inode.h" #include "xfs_alloc.h" #include "xfs_rmap.h" #include "xfs_ag.h" #include "xfs_defer.h" +#include "xfs_extfree_item.h" #include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/trace.h"
@@ -124,6 +126,139 @@ xrep_newbt_init_bare( XFS_AG_RESV_NONE); } +/* +* Set up automatic reaping of the blocks reserved for btree reconstruction in +* case we crash by logging a deferred free item for each extent we allocate so +* that we can get all of the space back if we crash before we can commit the +* new btree. This function returns a token that can be used to cancel +* automatic reaping if repair is successful. +*/ +static int +xrep_newbt_schedule_autoreap ( +struct xrep_newbt *xnr, +struct xrep_newbt_resv *resv) +{ +struct xfs_extent_free_item efi_item = { + .xefi_blockcount = resv->len, + .xefi_owner = xnr->oinfo.oi_owner, + .xefi_flags =XFS_EFI_SKIP_DISCARD , + .xefi_pag = resv->pag, + }; +struct xfs_scrub *sc = xnr->sc; +struct xfs_log_item *lip; +LIST_HEAD (items); + +ASSERT (xnr->oinfo.oi_offset ==0 ); + + efi_item.xefi_startblock =XFS_AGB_TO_FSB (sc->mp, resv->pag->pag_agno, + resv->agbno); +if (xnr->oinfo.oi_flags &XFS_OWNER_INFO_ATTR_FORK ) + efi_item.xefi_flags |=XFS_EFI_ATTR_FORK ; +if (xnr->oinfo.oi_flags &XFS_OWNER_INFO_BMBT_BLOCK ) + efi_item.xefi_flags |=XFS_EFI_BMBT_BLOCK ; + +INIT_LIST_HEAD (&efi_item.xefi_list); +list_add (&efi_item.xefi_list, &items); + +xfs_perag_intent_hold (resv->pag); + lip = xfs_extent_free_defer_type.create_intent (sc->tp, &items,1 , + false); +ASSERT (lip !=NULL && !IS_ERR (lip)); + + resv->efi = lip; +return 0 ; +} + +/* +* Earlier, we logged EFIs for the extents that we allocated to hold the new +* btree so that we could automatically roll back those allocations if the +* system crashed. Now we log an EFD to cancel the EFI, either because the +* repair succeeded and the new blocks are in use; or because the repair was +* cancelled and we're about to free the extents directly. +*/ +static inline void +xrep_newbt_finish_autoreap ( +struct xfs_scrub *sc, +struct xrep_newbt_resv *resv) +{ +struct xfs_efd_log_item *efdp; +struct xfs_extent *extp; +struct xfs_log_item *efd_lip; + + efd_lip = xfs_extent_free_defer_type.create_done (sc->tp, resv->efi,1 ); + efdp = container_of(efd_lip, struct xfs_efd_log_item, efd_item); + extp = efdp->efd_format.efd_extents; + extp->ext_start =XFS_AGB_TO_FSB (sc->mp, resv->pag->pag_agno, + resv->agbno); + extp->ext_len = resv->len; + efdp->efd_next_extent++; +set_bit (XFS_LI_DIRTY , &efd_lip->li_flags); +xfs_perag_intent_rele (resv->pag); +} + +/* Abort an EFI logged for a new btree block reservation. */ +static inline void +xrep_newbt_cancel_autoreap ( +struct xrep_newbt_resv *resv) +{ + xfs_extent_free_defer_type.abort_intent (resv->efi); +xfs_perag_intent_rele (resv->pag); +} + +/* +* Relog the EFIs attached to a staging btree so that we don't pin the log +* tail. Same logic as xfs_defer_relog. +*/ +int +xrep_newbt_relog_autoreap ( +struct xrep_newbt *xnr) +{ +struct xrep_newbt_resv *resv; +unsigned int efi_bytes =0 ; + +list_for_each_entry (resv, &xnr->resv_list, list) { +/* +* If the log intent item for this deferred op is in a +* different checkpoint, relog it to keep the log tail moving +* forward. We're ok with this being racy because an incorrect +* decision means we'll be a little slower at pushing the tail. +*/ +if (!resv->efi ||xfs_log_item_in_current_chkpt (resv->efi)) +continue ; + + resv->efi =xfs_trans_item_relog (resv->efi, xnr->sc->tp); + +/* +* If free space is very fragmented, it's possible that the new +* btree will be allocated a large number of small extents. +* On an active system, it's possible that so many of those +* EFIs will need relogging here that doing them all in one +* transaction will overflow the reservation. +* +* Each allocation for the new btree (xrep_newbt_resv) points +* to a unique single-mapping EFI, so each relog operation logs +* a single-mapping EFD followed by a new EFI. Each single +* mapping EF[ID] item consumes about 128 bytes, so we'll +* assume 256 bytes per relog. Roll if we consume more than +* half of the transaction reservation. +*/ + efi_bytes +=256 ; +if (efi_bytes > xnr->sc->tp->t_log_res /2 ) { +int error; + + error =xrep_roll_trans (xnr->sc); +if (error) +return error; + + efi_bytes =0 ; + } + } + +if (xnr->sc->tp->t_flags &XFS_TRANS_DIRTY ) +return xrep_roll_trans (xnr->sc); +return 0 ; +} +/* * Designate specific blocks to be used to build our new btree. @pag must be * a passive reference.
@@ -136,6 +271,7 @@ xrep_newbt_add_blocks( xfs_extlen_t len) {struct xrep_newbt_resv *resv; +int error; resv =kmalloc (sizeof (struct xrep_newbt_resv ),XCHK_GFP_FLAGS );if (!resv)
@@ -147,8 +283,16 @@ xrep_newbt_add_blocks( resv->used =0 ; resv->pag =xfs_perag_hold (pag); + error =xrep_newbt_schedule_autoreap (xnr, resv); +if (error) + goto out_pag; +list_add_tail (&resv->list, &xnr->resv_list);return 0 ; +out_pag: +xfs_perag_put (resv->pag); +kfree (resv); +return error; }/* Allocate disk space for a new per-AG btree. */
@@ -304,6 +448,8 @@ xrep_newbt_free_extent( free_aglen -= resv->used; } +xrep_newbt_finish_autoreap (sc, resv); +if (free_aglen ==0 )return 0 ;
@@ -389,6 +535,7 @@ xrep_newbt_free(* reservations. */ list_for_each_entry_safe (resv, n, &xnr->resv_list, list) { +xrep_newbt_cancel_autoreap (resv);list_del (&resv->list);xfs_perag_put (resv->pag);kfree (resv);
fs/xfs/scrub/newbt.h +4 -0
@@ -12,6 +12,9 @@ struct xrep_newbt_resv {struct xfs_perag *pag; +/* EFI tracking this space reservation */ +struct xfs_log_item *efi; +/* AG block of the extent we reserved. */ xfs_agblock_t agbno;
@@ -58,5 +61,6 @@ void xrep_newbt_cancel(struct xrep_newbt *xnr);int xrep_newbt_commit (struct xrep_newbt *xnr);int xrep_newbt_claim_block (struct xfs_btree_cur *cur,struct xrep_newbt *xnr,union xfs_btree_ptr *ptr); +int xrep_newbt_relog_autoreap (struct xrep_newbt *xnr);#endif /* __XFS_SCRUB_NEWBT_H__ */
fs/xfs/scrub/repair.c +10 -0
@@ -167,6 +167,16 @@ xrep_roll_ag_trans(return 0 ; } +/* Roll the scrub transaction, holding the primary metadata locked. */ +int +xrep_roll_trans ( +struct xfs_scrub *sc) +{ +if (!sc->ip) +return xrep_roll_ag_trans (sc); +return xfs_trans_roll_inode (&sc->tp, sc->ip); +} +/* Finish all deferred work attached to the repair transaction. */ int xrep_defer_finish(
fs/xfs/scrub/repair.h +1 -0
@@ -20,6 +20,7 @@ static inline int xrep_notsupported(struct xfs_scrub *sc)int xrep_attempt (struct xfs_scrub *sc);void xrep_failure (struct xfs_mount *mp);int xrep_roll_ag_trans (struct xfs_scrub *sc); +int xrep_roll_trans (struct xfs_scrub *sc);int xrep_defer_finish (struct xfs_scrub *sc);bool xrep_ag_has_space (struct xfs_perag *pag,xfs_extlen_t nr_blocks,enum xfs_ag_resv_type type);
PATCH 4/6 xfs: add debug knobs to control btree bulk load slack factors
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add some debug knobs so that we can control the leaf and node block slack when rebuilding btrees.
--- fs/xfs/scrub/newbt.c | 10 ++++++--- fs/xfs/xfs_globals.c | 12 +++++++++++ fs/xfs/xfs_sysctl.h | 2 ++ fs/xfs/xfs_sysfs.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 3 deletions(-)
fs/xfs/scrub/newbt.c +7 -3
@@ -49,9 +49,13 @@ xrep_newbt_estimate_slack(uint64_t free;uint64_t sz; -/* Let the btree code compute the default slack values. */ - bload->leaf_slack =-1 ; - bload->node_slack =-1 ; +/* +* The xfs_globals values are set to -1 (i.e. take the bload defaults) +* unless someone has set them otherwise, so we just pull the values +* here. +*/ + bload->leaf_slack = xfs_globals.bload_leaf_slack; + bload->node_slack = xfs_globals.bload_node_slack;if (sc->ops->type ==ST_PERAG ) { free = sc->sa.pag->pagf_freeblks;
fs/xfs/xfs_globals.c +12 -0
@@ -44,4 +44,16 @@ struct xfs_globals xfs_globals = { .pwork_threads = -1, /* automatic thread detection */ .larp = false, /* log attribute replay */#endif + +/* +* Leave this many record slots empty when bulk loading btrees. By +* default we load new btree leaf blocks 75% full. +*/ + .bload_leaf_slack = -1, + +/* +* Leave this many key/ptr slots empty when bulk loading btrees. By +* default we load new btree node blocks 75% full. +*/ + .bload_node_slack = -1, };
fs/xfs/xfs_sysctl.h +2 -0
@@ -85,6 +85,8 @@ struct xfs_globals {int pwork_threads;/* parallel workqueue threads */ bool larp;/* log attribute replay */ #endif +int bload_leaf_slack;/* btree bulk load leaf slack */ +int bload_node_slack;/* btree bulk load node slack */ int log_recovery_delay;/* log recovery delay (secs) */ int mount_delay;/* mount setup delay (secs) */ bool bug_on_assert;/* BUG() the kernel on assert failure */
fs/xfs/xfs_sysfs.c +54 -0
66 lines not on this page · raw message
PATCH 5/6 xfs: move btree bulkload record initialization to ->get_record implementations
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When we're performing a bulk load of a btree, move the code that actually stores the btree record in the new btree block out of the generic code and into the individual ->get_record implementations. This is preparation for being able to store multiple records with a single indirect call.
--- fs/xfs/libxfs/xfs_btree_staging.c | 17 +++++++---------- fs/xfs/libxfs/xfs_btree_staging.h | 15 ++++++++++----- 2 files changed, 17 insertions(+), 15 deletions(-)
fs/xfs/libxfs/xfs_btree_staging.c +7 -10
@@ -434,22 +434,19 @@ STATIC intxfs_btree_bload_leaf ( struct xfs_btree_cur *cur, unsigned int recs_this_block, - xfs_btree_bload_get_record_fn get_record, + xfs_btree_bload_get_records_fn get_records, struct xfs_btree_block *block, void *priv) { - unsigned int j; + unsigned int j = 1;int ret;/* Fill the leaf block with records. */ -for (j =1 ; j <= recs_this_block; j++) { -union xfs_btree_rec *block_rec; - - ret =get_record (cur, priv); -if (ret) +while (j <= recs_this_block) { + ret =get_records (cur, j, block, recs_this_block - j +1 , priv); +if (ret <0 )return ret; - block_rec =xfs_btree_rec_addr (cur, j, block); - cur->bc_ops->init_rec_from_cur (cur, block_rec); + j += ret; }return 0 ;
@@ -787,7 +784,7 @@ xfs_btree_bload(trace_xfs_btree_bload_block (cur, level, i, blocks, &ptr, nr_this_block); - ret =xfs_btree_bload_leaf (cur, nr_this_block, bbl->get_record, + ret =xfs_btree_bload_leaf (cur, nr_this_block, bbl->get_records, block, priv);if (ret) goto out;
fs/xfs/libxfs/xfs_btree_staging.h +10 -5
@@ -50,7 +50,9 @@ void xfs_btree_commit_ifakeroot(struct xfs_btree_cur *cur, struct xfs_trans *tp, int whichfork, const struct xfs_btree_ops *ops);/* Bulk loading of staged btrees. */ -typedef int (*xfs_btree_bload_get_record_fn )(struct xfs_btree_cur *cur,void *priv); +typedef int (*xfs_btree_bload_get_records_fn )(struct xfs_btree_cur *cur, +unsigned int idx,struct xfs_btree_block *block, +unsigned int nr_wanted,void *priv);typedef int (*xfs_btree_bload_claim_block_fn )(struct xfs_btree_cur *cur,union xfs_btree_ptr *ptr,void *priv); typedef size_t (*xfs_btree_bload_iroot_size_fn)(struct xfs_btree_cur *cur,
@@ -58,11 +60,14 @@ typedef size_t (*xfs_btree_bload_iroot_size_fn)(struct xfs_btree_cur *cur,struct xfs_btree_bload {/* -* This function will be called nr_records times to load records into -* the btree. The function does this by setting the cursor's bc_rec -* field in in-core format. Records must be returned in sort order. +* This function will be called to load @nr_wanted records into the +* btree. The implementation does this by setting the cursor's bc_rec +* field in in-core format and using init_rec_from_cur to set the +* records in the btree block. Records must be returned in sort order. +* The function must return the number of records loaded or the usual +* negative errno. */ -xfs_btree_bload_get_record_fn get_record; +xfs_btree_bload_get_records_fn get_records;/* * This function will be called nr_blocks times to obtain a pointer
PATCH 6/6 xfs: constrain dirty buffers while formatting a staged btree
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Constrain the number of dirty buffers that are locked by the btree staging code at any given time by establishing a threshold at which we put them all on the delwri queue and push them to disk. This limits memory consumption while writing out new btrees.
--- fs/xfs/libxfs/xfs_btree.c | 2 + fs/xfs/libxfs/xfs_btree.h | 3 ++ fs/xfs/libxfs/xfs_btree_staging.c | 50 +++++++++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_btree_staging.h | 10 +++++++ fs/xfs/scrub/newbt.c | 1 + 5 files changed, 54 insertions(+), 12 deletions(-)
fs/xfs/libxfs/xfs_btree.c +1 -1
@@ -1330,7 +1330,7 @@ xfs_btree_get_buf_block(* Read in the buffer at the given ptr and return the buffer and * the block pointer within the buffer. */ -STATIC int +int xfs_btree_read_buf_block( struct xfs_btree_cur *cur, const union xfs_btree_ptr *ptr,
fs/xfs/libxfs/xfs_btree.h +3 -0
@@ -700,6 +700,9 @@ void xfs_btree_set_ptr_null(struct xfs_btree_cur *cur,int xfs_btree_get_buf_block (struct xfs_btree_cur *cur,const union xfs_btree_ptr *ptr,struct xfs_btree_block **block,struct xfs_buf **bpp); +int xfs_btree_read_buf_block (struct xfs_btree_cur *cur, +const union xfs_btree_ptr *ptr,int flags, +struct xfs_btree_block **block,struct xfs_buf **bpp);void xfs_btree_set_sibling (struct xfs_btree_cur *cur,struct xfs_btree_block *block,const union xfs_btree_ptr *ptr,int lr);
fs/xfs/libxfs/xfs_btree_staging.c +39 -11
91 lines not on this page · raw message
fs/xfs/libxfs/xfs_btree_staging.h +10 -0
@@ -115,6 +115,16 @@ struct xfs_btree_bload {* height of the new btree. */ unsigned int btree_height; + +/* +* Flush the new btree block buffer list to disk after this many blocks +* have been formatted. Zero prohibits writing any buffers until all +* blocks have been formatted. +*/ +uint16_t max_dirty; + +/* Number of dirty buffers. */ +uint16_t nr_dirty; }; int xfs_btree_bload_compute_geometry(struct xfs_btree_cur *cur,
fs/xfs/scrub/newbt.c +1 -0
@@ -91,6 +91,7 @@ xrep_newbt_init_ag( xnr->alloc_hint = alloc_hint; xnr->resv = resv;INIT_LIST_HEAD (&xnr->resv_list); + xnr->bload.max_dirty =XFS_B_TO_FSBT (sc->mp,256U <<10 );/* 256K */ xrep_newbt_estimate_slack (xnr); }
cover xfs: stage repair information in pageable memory
In reply to Darrick J. WongHi all,
In general, online repair of an indexed record set walks the filesystem looking for records. These records are sorted and bulk-loaded into a new btree. To make this happen without pinning gigabytes of metadata in memory, first create an abstraction ('xfile') of memfd files so that kernel code can access paged memory, and then an array abstraction ('xfarray') based on xfiles so that online repair can create an array of new records without pinning memory.
These two data storage abstractions are critical for repair of space metadata -- the memory used is pageable, which helps us avoid pinning kernel memory and driving OOM problems; and they are byte-accessible enough that we can use them like (very slow and programmatic) memory buffers.
Later patchsets will build on this functionality to provide blob storage and btrees.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=big-array
--- fs/xfs/Kconfig | 1 fs/xfs/Makefile | 2 fs/xfs/scrub/trace.c | 4 fs/xfs/scrub/trace.h | 262 ++++++++++++ fs/xfs/scrub/xfarray.c | 1084 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/xfarray.h | 142 ++++++ fs/xfs/scrub/xfile.c | 433 +++++++++++++++++++ fs/xfs/scrub/xfile.h | 78 +++ 8 files changed, 2005 insertions(+), 1 deletion(-) create mode 100644 fs/xfs/scrub/xfarray.c create mode 100644 fs/xfs/scrub/xfarray.h create mode 100644 fs/xfs/scrub/xfile.c create mode 100644 fs/xfs/scrub/xfile.h
PATCH 1/7 xfs: create a big array data structure
From: Darrick J. Wong <[email protected]>
Create a simple 'big array' data structure for storage of fixed-size metadata records that will be used to reconstruct a btree index. For repair operations, the most important operations are append, iterate, and sort.
Earlier implementations of the big array used linked lists and suffered from severe problems -- pinning all records in kernel memory was not a good idea and frequently lead to OOM situations; random access was very inefficient; and record overhead for the lists was unacceptably high at 40-60%.
Therefore, the big memory array relies on the 'xfile' abstraction, which creates a memfd file and stores the records in page cache pages. Since the memfd is created in tmpfs, the memory pages can be pushed out to disk if necessary and we have a built-in usage limit of 50% of physical memory.
--- fs/xfs/Kconfig | 1 fs/xfs/Makefile | 2 fs/xfs/scrub/trace.c | 4 - fs/xfs/scrub/trace.h | 123 ++++++++++++++++ fs/xfs/scrub/xfarray.c | 370 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/xfarray.h | 58 ++++++++ fs/xfs/scrub/xfile.c | 325 ++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/xfile.h | 58 ++++++++ 8 files changed, 940 insertions(+), 1 deletion(-) create mode 100644 fs/xfs/scrub/xfarray.c create mode 100644 fs/xfs/scrub/xfarray.h create mode 100644 fs/xfs/scrub/xfile.c create mode 100644 fs/xfs/scrub/xfile.h
fs/xfs/Kconfig +1 -0
@@ -128,6 +128,7 @@ config XFS_ONLINE_SCRUB bool "XFS online metadata check support" default n depends on XFS_FS + depends on TMPFS && SHMEM select XFS_DRAIN_INTENTS help If you say Y here you will be able to check metadata on a
fs/xfs/Makefile +2 -0
@@ -164,6 +164,8 @@ xfs-y += $(addprefix scrub/, \ rmap.o \ scrub.o \ symlink.o \ + xfarray.o \ + xfile.o \ ) xfs-$(CONFIG_XFS_RT) += scrub/rtbitmap.o
fs/xfs/scrub/trace.c +3 -1
@@ -12,8 +12,10 @@#include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_btree.h" -#include "scrub/scrub.h" #include "xfs_ag.h" +#include "scrub/scrub.h" +#include "scrub/xfile.h" +#include "scrub/xfarray.h" /* Figure out which block the btree cursor was pointing to. */ static inline xfs_fsblock_t
fs/xfs/scrub/trace.h +123 -0
135 lines not on this page · raw message
fs/xfs/scrub/xfarray.c new file +370 -0
370 lines not on this page · raw message
fs/xfs/scrub/xfarray.h new file +58 -0
58 lines not on this page · raw message
fs/xfs/scrub/xfile.c new file +325 -0
325 lines not on this page · raw message
fs/xfs/scrub/xfile.h new file +58 -0
58 lines not on this page · raw message
Re: [PATCH 1/7] xfs: create a big array data structure
Quoted 19 lines · Darrick J. Wong
fs/xfs/scrub/xfarray.h new file +19
-0+struct xfarray { +/* Underlying file that backs the array. */ +struct xfile *xfile; + +/* Number of array elements. */ +xfarray_idx_t nr; + +/* Maximum possible array size. */ +xfarray_idx_t max_nr; + +/* Number of unset slots in the array below @nr. */ +uint64_t unset_slots; + +/* Size of an array element. */ +size_t obj_size; + +/* log2 of array element size, if possible. */ +int obj_size_log; +};
fs/xfs/scrub/xfarray.h line 47
Quoted 10 lines
fs/xfs/scrub/xfarray.h new file +10
-0+ +int xfarray_create (struct xfs_mount *mp,const char *descr, +unsigned long long required_capacity,size_t obj_size, +struct xfarray **arrayp); +void xfarray_destroy (struct xfarray *array); +int xfarray_load (struct xfarray *array,xfarray_idx_t idx,void *ptr); +int xfarray_unset (struct xfarray *array,xfarray_idx_t idx); +int xfarray_store (struct xfarray *array,xfarray_idx_t idx,const void *ptr); +int xfarray_store_anywhere (struct xfarray *array,const void *ptr); +bool xfarray_element_is_null (struct xfarray *array,const void *ptr);
Nice simple external interface... +1
Since you're storing fixed size elements, if you wanted to make it slicker you could steal the generic-radix tree approach of using a wrapper type to make the object size known at compile time, which lets you constant propagate through the index -> offset calculations.
But not worth it from a performance POV with the current implementation, because...
Quoted 66 lines
fs/xfs/scrub/xfile.c new file +66
-0+/* +* Read a memory object directly from the xfile's page cache. Unlike regular +* pread, we return -E2BIG and -EFBIG for reads that are too large or at too +* high an offset, instead of truncating the read. Otherwise, we return +* bytes read or an error code, like regular pread. +*/ +ssize_t +xfile_pread ( +struct xfile *xf, +void *buf, +size_t count, +loff_t pos) +{ +struct inode *inode =file_inode (xf->file); +struct address_space *mapping = inode->i_mapping; +struct page *page =NULL ; +ssize_t read =0 ; +unsigned int pflags; +int error =0 ; + +if (count >MAX_RW_COUNT ) +return -E2BIG ; +if (inode->i_sb->s_maxbytes - pos < count) +return -EFBIG ; + +trace_xfile_pread (xf, pos, count); + + pflags =memalloc_nofs_save (); +while (count >0 ) { +void *p, *kaddr; +unsigned int len; + + len =min_t (ssize_t, count,PAGE_SIZE -offset_in_page (pos)); + +/* +* In-kernel reads of a shmem file cause it to allocate a page +* if the mapping shows a hole. Therefore, if we hit ENOMEM +* we can continue by zeroing the caller's buffer. +*/ + page =shmem_read_mapping_page_gfp (mapping, pos >>PAGE_SHIFT , + __GFP_NOWARN); +if (IS_ERR (page)) { + error =PTR_ERR (page); +if (error != -ENOMEM ) +break ; + +memset (buf,0 , len); + goto advance; + } + +if (PageUptodate (page)) { +/* +* xfile pages must never be mapped into userspace, so +* we skip the dcache flush. +*/ + kaddr =kmap_local_page (page); + p = kaddr +offset_in_page (pos); +memcpy (buf, p, len); +kunmap_local (kaddr); + }else { +memset (buf,0 , len); + } +put_page (page); + +advance: + count -= len;
fs/xfs/scrub/xfile.c line 209
Quoted 10 lines
fs/xfs/scrub/xfile.c new file +10
-0+ pos += len; + buf += len; + read += len; + } +memalloc_nofs_restore (pflags); + +if (read >0 ) +return read; +return error; +}
this all, and the write path, looks a bit heavy - you're calling through shmem_read_mapping_page_gfp() on every lookup. Does it matter?
If we care about performance, we want to get it as much as possible down to just the page cache radix tree lookup - and possibly cache the last page returned if we care about sequential performance.
OTOH, maybe shmem_get_folio_gfp() and __filemap_get_folio() could benefit from some early returns -
if (likely(got_the_thing_we_want)) return folio;
Another thought... if obj_size <= PAGE_SIZE, maybe you could do what genradix does and not have objects span pages? That would let you get rid of the loop in read/write - but then you'd want to be doing an interface that works in terms of pages/folios, which wouldn't be as clean as what you've got.
Just spitballing random ideas, looks good :)
Re: [PATCH 1/7] xfs: create a big array data structure
Quoted 112 lines · Kent Overstreet
Quoted 19 lines · Darrick J. Wong
fs/xfs/scrub/xfarray.h new file +19
-0+struct xfarray { +/* Underlying file that backs the array. */ +struct xfile *xfile; + +/* Number of array elements. */ +xfarray_idx_t nr; + +/* Maximum possible array size. */ +xfarray_idx_t max_nr; + +/* Number of unset slots in the array below @nr. */ +uint64_t unset_slots; + +/* Size of an array element. */ +size_t obj_size; + +/* log2 of array element size, if possible. */ +int obj_size_log; +};fs/xfs/scrub/xfarray.h line 47
Quoted 10 lines
fs/xfs/scrub/xfarray.h new file +10
-0+ +int xfarray_create (struct xfs_mount *mp,const char *descr, +unsigned long long required_capacity,size_t obj_size, +struct xfarray **arrayp); +void xfarray_destroy (struct xfarray *array); +int xfarray_load (struct xfarray *array,xfarray_idx_t idx,void *ptr); +int xfarray_unset (struct xfarray *array,xfarray_idx_t idx); +int xfarray_store (struct xfarray *array,xfarray_idx_t idx,const void *ptr); +int xfarray_store_anywhere (struct xfarray *array,const void *ptr); +bool xfarray_element_is_null (struct xfarray *array,const void *ptr);Nice simple external interface... +1
Since you're storing fixed size elements, if you wanted to make it slicker you could steal the generic-radix tree approach of using a wrapper type to make the object size known at compile time, which lets you constant propagate through the index -> offset calculations.
But not worth it from a performance POV with the current implementation, because...
Quoted 71 lines
fs/xfs/scrub/xfile.c new file +71
-0+/* +* Read a memory object directly from the xfile's page cache. Unlike regular +* pread, we return -E2BIG and -EFBIG for reads that are too large or at too +* high an offset, instead of truncating the read. Otherwise, we return +* bytes read or an error code, like regular pread. +*/ +ssize_t +xfile_pread ( +struct xfile *xf, +void *buf, +size_t count, +loff_t pos) +{ +struct inode *inode =file_inode (xf->file); +struct address_space *mapping = inode->i_mapping; +struct page *page =NULL ; +ssize_t read =0 ; +unsigned int pflags; +int error =0 ; + +if (count >MAX_RW_COUNT ) +return -E2BIG ; +if (inode->i_sb->s_maxbytes - pos < count) +return -EFBIG ; + +trace_xfile_pread (xf, pos, count); + + pflags =memalloc_nofs_save (); +while (count >0 ) { +void *p, *kaddr; +unsigned int len; + + len =min_t (ssize_t, count,PAGE_SIZE -offset_in_page (pos)); + +/* +* In-kernel reads of a shmem file cause it to allocate a page +* if the mapping shows a hole. Therefore, if we hit ENOMEM +* we can continue by zeroing the caller's buffer. +*/ + page =shmem_read_mapping_page_gfp (mapping, pos >>PAGE_SHIFT , + __GFP_NOWARN); +if (IS_ERR (page)) { + error =PTR_ERR (page); +if (error != -ENOMEM ) +break ; + +memset (buf,0 , len); + goto advance; + } + +if (PageUptodate (page)) { +/* +* xfile pages must never be mapped into userspace, so +* we skip the dcache flush. +*/ + kaddr =kmap_local_page (page); + p = kaddr +offset_in_page (pos); +memcpy (buf, p, len); +kunmap_local (kaddr); + }else { +memset (buf,0 , len); + } +put_page (page); + +advance: + count -= len; + pos += len; + buf += len; + read += len; + } +memalloc_nofs_restore (pflags);
Quoted 8 lines
fs/xfs/scrub/xfile.c line 209
Quoted 5 lines
fs/xfs/scrub/xfile.c new file +5
-0+ +if (read >0 ) +return read; +return error; +}this all, and the write path, looks a bit heavy - you're calling through
shmem_read_mapping_page_gfp()on every lookup. Does it matter?
Longer term I'd like to work with willy on an in-kernel mmap and/or using large folios with the tmpfs file, but for now I only care that it works correctly and gets merged. :)
Quoted 3 lines
If we care about performance, we want to get it as much as possible down to just the page cache radix tree lookup - and possibly cache the last page returned if we care about sequential performance.
(That comes later in this megapatchset.)
Quoted 9 lines
OTOH, maybe
shmem_get_folio_gfp()and__filemap_get_folio()could benefit from some early returns -if (likely(got_the_thing_we_want)) return folio;Another thought... if
obj_size<=PAGE_SIZE, maybe you could do what genradix does and not have objects span pages? That would let you get rid of the loop in read/write - but then you'd want to be doing an interface that works in terms of pages/folios, which wouldn't be as clean as what you've got.
Yeah... the xfs dquot files store 136-byte dquot records which don't cross fsblock boundaries. There's a lot of math involved there, which at least there's an incore dquot object so we're mostly not pounding on the dquot file itself.
--D
Quoted 1 line
Just spitballing random ideas, looks good :)
Re: [PATCH 1/7] xfs: create a big array data structure
In reply to Darrick J. WongQuoted 6 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create a simple 'big array' data structure for storage of fixed-size metadata records that will be used to reconstruct a btree index. For repair operations, the most important operations are append, iterate, and sort.
....
Quoted 14 lines
fs/xfs/scrub/xfarray.c new file +14
-0+/* +* Initialize a big memory array. Array records cannot be larger than a +* page, and the array cannot span more bytes than the page cache supports. +* If @required_capacity is nonzero, the maximum array size will be set to this +* quantity and the array creation will fail if the underlying storage cannot +* support that many records. +*/ +int +xfarray_create ( +struct xfs_mount *mp, +const char *description, +unsigned long long required_capacity, +size_t obj_size, +struct xfarray **arrayp)
fs/xfs/scrub/xfarray.c line 85
Quoted 10 lines
fs/xfs/scrub/xfarray.c new file +10
-0+{ +struct xfarray *array; +struct xfile *xfile; +int error; + +ASSERT (obj_size <PAGE_SIZE ); + + error =xfile_create (mp, description,0 , &xfile); +if (error) +return error;
The xfarray and xfile can be completely independent of anything XFS at all by passing the full xfile "filename" that is to be used here rather than having xfile_create prefix the description with a string like "XFS (devname):".
.....
Otherwise this is all fine.
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 1/7] xfs: create a big array data structure
Quoted 29 lines · Dave Chinner
Quoted 6 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create a simple 'big array' data structure for storage of fixed-size metadata records that will be used to reconstruct a btree index. For repair operations, the most important operations are append, iterate, and sort.
....
Quoted 21 lines
fs/xfs/scrub/xfarray.c new file +21
-0+/* +* Initialize a big memory array. Array records cannot be larger than a +* page, and the array cannot span more bytes than the page cache supports. +* If @required_capacity is nonzero, the maximum array size will be set to this +* quantity and the array creation will fail if the underlying storage cannot +* support that many records. +*/ +int +xfarray_create ( +struct xfs_mount *mp, +const char *description, +unsigned long long required_capacity, +size_t obj_size, +struct xfarray **arrayp) +{ +struct xfarray *array; +struct xfile *xfile; +int error; + +ASSERT (obj_size <PAGE_SIZE ); +
Quoted 8 lines
fs/xfs/scrub/xfarray.c line 85
Quoted 3 lines
fs/xfs/scrub/xfarray.c new file +3
-0+ error =xfile_create (mp, description,0 , &xfile); +if (error) +return error;The xfarray and xfile can be completely independent of anything XFS at all by passing the full xfile "filename" that is to be used here rather than having
xfile_createprefix the description with a string like "XFS (devname):".
Ok, I'll shift the "XFS (devname)" part into the callers for the next round.
--D
Quoted 8 lines
.....
Otherwise this is all fine.
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 2/7 xfs: enable sorting of xfile-backed arrays
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The btree bulk loading code requires that records be provided in the correct record sort order for the given btree type. In general, repair code cannot be required to collect records in order, and it is not feasible to insert new records in the middle of an array to maintain sort order.
Implement a sorting algorithm so that we can sort the records just prior to bulk loading. In principle, an xfarray could consume many gigabytes of memory and its backing pages can be sent out to disk at any time. This means that we cannot map the entire array into memory at once, so we must find a way to divide the work into smaller portions (e.g. a page) that /can/ be mapped into memory.
Quicksort seems like a reasonable fit for this purpose, since it uses a divide and conquer strategy to keep its average runtime logarithmic. The solution presented here is a port of the glibc implementation, which itself is derived from the median-of-three and tail call recursion strategies outlined by Sedgwick.
Subsequent patches will optimize the implementation further by utilizing the kernel's heapsort on directly-mapped memory whenever possible, and improving the quicksort pivot selection algorithm to try to avoid O(n^2) collapses.
Note: The sorting functionality gets its own patch because the basic big array mechanisms were plenty for a single code patch.
--- fs/xfs/scrub/trace.h | 114 ++++++++++ fs/xfs/scrub/xfarray.c | 569 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/xfarray.h | 67 ++++++ 3 files changed, 750 insertions(+)
fs/xfs/scrub/trace.h +114 -0
@@ -18,6 +18,7 @@struct xfile ;struct xfarray ; +struct xfarray_sortinfo ;/* * ftrace's __print_symbolic requires that all enum values be wrapped in the
@@ -848,6 +849,119 @@ TRACE_EVENT(xfarray_create, __entry->obj_size_log) ); +TRACE_EVENT (xfarray_isort, + TP_PROTO(struct xfarray_sortinfo *si, uint64_t lo, uint64_t hi), +TP_ARGS (si, lo, hi), +TP_STRUCT__entry ( + __field(unsigned long, ino) + __field(unsigned long long, lo) + __field(unsigned long long, hi) + ), +TP_fast_assign ( + __entry->ino = file_inode(si->array->xfile->file)->i_ino; + __entry->lo = lo; + __entry->hi = hi; + ), +TP_printk ("xfino 0x%lx lo %llu hi %llu elts %llu" , + __entry->ino, + __entry->lo, + __entry->hi, + __entry->hi - __entry->lo) +); + +TRACE_EVENT (xfarray_qsort, + TP_PROTO(struct xfarray_sortinfo *si, uint64_t lo, uint64_t hi), +TP_ARGS (si, lo, hi), +TP_STRUCT__entry ( + __field(unsigned long, ino) + __field(unsigned long long, lo) + __field(unsigned long long, hi) + __field(int, stack_depth) +__field (int, max_stack_depth) + ), +TP_fast_assign ( + __entry->ino = file_inode(si->array->xfile->file)->i_ino; + __entry->lo = lo; + __entry->hi = hi; + __entry->stack_depth = si->stack_depth; + __entry->max_stack_depth = si->max_stack_depth; + ), +TP_printk ("xfino 0x%lx lo %llu hi %llu elts %llu stack %d/%d" , + __entry->ino, + __entry->lo, + __entry->hi, + __entry->hi - __entry->lo, + __entry->stack_depth, + __entry->max_stack_depth) +); + +TRACE_EVENT (xfarray_sort, + TP_PROTO(struct xfarray_sortinfo *si, size_t bytes), +TP_ARGS (si, bytes), +TP_STRUCT__entry ( + __field(unsigned long, ino) + __field(unsigned long long, nr) + __field(size_t, obj_size) + __field(size_t, bytes) + __field(unsigned int, max_stack_depth) + ), +TP_fast_assign ( + __entry->nr = si->array->nr; + __entry->obj_size = si->array->obj_size; + __entry->ino = file_inode(si->array->xfile->file)->i_ino; + __entry->bytes = bytes; + __entry->max_stack_depth = si->max_stack_depth; + ), +TP_printk ("xfino 0x%lx nr %llu objsz %zu stack %u bytes %zu" , + __entry->ino, + __entry->nr, + __entry->obj_size, + __entry->max_stack_depth, + __entry->bytes) +); + +TRACE_EVENT (xfarray_sort_stats, + TP_PROTO(struct xfarray_sortinfo *si, int error), +TP_ARGS (si, error), +TP_STRUCT__entry ( + __field(unsigned long, ino) +#ifdef DEBUG + __field(unsigned long long, loads) + __field(unsigned long long, stores) + __field(unsigned long long, compares) +#endif + __field(unsigned int, max_stack_depth) + __field(unsigned int, max_stack_used) +__field (int, error) + ), +TP_fast_assign ( + __entry->ino = file_inode(si->array->xfile->file)->i_ino; +#ifdef DEBUG + __entry->loads = si->loads; + __entry->stores = si->stores; + __entry->compares = si->compares; +#endif + __entry->max_stack_depth = si->max_stack_depth; + __entry->max_stack_used = si->max_stack_used; + __entry->error = error; + ), +TP_printk ( +#ifdef DEBUG +"xfino 0x%lx loads %llu stores %llu compares %llu stack_depth %u/%u error %d" , +#else +"xfino 0x%lx stack_depth %u/%u error %d" , +#endif + __entry->ino, +#ifdef DEBUG + __entry->loads, + __entry->stores, + __entry->compares, +#endif + __entry->max_stack_used, + __entry->max_stack_depth, + __entry->error) +); +/* repair tracepoints */ #if IS_ENABLED (CONFIG_XFS_ONLINE_REPAIR )
fs/xfs/scrub/xfarray.c +569 -0
572 lines not on this page · raw message
fs/xfs/scrub/xfarray.h +67 -0
71 lines not on this page · raw message
PATCH 3/7 xfs: convert xfarray insertion sort to heapsort using scratchpad memory
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In the previous patch, we created a very basic quicksort implementation for xfile arrays. While the use of an alternate sorting algorithm to avoid quicksort recursion on very small subsets reduces the runtime modestly, we could do better than a load and store-heavy insertion sort, particularly since each load and store requires a page mapping lookup in the xfile.
For a small increase in kernel memory requirements, we could instead bulk load the xfarray records into memory, use the kernel's existing heapsort implementation to sort the records, and bulk store the memory buffer back into the xfile. On the author's computer, this reduces the runtime by about 5% on a 500,000 element array.
--- fs/xfs/scrub/trace.h | 5 +- fs/xfs/scrub/xfarray.c | 142 +++++++++--------------------------------------- fs/xfs/scrub/xfarray.h | 12 +++- 3 files changed, 39 insertions(+), 120 deletions(-)
fs/xfs/scrub/trace.h +4 -1
@@ -929,6 +929,7 @@ TRACE_EVENT(xfarray_sort_stats, __field(unsigned long long, loads) __field(unsigned long long, stores) __field(unsigned long long, compares) + __field(unsigned long long, heapsorts)#endif __field(unsigned int, max_stack_depth)__field (unsigned int , max_stack_used)
@@ -940,6 +941,7 @@ TRACE_EVENT(xfarray_sort_stats, __entry->loads = si->loads; __entry->stores = si->stores; __entry->compares = si->compares; + __entry->heapsorts = si->heapsorts;#endif __entry->max_stack_depth = si->max_stack_depth; __entry->max_stack_used = si->max_stack_used;
@@ -947,7 +949,7 @@ TRACE_EVENT(xfarray_sort_stats, ), TP_printk(#ifdef DEBUG - "xfino 0x%lx loads %llu stores %llu compares %llu stack_depth %u/%u error %d", +"xfino 0x%lx loads %llu stores %llu compares %llu heapsorts %llu stack_depth %u/%u error %d" , #else "xfino 0x%lx stack_depth %u/%u error %d", #endif
@@ -956,6 +958,7 @@ TRACE_EVENT(xfarray_sort_stats, __entry->loads, __entry->stores, __entry->compares, + __entry->heapsorts, #endif __entry->max_stack_used, __entry->max_stack_depth,
fs/xfs/scrub/xfarray.c +27 -115
202 lines not on this page · raw message
fs/xfs/scrub/xfarray.h +8 -4
@@ -59,6 +59,10 @@ int xfarray_load_next(struct xfarray *array, xfarray_idx_t *idx, void *rec);typedef cmp_func_t xfarray_cmp_fn ; +/* Perform an in-memory heapsort for small subsets. */ +#define XFARRAY_ISORT_SHIFT (4) +#define XFARRAY_ISORT_NR (1U << XFARRAY_ISORT_SHIFT) +struct xfarray_sortinfo {struct xfarray *array;
@@ -82,6 +86,7 @@ struct xfarray_sortinfo {uint64_t loads;uint64_t stores;uint64_t compares; +uint64_t heapsorts;#endif /*
@@ -100,11 +105,10 @@ struct xfarray_sortinfo {* * union { * -* If for a given subset we decide to use an insertion sort, we use the -* scratchpad record after the xfarray and a second scratchpad record -* here to compare items: +* If for a given subset we decide to use an in-memory sort, we use a +* block of scratchpad records here to compare items: * -* xfarray_rec_t scratch; +* xfarray_rec_t scratch[ISORT_NR]; * * Otherwise, we want to partition the records to partition the array. * We store the chosen pivot record here and use the xfarray scratchpad
PATCH 4/7 xfs: teach xfile to pass back direct-map pages to caller
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Certain xfile array operations (such as sorting) can be sped up quite a bit by allowing xfile users to grab a page to bulk-read the records contained within it. Create helper methods to facilitate this.
--- fs/xfs/scrub/trace.h | 2 + fs/xfs/scrub/xfile.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/xfile.h | 10 +++++ 3 files changed, 120 insertions(+)
fs/xfs/scrub/trace.h +2 -0
@@ -823,6 +823,8 @@ DEFINE_EVENT(xfile_class, name, \DEFINE_XFILE_EVENT (xfile_pread);DEFINE_XFILE_EVENT (xfile_pwrite);DEFINE_XFILE_EVENT (xfile_seek_data); +DEFINE_XFILE_EVENT (xfile_get_page); +DEFINE_XFILE_EVENT (xfile_put_page); TRACE_EVENT(xfarray_create, TP_PROTO(struct xfarray *xfa, unsigned long long required_capacity),
fs/xfs/scrub/xfile.c +108 -0
111 lines not on this page · raw message
fs/xfs/scrub/xfile.h +10 -0
@@ -6,6 +6,12 @@#ifndef __XFS_SCRUB_XFILE_H__#define __XFS_SCRUB_XFILE_H__ +struct xfile_page { +struct page *page; +void *fsdata; +loff_t pos; +}; +struct xfile {struct file *file; };
@@ -55,4 +61,8 @@ struct xfile_stat {int xfile_stat (struct xfile *xf,struct xfile_stat *statbuf); +int xfile_get_page (struct xfile *xf,loff_t offset,unsigned int len, +struct xfile_page *xbuf); +int xfile_put_page (struct xfile *xf,struct xfile_page *xbuf); +#endif /* __XFS_SCRUB_XFILE_H__ */
PATCH 5/7 xfs: speed up xfarray sort by sorting xfile page contents directly
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If all the records in an xfarray subset live within the same memory page, we can short-circuit even more quicksort recursion by mapping that page into the local CPU and using the kernel's heapsort function to sort the subset. On the author's computer, this reduces the runtime by another 15% on a 500,000 element array.
--- fs/xfs/scrub/trace.h | 20 ++++++++++ fs/xfs/scrub/xfarray.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/xfarray.h | 4 ++ 3 files changed, 121 insertions(+)
fs/xfs/scrub/trace.h +20 -0
@@ -871,6 +871,26 @@ TRACE_EVENT(xfarray_isort, __entry->hi - __entry->lo) ); +TRACE_EVENT (xfarray_pagesort, + TP_PROTO(struct xfarray_sortinfo *si, uint64_t lo, uint64_t hi), +TP_ARGS (si, lo, hi), +TP_STRUCT__entry ( + __field(unsigned long, ino) + __field(unsigned long long, lo) + __field(unsigned long long, hi) + ), +TP_fast_assign ( + __entry->ino = file_inode(si->array->xfile->file)->i_ino; + __entry->lo = lo; + __entry->hi = hi; + ), +TP_printk ("xfino 0x%lx lo %llu hi %llu elts %llu" , + __entry->ino, + __entry->lo, + __entry->hi, + __entry->hi - __entry->lo) +); + TRACE_EVENT(xfarray_qsort, TP_PROTO(struct xfarray_sortinfo *si, uint64_t lo, uint64_t hi), TP_ARGS(si, lo, hi),
fs/xfs/scrub/xfarray.c +97 -0
115 lines not on this page · raw message
fs/xfs/scrub/xfarray.h +4 -0
@@ -81,6 +81,10 @@ struct xfarray_sortinfo {/* XFARRAY_SORT_* flags; see below. */ unsigned int flags; +/* Cache a page here for faster access. */ +struct xfile_page xfpage; +void *page_kaddr; +#ifdef DEBUG /* Performance statistics. */ uint64_t loads;
PATCH 6/7 xfs: cache pages used for xfarray quicksort convergence
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
After quicksort picks a pivot item for a particular subsort, it walks the records in that subset from the outside in, rearranging them so that every record less than the pivot comes before it, and every record greater than the pivot comes after it. This scan has a lot of locality, so we can speed it up quite a bit by grabbing the xfile backing page and holding onto it as long as we possibly can. Doing so reduces the runtime by another 5% on the author's computer.
--- fs/xfs/scrub/xfarray.c | 86 ++++++++++++++++++++++++++++++++++++++++++------ fs/xfs/scrub/xfile.h | 10 ++++++ 2 files changed, 86 insertions(+), 10 deletions(-)
fs/xfs/scrub/xfarray.c +76 -10
@@ -760,6 +760,66 @@ xfarray_qsort_push(return 0 ; } +/* +* Load an element from the array into the first scratchpad and cache the page, +* if possible. +*/ +static inline int +xfarray_sort_load_cached ( +struct xfarray_sortinfo *si, +xfarray_idx_t idx, +void *ptr) +{ +loff_t idx_pos =xfarray_pos (si->array, idx); +pgoff_t startpage; +pgoff_t endpage; +int error =0 ; + +/* +* If this load would split a page, release the cached page, if any, +* and perform a traditional read. +*/ + startpage = idx_pos >>PAGE_SHIFT ; + endpage = (idx_pos + si->array->obj_size -1 ) >>PAGE_SHIFT ; +if (startpage != endpage) { + error =xfarray_sort_put_page (si); +if (error) +return error; + +if (xfarray_sort_terminated (si, &error)) +return error; + +return xfile_obj_load (si->array->xfile, ptr, + si->array->obj_size, idx_pos); + } + +/* If the cached page is not the one we want, release it. */ +if (xfile_page_cached (&si->xfpage) && +xfile_page_index (&si->xfpage) != startpage) { + error =xfarray_sort_put_page (si); +if (error) +return error; + } + +/* +* If we don't have a cached page (and we know the load is contained +* in a single page) then grab it. +*/ +if (!xfile_page_cached (&si->xfpage)) { +if (xfarray_sort_terminated (si, &error)) +return error; + + error =xfarray_sort_get_page (si, startpage <<PAGE_SHIFT , +PAGE_SIZE ); +if (error) +return error; + } + +memcpy (ptr, si->page_kaddr +offset_in_page (idx_pos), + si->array->obj_size); +return 0 ; +} +/* * Sort the array elements via quicksort. This implementation incorporates * four optimizations discussed in Sedgewick:
@@ -785,6 +845,10 @@ xfarray_qsort_push(* If a small set is contained entirely within a single xfile memory page, * map the page directly and run heap sort directly on the xfile page * instead of using the load/store interface. This halves the runtime. +* +* 5. This optimization is specific to the implementation. When converging lo +* and hi after selecting a pivot, we will try to retain the xfile memory +* page between load calls, which reduces run time by 50%. */ /*
@@ -866,19 +930,20 @@ xfarray_sort(* Decrement hi until it finds an a[hi] less than the * pivot value. */ - error =xfarray_sort_load (si, hi, scratch); + error =xfarray_sort_load_cached (si, hi, scratch);if (error) goto out_free;while (xfarray_sort_cmp (si, scratch, pivot) >=0 && lo < hi) { -if (xfarray_sort_terminated (si, &error)) - goto out_free; - hi--; - error =xfarray_sort_load (si, hi, scratch); + error =xfarray_sort_load_cached (si, hi, + scratch);if (error) goto out_free; } + error =xfarray_sort_put_page (si); +if (error) + goto out_free;if (xfarray_sort_terminated (si, &error)) goto out_free;
@@ -894,19 +959,20 @@ xfarray_sort(* Increment lo until it finds an a[lo] greater than * the pivot value. */ - error =xfarray_sort_load (si, lo, scratch); + error =xfarray_sort_load_cached (si, lo, scratch);if (error) goto out_free;while (xfarray_sort_cmp (si, scratch, pivot) <=0 && lo < hi) { -if (xfarray_sort_terminated (si, &error)) - goto out_free; - lo++; - error =xfarray_sort_load (si, lo, scratch); + error =xfarray_sort_load_cached (si, lo, + scratch);if (error) goto out_free; } + error =xfarray_sort_put_page (si); +if (error) + goto out_free;if (xfarray_sort_terminated (si, &error)) goto out_free;
fs/xfs/scrub/xfile.h +10 -0
@@ -12,6 +12,16 @@ struct xfile_page {loff_t pos; }; +static inline bool xfile_page_cached (const struct xfile_page *xfpage) +{ +return xfpage->page !=NULL ; +} + +static inline pgoff_t xfile_page_index (const struct xfile_page *xfpage) +{ +return xfpage->page->index; +} +struct xfile {struct file *file; };
PATCH 7/7 xfs: improve xfarray quicksort pivot
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Now that we have the means to do insertion sorts of small in-memory subsets of an xfarray, use it to improve the quicksort pivot algorithm by reading 7 records into memory and finding the median of that. This should prevent bad partitioning when a[lo] and a[hi] end up next to each other in the final sort, which can happen when sorting for cntbt repair when the free space is extremely fragmented (e.g. generic/176).
This doesn't speed up the average quicksort run by much, but it will (hopefully) avoid the quadratic time collapse for which quicksort is famous.
--- fs/xfs/scrub/xfarray.c | 198 ++++++++++++++++++++++++++++++++---------------- fs/xfs/scrub/xfarray.h | 19 +++-- 2 files changed, 148 insertions(+), 69 deletions(-)
fs/xfs/scrub/xfarray.c +134 -64
@@ -428,6 +428,14 @@ static inline xfarray_idx_t *xfarray_sortinfo_hi(struct xfarray_sortinfo *si)return xfarray_sortinfo_lo (si) + si->max_stack_depth; } +/* Size of each element in the quicksort pivot array. */ +static inline size_t +xfarray_pivot_rec_sz ( +struct xfarray *array) +{ +return round_up (array->obj_size,8 ) +sizeof (xfarray_idx_t); +} +/* Allocate memory to handle the sort. */ static inline int xfarray_sortinfo_alloc(
@@ -438,8 +446,16 @@ xfarray_sortinfo_alloc( {struct xfarray_sortinfo *si;size_t nr_bytes =sizeof (struct xfarray_sortinfo ); +size_t pivot_rec_sz =xfarray_pivot_rec_sz (array);int max_stack_depth; +/* +* The median-of-nine pivot algorithm doesn't work if a subset has +* fewer than 9 items. Make sure the in-memory sort will always take +* over for subsets where this wouldn't be the case. +*/ +BUILD_BUG_ON (XFARRAY_QSORT_PIVOT_NR >=XFARRAY_ISORT_NR ); +/* * Tail-call recursion during the partitioning phase means that * quicksort will never recurse more than log2(nr) times. We need one
@@ -454,8 +470,10 @@ xfarray_sortinfo_alloc(/* Each level of quicksort uses a lo and a hi index */ nr_bytes += max_stack_depth *sizeof (xfarray_idx_t) *2 ; -/* Scratchpad for in-memory sort, or one record for the pivot */ - nr_bytes += (XFARRAY_ISORT_NR * array->obj_size); +/* Scratchpad for in-memory sort, or finding the pivot */ + nr_bytes +=max_t (size_t, + (XFARRAY_QSORT_PIVOT_NR +1 ) * pivot_rec_sz, +XFARRAY_ISORT_NR * array->obj_size); si =kvzalloc (nr_bytes,XCHK_GFP_FLAGS );if (!si)
@@ -633,14 +651,43 @@ static inline void *xfarray_sortinfo_pivot(struct xfarray_sortinfo *si)return xfarray_sortinfo_hi (si) + si->max_stack_depth; } +/* Return a pointer to the start of the pivot array. */ +static inline void * +xfarray_sortinfo_pivot_array ( +struct xfarray_sortinfo *si) +{ +return xfarray_sortinfo_pivot (si) + si->array->obj_size; +} + +/* The xfarray record is stored at the start of each pivot array element. */ +static inline void * +xfarray_pivot_array_rec ( +void *pa, +size_t pa_recsz, +unsigned int pa_idx) +{ +return pa + (pa_recsz * pa_idx); +} + +/* The xfarray index is stored at the end of each pivot array element. */ +static inline xfarray_idx_t * +xfarray_pivot_array_idx ( +void *pa, +size_t pa_recsz, +unsigned int pa_idx) +{ +return xfarray_pivot_array_rec (pa, pa_recsz, pa_idx +1 ) - +sizeof (xfarray_idx_t); +} +/* * Find a pivot value for quicksort partitioning, swap it with a[lo], and save * the cached pivot record for the next step. * -* Select the median value from a[lo], a[mid], and a[hi]. Put the median in -* a[lo], the lowest in a[mid], and the highest in a[hi]. Using the median of -* the three reduces the chances that we pick the worst case pivot value, since -* it's likely that our array values are nearly sorted. +* Load evenly-spaced records within the given range into memory, sort them, +* and choose the pivot from the median record. Using multiple points will +* improve the quality of the pivot selection, and hopefully avoid the worst +* quicksort behavior, since our array values are nearly always evenly sorted. */ STATIC int xfarray_qsort_pivot(
@@ -648,76 +695,99 @@ xfarray_qsort_pivot(xfarray_idx_t lo, xfarray_idx_t hi) { - void *a = xfarray_sortinfo_pivot(si); -void *b =xfarray_scratch (si->array); -xfarray_idx_t mid = lo + ((hi - lo) /2 ); + void *pivot = xfarray_sortinfo_pivot(si); +void *parray =xfarray_sortinfo_pivot_array (si); +void *recp; +xfarray_idx_t *idxp; +xfarray_idx_t step = (hi - lo) / (XFARRAY_QSORT_PIVOT_NR -1 ); +size_t pivot_rec_sz =xfarray_pivot_rec_sz (si->array); +int i, j;int error; -/* if a[mid] < a[lo], swap a[mid] and a[lo]. */ - error =xfarray_sort_load (si, mid, a); -if (error) -return error; - error =xfarray_sort_load (si, lo, b); -if (error) -return error; -if (xfarray_sort_cmp (si, a, b) <0 ) { - error =xfarray_sort_store (si, lo, a); -if (error) -return error; - error =xfarray_sort_store (si, mid, b); -if (error) -return error; - } +ASSERT (step >0 ); -/* if a[hi] < a[mid], swap a[mid] and a[hi]. */ - error =xfarray_sort_load (si, hi, a); -if (error) -return error; - error =xfarray_sort_load (si, mid, b); -if (error) -return error; -if (xfarray_sort_cmp (si, a, b) <0 ) { - error =xfarray_sort_store (si, mid, a); -if (error) -return error; - error =xfarray_sort_store (si, hi, b); -if (error) -return error; - }else { - goto move_front; +/* +* Load the xfarray indexes of the records we intend to sample into the +* pivot array. +*/ + idxp =xfarray_pivot_array_idx (parray, pivot_rec_sz,0 ); + *idxp = lo; +for (i =1 ; i <XFARRAY_QSORT_PIVOT_NR -1 ; i++) { + idxp =xfarray_pivot_array_idx (parray, pivot_rec_sz, i); + *idxp = lo + (i * step); } + idxp =xfarray_pivot_array_idx (parray, pivot_rec_sz, +XFARRAY_QSORT_PIVOT_NR -1 ); + *idxp = hi; -/* if a[mid] < a[lo], swap a[mid] and a[lo]. */ - error =xfarray_sort_load (si, mid, a); -if (error) -return error; - error =xfarray_sort_load (si, lo, b); -if (error) -return error; -if (xfarray_sort_cmp (si, a, b) <0 ) { - error =xfarray_sort_store (si, lo, a); -if (error) -return error; - error =xfarray_sort_store (si, mid, b); +/* Load the selected xfarray records into the pivot array. */ +for (i =0 ; i <XFARRAY_QSORT_PIVOT_NR ; i++) { +xfarray_idx_t idx; + + recp =xfarray_pivot_array_rec (parray, pivot_rec_sz, i); + idxp =xfarray_pivot_array_idx (parray, pivot_rec_sz, i); + +/* No unset records; load directly into the array. */ +if (likely (si->array->unset_slots ==0 )) { + error =xfarray_sort_load (si, *idxp, recp); +if (error) +return error; +continue ; + } + +/* +* Load non-null records into the scratchpad without changing +* the xfarray_idx_t in the pivot array. +*/ + idx = *idxp; +xfarray_sort_bump_loads (si); + error =xfarray_load_next (si->array, &idx, recp);if (error)return error; } -move_front: +xfarray_sort_bump_heapsorts (si); +sort (parray,XFARRAY_QSORT_PIVOT_NR , pivot_rec_sz, si->cmp_fn,NULL ); +/* -* Move our selected pivot to a[lo]. Recall that a == si->pivot, so -* this leaves us with the pivot cached in the sortinfo structure. +* We sorted the pivot array records (which includes the xfarray +* indices) in xfarray record order. The median element of the pivot +* array contains the xfarray record that we will use as the pivot. +* Copy that xfarray record to the designated space. */ - error =xfarray_sort_load (si, lo, b); -if (error) -return error; - error =xfarray_sort_load (si, mid, a); -if (error) -return error; - error =xfarray_sort_store (si, mid, b); + recp =xfarray_pivot_array_rec (parray, pivot_rec_sz, +XFARRAY_QSORT_PIVOT_NR /2 ); +memcpy (pivot, recp, si->array->obj_size); + +/* If the pivot record we chose was already in a[lo] then we're done. */ + idxp =xfarray_pivot_array_idx (parray, pivot_rec_sz, +XFARRAY_QSORT_PIVOT_NR /2 ); +if (*idxp == lo) +return 0 ; + +/* +* Find the cached copy of a[lo] in the pivot array so that we can swap +* a[lo] and a[pivot]. +*/ +for (i =0 , j =-1 ; i <XFARRAY_QSORT_PIVOT_NR ; i++) { + idxp =xfarray_pivot_array_idx (parray, pivot_rec_sz, i); +if (*idxp == lo) + j = i; + } +if (j <0 ) { +ASSERT (j >=0 ); +return -EFSCORRUPTED ; + } + +/* Swap a[lo] and a[pivot]. */ + error =xfarray_sort_store (si, lo, pivot);if (error)return error; -return xfarray_sort_store (si, lo, a); + + recp =xfarray_pivot_array_rec (parray, pivot_rec_sz, j); + idxp =xfarray_pivot_array_idx (parray, pivot_rec_sz, +XFARRAY_QSORT_PIVOT_NR /2 ); +return xfarray_sort_store (si, *idxp, recp); }/*
@@ -829,7 +899,7 @@ xfarray_sort_load_cached(* particularly expensive in the kernel. * * 2. For arrays with records in arbitrary or user-controlled order, choose the -* pivot element using a median-of-three decision tree. This reduces the +* pivot element using a median-of-nine decision tree. This reduces the * probability of selecting a bad pivot value which causes worst case * behavior (i.e. partition sizes of 1). *
fs/xfs/scrub/xfarray.h +14 -5
@@ -63,6 +63,9 @@ typedef cmp_func_t xfarray_cmp_fn;#define XFARRAY_ISORT_SHIFT (4)#define XFARRAY_ISORT_NR (1U << XFARRAY_ISORT_SHIFT) +/* Evalulate this many points to find the qsort pivot. */ +#define XFARRAY_QSORT_PIVOT_NR (9) +struct xfarray_sortinfo {struct xfarray *array;
@@ -92,7 +95,6 @@ struct xfarray_sortinfo {uint64_t compares;uint64_t heapsorts;#endif -/* * Extra bytes are allocated beyond the end of the structure to store * quicksort information. C does not permit multiple VLAs per struct,
@@ -115,11 +117,18 @@ struct xfarray_sortinfo {* xfarray_rec_t scratch[ISORT_NR]; * * Otherwise, we want to partition the records to partition the array. -* We store the chosen pivot record here and use the xfarray scratchpad -* to rearrange the array around the pivot: -* -* xfarray_rec_t pivot; +* We store the chosen pivot record at the start of the scratchpad area +* and use the rest to sample some records to estimate the median. +* The format of the qsort_pivot array enables us to use the kernel +* heapsort function to place the median value in the middle. * +* struct { +* xfarray_rec_t pivot; +* struct { +* xfarray_rec_t rec; (rounded up to 8 bytes) +* xfarray_idx_t idx; +* } qsort_pivot[QSORT_PIVOT_NR]; +* }; * } */ };
Re: [PATCHSET v25.0 0/7] xfs: stage repair information in pageable memory
In reply to Darrick J. WongQuoted 10 lines · Darrick J. Wong
Hi all,
In general, online repair of an indexed record set walks the filesystem looking for records. These records are sorted and bulk-loaded into a new btree. To make this happen without pinning gigabytes of metadata in memory, first create an abstraction ('xfile') of memfd files so that kernel code can access paged memory, and then an array abstraction ('xfarray') based on xfiles so that online repair can create an array of new records without pinning memory.
Quoted 8 lines
These two data storage abstractions are critical for repair of space metadata -- the memory used is pageable, which helps us avoid pinning kernel memory and driving OOM problems; and they are byte-accessible enough that we can use them like (very slow and programmatic) memory buffers.
Later patchsets will build on this functionality to provide blob storage and btrees.
Apart from the need for a struct xfs-mount just for the xfile name at creation time, this all looks OK.
Is there any specific test harness for this infrastructure, or is it just validated by having other functions built on top of it "work correctly"?
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
cover xfs: online scrubbing of realtime summary files
In reply to Darrick J. WongHi all,
This patchset implements an online checker for the realtime summary file. The first few changes are some general cleanups -- scrub should get its own references to all inodes, and we also wrap the inode lock functions so that we can standardize unlocking and releasing inodes that are the focus of a scrub.
With that out of the way, we move on to constructing a shadow copy of the rtsummary information from the rtbitmap, and compare the new copy against the ondisk copy.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=scrub-rtsummary
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=scrub-rtsummary
--- fs/xfs/Makefile | 6 + fs/xfs/scrub/bmap.c | 9 +- fs/xfs/scrub/common.c | 63 +++++++++-- fs/xfs/scrub/common.h | 16 ++- fs/xfs/scrub/inode.c | 11 +- fs/xfs/scrub/parent.c | 4 - fs/xfs/scrub/quota.c | 15 +-- fs/xfs/scrub/rtbitmap.c | 48 +------- fs/xfs/scrub/rtsummary.c | 262 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/scrub.c | 17 ++- fs/xfs/scrub/scrub.h | 4 + fs/xfs/scrub/trace.h | 34 ++++++ fs/xfs/xfs_trace.h | 3 + 13 files changed, 410 insertions(+), 82 deletions(-) create mode 100644 fs/xfs/scrub/rtsummary.c
PATCH 1/4 xfs: get our own reference to inodes that we want to scrub
From: Darrick J. Wong <[email protected]>
When we want to scrub a file, get our own reference to the inode unconditionally. This will make disposal rules simpler in the long run.
--- fs/xfs/scrub/common.c | 25 +++++++++++++++++++++---- fs/xfs/scrub/common.h | 1 + fs/xfs/scrub/inode.c | 5 ++++- fs/xfs/scrub/quota.c | 6 +++++- fs/xfs/scrub/rtbitmap.c | 6 ++++-- fs/xfs/scrub/scrub.c | 6 +----- 6 files changed, 36 insertions(+), 13 deletions(-)
fs/xfs/scrub/common.c +21 -4
@@ -832,6 +832,25 @@ xchk_install_handle_inode(return 0 ; } +/* +* Install an already-referenced inode for scrubbing. Get our own reference to +* the inode to make disposal simpler. The inode must not be in I_FREEING or +* I_WILL_FREE state! +*/ +int +xchk_install_live_inode ( +struct xfs_scrub *sc, +struct xfs_inode *ip) +{ +if (!igrab (VFS_I (ip))) { +xchk_ino_set_corrupt (sc, ip->i_ino); +return -EFSCORRUPTED ; + } + + sc->ip = ip; +return 0 ; +} +/* * In preparation to scrub metadata structures that hang off of an inode, * grab either the inode referenced in the scrub control structure or the
@@ -855,10 +874,8 @@ xchk_iget_for_scrubbing(ASSERT (sc->tp ==NULL );/* We want to scan the inode we already had opened. */ -if (sc->sm->sm_ino ==0 || sc->sm->sm_ino == ip_in->i_ino) { - sc->ip = ip_in; -return 0 ; - } +if (sc->sm->sm_ino ==0 || sc->sm->sm_ino == ip_in->i_ino) +return xchk_install_live_inode (sc, ip_in);/* Reject internal metadata files and obviously bad inode numbers. */ if (xfs_internal_inum (mp, sc->sm->sm_ino))
fs/xfs/scrub/common.h +1 -0
@@ -137,6 +137,7 @@ int xchk_count_rmap_ownedby_ag(struct xfs_scrub *sc, struct xfs_btree_cur *cur,int xchk_setup_ag_btree (struct xfs_scrub *sc,bool force_log);int xchk_iget_for_scrubbing (struct xfs_scrub *sc);int xchk_setup_inode_contents (struct xfs_scrub *sc,unsigned int resblks); +int xchk_install_live_inode (struct xfs_scrub *sc,struct xfs_inode *ip);void xchk_buffer_recheck (struct xfs_scrub *sc,struct xfs_buf *bp);int xchk_iget (struct xfs_scrub *sc,xfs_ino_t inum,struct xfs_inode **ipp);
fs/xfs/scrub/inode.c +4 -1
@@ -83,7 +83,10 @@ xchk_setup_inode(/* We want to scan the opened inode, so lock it and exit. */ if (sc->sm->sm_ino ==0 || sc->sm->sm_ino == ip_in->i_ino) { - sc->ip = ip_in; + error =xchk_install_live_inode (sc, ip_in); +if (error) +return error; +return xchk_prepare_iscrub (sc); }
fs/xfs/scrub/quota.c +5 -1
@@ -59,7 +59,11 @@ xchk_setup_quota( error =xchk_setup_fs (sc);if (error)return error; - sc->ip =xfs_quota_inode (sc->mp, dqtype); + + error =xchk_install_live_inode (sc,xfs_quota_inode (sc->mp, dqtype)); +if (error) +return error; +xfs_ilock (sc->ip,XFS_ILOCK_EXCL ); sc->ilock_flags =XFS_ILOCK_EXCL ;return 0 ;
fs/xfs/scrub/rtbitmap.c +4 -2
@@ -28,10 +28,12 @@ xchk_setup_rt(if (error)return error; + error =xchk_install_live_inode (sc, sc->mp->m_rbmip); +if (error) +return error; + sc->ilock_flags =XFS_ILOCK_EXCL |XFS_ILOCK_RTBITMAP ; - sc->ip = sc->mp->m_rbmip;xfs_ilock (sc->ip, sc->ilock_flags); -return 0 ; }
fs/xfs/scrub/scrub.c +1 -5
@@ -168,8 +168,6 @@ xchk_teardown(struct xfs_scrub *sc, int error) { -struct xfs_inode *ip_in =XFS_I (file_inode (sc->file)); - xchk_ag_free(sc, &sc->sa);if (sc->tp) {if (error ==0 && (sc->sm->sm_flags &XFS_SCRUB_IFLAG_REPAIR ))
@@ -181,9 +179,7 @@ xchk_teardown(if (sc->ip) {if (sc->ilock_flags)xfs_iunlock (sc->ip, sc->ilock_flags); -if (sc->ip != ip_in && - !xfs_internal_inum (sc->mp, sc->ip->i_ino)) -xchk_irele (sc, sc->ip); +xchk_irele (sc, sc->ip); sc->ip =NULL ; }if (sc->sm->sm_flags &XFS_SCRUB_IFLAG_REPAIR )
PATCH 2/4 xfs: wrap ilock/iunlock operations on sc->ip
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Scrub tracks the resources that it's holding onto in the xfs_scrub structure. This includes the inode being checked (if applicable) and the inode lock state of that inode. Replace the open-coded structure manipulation with a trivial helper to eliminate sources of error.
--- fs/xfs/scrub/bmap.c | 9 +++------ fs/xfs/scrub/common.c | 38 +++++++++++++++++++++++++++++++++----- fs/xfs/scrub/common.h | 5 +++++ fs/xfs/scrub/inode.c | 6 ++---- fs/xfs/scrub/parent.c | 4 ++-- fs/xfs/scrub/quota.c | 9 +++------ fs/xfs/scrub/rtbitmap.c | 9 ++++----- fs/xfs/scrub/scrub.c | 2 +- 8 files changed, 53 insertions(+), 29 deletions(-)
fs/xfs/scrub/bmap.c +3 -6
@@ -38,8 +38,7 @@ xchk_setup_inode_bmap(if (error) goto out; - sc->ilock_flags =XFS_IOLOCK_EXCL ; -xfs_ilock (sc->ip,XFS_IOLOCK_EXCL ); +xchk_ilock (sc,XFS_IOLOCK_EXCL );/* * We don't want any ephemeral data/cow fork updates sitting around
@@ -50,8 +49,7 @@ xchk_setup_inode_bmap( sc->sm->sm_type != XFS_SCRUB_TYPE_BMBTA) {struct address_space *mapping =VFS_I (sc->ip)->i_mapping; - sc->ilock_flags |=XFS_MMAPLOCK_EXCL ; -xfs_ilock (sc->ip,XFS_MMAPLOCK_EXCL ); +xchk_ilock (sc,XFS_MMAPLOCK_EXCL );inode_dio_wait (VFS_I (sc->ip));
@@ -79,9 +77,8 @@ xchk_setup_inode_bmap( error =xchk_trans_alloc (sc,0 );if (error) goto out; - sc->ilock_flags |=XFS_ILOCK_EXCL ; -xfs_ilock (sc->ip,XFS_ILOCK_EXCL ); +xchk_ilock (sc,XFS_ILOCK_EXCL ); out:/* scrub teardown will unlock and release the inode */ return error;
fs/xfs/scrub/common.c +33 -5
@@ -1023,20 +1023,48 @@ xchk_setup_inode_contents(return error;/* Lock the inode so the VFS cannot touch this file. */ - sc->ilock_flags =XFS_IOLOCK_EXCL ; -xfs_ilock (sc->ip, sc->ilock_flags); +xchk_ilock (sc,XFS_IOLOCK_EXCL ); error =xchk_trans_alloc (sc, resblks);if (error) goto out; - sc->ilock_flags |=XFS_ILOCK_EXCL ; -xfs_ilock (sc->ip,XFS_ILOCK_EXCL ); - +xchk_ilock (sc,XFS_ILOCK_EXCL ); out:/* scrub teardown will unlock and release the inode for us */ return error; } +void +xchk_ilock ( +struct xfs_scrub *sc, +unsigned int ilock_flags) +{ +xfs_ilock (sc->ip, ilock_flags); + sc->ilock_flags |= ilock_flags; +} + +bool +xchk_ilock_nowait ( +struct xfs_scrub *sc, +unsigned int ilock_flags) +{ +if (xfs_ilock_nowait (sc->ip, ilock_flags)) { + sc->ilock_flags |= ilock_flags; +return true; + } + +return false; +} + +void +xchk_iunlock ( +struct xfs_scrub *sc, +unsigned int ilock_flags) +{ + sc->ilock_flags &= ~ilock_flags; +xfs_iunlock (sc->ip, ilock_flags); +} +/* * Predicate that decides if we need to evaluate the cross-reference check. * If there was an error accessing the cross-reference btree, just delete
fs/xfs/scrub/common.h +5 -0
@@ -138,6 +138,11 @@ int xchk_setup_ag_btree(struct xfs_scrub *sc, bool force_log);int xchk_iget_for_scrubbing (struct xfs_scrub *sc);int xchk_setup_inode_contents (struct xfs_scrub *sc,unsigned int resblks);int xchk_install_live_inode (struct xfs_scrub *sc,struct xfs_inode *ip); + +void xchk_ilock (struct xfs_scrub *sc,unsigned int ilock_flags); +bool xchk_ilock_nowait (struct xfs_scrub *sc,unsigned int ilock_flags); +void xchk_iunlock (struct xfs_scrub *sc,unsigned int ilock_flags); +void xchk_buffer_recheck (struct xfs_scrub *sc,struct xfs_buf *bp);int xchk_iget (struct xfs_scrub *sc,xfs_ino_t inum,struct xfs_inode **ipp);
fs/xfs/scrub/inode.c +2 -4
@@ -32,15 +32,13 @@ xchk_prepare_iscrub( {int error; - sc->ilock_flags =XFS_IOLOCK_EXCL ; -xfs_ilock (sc->ip, sc->ilock_flags); +xchk_ilock (sc,XFS_IOLOCK_EXCL ); error =xchk_trans_alloc (sc,0 );if (error)return error; - sc->ilock_flags |=XFS_ILOCK_EXCL ; -xfs_ilock (sc->ip,XFS_ILOCK_EXCL ); +xchk_ilock (sc,XFS_ILOCK_EXCL );return 0 ; }
fs/xfs/scrub/parent.c +2 -2
@@ -150,8 +150,8 @@ xchk_parent_validate( lock_mode =xchk_parent_ilock_dir (dp);if (!lock_mode) { -xfs_iunlock (sc->ip,XFS_ILOCK_EXCL ); -xfs_ilock (sc->ip,XFS_ILOCK_EXCL ); +xchk_iunlock (sc,XFS_ILOCK_EXCL ); +xchk_ilock (sc,XFS_ILOCK_EXCL ); error = -EAGAIN ; goto out_rele; }
fs/xfs/scrub/quota.c +3 -6
@@ -64,8 +64,7 @@ xchk_setup_quota(if (error)return error; -xfs_ilock (sc->ip,XFS_ILOCK_EXCL ); - sc->ilock_flags =XFS_ILOCK_EXCL ; +xchk_ilock (sc,XFS_ILOCK_EXCL );return 0 ; }
@@ -239,13 +238,11 @@ xchk_quota(* data fork we have to drop ILOCK_EXCL to use the regular dquot * functions. */ -xfs_iunlock (sc->ip, sc->ilock_flags); - sc->ilock_flags =0 ; +xchk_iunlock (sc, sc->ilock_flags); sqi.sc = sc; sqi.last_id =0 ; error =xfs_qm_dqiterate (mp, dqtype, xchk_quota_item, &sqi); - sc->ilock_flags =XFS_ILOCK_EXCL ; -xfs_ilock (sc->ip, sc->ilock_flags); +xchk_ilock (sc,XFS_ILOCK_EXCL );if (error == -ECANCELED ) error =0 ; if (!xchk_fblock_process_error(sc, XFS_DATA_FORK,
fs/xfs/scrub/rtbitmap.c +4 -5
@@ -32,8 +32,7 @@ xchk_setup_rt(if (error)return error; - sc->ilock_flags =XFS_ILOCK_EXCL |XFS_ILOCK_RTBITMAP ; -xfs_ilock (sc->ip, sc->ilock_flags); +xchk_ilock (sc,XFS_ILOCK_EXCL |XFS_ILOCK_RTBITMAP );return 0 ; }
@@ -143,8 +142,8 @@ xchk_rtsummary(* flags so that we don't mix up the inode state that @sc tracks. */ sc->ip = rsumip; - sc->ilock_flags =XFS_ILOCK_EXCL |XFS_ILOCK_RTSUM ; -xfs_ilock (sc->ip, sc->ilock_flags); + sc->ilock_flags =0 ; +xchk_ilock (sc,XFS_ILOCK_EXCL |XFS_ILOCK_RTSUM );/* Invoke the fork scrubber. */ error =xchk_metadata_inode_forks (sc);
@@ -155,7 +154,7 @@ xchk_rtsummary(xchk_set_incomplete (sc); out:/* Switch back to the rtbitmap inode and lock flags. */ -xfs_iunlock (sc->ip, sc->ilock_flags); +xchk_iunlock (sc,XFS_ILOCK_EXCL |XFS_ILOCK_RTSUM ); sc->ilock_flags = old_ilock_flags; sc->ip = old_ip;return error;
fs/xfs/scrub/scrub.c +1 -1
@@ -178,7 +178,7 @@ xchk_teardown( }if (sc->ip) {if (sc->ilock_flags) -xfs_iunlock (sc->ip, sc->ilock_flags); +xchk_iunlock (sc, sc->ilock_flags);xchk_irele (sc, sc->ip); sc->ip =NULL ; }
PATCH 3/4 xfs: move the realtime summary file scrubber to a separate source file
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move the realtime summary file checking code to a separate file in preparation to actually implement it.
--- fs/xfs/Makefile | 6 ++++- fs/xfs/scrub/rtbitmap.c | 37 -------------------------------- fs/xfs/scrub/rtsummary.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 38 deletions(-) create mode 100644 fs/xfs/scrub/rtsummary.c
fs/xfs/Makefile +5 -1
@@ -168,7 +168,11 @@ xfs-y += $(addprefix scrub/, \ xfile.o \ ) -xfs-$(CONFIG_XFS_RT) += scrub/rtbitmap.o +xfs-$(CONFIG_XFS_RT) += $(addprefix scrub/, \ + rtbitmap.o \ + rtsummary.o \ + ) + xfs-$(CONFIG_XFS_QUOTA) += scrub/quota.o # online repair
fs/xfs/scrub/rtbitmap.c +0 -37
@@ -124,43 +124,6 @@ xchk_rtbitmap(return error; } -/* Scrub the realtime summary. */ -int -xchk_rtsummary ( -struct xfs_scrub *sc) -{ -struct xfs_inode *rsumip = sc->mp->m_rsumip; -struct xfs_inode *old_ip = sc->ip; -uint old_ilock_flags = sc->ilock_flags; -int error =0 ; - -/* -* We ILOCK'd the rt bitmap ip in the setup routine, now lock the -* rt summary ip in compliance with the rt inode locking rules. -* -* Since we switch sc->ip to rsumip we have to save the old ilock -* flags so that we don't mix up the inode state that @sc tracks. -*/ - sc->ip = rsumip; - sc->ilock_flags =0 ; -xchk_ilock (sc,XFS_ILOCK_EXCL |XFS_ILOCK_RTSUM ); - -/* Invoke the fork scrubber. */ - error =xchk_metadata_inode_forks (sc); -if (error || (sc->sm->sm_flags &XFS_SCRUB_OFLAG_CORRUPT )) - goto out; - -/* XXX: implement this some day */ -xchk_set_incomplete (sc); -out: -/* Switch back to the rtbitmap inode and lock flags. */ -xchk_iunlock (sc,XFS_ILOCK_EXCL |XFS_ILOCK_RTSUM ); - sc->ilock_flags = old_ilock_flags; - sc->ip = old_ip; -return error; -} - -/* xref check that the extent is not free in the rtbitmap */ void xchk_xref_is_used_rt_space(
fs/xfs/scrub/rtsummary.c new file +54 -0
54 lines not on this page · raw message
PATCH 4/4 xfs: implement online scrubbing of rtsummary info
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Finish the realtime summary scrubber by adding the functions we need to compute a fresh copy of the rtsummary info and comparing it to the copy on disk.
--- fs/xfs/scrub/common.h | 10 +- fs/xfs/scrub/rtbitmap.c | 4 - fs/xfs/scrub/rtsummary.c | 252 ++++++++++++++++++++++++++++++++++++++++++---- fs/xfs/scrub/scrub.c | 9 +- fs/xfs/scrub/scrub.h | 4 + fs/xfs/scrub/trace.h | 34 ++++++ fs/xfs/xfs_trace.h | 3 + 7 files changed, 288 insertions(+), 28 deletions(-)
fs/xfs/scrub/common.h +8 -2
@@ -88,10 +88,16 @@ int xchk_setup_xattr(struct xfs_scrub *sc);int xchk_setup_symlink (struct xfs_scrub *sc);int xchk_setup_parent (struct xfs_scrub *sc);#ifdef CONFIG_XFS_RT -int xchk_setup_rt (struct xfs_scrub *sc); +int xchk_setup_rtbitmap (struct xfs_scrub *sc); +int xchk_setup_rtsummary (struct xfs_scrub *sc);#else static inline int -xchk_setup_rt (struct xfs_scrub *sc) +xchk_setup_rtbitmap (struct xfs_scrub *sc) +{ +return -ENOENT ; +} +static inline int +xchk_setup_rtsummary (struct xfs_scrub *sc) {return -ENOENT ; }
fs/xfs/scrub/rtbitmap.c +2 -2
@@ -19,12 +19,12 @@/* Set us up with the realtime metadata locked. */ int -xchk_setup_rt ( +xchk_setup_rtbitmap (struct xfs_scrub *sc) {int error; - error =xchk_setup_fs (sc); + error =xchk_trans_alloc (sc,0 );if (error)return error;
fs/xfs/scrub/rtsummary.c +230 -22
271 lines not on this page · raw message
fs/xfs/scrub/scrub.c +7 -2
@@ -24,6 +24,7 @@#include "scrub/trace.h" #include "scrub/repair.h" #include "scrub/health.h" +#include "scrub/xfile.h" /* * Online Scrub and Repair
@@ -184,6 +185,10 @@ xchk_teardown( }if (sc->sm->sm_flags &XFS_SCRUB_IFLAG_REPAIR )mnt_drop_write_file (sc->file); +if (sc->xfile) { +xfile_destroy (sc->xfile); + sc->xfile =NULL ; + }if (sc->buf) {if (sc->buf_cleanup) sc->buf_cleanup (sc->buf);
@@ -318,14 +323,14 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { }, [XFS_SCRUB_TYPE_RTBITMAP] = { /* realtime bitmap */ .type = ST_FS, - .setup = xchk_setup_rt, + .setup = xchk_setup_rtbitmap, .scrub = xchk_rtbitmap, .has = xfs_has_realtime, .repair = xrep_notsupported, }, [XFS_SCRUB_TYPE_RTSUM] = { /* realtime summary */ .type = ST_FS, - .setup = xchk_setup_rt, + .setup = xchk_setup_rtsummary, .scrub = xchk_rtsummary, .has = xfs_has_realtime, .repair = xrep_notsupported,
fs/xfs/scrub/scrub.h +4 -0
@@ -88,6 +88,10 @@ struct xfs_scrub {*/ void (*buf_cleanup)(void *buf); +/* xfile used by the scrubbers; freed at teardown. */ +struct xfile *xfile; + +/* Lock flags for @ip. */ uint ilock_flags;/* See the XCHK/XREP state flags below. */
fs/xfs/scrub/trace.h +34 -0
@@ -987,6 +987,40 @@ TRACE_EVENT(xfarray_sort_stats, __entry->error) ); +#ifdef CONFIG_XFS_RT +TRACE_EVENT (xchk_rtsum_record_free, + TP_PROTO(struct xfs_mount *mp, xfs_rtblock_t start, + uint64_t len, unsigned int log, loff_t pos, xfs_suminfo_t v), +TP_ARGS (mp, start, len, log, pos, v), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(dev_t, rtdev) + __field(xfs_rtblock_t, start) + __field(unsigned long long, len) + __field(unsigned int, log) + __field(loff_t, pos) +__field (xfs_suminfo_t, v) + ), +TP_fast_assign ( + __entry->dev = mp->m_super->s_dev; + __entry->rtdev = mp->m_rtdev_targp->bt_dev; + __entry->start = start; + __entry->len = len; + __entry->log = log; + __entry->pos = pos; + __entry->v = v; + ), +TP_printk ("dev %d:%d rtdev %d:%d rtx 0x%llx rtxcount 0x%llx log %u rsumpos 0x%llx sumcount %u" , +MAJOR (__entry->dev),MINOR (__entry->dev), +MAJOR (__entry->rtdev),MINOR (__entry->rtdev), + __entry->start, + __entry->len, + __entry->log, + __entry->pos, + __entry->v) +); +#endif /* CONFIG_XFS_RT */ +/* repair tracepoints */ #if IS_ENABLED (CONFIG_XFS_ONLINE_REPAIR )
fs/xfs/xfs_trace.h +3 -0
@@ -22,6 +22,9 @@* daddr: physical block number in 512b blocks * bbcount: number of blocks in a physical extent, in 512b blocks * +* rtx: physical rt extent number for extent mappings +* rtxcount: number of rt extents in an extent mapping +* * owner: reverse-mapping owner, usually inodes * * fileoff: file offset, in fs blocks
Re: [PATCHSET v25.0 0/4] xfs: online scrubbing of realtime summary files
In reply to Darrick J. WongQuoted 25 lines · Darrick J. Wong
Hi all,
This patchset implements an online checker for the realtime summary file. The first few changes are some general cleanups -- scrub should get its own references to all inodes, and we also wrap the inode lock functions so that we can standardize unlocking and releasing inodes that are the focus of a scrub.
With that out of the way, we move on to constructing a shadow copy of the rtsummary information from the rtbitmap, and compare the new copy against the ondisk copy.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=scrub-rtsummaryfstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=scrub-rtsummary
Quoted 16 lines
--- fs/xfs/Makefile | 6 + fs/xfs/scrub/bmap.c | 9 +- fs/xfs/scrub/common.c | 63 +++++++++-- fs/xfs/scrub/common.h | 16 ++- fs/xfs/scrub/inode.c | 11 +- fs/xfs/scrub/parent.c | 4 - fs/xfs/scrub/quota.c | 15 +-- fs/xfs/scrub/rtbitmap.c | 48 +------- fs/xfs/scrub/rtsummary.c | 262 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/scrub.c | 17 ++- fs/xfs/scrub/scrub.h | 4 + fs/xfs/scrub/trace.h | 34 ++++++ fs/xfs/xfs_trace.h | 3 + 13 files changed, 410 insertions(+), 82 deletions(-) create mode 100644 fs/xfs/scrub/rtsummary.c
Looks OK, nothing screams out at me that "this is wrong!".
Signature · 2 lines
Dave Chinner [email protected]
cover xfs: miscellaneous repair tweaks
In reply to Darrick J. WongHi all,
Before we start adding online repair functionality, there's a few tweaks that I'd like to make to the common repair code. First is a fix to the integration between repair and the health status code that was interfering with repair re-evaluations. Second is a minor tweak to the sole existing repair functions to make one last check that the user hasn't terminated the calling process before we start writing to the filesystem. This is a pattern that will repeat throughout the rest of the repair functions.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-tweaks
--- fs/xfs/scrub/agheader_repair.c | 16 ++++++++++++++++ fs/xfs/scrub/health.c | 10 ++++++++++ 2 files changed, 26 insertions(+)
PATCH 1/2 xfs: always rescan allegedly healthy per-ag metadata after repair
From: Darrick J. Wong <[email protected]>
After an online repair function runs for a per-AG metadata structure, sc->sick_mask is supposed to reflect the per-AG metadata that the repair function fixed. Our next move is to re-check the metadata to assess the completeness of our repair, so we don't want the rebuilt structure to be excluded from the rescan just because the health system previously logged a problem with the data structure.
--- fs/xfs/scrub/health.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/xfs/scrub/health.c +10 -0
@@ -226,6 +226,16 @@ xchk_ag_btree_healthy_enough(return true; } +/* +* If we just repaired some AG metadata, sc->sick_mask will reflect all +* the per-AG metadata types that were repaired. Exclude these from +* the filesystem health query because we have not yet updated the +* health status and we want everything to be scanned. +*/ +if ((sc->flags &XREP_ALREADY_FIXED ) && + type_to_health_flag[sc->sm->sm_type].group ==XHG_AG ) + mask &= ~sc->sick_mask; +if (xfs_ag_has_sickness (pag, mask)) { sc->sm->sm_flags |=XFS_SCRUB_OFLAG_XFAIL ;return false;
PATCH 2/2 xfs: allow the user to cancel repairs before we start writing
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
All online repair functions have the same structure: walk filesystem metadata structures gathering enough data to rebuild the structure, stage a new copy, and then commit the new copy.
The gathering steps do not write anything to disk, so they are peppered with xchk_should_terminate calls to avoid softlockup warnings and to provide an opportunity to abort the repair (by killing xfs_scrub). However, it's not clear in the code base when is the last chance to abort cleanly without having to undo a bunch of structure.
Therefore, add one more call to xchk_should_terminate (along with a comment) providing the sysadmin with the ability to abort before it's too late and to make it clear in the source code when it's no longer
convenient or safe to abort a repair. As there are only four repair
functions right now, this patch exists more to establish a precedent for subsequent additions than to deliver practical functionality.
--- fs/xfs/scrub/agheader_repair.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/xfs/scrub/agheader_repair.c +16 -0
@@ -50,6 +50,10 @@ xrep_superblock(if (error)return error; +/* Last chance to abort before we start committing fixes. */ +if (xchk_should_terminate (sc, &error)) +return error; +/* Copy AG 0's superblock to this one. */ xfs_buf_zero (bp,0 ,BBTOB (bp->b_length));xfs_sb_to_disk (bp->b_addr, &mp->m_sb);
@@ -425,6 +429,10 @@ xrep_agf(if (error)return error; +/* Last chance to abort before we start committing fixes. */ +if (xchk_should_terminate (sc, &error)) +return error; +/* Start rewriting the header and implant the btrees we found. */ xrep_agf_init_header (sc, agf_bp, &old_agf);xrep_agf_set_roots (sc, agf, fab);
@@ -749,6 +757,10 @@ xrep_agfl(if (error) goto err; +/* Last chance to abort before we start committing fixes. */ +if (xchk_should_terminate (sc, &error)) + goto err; +/* * Update AGF and AGFL. We reset the global free block counter when * we adjust the AGF flcount (which can fail) so avoid updating any
@@ -996,6 +1008,10 @@ xrep_agi(if (error)return error; +/* Last chance to abort before we start committing fixes. */ +if (xchk_should_terminate (sc, &error)) +return error; +/* Start rewriting the header and implant the btrees we found. */ xrep_agi_init_header (sc, agi_bp, &old_agi);xrep_agi_set_roots (sc, agi, fab);
Re: [PATCHSET v25.0 0/2] xfs: miscellaneous repair tweaks
In reply to Darrick J. WongQuoted 17 lines · Darrick J. Wong
Hi all,
Before we start adding online repair functionality, there's a few tweaks that I'd like to make to the common repair code. First is a fix to the integration between repair and the health status code that was interfering with repair re-evaluations. Second is a minor tweak to the sole existing repair functions to make one last check that the user hasn't terminated the calling process before we start writing to the filesystem. This is a pattern that will repeat throughout the rest of the repair functions.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
Quoted 8 lines
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-tweaks--- fs/xfs/scrub/agheader_repair.c | 16 ++++++++++++++++ fs/xfs/scrub/health.c | 10 ++++++++++ 2 files changed, 26 insertions(+)
LGTM.
Signature · 2 lines
Dave Chinner [email protected]
cover xfs: force rebuilding of metadata
In reply to Darrick J. WongHi all,
This patchset adds a new IFLAG to the scrub ioctl so that userspace can force a rebuild of an otherwise consistent piece of metadata. This will eventually enable the use of online repair to relocate metadata during a filesystem reorganization (e.g. shrink). For now, it facilitates stress testing of online repair without needing the debugging knobs to be enabled.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-force-rebuild
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-force-rebuild
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=repair-force-rebuild
--- fs/xfs/libxfs/xfs_fs.h | 6 +++++- fs/xfs/scrub/common.h | 12 ++++++++++++ fs/xfs/scrub/scrub.c | 18 ++++++++++++------ fs/xfs/scrub/trace.h | 3 ++- 4 files changed, 31 insertions(+), 8 deletions(-)
PATCH 1/2 xfs: don't complain about unfixed metadata when repairs were injected
From: Darrick J. Wong <[email protected]>
While debugging other parts of online repair, I noticed that if someone injects FORCE_SCRUB_REPAIR, starts an IFLAG_REPAIR scrub on a piece of metadata, and the metadata repair fails, we'll log a message about uncorrected errors in the filesystem.
This isn't strictly true if the scrub function didn't set OFLAG_CORRUPT and we're only doing the repair because the error injection knob is set. Repair functions are allowed to abort the entire operation at any point before committing new metadata, in which case the piece of metadata is in the same state as it was before. Therefore, the log message should be gated on the results of the scrub. Refactor the predicate and rearrange the code flow to make this happen.
Note: If the repair function errors out after it commits the new metadata, the transaction cancellation will shut down the filesystem, which is an obvious sign of corrupt metadata.
--- fs/xfs/scrub/common.h | 12 ++++++++++++ fs/xfs/scrub/scrub.c | 7 ++----- 2 files changed, 14 insertions(+), 5 deletions(-)
fs/xfs/scrub/common.h +12 -0
@@ -167,6 +167,18 @@ static inline bool xchk_skip_xref(struct xfs_scrub_metadata *sm) XFS_SCRUB_OFLAG_XCORRUPT); } +#ifdef CONFIG_XFS_ONLINE_REPAIR +/* Decide if a repair is required. */ +static inline bool xchk_needs_repair (const struct xfs_scrub_metadata *sm) +{ +return sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT | +XFS_SCRUB_OFLAG_XCORRUPT | +XFS_SCRUB_OFLAG_PREEN ); +} +#else +# define xchk_needs_repair (sc) (false) +#endif /* CONFIG_XFS_ONLINE_REPAIR */ +int xchk_metadata_inode_forks (struct xfs_scrub *sc);/*
fs/xfs/scrub/scrub.c +2 -5
@@ -532,15 +532,12 @@ xfs_scrub_metadata(if ((sc->sm->sm_flags &XFS_SCRUB_IFLAG_REPAIR ) && !(sc->flags &XREP_ALREADY_FIXED )) { -bool needs_fix; +bool needs_fix =xchk_needs_repair (sc->sm);/* Let debug users force us into the repair routines. */ if (XFS_TEST_ERROR (false, mp,XFS_ERRTAG_FORCE_SCRUB_REPAIR )) - sc->sm->sm_flags |=XFS_SCRUB_OFLAG_CORRUPT ; + needs_fix = true; - needs_fix = (sc->sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT | -XFS_SCRUB_OFLAG_XCORRUPT | -XFS_SCRUB_OFLAG_PREEN ));/* * If userspace asked for a repair but it wasn't necessary, * report that back to userspace.
PATCH 2/2 xfs: allow userspace to rebuild metadata structures
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a new (superuser-only) flag to the online metadata repair ioctl to force it to rebuild structures, even if they're not broken. We will use this to move metadata structures out of the way during a free space defragmentation operation.
--- fs/xfs/libxfs/xfs_fs.h | 6 +++++- fs/xfs/scrub/scrub.c | 11 ++++++++++- fs/xfs/scrub/trace.h | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_fs.h +5 -1
@@ -741,7 +741,11 @@ struct xfs_scrub_metadata {*/ #define XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED (1u << 7) -#define XFS_SCRUB_FLAGS_IN (XFS_SCRUB_IFLAG_REPAIR) +/* i: Rebuild the data structure. */ +#define XFS_SCRUB_IFLAG_FORCE_REBUILD (1 << 31) + +#define XFS_SCRUB_FLAGS_IN (XFS_SCRUB_IFLAG_REPAIR | \ + XFS_SCRUB_IFLAG_FORCE_REBUILD)#define XFS_SCRUB_FLAGS_OUT (XFS_SCRUB_OFLAG_CORRUPT | \ XFS_SCRUB_OFLAG_PREEN | \ XFS_SCRUB_OFLAG_XFAIL | \
fs/xfs/scrub/scrub.c +10 -1
@@ -410,6 +410,11 @@ xchk_validate_inputs( goto out; } +/* No rebuild without repair. */ +if ((sm->sm_flags &XFS_SCRUB_IFLAG_FORCE_REBUILD ) && + !(sm->sm_flags &XFS_SCRUB_IFLAG_REPAIR )) +return -EINVAL ; +/* * We only want to repair read-write v5+ filesystems. Defer the check * for ops->repair until after our scrub confirms that we need to
@@ -534,8 +539,12 @@ xfs_scrub_metadata( !(sc->flags & XREP_ALREADY_FIXED)) {bool needs_fix =xchk_needs_repair (sc->sm); +/* Userspace asked us to rebuild the structure regardless. */ +if (sc->sm->sm_flags &XFS_SCRUB_IFLAG_FORCE_REBUILD ) + needs_fix = true; +/* Let debug users force us into the repair routines. */ -if (XFS_TEST_ERROR (false, mp,XFS_ERRTAG_FORCE_SCRUB_REPAIR )) +if (XFS_TEST_ERROR (needs_fix, mp,XFS_ERRTAG_FORCE_SCRUB_REPAIR )) needs_fix = true;/*
fs/xfs/scrub/trace.h +2 -1
@@ -98,7 +98,8 @@ TRACE_DEFINE_ENUM(XFS_SCRUB_TYPE_FSCOUNTERS); { XFS_SCRUB_OFLAG_XCORRUPT, "xcorrupt" }, \ { XFS_SCRUB_OFLAG_INCOMPLETE, "incomplete" }, \ { XFS_SCRUB_OFLAG_WARNING, "warning" }, \ - { XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED, "norepair" } + { XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED, "norepair" }, \ + { XFS_SCRUB_IFLAG_FORCE_REBUILD, "rebuild" } #define XFS_SCRUB_STATE_STRINGS \ { XCHK_TRY_HARDER, "try_harder" }, \
Re: [PATCH 2/2] xfs: allow userspace to rebuild metadata structures
Quoted 20 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Add a new (superuser-only) flag to the online metadata repair ioctl to force it to rebuild structures, even if they're not broken. We will use this to move metadata structures out of the way during a free space defragmentation operation.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_fs.h | 6 +++++- fs/xfs/scrub/scrub.c | 11 ++++++++++- fs/xfs/scrub/trace.h | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-)fs/xfs/libxfs/xfs_fs.h +0
-0
fs/xfs/libxfs/xfs_fs.h struct xfs_scrub_metadata { · line 745
Quoted 6 lines
fs/xfs/libxfs/xfs_fs.h +2
-1@@ -741,7 +741,11 @@ struct xfs_scrub_metadata {*/ #define XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED (1u << 7) -#define XFS_SCRUB_FLAGS_IN (XFS_SCRUB_IFLAG_REPAIR) +/* i: Rebuild the data structure. */ +#define XFS_SCRUB_IFLAG_FORCE_REBUILD (1 << 31)
(1U << 31), otherwise a compiler somewhere will complain.
Also, why use the high bit here?
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 2/2] xfs: allow userspace to rebuild metadata structures
Quoted 24 lines · Dave Chinner
Quoted 23 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Add a new (superuser-only) flag to the online metadata repair ioctl to force it to rebuild structures, even if they're not broken. We will use this to move metadata structures out of the way during a free space defragmentation operation.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_fs.h | 6 +++++- fs/xfs/scrub/scrub.c | 11 ++++++++++- fs/xfs/scrub/trace.h | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-)fs/xfs/libxfs/xfs_fs.h +0
-0@@ -741,7 +741,11 @@ struct xfs_scrub_metadata {*/ #define XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED (1u << 7)
Quoted 7 lines
fs/xfs/libxfs/xfs_fs.h struct xfs_scrub_metadata { · line 745
Quoted 3 lines
fs/xfs/libxfs/xfs_fs.h +2
-1-#define XFS_SCRUB_FLAGS_IN (XFS_SCRUB_IFLAG_REPAIR) +/* i: Rebuild the data structure. */ +#define XFS_SCRUB_IFLAG_FORCE_REBUILD (1 << 31)(1U << 31), otherwise a compiler somewhere will complain.
Also, why use the high bit here?
Mostly to make it much more obvious that some new flag bit is in use here. I'll change it to 1U<<8 before I merge it upstream. You'll see it in v26 which will also have all the api adjustments for 6.5.
--D
Quoted 4 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCHSET v25.0 0/2] xfs: force rebuilding of metadata
In reply to Darrick J. WongQuoted 23 lines · Darrick J. Wong
Hi all,
This patchset adds a new IFLAG to the scrub ioctl so that userspace can force a rebuild of an otherwise consistent piece of metadata. This will eventually enable the use of online repair to relocate metadata during a filesystem reorganization (e.g. shrink). For now, it facilitates stress testing of online repair without needing the debugging knobs to be enabled.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-force-rebuildxfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-force-rebuild
Quoted 8 lines
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=repair-force-rebuild--- fs/xfs/libxfs/xfs_fs.h | 6 +++++- fs/xfs/scrub/common.h | 12 ++++++++++++ fs/xfs/scrub/scrub.c | 18 ++++++++++++------ fs/xfs/scrub/trace.h | 3 ++- 4 files changed, 31 insertions(+), 8 deletions(-)
With the high flag bit changed to unsigned,
Signature · 2 lines
Dave Chinner [email protected]
cover xfs: online repair of AG btrees
In reply to Darrick J. WongHi all,
Now that we've spent a lot of time reworking common code in online fsck, we're ready to start rebuilding the AG space btrees. This series implements repair functions for the free space, inode, and refcount btrees. Rebuilding the reverse mapping btree is much more intense and is left for a subsequent patchset. The fstests counterpart of this patchset implements stress testing of repair.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-ag-btrees
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-ag-btrees
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=repair-ag-btrees
--- fs/xfs/Makefile | 3 fs/xfs/libxfs/xfs_ag.h | 10 fs/xfs/libxfs/xfs_ag_resv.c | 2 fs/xfs/libxfs/xfs_alloc.c | 18 - fs/xfs/libxfs/xfs_alloc.h | 2 fs/xfs/libxfs/xfs_alloc_btree.c | 13 - fs/xfs/libxfs/xfs_btree.c | 26 + fs/xfs/libxfs/xfs_btree.h | 2 fs/xfs/libxfs/xfs_ialloc.c | 41 +- fs/xfs/libxfs/xfs_ialloc.h | 3 fs/xfs/libxfs/xfs_refcount.c | 18 - fs/xfs/libxfs/xfs_refcount.h | 2 fs/xfs/libxfs/xfs_refcount_btree.c | 13 - fs/xfs/libxfs/xfs_types.h | 7 fs/xfs/scrub/agheader_repair.c | 5 fs/xfs/scrub/alloc.c | 14 - fs/xfs/scrub/alloc_repair.c | 910 ++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/common.c | 1 fs/xfs/scrub/common.h | 13 + fs/xfs/scrub/ialloc_repair.c | 872 ++++++++++++++++++++++++++++++++++ fs/xfs/scrub/newbt.c | 44 ++ fs/xfs/scrub/newbt.h | 6 fs/xfs/scrub/reap.c | 17 + fs/xfs/scrub/refcount_repair.c | 791 +++++++++++++++++++++++++++++++ fs/xfs/scrub/repair.c | 128 +++++ fs/xfs/scrub/repair.h | 43 ++ fs/xfs/scrub/scrub.c | 22 + fs/xfs/scrub/scrub.h | 9 fs/xfs/scrub/trace.h | 112 +++- fs/xfs/scrub/xfarray.h | 22 + fs/xfs/xfs_extent_busy.c | 13 + fs/xfs/xfs_extent_busy.h | 2 fs/xfs/xfs_icache.c | 127 ++++- fs/xfs/xfs_trace.h | 22 + 34 files changed, 3223 insertions(+), 110 deletions(-) create mode 100644 fs/xfs/scrub/alloc_repair.c create mode 100644 fs/xfs/scrub/ialloc_repair.c create mode 100644 fs/xfs/scrub/refcount_repair.c
PATCH 1/5 xfs: clear pagf_agflreset when repairing the AGFL
From: Darrick J. Wong <[email protected]>
Clear the pagf_agflreset flag when we're repairing the AGFL because we fix all the same padding problems that xfs_agfl_reset does.
--- fs/xfs/scrub/agheader_repair.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/xfs/scrub/agheader_repair.c +4 -1
@@ -621,8 +621,11 @@ xrep_agfl_update_agf(xfs_force_summary_recalc (sc->mp);/* Update the AGF counters. */ -if (xfs_perag_initialised_agf (sc->sa.pag)) +if (xfs_perag_initialised_agf (sc->sa.pag)) { sc->sa.pag->pagf_flcount = flcount; +clear_bit (XFS_AGSTATE_AGFL_NEEDS_RESET , + &sc->sa.pag->pag_opstate); + } agf->agf_flfirst =cpu_to_be32 (0 ); agf->agf_flcount =cpu_to_be32 (flcount); agf->agf_fllast =cpu_to_be32 (flcount -1 );
PATCH 2/5 xfs: repair free space btrees
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Rebuild the free space btrees from the gaps in the rmap btree.
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_ag.h | 9 fs/xfs/libxfs/xfs_ag_resv.c | 2 fs/xfs/libxfs/xfs_alloc.c | 18 + fs/xfs/libxfs/xfs_alloc.h | 2 fs/xfs/libxfs/xfs_alloc_btree.c | 13 + fs/xfs/libxfs/xfs_types.h | 7 fs/xfs/scrub/alloc.c | 14 + fs/xfs/scrub/alloc_repair.c | 910 +++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/common.h | 13 + fs/xfs/scrub/newbt.c | 44 ++ fs/xfs/scrub/newbt.h | 6 fs/xfs/scrub/reap.c | 17 + fs/xfs/scrub/repair.c | 69 +++ fs/xfs/scrub/repair.h | 24 + fs/xfs/scrub/scrub.c | 14 - fs/xfs/scrub/scrub.h | 8 fs/xfs/scrub/trace.h | 24 + fs/xfs/scrub/xfarray.h | 22 + fs/xfs/xfs_extent_busy.c | 13 + fs/xfs/xfs_extent_busy.h | 2 21 files changed, 1209 insertions(+), 23 deletions(-) create mode 100644 fs/xfs/scrub/alloc_repair.c
fs/xfs/Makefile +1 -0
@@ -179,6 +179,7 @@ xfs-$(CONFIG_XFS_QUOTA) += scrub/quota.o ifeq ($(CONFIG_XFS_ONLINE_REPAIR),y) xfs-y += $(addprefix scrub/, \ agheader_repair.o \ + alloc_repair.o \ newbt.o \ reap.o \ repair.o \
fs/xfs/libxfs/xfs_ag.h +9 -0
@@ -80,6 +80,15 @@ struct xfs_perag {*/ uint16_t pag_checked;uint16_t pag_sick; + +#ifdef CONFIG_XFS_ONLINE_REPAIR +/* +* Alternate btree heights so that online repair won't trip the write +* verifiers while rebuilding the AG btrees. +*/ +uint8_t pagf_alt_levels[XFS_BTNUM_AGF ]; +#endif +spinlock_t pag_state_lock;spinlock_t pagb_lock;/* lock for pagb_tree */
fs/xfs/libxfs/xfs_ag_resv.c +2 -0
@@ -411,6 +411,8 @@ xfs_ag_resv_free_extent( fallthrough;case XFS_AG_RESV_NONE :xfs_trans_mod_sb (tp,XFS_TRANS_SB_FDBLOCKS , (int64_t )len); + fallthrough; +case XFS_AG_RESV_IGNORE :return ; }
fs/xfs/libxfs/xfs_alloc.c +12 -6
@@ -243,14 +243,11 @@ xfs_alloc_btrec_to_irec( irec->ar_blockcount =be32_to_cpu (rec->alloc.ar_blockcount); } -/* Simple checks for free space records. */ -xfs_failaddr_t -xfs_alloc_check_irec ( -struct xfs_btree_cur *cur, +inline xfs_failaddr_t +xfs_alloc_check_perag_irec ( +struct xfs_perag *pag,const struct xfs_alloc_rec_incore *irec) { -struct xfs_perag *pag = cur->bc_ag.pag; -if (irec->ar_blockcount ==0 )return __this_address;
@@ -261,6 +258,15 @@ xfs_alloc_check_irec(return NULL ; } +/* Simple checks for free space records. */ +xfs_failaddr_t +xfs_alloc_check_irec ( +struct xfs_btree_cur *cur, +const struct xfs_alloc_rec_incore *irec) +{ +return xfs_alloc_check_perag_irec (cur->bc_ag.pag, irec); +} + static inline int xfs_alloc_complain_bad_rec( struct xfs_btree_cur *cur,
fs/xfs/libxfs/xfs_alloc.h +2 -0
@@ -184,6 +184,8 @@ xfs_alloc_get_rec(union xfs_btree_rec ;void xfs_alloc_btrec_to_irec (const union xfs_btree_rec *rec,struct xfs_alloc_rec_incore *irec); +xfs_failaddr_t xfs_alloc_check_perag_irec (struct xfs_perag *pag, +const struct xfs_alloc_rec_incore *irec);xfs_failaddr_t xfs_alloc_check_irec (struct xfs_btree_cur *cur,const struct xfs_alloc_rec_incore *irec);
fs/xfs/libxfs/xfs_alloc_btree.c +12 -1
@@ -323,7 +323,18 @@ xfs_allocbt_verify(if (bp->b_ops->magic[0 ] ==cpu_to_be32 (XFS_ABTC_MAGIC )) btnum = XFS_BTNUM_CNTi;if (pag &&xfs_perag_initialised_agf (pag)) { -if (level >= pag->pagf_levels[btnum]) +unsigned int maxlevel = pag->pagf_levels[btnum]; + +#ifdef CONFIG_XFS_ONLINE_REPAIR +/* +* Online repair could be rewriting the free space btrees, so +* we'll validate against the larger of either tree while this +* is going on. +*/ + maxlevel = max_t(unsigned int, maxlevel, + pag->pagf_alt_levels[btnum]); +#endif +if (level >= maxlevel)return __this_address; }else if (level >= mp->m_alloc_maxlevels)return __this_address;
fs/xfs/libxfs/xfs_types.h +7 -0
@@ -202,6 +202,13 @@ enum xfs_ag_resv_type {XFS_AG_RESV_AGFL ,XFS_AG_RESV_METADATA ,XFS_AG_RESV_RMAPBT , + +/* +* Don't increase fdblocks when freeing extent. This is a pony for +* the bnobt repair functions to re-free the free space without +* altering fdblocks. If you think you need this you're wrong. +*/ + XFS_AG_RESV_IGNORE, };/* Results of scanning a btree keyspace to check occupancy. */
fs/xfs/scrub/alloc.c +12 -2
@@ -12,10 +12,11 @@#include "xfs_btree.h" #include "xfs_alloc.h" #include "xfs_rmap.h" +#include "xfs_ag.h" #include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/btree.h" -#include "xfs_ag.h" +#include "scrub/repair.h" /* * Set us up to scrub free space btrees.
@@ -24,10 +25,19 @@ intxchk_setup_ag_allocbt ( struct xfs_scrub *sc) { +int error; +if (xchk_need_intent_drain (sc))xchk_fsgates_enable (sc,XCHK_FSGATES_DRAIN ); -return xchk_setup_ag_btree (sc, false); + error =xchk_setup_ag_btree (sc, false); +if (error) +return error; + +if (xchk_could_repair (sc)) +return xrep_setup_ag_allocbt (sc); + +return 0 ; }/* Free space btree scrubber. */
fs/xfs/scrub/alloc_repair.c new file +910 -0
910 lines not on this page · raw message
fs/xfs/scrub/common.h +13 -0
@@ -175,8 +175,21 @@ static inline bool xchk_needs_repair(const struct xfs_scrub_metadata *sm)XFS_SCRUB_OFLAG_XCORRUPT | XFS_SCRUB_OFLAG_PREEN); } + +/* +* "Should we prepare for a repair?" +* +* Return true if the caller permits us to repair metadata and we're not +* setting up for a post-repair evaluation. +*/ +static inline bool xchk_could_repair (const struct xfs_scrub *sc) +{ +return (sc->sm->sm_flags &XFS_SCRUB_IFLAG_REPAIR ) && + !(sc->flags &XREP_ALREADY_FIXED ); +}#else # define xchk_needs_repair (sc) (false) +# define xchk_could_repair (sc) (false)#endif /* CONFIG_XFS_ONLINE_REPAIR */ int xchk_metadata_inode_forks (struct xfs_scrub *sc);
fs/xfs/scrub/newbt.c +38 -6
77 lines not on this page · raw message
fs/xfs/scrub/newbt.h +6 -0
@@ -50,6 +50,9 @@ struct xrep_newbt {enum xfs_ag_resv_type resv; }; +#define for_each_xrep_newbt_reservation (xnr, resv, n) \ + list_for_each_entry_safe((resv), (n), &(xnr)->resv_list, list) +void xrep_newbt_init_bare (struct xrep_newbt *xnr,struct xfs_scrub *sc); void xrep_newbt_init_ag(struct xrep_newbt *xnr, struct xfs_scrub *sc, const struct xfs_owner_info *oinfo, xfs_fsblock_t alloc_hint,
@@ -57,10 +60,13 @@ void xrep_newbt_init_ag(struct xrep_newbt *xnr, struct xfs_scrub *sc,int xrep_newbt_init_inode (struct xrep_newbt *xnr,struct xfs_scrub *sc,int whichfork,const struct xfs_owner_info *oinfo);int xrep_newbt_alloc_blocks (struct xrep_newbt *xnr,uint64_t nr_blocks); +int xrep_newbt_add_extent (struct xrep_newbt *xnr,struct xfs_perag *pag, +xfs_agblock_t agbno,xfs_extlen_t len);void xrep_newbt_cancel (struct xrep_newbt *xnr);int xrep_newbt_commit (struct xrep_newbt *xnr);int xrep_newbt_claim_block (struct xfs_btree_cur *cur,struct xrep_newbt *xnr,union xfs_btree_ptr *ptr);int xrep_newbt_relog_autoreap (struct xrep_newbt *xnr); +unsigned int xrep_newbt_unused_blocks (struct xrep_newbt *xnr);#endif /* __XFS_SCRUB_NEWBT_H__ */
fs/xfs/scrub/reap.c +15 -2
@@ -331,11 +331,23 @@ xreap_agextent(return 0 ; } -if (rs->resv ==XFS_AG_RESV_AGFL ) { +switch (rs->resv) { +case XFS_AG_RESV_AGFL :ASSERT (*aglenp ==1 ); error =xreap_put_freelist (sc, agbno); rs->force_roll = true; - }else { +break ; +case XFS_AG_RESV_IGNORE : +/* +* bnobt/cntbt blocks are counted as free space, so we pass +* XFS_AG_RESV_IGNORE when reaping the old free space btree +* blocks to avoid changing fdblocks. +*/ + error =__xfs_free_extent (sc->tp, sc->sa.pag, agbno, *aglenp, + rs->oinfo, rs->resv, true); + rs->force_roll = true; +break ; +default :/* * Use deferred frees to get rid of the old btree blocks to try * to minimize the window in which we could crash and lose the
@@ -343,6 +355,7 @@ xreap_agextent(*/ __xfs_free_extent_later (sc->tp, fsbno, *aglenp, rs->oinfo, true); rs->deferred++; +break ; }return error;
fs/xfs/scrub/repair.c +69 -0
72 lines not on this page · raw message
fs/xfs/scrub/repair.h +24 -0
@@ -51,6 +51,15 @@ int xrep_find_ag_btree_roots(struct xfs_scrub *sc, struct xfs_buf *agf_bp,void xrep_force_quotacheck (struct xfs_scrub *sc,xfs_dqtype_t type);int xrep_ino_dqattach (struct xfs_scrub *sc); +/* Repair setup functions */ +int xrep_setup_ag_allocbt (struct xfs_scrub *sc); + +void xrep_ag_btcur_init (struct xfs_scrub *sc,struct xchk_ag *sa); + +/* Metadata revalidators */ + +int xrep_revalidate_allocbt (struct xfs_scrub *sc); +/* Metadata repairers */ int xrep_probe (struct xfs_scrub *sc);
@@ -58,6 +67,9 @@ int xrep_superblock(struct xfs_scrub *sc);int xrep_agf (struct xfs_scrub *sc);int xrep_agfl (struct xfs_scrub *sc);int xrep_agi (struct xfs_scrub *sc); +int xrep_allocbt (struct xfs_scrub *sc); + +int xrep_reinit_pagf (struct xfs_scrub *sc);#else
@@ -77,11 +89,23 @@ xrep_calc_ag_resblks( return 0; } +/* repair setup functions for no-repair */ +static inline int +xrep_setup_nothing ( +struct xfs_scrub *sc) +{ +return 0 ; +} +#define xrep_setup_ag_allocbt xrep_setup_nothing + +#define xrep_revalidate_allocbt (NULL) +#define xrep_probe xrep_notsupported#define xrep_superblock xrep_notsupported#define xrep_agf xrep_notsupported#define xrep_agfl xrep_notsupported#define xrep_agi xrep_notsupported +#define xrep_allocbt xrep_notsupported#endif /* CONFIG_XFS_ONLINE_REPAIR */
fs/xfs/scrub/scrub.c +9 -5
@@ -238,13 +238,15 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .type = ST_PERAG, .setup = xchk_setup_ag_allocbt, .scrub = xchk_bnobt, - .repair = xrep_notsupported, + .repair = xrep_allocbt, + .repair_eval = xrep_revalidate_allocbt, }, [XFS_SCRUB_TYPE_CNTBT] = { /* cntbt */ .type = ST_PERAG, .setup = xchk_setup_ag_allocbt, .scrub = xchk_cntbt, - .repair = xrep_notsupported, + .repair = xrep_allocbt, + .repair_eval = xrep_revalidate_allocbt, }, [XFS_SCRUB_TYPE_INOBT] = { /* inobt */ .type = ST_PERAG,
@@ -525,7 +527,10 @@ xfs_scrub_metadata( goto out_teardown;/* Scrub for errors. */ - error = sc->ops->scrub (sc); +if ((sc->flags &XREP_ALREADY_FIXED ) && sc->ops->repair_eval !=NULL ) + error = sc->ops->repair_eval (sc); +else + error = sc->ops->scrub (sc);if (error == -EDEADLOCK && !(sc->flags &XCHK_TRY_HARDER )) goto try_harder;if (error == -ECHRNG && !(sc->flags &XCHK_NEED_DRAIN ))
@@ -535,8 +540,7 @@ xfs_scrub_metadata(xchk_update_health (sc); -if ((sc->sm->sm_flags &XFS_SCRUB_IFLAG_REPAIR ) && - !(sc->flags &XREP_ALREADY_FIXED )) { +if (xchk_could_repair (sc)) {bool needs_fix =xchk_needs_repair (sc->sm);/* Userspace asked us to rebuild the structure regardless. */
fs/xfs/scrub/scrub.h +8 -0
@@ -35,6 +35,14 @@ struct xchk_meta_ops {/* Repair or optimize the metadata. */ int (*repair)(struct xfs_scrub *); +/* +* Re-scrub the metadata we repaired, in case there's extra work that +* we need to do to check our repair work. If this is NULL, we'll use +* the ->scrub function pointer, assuming that the regular scrub is +* sufficient. +*/ +int (*repair_eval)(struct xfs_scrub *sc); +/* Decide if we even have this piece of metadata. */ bool (*has)(struct xfs_mount *);
fs/xfs/scrub/trace.h +23 -1
@@ -1125,11 +1125,33 @@ DEFINE_EVENT(xrep_rmap_class, name, \ xfs_agblock_t agbno, xfs_extlen_t len, \ uint64_t owner, uint64_t offset, unsigned int flags), \ TP_ARGS(mp, agno, agbno, len, owner, offset, flags)) -DEFINE_REPAIR_RMAP_EVENT(xrep_alloc_extent_fn); DEFINE_REPAIR_RMAP_EVENT(xrep_ialloc_extent_fn);DEFINE_REPAIR_RMAP_EVENT (xrep_rmap_extent_fn);DEFINE_REPAIR_RMAP_EVENT (xrep_bmap_extent_fn); +TRACE_EVENT (xrep_abt_found, + TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, + const struct xfs_alloc_rec_incore *rec), +TP_ARGS (mp, agno, rec), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(xfs_agnumber_t, agno) + __field(xfs_agblock_t, startblock) +__field (xfs_extlen_t, blockcount) + ), +TP_fast_assign ( + __entry->dev = mp->m_super->s_dev; + __entry->agno = agno; + __entry->startblock = rec->ar_startblock; + __entry->blockcount = rec->ar_blockcount; + ), +TP_printk ("dev %d:%d agno 0x%x agbno 0x%x fsbcount 0x%x" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->agno, + __entry->startblock, + __entry->blockcount) +) + TRACE_EVENT(xrep_refcount_extent_fn, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, struct xfs_refcount_irec *irec),
fs/xfs/scrub/xfarray.h +22 -0
@@ -55,6 +55,28 @@ static inline int xfarray_append(struct xfarray *array, const void *ptr)uint64_t xfarray_length (struct xfarray *array);int xfarray_load_next (struct xfarray *array,xfarray_idx_t *idx,void *rec); +/* +* Iterate the non-null elements in a sparse xfarray. Callers should +* initialize *idx to XFARRAY_CURSOR_INIT before the first call; on return, it +* will be set to one more than the index of the record that was retrieved. +* Returns 1 if a record was retrieved, 0 if there weren't any more records, or +* a negative errno. +*/ +static inline int +xfarray_iter ( +struct xfarray *array, +xfarray_idx_t *idx, +void *rec) +{ +int ret =xfarray_load_next (array, idx, rec); + +if (ret == -ENODATA ) +return 0 ; +if (ret ==0 ) +return 1 ; +return ret; +} +/* Declarations for xfile array sort functionality. */ typedef cmp_func_t xfarray_cmp_fn ;
fs/xfs/xfs_extent_busy.c +13 -0
@@ -629,3 +629,16 @@ xfs_extent_busy_ag_cmp( diff = b1->bno - b2->bno;return diff; } + +/* Are there any busy extents in this AG? */ +bool +xfs_extent_busy_list_empty ( +struct xfs_perag *pag) +{ +bool res; + +spin_lock (&pag->pagb_lock); + res =RB_EMPTY_ROOT (&pag->pagb_tree); +spin_unlock (&pag->pagb_lock); +return res; +}
fs/xfs/xfs_extent_busy.h +2 -0
@@ -67,4 +67,6 @@ static inline void xfs_extent_busy_sort(struct list_head *list) list_sort(NULL, list, xfs_extent_busy_ag_cmp); } +bool xfs_extent_busy_list_empty (struct xfs_perag *pag); +#endif /* __XFS_EXTENT_BUSY_H__ */
PATCH 3/5 xfs: rewrite xfs_icache_inode_is_allocated
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Back in the mists of time[1], I proposed this function to assist the inode btree scrubbers in checking the inode btree contents against the allocation state of the inode records. The original version performed a direct lookup in the inode cache and returned the allocation status if the cached inode hadn't been reused and wasn't in an intermediate state. Brian thought it would be better to use the usual iget/irele mechanisms, so that was changed for the final version.
Unfortunately, this hasn't aged well -- the IGET_INCORE flag only has one user and clutters up the regular iget path, which makes it hard to reason about how it actually works. Worse yet, the inode inactivation series silently broke it because iget won't return inodes that are anywhere in the inactivation machinery, even though the caller is already required to prevent inode allocation and freeing. Inodes in the inactivation machinery are still allocated, but the current code's interactions with the iget code prevent us from being able to say that.
Now that I understand the inode lifecycle better than I did in early 2017, I now realize that as long as the cached inode hasn't been reused and isn't actively being reclaimed, it's safe to access the i_mode field (with the AGI, rcu, and i_flags locks held), and we don't need to worry about the inode being freed out from under us.
Therefore, port the original version to modern code structure, which fixes the brokennes w.r.t. inactivation. In the next patch we'll remove IGET_INCORE since it's no longer necessary.
[1] https://lore.kernel.org/linux-xfs/[email protected]/
--- fs/xfs/xfs_icache.c | 127 +++++++++++++++++++++++++++++++++++++++++++-------- fs/xfs/xfs_trace.h | 22 +++++++++ 2 files changed, 129 insertions(+), 20 deletions(-)
fs/xfs/xfs_icache.c +107 -20
@@ -782,23 +782,23 @@ xfs_iget( }/* -* "Is this a cached inode that's also allocated?" +* Decide if this is this a cached inode that's also allocated. The caller +* must hold the AGI buffer lock to prevent inodes from being allocated or +* freed. * -* Look up an inode by number in the given file system. If the inode is -* in cache and isn't in purgatory, return 1 if the inode is allocated -* and 0 if it is not. For all other cases (not in cache, being torn -* down, etc.), return a negative error code. +* Look up an inode by number in the given file system. If the inode number +* is invalid, return -EINVAL. If the inode is not in cache, return -ENODATA. +* If the inode is in an intermediate state (new, being reclaimed, reused) then +* return -EAGAIN. * -* The caller has to prevent inode allocation and freeing activity, -* presumably by locking the AGI buffer. This is to ensure that an -* inode cannot transition from allocated to freed until the caller is -* ready to allow that. If the inode is in an intermediate state (new, -* reclaimable, or being reclaimed), -EAGAIN will be returned; if the -* inode is not in the cache, -ENOENT will be returned. The caller must -* deal with these scenarios appropriately. +* Otherwise, the incore inode is the one we want, and it is either live, +* somewhere in the inactivation machinery, or reclaimable. The inode is +* allocated if i_mode is nonzero. In all three cases, the cached inode will +* be more up to date than the ondisk inode buffer, so we must use the incore +* i_mode. * -* This is a specialized use case for the online scrubber; if you're -* reading this, you probably want xfs_iget. +* This is a specialized use case for the online fsck; if you're reading this, +* you probably want xfs_iget. */ int xfs_icache_inode_is_allocated(
@@ -808,15 +808,102 @@ xfs_icache_inode_is_allocated( bool *inuse) {struct xfs_inode *ip; +struct xfs_perag *pag; +xfs_agino_t agino;int error; - error =xfs_iget (mp, tp, ino,XFS_IGET_INCORE ,0 , &ip); -if (error) -return error; +/* reject inode numbers outside existing AGs */ +if (!ino ||XFS_INO_TO_AGNO (mp, ino) >= mp->m_sb.sb_agcount) +return -EINVAL ; - *inuse = !!(VFS_I (ip)->i_mode); -xfs_irele (ip); -return 0 ; +/* get the perag structure and ensure that it's inode capable */ + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ino)); +if (!pag) { +/* No perag means this inode can't possibly be allocated */ +return -EINVAL ; + } + + agino =XFS_INO_TO_AGINO (mp, ino); + +rcu_read_lock (); + ip =radix_tree_lookup (&pag->pag_ici_root, agino); +if (!ip) { +/* cache miss */ + error = -ENODATA ; + goto out_pag; + } + +/* +* If the inode number doesn't match, the incore inode got reused +* during an RCU grace period and the radix tree hasn't been updated. +* This isn't the inode we want. +*/ + error = -ENODATA ; +spin_lock (&ip->i_flags_lock); +if (ip->i_ino != ino) + goto out_skip; + +trace_xfs_icache_inode_is_allocated (ip); + +/* +* We have an incore inode that matches the inode we want, and the +* caller holds the AGI buffer. +* +* If the incore inode is INEW, there are several possibilities: +* +* For a file that is being created, note that we allocate the ondisk +* inode before allocating, initializing, and adding the incore inode +* to the radix tree. +* +* If the incore inode is being recycled, the inode has to be allocated +* because we don't allow freed inodes to be recycled. +* +* If the inode is queued for inactivation, it should still be +* allocated. +* +* If the incore inode is undergoing inactivation, either it is before +* the point where it would get freed ondisk (in which case i_mode is +* still nonzero), or it has already been freed, in which case i_mode +* is zero. We don't take the ILOCK here, but difree and dialloc +* require the AGI, which we do hold. +* +* If the inode is anywhere in the reclaim mechanism, we know that it's +* still ok to query i_mode because we don't allow uncached inode +* updates. +* +* If the incore inode is live (i.e. referenced from the dcache), the +* ondisk inode had better be allocated. This is the most trivial +* case. +*/ +#ifdef DEBUG +if (ip->i_flags &XFS_INEW ) { +/* created on disk already or recycling */ +ASSERT (VFS_I (ip)->i_mode !=0 ); + } + +if ((ip->i_flags &XFS_NEED_INACTIVE ) && + !(ip->i_flags &XFS_INACTIVATING )) { +/* definitely before difree */ +ASSERT (VFS_I (ip)->i_mode !=0 ); + } + +/* XFS_INACTIVATING and XFS_IRECLAIMABLE could be either state */ + +if (!(ip->i_flags & (XFS_NEED_INACTIVE |XFS_INEW |XFS_IRECLAIMABLE | +XFS_INACTIVATING ))) { +/* live inode */ +ASSERT (VFS_I (ip)->i_mode !=0 ); + } +#endif + *inuse =VFS_I (ip)->i_mode !=0 ; + error =0 ; + +out_skip: +spin_unlock (&ip->i_flags_lock); +out_pag: +rcu_read_unlock (); +xfs_perag_put (pag); +return error; }/*
fs/xfs/xfs_trace.h +22 -0
@@ -799,6 +799,28 @@ DEFINE_INODE_EVENT(xfs_inode_reclaiming);DEFINE_INODE_EVENT (xfs_inode_set_need_inactive);DEFINE_INODE_EVENT (xfs_inode_inactivating); +TRACE_EVENT (xfs_icache_inode_is_allocated, + TP_PROTO(struct xfs_inode *ip), +TP_ARGS (ip), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(xfs_ino_t, ino) + __field(unsigned long, iflags) +__field (umode_t, mode) + ), +TP_fast_assign ( + __entry->dev = VFS_I(ip)->i_sb->s_dev; + __entry->ino = ip->i_ino; + __entry->iflags = ip->i_flags; + __entry->mode = VFS_I(ip)->i_mode; + ), +TP_printk ("dev %d:%d ino 0x%llx iflags 0x%lx mode 0x%x" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->ino, + __entry->iflags, + __entry->mode) +); +/* * ftrace's __print_symbolic requires that all enum values be wrapped in the * TRACE_DEFINE_ENUM macro so that the enum value can be encoded in the ftrace
Re: [PATCH 3/5] xfs: rewrite xfs_icache_inode_is_allocated
Quoted 84 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Back in the mists of time[1], I proposed this function to assist the inode btree scrubbers in checking the inode btree contents against the allocation state of the inode records. The original version performed a direct lookup in the inode cache and returned the allocation status if the cached inode hadn't been reused and wasn't in an intermediate state. Brian thought it would be better to use the usual iget/irele mechanisms, so that was changed for the final version.
Unfortunately, this hasn't aged well -- the
IGET_INCOREflag only has one user and clutters up the regular iget path, which makes it hard to reason about how it actually works. Worse yet, the inode inactivation series silently broke it because iget won't return inodes that are anywhere in the inactivation machinery, even though the caller is already required to prevent inode allocation and freeing. Inodes in the inactivation machinery are still allocated, but the current code's interactions with the iget code prevent us from being able to say that.Now that I understand the inode lifecycle better than I did in early 2017, I now realize that as long as the cached inode hasn't been reused and isn't actively being reclaimed, it's safe to access the
i_modefield (with the AGI, rcu, andi_flagslocks held), and we don't need to worry about the inode being freed out from under us.Therefore, port the original version to modern code structure, which fixes the brokennes w.r.t. inactivation. In the next patch we'll remove
IGET_INCOREsince it's no longer necessary.[1] https://lore.kernel.org/linux-xfs/[email protected]/
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_icache.c | 127 +++++++++++++++++++++++++++++++++++++++++++-------- fs/xfs/xfs_trace.h | 22 +++++++++ 2 files changed, 129 insertions(+), 20 deletions(-)fs/xfs/xfs_icache.c +14
-14@@ -782,23 +782,23 @@ xfs_iget( }/* -* "Is this a cached inode that's also allocated?" +* Decide if this is this a cached inode that's also allocated. The caller +* must hold the AGI buffer lock to prevent inodes from being allocated or +* freed. * -* Look up an inode by number in the given file system. If the inode is -* in cache and isn't in purgatory, return 1 if the inode is allocated -* and 0 if it is not. For all other cases (not in cache, being torn -* down, etc.), return a negative error code. +* Look up an inode by number in the given file system. If the inode number +* is invalid, return -EINVAL. If the inode is not in cache, return -ENODATA. +* If the inode is in an intermediate state (new, being reclaimed, reused) then +* return -EAGAIN. * -* The caller has to prevent inode allocation and freeing activity, -* presumably by locking the AGI buffer. This is to ensure that an -* inode cannot transition from allocated to freed until the caller is -* ready to allow that. If the inode is in an intermediate state (new, -* reclaimable, or being reclaimed), -EAGAIN will be returned; if the -* inode is not in the cache, -ENOENT will be returned. The caller must -* deal with these scenarios appropriately. +* Otherwise, the incore inode is the one we want, and it is either live, +* somewhere in the inactivation machinery, or reclaimable. The inode is +* allocated if i_mode is nonzero. In all three cases, the cached inode will +* be more up to date than the ondisk inode buffer, so we must use the incore +* i_mode. * -* This is a specialized use case for the online scrubber; if you're -* reading this, you probably want xfs_iget. +* This is a specialized use case for the online fsck; if you're reading this, +* you probably want xfs_iget. */ int xfs_icache_inode_is_allocated(@@ -808,15 +808,102 @@ xfs_icache_inode_is_allocated( bool *inuse) {struct xfs_inode *ip;
fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 817
Quoted 10 lines
fs/xfs/xfs_icache.c +5
-3+struct xfs_perag *pag; +xfs_agino_t agino;int error; - error =xfs_iget (mp, tp, ino,XFS_IGET_INCORE ,0 , &ip); -if (error) -return error; +/* reject inode numbers outside existing AGs */ +if (!ino ||XFS_INO_TO_AGNO (mp, ino) >= mp->m_sb.sb_agcount) +return -EINVAL ;
xfs_verify_ino(mp, ino)
fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 824
Quoted 10 lines
fs/xfs/xfs_icache.c +6
-3- *inuse = !!(VFS_I (ip)->i_mode); -xfs_irele (ip); -return 0 ; +/* get the perag structure and ensure that it's inode capable */ + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ino)); +if (!pag) { +/* No perag means this inode can't possibly be allocated */ +return -EINVAL ; + }
Probably should be xfs_perag_grab/rele in this function.
Quoted 6 lines
fs/xfs/xfs_icache.c +6
-0+ agino =XFS_INO_TO_AGINO (mp, ino); + +rcu_read_lock (); + ip =radix_tree_lookup (&pag->pag_ici_root, agino); +if (!ip) { +/* cache miss */
fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 841
Quoted 10 lines
fs/xfs/xfs_icache.c +10
-0+ error = -ENODATA ; + goto out_pag; + } + +/* +* If the inode number doesn't match, the incore inode got reused +* during an RCU grace period and the radix tree hasn't been updated. +* This isn't the inode we want. +*/ + error = -ENODATA ;
move this up to before the rcu_read_lock(), and it can be removed from the !ip branch above, too.
Quoted 21 lines
fs/xfs/xfs_icache.c +21
-0+spin_lock (&ip->i_flags_lock); +if (ip->i_ino != ino) + goto out_skip; + +trace_xfs_icache_inode_is_allocated (ip); + +/* +* We have an incore inode that matches the inode we want, and the +* caller holds the AGI buffer. +* +* If the incore inode is INEW, there are several possibilities: +* +* For a file that is being created, note that we allocate the ondisk +* inode before allocating, initializing, and adding the incore inode +* to the radix tree. +* +* If the incore inode is being recycled, the inode has to be allocated +* because we don't allow freed inodes to be recycled. +* +* If the inode is queued for inactivation, it should still be +* allocated.
fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 872
Quoted 10 lines
fs/xfs/xfs_icache.c +10
-0+* +* If the incore inode is undergoing inactivation, either it is before +* the point where it would get freed ondisk (in which case i_mode is +* still nonzero), or it has already been freed, in which case i_mode +* is zero. We don't take the ILOCK here, but difree and dialloc +* require the AGI, which we do hold. +* +* If the inode is anywhere in the reclaim mechanism, we know that it's +* still ok to query i_mode because we don't allow uncached inode +* updates.
Is it? We explicitly consider XFS_IRECLAIM inodes as in the process of being freed, so there is no guarantee that anything in them is valid anymore. Indeed, there's a transient state in recycling an inode where we set XFS_IRECLAIM, then re-initialise the inode (which trashes i_mode) and then restore i_mode to it's correct value before clearing XFS_IRECLAIM.
Hence I think that if XFS_IRECLAIM is set, we can't make any safe judgement of the state of i_mode here with just a rcu_read_lock() being held.
fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 882
Quoted 10 lines
fs/xfs/xfs_icache.c +10
-0+* +* If the incore inode is live (i.e. referenced from the dcache), the +* ondisk inode had better be allocated. This is the most trivial +* case. +*/ +#ifdef DEBUG +if (ip->i_flags &XFS_INEW ) { +/* created on disk already or recycling */ +ASSERT (VFS_I (ip)->i_mode !=0 ); + }
I don't think this is correct. In xfs_iget_cache_miss() when allocating a new inode, we set XFS_INEW and we don't set i_mode until we call xfs_init_new_inode() after xfs_iget() on the newly allocated inode returns. Hence there is a long period where XFS_INEW can be set and i_mode is zero and the i_flags_lock is not held.
Remember, if this is a generic function (which by placing it in fs/xfs/xfs_icache.c is essentially asserting that it is) then the inode state is only being serialised by RCU. Hence the debug code here cannot assume that it has been called with the AGI locked to serialise it against create/free operations, nor that there aren't other operations being performed on the inode as the lookup is done.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 3/5] xfs: rewrite xfs_icache_inode_is_allocated
Quoted 89 lines · Dave Chinner
Quoted 88 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Back in the mists of time[1], I proposed this function to assist the inode btree scrubbers in checking the inode btree contents against the allocation state of the inode records. The original version performed a direct lookup in the inode cache and returned the allocation status if the cached inode hadn't been reused and wasn't in an intermediate state. Brian thought it would be better to use the usual iget/irele mechanisms, so that was changed for the final version.
Unfortunately, this hasn't aged well -- the
IGET_INCOREflag only has one user and clutters up the regular iget path, which makes it hard to reason about how it actually works. Worse yet, the inode inactivation series silently broke it because iget won't return inodes that are anywhere in the inactivation machinery, even though the caller is already required to prevent inode allocation and freeing. Inodes in the inactivation machinery are still allocated, but the current code's interactions with the iget code prevent us from being able to say that.Now that I understand the inode lifecycle better than I did in early 2017, I now realize that as long as the cached inode hasn't been reused and isn't actively being reclaimed, it's safe to access the
i_modefield (with the AGI, rcu, andi_flagslocks held), and we don't need to worry about the inode being freed out from under us.Therefore, port the original version to modern code structure, which fixes the brokennes w.r.t. inactivation. In the next patch we'll remove
IGET_INCOREsince it's no longer necessary.[1] https://lore.kernel.org/linux-xfs/[email protected]/
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_icache.c | 127 +++++++++++++++++++++++++++++++++++++++++++-------- fs/xfs/xfs_trace.h | 22 +++++++++ 2 files changed, 129 insertions(+), 20 deletions(-)fs/xfs/xfs_icache.c +16
-14@@ -782,23 +782,23 @@ xfs_iget( }/* -* "Is this a cached inode that's also allocated?" +* Decide if this is this a cached inode that's also allocated. The caller +* must hold the AGI buffer lock to prevent inodes from being allocated or +* freed. * -* Look up an inode by number in the given file system. If the inode is -* in cache and isn't in purgatory, return 1 if the inode is allocated -* and 0 if it is not. For all other cases (not in cache, being torn -* down, etc.), return a negative error code. +* Look up an inode by number in the given file system. If the inode number +* is invalid, return -EINVAL. If the inode is not in cache, return -ENODATA. +* If the inode is in an intermediate state (new, being reclaimed, reused) then +* return -EAGAIN. * -* The caller has to prevent inode allocation and freeing activity, -* presumably by locking the AGI buffer. This is to ensure that an -* inode cannot transition from allocated to freed until the caller is -* ready to allow that. If the inode is in an intermediate state (new, -* reclaimable, or being reclaimed), -EAGAIN will be returned; if the -* inode is not in the cache, -ENOENT will be returned. The caller must -* deal with these scenarios appropriately. +* Otherwise, the incore inode is the one we want, and it is either live, +* somewhere in the inactivation machinery, or reclaimable. The inode is +* allocated if i_mode is nonzero. In all three cases, the cached inode will +* be more up to date than the ondisk inode buffer, so we must use the incore +* i_mode. * -* This is a specialized use case for the online scrubber; if you're -* reading this, you probably want xfs_iget. +* This is a specialized use case for the online fsck; if you're reading this, +* you probably want xfs_iget. */ int xfs_icache_inode_is_allocated(@@ -808,15 +808,102 @@ xfs_icache_inode_is_allocated( bool *inuse) {struct xfs_inode *ip; +struct xfs_perag *pag; +xfs_agino_t agino;int error;
Quoted 8 lines
fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 817
Quoted 6 lines
fs/xfs/xfs_icache.c +3
-3- error =xfs_iget (mp, tp, ino,XFS_IGET_INCORE ,0 , &ip); -if (error) -return error; +/* reject inode numbers outside existing AGs */ +if (!ino ||XFS_INO_TO_AGNO (mp, ino) >= mp->m_sb.sb_agcount) +return -EINVAL ;
xfs_verify_ino(mp, ino)
Fixed, though the other iget functions still open code this.
Quoted 12 lines
fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 824
Quoted 10 lines
fs/xfs/xfs_icache.c +6
-3- *inuse = !!(VFS_I (ip)->i_mode); -xfs_irele (ip); -return 0 ; +/* get the perag structure and ensure that it's inode capable */ + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ino)); +if (!pag) { +/* No perag means this inode can't possibly be allocated */ +return -EINVAL ; + }Probably should be xfs_perag_grab/rele in this function.
Why? Is it because we presuppose that the caller holds the AGI buffer and hence we only need a passive reference?
Quoted 11 lines
Quoted 11 lines
fs/xfs/xfs_icache.c +11
-0+ agino =XFS_INO_TO_AGINO (mp, ino); + +rcu_read_lock (); + ip =radix_tree_lookup (&pag->pag_ici_root, agino); +if (!ip) { +/* cache miss */ + error = -ENODATA ; + goto out_pag; + } + +/*
Quoted 8 lines
fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 841
Quoted 5 lines
fs/xfs/xfs_icache.c +5
-0+* If the inode number doesn't match, the incore inode got reused +* during an RCU grace period and the radix tree hasn't been updated. +* This isn't the inode we want. +*/ + error = -ENODATA ;move this up to before the
rcu_read_lock(), and it can be removed from the !ip branch above, too.
Fixed.
Quoted 39 lines
Quoted 21 lines
fs/xfs/xfs_icache.c +21
-0+spin_lock (&ip->i_flags_lock); +if (ip->i_ino != ino) + goto out_skip; + +trace_xfs_icache_inode_is_allocated (ip); + +/* +* We have an incore inode that matches the inode we want, and the +* caller holds the AGI buffer. +* +* If the incore inode is INEW, there are several possibilities: +* +* For a file that is being created, note that we allocate the ondisk +* inode before allocating, initializing, and adding the incore inode +* to the radix tree. +* +* If the incore inode is being recycled, the inode has to be allocated +* because we don't allow freed inodes to be recycled. +* +* If the inode is queued for inactivation, it should still be +* allocated. fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 872
Quoted 10 lines
fs/xfs/xfs_icache.c +10
-0+* +* If the incore inode is undergoing inactivation, either it is before +* the point where it would get freed ondisk (in which case i_mode is +* still nonzero), or it has already been freed, in which case i_mode +* is zero. We don't take the ILOCK here, but difree and dialloc +* require the AGI, which we do hold. +* +* If the inode is anywhere in the reclaim mechanism, we know that it's +* still ok to query i_mode because we don't allow uncached inode +* updates. Is it? We explicitly consider
XFS_IRECLAIMinodes as in the process of being freed, so there is no guarantee that anything in them is valid anymore. Indeed, there's a transient state in recycling an inode where we setXFS_IRECLAIM, then re-initialise the inode (which trashesi_mode) and then restorei_modeto it's correct value before clearingXFS_IRECLAIM.
Quoted 3 lines
Hence I think that if
XFS_IRECLAIMis set, we can't make any safe judgement of the state ofi_modehere with just arcu_read_lock()being held.
I wrote this much too long ago, back when reclaim actually could write inode clusters to disk.
At this point the comment and the code are both wrong -- if the inode is in IRECLAIM, then it's either being recycled or reclaimed. Neither of those things modify the ondisk buffers anymore, so we actually could return ENODATA here because all three callers of this function use that as a signal to read i_mode from the icluster buffer.
Quoted 9 lines
Quoted 9 lines
fs/xfs/xfs_icache.c +9
-0+* +* If the incore inode is live (i.e. referenced from the dcache), the +* ondisk inode had better be allocated. This is the most trivial +* case. +*/ +#ifdef DEBUG +if (ip->i_flags &XFS_INEW ) { +/* created on disk already or recycling */ +ASSERT (VFS_I (ip)->i_mode !=0 );
Quoted 8 lines
fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 880
Quoted 1 line
fs/xfs/xfs_icache.c +1
-0+ }I don't think this is correct. In
xfs_iget_cache_miss()when allocating a new inode, we setXFS_INEWand we don't seti_modeuntil we callxfs_init_new_inode()afterxfs_iget()on the newly allocated inode returns. Hence there is a long period whereXFS_INEWcan be set andi_modeis zero and thei_flags_lockis not held.
I think you're referring to the situation where an icreate calls xfs_iget_cache_miss in the (v5 && IGET_CREATE && !ikeep) scenario, in which case we don't get around to setting i_mode until xfs_init_new_inode?
The icreate transaction holds the AGI all the way to the end, so a different thread calling _is_allocated shouldn't find any inodes in this state as long as it holds the AGI buffer, right?
Quoted 6 lines
Remember, if this is a generic function (which by placing it in
fs/xfs/xfs_icache.cis essentially asserting that it is) then the inode state is only being serialised by RCU. Hence the debug code here cannot assume that it has been called with the AGI locked to serialise it against create/free operations, nor that there aren't other operations being performed on the inode as the lookup is done.
How about I stuff it into fs/xfs/scrub/ instead? The only reason it's in xfs_icache.c is because I wanted to keep the rcu lock and radix tree lookup stuff in there... but yes I agree it's dangerous to let anyone else see this weird function.
Plus then I can require the caller pass in a valid AGI buffer to prove they've serialized against icreate/ifree. :)
--D
Quoted 6 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 3/5] xfs: rewrite xfs_icache_inode_is_allocated
Quoted 15 lines · Darrick J. Wong
Quoted 13 lines · Dave Chinner
fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 824
Quoted 10 lines · Darrick J. Wong
fs/xfs/xfs_icache.c +6
-3- *inuse = !!(VFS_I (ip)->i_mode); -xfs_irele (ip); -return 0 ; +/* get the perag structure and ensure that it's inode capable */ + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ino)); +if (!pag) { +/* No perag means this inode can't possibly be allocated */ +return -EINVAL ; + }Probably should be xfs_perag_grab/rele in this function.
Quoted 2 lines
Why? Is it because we presuppose that the caller holds the AGI buffer and hence we only need a passive reference?
Right, there's nothing in this function to guarantee that the perag is valid and active, so it might be in the process of being torn down by, say, shrink or memory reclaim. And while we are using the perag, we want to ensure that nothing can start a teardown operation...
Quoted 43 lines
Quoted 39 lines
Quoted 21 lines
fs/xfs/xfs_icache.c +21
-0+spin_lock (&ip->i_flags_lock); +if (ip->i_ino != ino) + goto out_skip; + +trace_xfs_icache_inode_is_allocated (ip); + +/* +* We have an incore inode that matches the inode we want, and the +* caller holds the AGI buffer. +* +* If the incore inode is INEW, there are several possibilities: +* +* For a file that is being created, note that we allocate the ondisk +* inode before allocating, initializing, and adding the incore inode +* to the radix tree. +* +* If the incore inode is being recycled, the inode has to be allocated +* because we don't allow freed inodes to be recycled. +* +* If the inode is queued for inactivation, it should still be +* allocated. fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 872
Quoted 10 lines
fs/xfs/xfs_icache.c +10
-0+* +* If the incore inode is undergoing inactivation, either it is before +* the point where it would get freed ondisk (in which case i_mode is +* still nonzero), or it has already been freed, in which case i_mode +* is zero. We don't take the ILOCK here, but difree and dialloc +* require the AGI, which we do hold. +* +* If the inode is anywhere in the reclaim mechanism, we know that it's +* still ok to query i_mode because we don't allow uncached inode +* updates. Is it? We explicitly consider
XFS_IRECLAIMinodes as in the process of being freed, so there is no guarantee that anything in them is valid anymore. Indeed, there's a transient state in recycling an inode where we setXFS_IRECLAIM, then re-initialise the inode (which trashesi_mode) and then restorei_modeto it's correct value before clearingXFS_IRECLAIM.Quoted 3 lines
Hence I think that if
XFS_IRECLAIMis set, we can't make any safe judgement of the state ofi_modehere with just arcu_read_lock()being held.
Quoted 8 lines
I wrote this much too long ago, back when reclaim actually could write inode clusters to disk.
At this point the comment and the code are both wrong -- if the inode is in IRECLAIM, then it's either being recycled or reclaimed. Neither of those things modify the ondisk buffers anymore, so we actually could return ENODATA here because all three callers of this function use that as a signal to read
i_modefrom the icluster buffer.
OK.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
fs/xfs/xfs_icache.c +9
-0+* +* If the incore inode is live (i.e. referenced from the dcache), the +* ondisk inode had better be allocated. This is the most trivial +* case. +*/ +#ifdef DEBUG +if (ip->i_flags &XFS_INEW ) { +/* created on disk already or recycling */ +ASSERT (VFS_I (ip)->i_mode !=0 );Quoted 8 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ }I don't think this is correct. In
xfs_iget_cache_miss()when allocating a new inode, we setXFS_INEWand we don't seti_modeuntil we callxfs_init_new_inode()afterxfs_iget()on the newly allocated inode returns. Hence there is a long period whereXFS_INEWcan be set andi_modeis zero and thei_flags_lockis not held.
Quoted 4 lines
I think you're referring to the situation where an icreate calls
xfs_iget_cache_missin the (v5 &&IGET_CREATE&& !ikeep) scenario, in which case we don't get around to settingi_modeuntilxfs_init_new_inode?
Yes, that is one example I can think of.
Quoted 3 lines
The icreate transaction holds the AGI all the way to the end, so a different thread calling
_is_allocatedshouldn't find any inodes in this state as long as it holds the AGI buffer, right?
Yes, I think that is correct.
Quoted 7 lines
Quoted 6 lines
Remember, if this is a generic function (which by placing it in
fs/xfs/xfs_icache.cis essentially asserting that it is) then the inode state is only being serialised by RCU. Hence the debug code here cannot assume that it has been called with the AGI locked to serialise it against create/free operations, nor that there aren't other operations being performed on the inode as the lookup is done.
Quoted 7 lines
How about I stuff it into
fs/xfs/scrub/instead? The only reason it's inxfs_icache.cis because I wanted to keep the rcu lock and radix tree lookup stuff in there... but yes I agree it's dangerous to let anyone else see this weird function.Plus then I can require the caller pass in a valid AGI buffer to prove they've serialized against icreate/ifree. :)
That's fine by me. If we need it at a later date as generic functionality, we can sort out the semantics then. :)
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 3/5] xfs: rewrite xfs_icache_inode_is_allocated
Quoted 123 lines · Dave Chinner
Quoted 15 lines · Darrick J. Wong
Quoted 13 lines · Dave Chinner
fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 824
Quoted 10 lines · Darrick J. Wong
fs/xfs/xfs_icache.c +6
-3- *inuse = !!(VFS_I (ip)->i_mode); -xfs_irele (ip); -return 0 ; +/* get the perag structure and ensure that it's inode capable */ + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ino)); +if (!pag) { +/* No perag means this inode can't possibly be allocated */ +return -EINVAL ; + }Probably should be xfs_perag_grab/rele in this function.
Quoted 2 lines
Why? Is it because we presuppose that the caller holds the AGI buffer and hence we only need a passive reference?
Right, there's nothing in this function to guarantee that the perag is valid and active, so it might be in the process of being torn down by, say, shrink or memory reclaim. And while we are using the perag, we want to ensure that nothing can start a teardown operation...
Quoted 43 lines
Quoted 39 lines
Quoted 21 lines
fs/xfs/xfs_icache.c +21
-0+spin_lock (&ip->i_flags_lock); +if (ip->i_ino != ino) + goto out_skip; + +trace_xfs_icache_inode_is_allocated (ip); + +/* +* We have an incore inode that matches the inode we want, and the +* caller holds the AGI buffer. +* +* If the incore inode is INEW, there are several possibilities: +* +* For a file that is being created, note that we allocate the ondisk +* inode before allocating, initializing, and adding the incore inode +* to the radix tree. +* +* If the incore inode is being recycled, the inode has to be allocated +* because we don't allow freed inodes to be recycled. +* +* If the inode is queued for inactivation, it should still be +* allocated. fs/xfs/xfs_icache.c xfs_icache_inode_is_allocated( · line 872
Quoted 10 lines
fs/xfs/xfs_icache.c +10
-0+* +* If the incore inode is undergoing inactivation, either it is before +* the point where it would get freed ondisk (in which case i_mode is +* still nonzero), or it has already been freed, in which case i_mode +* is zero. We don't take the ILOCK here, but difree and dialloc +* require the AGI, which we do hold. +* +* If the inode is anywhere in the reclaim mechanism, we know that it's +* still ok to query i_mode because we don't allow uncached inode +* updates. Is it? We explicitly consider
XFS_IRECLAIMinodes as in the process of being freed, so there is no guarantee that anything in them is valid anymore. Indeed, there's a transient state in recycling an inode where we setXFS_IRECLAIM, then re-initialise the inode (which trashesi_mode) and then restorei_modeto it's correct value before clearingXFS_IRECLAIM.Quoted 3 lines
Hence I think that if
XFS_IRECLAIMis set, we can't make any safe judgement of the state ofi_modehere with just arcu_read_lock()being held.Quoted 8 lines
I wrote this much too long ago, back when reclaim actually could write inode clusters to disk.
At this point the comment and the code are both wrong -- if the inode is in IRECLAIM, then it's either being recycled or reclaimed. Neither of those things modify the ondisk buffers anymore, so we actually could return ENODATA here because all three callers of this function use that as a signal to read
i_modefrom the icluster buffer.OK.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
fs/xfs/xfs_icache.c +9
-0+* +* If the incore inode is live (i.e. referenced from the dcache), the +* ondisk inode had better be allocated. This is the most trivial +* case. +*/ +#ifdef DEBUG +if (ip->i_flags &XFS_INEW ) { +/* created on disk already or recycling */ +ASSERT (VFS_I (ip)->i_mode !=0 );Quoted 8 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ }I don't think this is correct. In
xfs_iget_cache_miss()when allocating a new inode, we setXFS_INEWand we don't seti_modeuntil we callxfs_init_new_inode()afterxfs_iget()on the newly allocated inode returns. Hence there is a long period whereXFS_INEWcan be set andi_modeis zero and thei_flags_lockis not held.Quoted 4 lines
I think you're referring to the situation where an icreate calls
xfs_iget_cache_missin the (v5 &&IGET_CREATE&& !ikeep) scenario, in which case we don't get around to settingi_modeuntilxfs_init_new_inode?Yes, that is one example I can think of.
Quoted 3 lines
The icreate transaction holds the AGI all the way to the end, so a different thread calling
_is_allocatedshouldn't find any inodes in this state as long as it holds the AGI buffer, right?Yes, I think that is correct.
Quoted 12 lines
Quoted 6 lines
Remember, if this is a generic function (which by placing it in
fs/xfs/xfs_icache.cis essentially asserting that it is) then the inode state is only being serialised by RCU. Hence the debug code here cannot assume that it has been called with the AGI locked to serialise it against create/free operations, nor that there aren't other operations being performed on the inode as the lookup is done.How about I stuff it into
fs/xfs/scrub/instead? The only reason it's inxfs_icache.cis because I wanted to keep the rcu lock and radix tree lookup stuff in there... but yes I agree it's dangerous to let anyone else see this weird function.
Quoted 5 lines
Quoted 2 lines
Plus then I can require the caller pass in a valid AGI buffer to prove they've serialized against icreate/ifree. :)
That's fine by me. If we need it at a later date as generic functionality, we can sort out the semantics then. :)
Ok. Even better, the xfs_perag_grab/get thing becomes irrelevant, since scrub already got its own reference and we can just use it here in xchk_inode_is_allocated. :)
--D
Quoted 6 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 4/5 xfs: repair inode btrees
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Use the rmapbt to find inode chunks, query the chunks to compute hole and free masks, and with that information rebuild the inobt and finobt.
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_ialloc.c | 41 +- fs/xfs/libxfs/xfs_ialloc.h | 3 fs/xfs/scrub/common.c | 1 fs/xfs/scrub/ialloc_repair.c | 872 ++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/repair.c | 59 +++ fs/xfs/scrub/repair.h | 17 + fs/xfs/scrub/scrub.c | 6 fs/xfs/scrub/scrub.h | 1 fs/xfs/scrub/trace.h | 68 ++- 10 files changed, 1020 insertions(+), 49 deletions(-) create mode 100644 fs/xfs/scrub/ialloc_repair.c
fs/xfs/Makefile +1 -0
@@ -180,6 +180,7 @@ ifeq ($(CONFIG_XFS_ONLINE_REPAIR),y) xfs-y += $(addprefix scrub/, \ agheader_repair.o \ alloc_repair.o \ + ialloc_repair.o \ newbt.o \ reap.o \ repair.o \
fs/xfs/libxfs/xfs_ialloc.c +28 -13
63 lines not on this page · raw message
fs/xfs/libxfs/xfs_ialloc.h +3 -0
@@ -79,6 +79,7 @@ int xfs_inobt_lookup(struct xfs_btree_cur *cur, xfs_agino_t ino,*/ int xfs_inobt_get_rec (struct xfs_btree_cur *cur,xfs_inobt_rec_incore_t *rec,int *stat); +uint8_t xfs_inobt_rec_freecount (const struct xfs_inobt_rec_incore *irec);/* * Inode chunk initialisation routine
@@ -93,6 +94,8 @@ union xfs_btree_rec;void xfs_inobt_btrec_to_irec (struct xfs_mount *mp,const union xfs_btree_rec *rec,struct xfs_inobt_rec_incore *irec); +xfs_failaddr_t xfs_inobt_check_perag_irec (struct xfs_perag *pag, +const struct xfs_inobt_rec_incore *irec);xfs_failaddr_t xfs_inobt_check_irec (struct xfs_btree_cur *cur,const struct xfs_inobt_rec_incore *irec); int xfs_ialloc_has_inodes_at_extent(struct xfs_btree_cur *cur,
fs/xfs/scrub/common.c +1 -0
@@ -605,6 +605,7 @@ xchk_ag_free( struct xchk_ag *sa) {xchk_ag_btcur_free (sa); +xrep_reset_perag_resv (sc);if (sa->agf_bp) {xfs_trans_brelse (sc->tp, sa->agf_bp); sa->agf_bp =NULL ;
fs/xfs/scrub/ialloc_repair.c new file +872 -0
872 lines not on this page · raw message
fs/xfs/scrub/repair.c +59 -0
62 lines not on this page · raw message
fs/xfs/scrub/repair.h +17 -0
@@ -50,6 +50,7 @@ int xrep_find_ag_btree_roots(struct xfs_scrub *sc, struct xfs_buf *agf_bp, struct xrep_find_ag_btree *btree_info, struct xfs_buf *agfl_bp);void xrep_force_quotacheck (struct xfs_scrub *sc,xfs_dqtype_t type);int xrep_ino_dqattach (struct xfs_scrub *sc); +int xrep_reset_perag_resv (struct xfs_scrub *sc);/* Repair setup functions */ int xrep_setup_ag_allocbt (struct xfs_scrub *sc);
@@ -59,6 +60,7 @@ void xrep_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa);/* Metadata revalidators */ int xrep_revalidate_allocbt (struct xfs_scrub *sc); +int xrep_revalidate_iallocbt (struct xfs_scrub *sc);/* Metadata repairers */
@@ -68,8 +70,10 @@ int xrep_agf(struct xfs_scrub *sc);int xrep_agfl (struct xfs_scrub *sc);int xrep_agi (struct xfs_scrub *sc);int xrep_allocbt (struct xfs_scrub *sc); +int xrep_iallocbt (struct xfs_scrub *sc);int xrep_reinit_pagf (struct xfs_scrub *sc); +int xrep_reinit_pagi (struct xfs_scrub *sc);#else
@@ -89,6 +93,17 @@ xrep_calc_ag_resblks(return 0 ; } +static inline int +xrep_reset_perag_resv ( +struct xfs_scrub *sc) +{ +if (!(sc->flags &XREP_RESET_PERAG_RESV )) +return 0 ; + +ASSERT (0 ); +return -EOPNOTSUPP ; +} +/* repair setup functions for no-repair */ static inline int xrep_setup_nothing(
@@ -99,6 +114,7 @@ xrep_setup_nothing(#define xrep_setup_ag_allocbt xrep_setup_nothing#define xrep_revalidate_allocbt (NULL) +#define xrep_revalidate_iallocbt (NULL)#define xrep_probe xrep_notsupported#define xrep_superblock xrep_notsupported
@@ -106,6 +122,7 @@ xrep_setup_nothing(#define xrep_agfl xrep_notsupported#define xrep_agi xrep_notsupported#define xrep_allocbt xrep_notsupported +#define xrep_iallocbt xrep_notsupported#endif /* CONFIG_XFS_ONLINE_REPAIR */
fs/xfs/scrub/scrub.c +4 -2
@@ -252,14 +252,16 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .type = ST_PERAG, .setup = xchk_setup_ag_iallocbt, .scrub = xchk_inobt, - .repair = xrep_notsupported, + .repair = xrep_iallocbt, + .repair_eval = xrep_revalidate_iallocbt, }, [XFS_SCRUB_TYPE_FINOBT] = { /* finobt */ .type = ST_PERAG, .setup = xchk_setup_ag_iallocbt, .scrub = xchk_finobt, .has = xfs_has_finobt, - .repair = xrep_notsupported, + .repair = xrep_iallocbt, + .repair_eval = xrep_revalidate_iallocbt, }, [XFS_SCRUB_TYPE_RMAPBT] = { /* rmapbt */ .type = ST_PERAG,
fs/xfs/scrub/scrub.h +1 -0
@@ -120,6 +120,7 @@ struct xfs_scrub {#define XCHK_TRY_HARDER (1 << 0)/* can't get resources, try again */ #define XCHK_FSGATES_DRAIN (1 << 2)/* defer ops draining enabled */ #define XCHK_NEED_DRAIN (1 << 3)/* scrub needs to drain defer ops */ +#define XREP_RESET_PERAG_RESV (1 << 30)/* must reset AG space reservation */ #define XREP_ALREADY_FIXED (1 << 31)/* checking our repair work */ /*
fs/xfs/scrub/trace.h +34 -34
92 lines not on this page · raw message
PATCH 5/5 xfs: repair refcount btrees
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Reconstruct the refcount data from the rmap btree.
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_ag.h | 1 fs/xfs/libxfs/xfs_btree.c | 26 + fs/xfs/libxfs/xfs_btree.h | 2 fs/xfs/libxfs/xfs_refcount.c | 18 + fs/xfs/libxfs/xfs_refcount.h | 2 fs/xfs/libxfs/xfs_refcount_btree.c | 13 + fs/xfs/scrub/refcount_repair.c | 791 ++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/repair.h | 2 fs/xfs/scrub/scrub.c | 2 fs/xfs/scrub/trace.h | 22 + 11 files changed, 862 insertions(+), 18 deletions(-) create mode 100644 fs/xfs/scrub/refcount_repair.c
fs/xfs/Makefile +1 -0
@@ -183,6 +183,7 @@ xfs-y += $(addprefix scrub/, \ ialloc_repair.o \ newbt.o \ reap.o \ + refcount_repair.o \ repair.o \ ) endif
fs/xfs/libxfs/xfs_ag.h +1 -0
@@ -87,6 +87,7 @@ struct xfs_perag {* verifiers while rebuilding the AG btrees. */ uint8_t pagf_alt_levels[XFS_BTNUM_AGF ]; +uint8_t pagf_alt_refcount_level;#endif spinlock_t pag_state_lock;
fs/xfs/libxfs/xfs_btree.c +26 -0
@@ -5212,3 +5212,29 @@ xfs_btree_destroy_cur_caches(void)xfs_rmapbt_destroy_cur_cache ();xfs_refcountbt_destroy_cur_cache (); } + +/* Move the btree cursor before the first record. */ +int +xfs_btree_goto_left_edge ( +struct xfs_btree_cur *cur) +{ +int stat =0 ; +int error; + +memset (&cur->bc_rec,0 ,sizeof (cur->bc_rec)); + error =xfs_btree_lookup (cur,XFS_LOOKUP_LE , &stat); +if (error) +return error; +if (!stat) +return 0 ; + + error =xfs_btree_decrement (cur,0 , &stat); +if (error) +return error; +if (stat !=0 ) { +ASSERT (0 ); +return -EFSCORRUPTED ; + } + +return 0 ; +}
fs/xfs/libxfs/xfs_btree.h +2 -0
@@ -738,4 +738,6 @@ xfs_btree_alloc_cursor(int __init xfs_btree_init_cur_caches (void );void xfs_btree_destroy_cur_caches (void ); +int xfs_btree_goto_left_edge (struct xfs_btree_cur *cur); +#endif /* __XFS_BTREE_H__ */
fs/xfs/libxfs/xfs_refcount.c +12 -6
@@ -120,14 +120,11 @@ xfs_refcount_btrec_to_irec( irec->rc_refcount =be32_to_cpu (rec->refc.rc_refcount); } -/* Simple checks for refcount records. */ -xfs_failaddr_t -xfs_refcount_check_irec ( -struct xfs_btree_cur *cur, +inline xfs_failaddr_t +xfs_refcount_check_perag_irec ( +struct xfs_perag *pag,const struct xfs_refcount_irec *irec) { -struct xfs_perag *pag = cur->bc_ag.pag; -if (irec->rc_blockcount ==0 || irec->rc_blockcount >MAXREFCEXTLEN )return __this_address;
@@ -144,6 +141,15 @@ xfs_refcount_check_irec(return NULL ; } +/* Simple checks for refcount records. */ +xfs_failaddr_t +xfs_refcount_check_irec ( +struct xfs_btree_cur *cur, +const struct xfs_refcount_irec *irec) +{ +return xfs_refcount_check_perag_irec (cur->bc_ag.pag, irec); +} + static inline int xfs_refcount_complain_bad_rec( struct xfs_btree_cur *cur,
fs/xfs/libxfs/xfs_refcount.h +2 -0
@@ -117,6 +117,8 @@ extern int xfs_refcount_has_records(struct xfs_btree_cur *cur,union xfs_btree_rec ;extern void xfs_refcount_btrec_to_irec (const union xfs_btree_rec *rec,struct xfs_refcount_irec *irec); +xfs_failaddr_t xfs_refcount_check_perag_irec (struct xfs_perag *pag, +const struct xfs_refcount_irec *irec);xfs_failaddr_t xfs_refcount_check_irec (struct xfs_btree_cur *cur,const struct xfs_refcount_irec *irec); extern int xfs_refcount_insert(struct xfs_btree_cur *cur,
fs/xfs/libxfs/xfs_refcount_btree.c +12 -1
@@ -232,7 +232,18 @@ xfs_refcountbt_verify( level =be16_to_cpu (block->bb_level);if (pag &&xfs_perag_initialised_agf (pag)) { -if (level >= pag->pagf_refcount_level) +unsigned int maxlevel = pag->pagf_refcount_level; + +#ifdef CONFIG_XFS_ONLINE_REPAIR +/* +* Online repair could be rewriting the refcount btree, so +* we'll validate against the larger of either tree while this +* is going on. +*/ + maxlevel = max_t(unsigned int, maxlevel, + pag->pagf_alt_refcount_level); +#endif +if (level >= maxlevel)return __this_address; }else if (level >= mp->m_refc_maxlevels)return __this_address;
fs/xfs/scrub/refcount_repair.c new file +791 -0
791 lines not on this page · raw message
fs/xfs/scrub/repair.h +2 -0
@@ -71,6 +71,7 @@ int xrep_agfl(struct xfs_scrub *sc);int xrep_agi (struct xfs_scrub *sc);int xrep_allocbt (struct xfs_scrub *sc);int xrep_iallocbt (struct xfs_scrub *sc); +int xrep_refcountbt (struct xfs_scrub *sc);int xrep_reinit_pagf (struct xfs_scrub *sc);int xrep_reinit_pagi (struct xfs_scrub *sc);
@@ -123,6 +124,7 @@ xrep_setup_nothing(#define xrep_agi xrep_notsupported#define xrep_allocbt xrep_notsupported#define xrep_iallocbt xrep_notsupported +#define xrep_refcountbt xrep_notsupported#endif /* CONFIG_XFS_ONLINE_REPAIR */
fs/xfs/scrub/scrub.c +1 -1
@@ -275,7 +275,7 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .setup = xchk_setup_ag_refcountbt, .scrub = xchk_refcountbt, .has = xfs_has_reflink, - .repair = xrep_notsupported, + .repair = xrep_refcountbt, }, [XFS_SCRUB_TYPE_INODE] = { /* inode record */ .type = ST_INODE,
fs/xfs/scrub/trace.h +12 -10
@@ -1185,27 +1185,29 @@ TRACE_EVENT(xrep_ibt_found, __entry->freemask) ) -TRACE_EVENT (xrep_refcount_extent_fn, - TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, - struct xfs_refcount_irec *irec), -TP_ARGS (mp, agno, irec), +TRACE_EVENT (xrep_refc_found, + TP_PROTO(struct xfs_perag *pag, const struct xfs_refcount_irec *rec), +TP_ARGS (pag, rec),TP_STRUCT__entry ( __field(dev_t, dev) __field(xfs_agnumber_t, agno) + __field(enum xfs_refc_domain, domain) __field(xfs_agblock_t, startblock) __field(xfs_extlen_t, blockcount)__field (xfs_nlink_t, refcount) ),TP_fast_assign ( - __entry->dev = mp->m_super->s_dev; - __entry->agno = agno; - __entry->startblock = irec->rc_startblock; - __entry->blockcount = irec->rc_blockcount; - __entry->refcount = irec->rc_refcount; + __entry->dev = pag->pag_mount->m_super->s_dev; + __entry->agno = pag->pag_agno; + __entry->domain = rec->rc_domain; + __entry->startblock = rec->rc_startblock; + __entry->blockcount = rec->rc_blockcount; + __entry->refcount = rec->rc_refcount; ), -TP_printk ("dev %d:%d agno 0x%x agbno 0x%x fsbcount 0x%x refcount %u" , +TP_printk ("dev %d:%d agno 0x%x dom %s agbno 0x%x fsbcount 0x%x refcount %u" ,MAJOR (__entry->dev),MINOR (__entry->dev), __entry->agno, +__print_symbolic (__entry->domain,XFS_REFC_DOMAIN_STRINGS ), __entry->startblock, __entry->blockcount, __entry->refcount)
Re: [PATCHSET v25.0 0/5] xfs: online repair of AG btrees
In reply to Darrick J. WongQuoted 9 lines · Darrick J. Wong
Hi all,
Now that we've spent a lot of time reworking common code in online fsck, we're ready to start rebuilding the AG space btrees. This series implements repair functions for the free space, inode, and refcount btrees. Rebuilding the reverse mapping btree is much more intense and is left for a subsequent patchset. The fstests counterpart of this patchset implements stress testing of repair.
Quoted 5 lines
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
This all looks fairly sane. The only concerns I have are the icache lookup bits I commented on. Hence for everything but that patch,
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
cover xfs: online repair of inodes and forks
In reply to Darrick J. WongHi all,
In this series, online repair gains the ability to repair inode records. To do this, we must repair the ondisk inode and fork information enough to pass the iget verifiers and hence make the inode igettable again. Once that's done, we can perform higher level repairs on the incore inode. The fstests counterpart of this patchset implements stress testing of repair.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-inodes
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-inodes
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=repair-inodes
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_attr_leaf.c | 32 - fs/xfs/libxfs/xfs_attr_leaf.h | 2 fs/xfs/libxfs/xfs_bmap.c | 22 fs/xfs/libxfs/xfs_bmap.h | 2 fs/xfs/libxfs/xfs_dir2_priv.h | 2 fs/xfs/libxfs/xfs_dir2_sf.c | 29 - fs/xfs/libxfs/xfs_format.h | 3 fs/xfs/libxfs/xfs_shared.h | 1 fs/xfs/libxfs/xfs_symlink_remote.c | 21 fs/xfs/scrub/alloc.c | 2 fs/xfs/scrub/bmap.c | 4 fs/xfs/scrub/common.c | 26 + fs/xfs/scrub/common.h | 8 fs/xfs/scrub/dir.c | 21 fs/xfs/scrub/inode.c | 14 fs/xfs/scrub/inode_repair.c | 1618 ++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/parent.c | 10 fs/xfs/scrub/repair.c | 47 + fs/xfs/scrub/repair.h | 28 + fs/xfs/scrub/rtbitmap.c | 4 fs/xfs/scrub/rtsummary.c | 4 fs/xfs/scrub/scrub.c | 2 fs/xfs/scrub/trace.h | 174 ++++ 24 files changed, 2034 insertions(+), 43 deletions(-) create mode 100644 fs/xfs/scrub/inode_repair.c
PATCH 1/6 xfs: disable online repair quota helpers when quota not enabled
From: Darrick J. Wong <[email protected]>
Don't compile the quota helper functions if quota isn't being built into the XFS module.
--- fs/xfs/scrub/repair.c | 2 ++ fs/xfs/scrub/repair.h | 9 +++++++++ 2 files changed, 11 insertions(+)
fs/xfs/scrub/repair.c +2 -0
@@ -674,6 +674,7 @@ xrep_find_ag_btree_roots(return error; } +#ifdef CONFIG_XFS_QUOTA /* Force a quotacheck the next time we mount. */ void xrep_force_quotacheck(
@@ -735,6 +736,7 @@ xrep_ino_dqattach( return error; } +#endif /* CONFIG_XFS_QUOTA */ /* Initialize all the btree cursors for an AG repair. */ void
fs/xfs/scrub/repair.h +9 -0
@@ -48,8 +48,15 @@ struct xrep_find_ag_btree {int xrep_find_ag_btree_roots (struct xfs_scrub *sc,struct xfs_buf *agf_bp,struct xrep_find_ag_btree *btree_info,struct xfs_buf *agfl_bp); + +#ifdef CONFIG_XFS_QUOTA void xrep_force_quotacheck (struct xfs_scrub *sc,xfs_dqtype_t type);int xrep_ino_dqattach (struct xfs_scrub *sc); +#else +# define xrep_force_quotacheck (sc, type) ((void)0) +# define xrep_ino_dqattach (sc) (0) +#endif /* CONFIG_XFS_QUOTA */ +int xrep_reset_perag_resv (struct xfs_scrub *sc);/* Repair setup functions */
@@ -78,6 +85,8 @@ int xrep_reinit_pagi(struct xfs_scrub *sc);#else +#define xrep_ino_dqattach (sc) (0) +static inline int xrep_attempt (struct xfs_scrub *sc)
PATCH 2/6 xfs: try to attach dquots to files before repairing them
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Inode resource usage is tracked in the quota metadata. Repairing a file might change the resources used by that file, which means that we need to attach dquots to the file that we're examining before accessing anything in the file protected by the ILOCK.
However, there's a twist: a dquot cache miss requires the dquot to be read in from the quota file, during which we drop the ILOCK on the file being examined. This means that we *must* try to attach the dquots before taking the ILOCK.
Therefore, dquots must be attached to files in the scrub setup function. If doing so yields corruption errors (or unknown dquot errors), we instead clear the quotachecked status, which will cause a quotacheck on next mount. A future series will make this trigger live quotacheck.
While we're here, change the xrep_ino_dqattach function to use the unlocked dqattach functions so that we avoid cycling the ILOCK if the inode already has dquots attached. This makes the naming and locking requirements consistent with the rest of the filesystem.
--- fs/xfs/scrub/bmap.c | 4 ++++ fs/xfs/scrub/common.c | 25 +++++++++++++++++++++++++ fs/xfs/scrub/common.h | 6 ++++++ fs/xfs/scrub/inode.c | 4 ++++ fs/xfs/scrub/repair.c | 13 ++++++++----- fs/xfs/scrub/rtbitmap.c | 4 ++++ fs/xfs/scrub/rtsummary.c | 4 ++++ 7 files changed, 55 insertions(+), 5 deletions(-)
fs/xfs/scrub/bmap.c +4 -0
@@ -78,6 +78,10 @@ xchk_setup_inode_bmap(if (error) goto out; + error =xchk_ino_dqattach (sc); +if (error) + goto out; +xchk_ilock (sc,XFS_ILOCK_EXCL ); out:/* scrub teardown will unlock and release the inode */
fs/xfs/scrub/common.c +25 -0
@@ -818,6 +818,26 @@ xchk_iget_agi(return 0 ; } +#ifdef CONFIG_XFS_QUOTA +/* +* Try to attach dquots to this inode if we think we might want to repair it. +* Callers must not hold any ILOCKs. If the dquots are broken and cannot be +* attached, a quotacheck will be scheduled. +*/ +int +xchk_ino_dqattach ( +struct xfs_scrub *sc) +{ +ASSERT (sc->tp !=NULL ); +ASSERT (sc->ip !=NULL ); + +if (!xchk_could_repair (sc)) +return 0 ; + +return xrep_ino_dqattach (sc); +} +#endif +/* Install an inode that we opened by handle for scrubbing. */ int xchk_install_handle_inode(
@@ -1029,6 +1049,11 @@ xchk_setup_inode_contents( error =xchk_trans_alloc (sc, resblks);if (error) goto out; + + error =xchk_ino_dqattach (sc); +if (error) + goto out; +xchk_ilock (sc,XFS_ILOCK_EXCL ); out:/* scrub teardown will unlock and release the inode for us */
fs/xfs/scrub/common.h +6 -0
@@ -103,9 +103,15 @@ xchk_setup_rtsummary(struct xfs_scrub *sc) }#endif #ifdef CONFIG_XFS_QUOTA +int xchk_ino_dqattach (struct xfs_scrub *sc);int xchk_setup_quota (struct xfs_scrub *sc);#else static inline int +xchk_ino_dqattach (struct xfs_scrub *sc) +{ +return 0 ; +} +static inline int xchk_setup_quota (struct xfs_scrub *sc) {return -ENOENT ;
fs/xfs/scrub/inode.c +4 -0
@@ -38,6 +38,10 @@ xchk_prepare_iscrub(if (error)return error; + error =xchk_ino_dqattach (sc); +if (error) +return error; +xchk_ilock (sc,XFS_ILOCK_EXCL );return 0 ; }
fs/xfs/scrub/repair.c +8 -5
@@ -701,10 +701,10 @@ xrep_force_quotacheck(* * This function ensures that the appropriate dquots are attached to an inode. * We cannot allow the dquot code to allocate an on-disk dquot block here -* because we're already in transaction context with the inode locked. The -* on-disk dquot should already exist anyway. If the quota code signals -* corruption or missing quota information, schedule quotacheck, which will -* repair corruptions in the quota metadata. +* because we're already in transaction context. The on-disk dquot should +* already exist anyway. If the quota code signals corruption or missing quota +* information, schedule quotacheck, which will repair corruptions in the quota +* metadata. */ int xrep_ino_dqattach(
@@ -712,7 +712,10 @@ xrep_ino_dqattach( {int error; - error =xfs_qm_dqattach_locked (sc->ip, false); +ASSERT (sc->tp !=NULL ); +ASSERT (sc->ip !=NULL ); + + error =xfs_qm_dqattach (sc->ip);switch (error) {case -EFSBADCRC :case -EFSCORRUPTED :
fs/xfs/scrub/rtbitmap.c +4 -0
@@ -32,6 +32,10 @@ xchk_setup_rtbitmap(if (error)return error; + error =xchk_ino_dqattach (sc); +if (error) +return error; +xchk_ilock (sc,XFS_ILOCK_EXCL |XFS_ILOCK_RTBITMAP );return 0 ; }
fs/xfs/scrub/rtsummary.c +4 -0
@@ -61,6 +61,10 @@ xchk_setup_rtsummary(if (error)return error; + error =xchk_ino_dqattach (sc); +if (error) +return error; +/* * Locking order requires us to take the rtbitmap first. We must be * careful to unlock it ourselves when we are done with the rtbitmap
PATCH 3/6 xfs: repair inode records
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If an inode is so badly damaged that it cannot be loaded into the cache, fix the ondisk metadata and try again. If there /is/ a cached inode, fix any problems and apply any optimizations that can be solved incore.
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_format.h | 3 fs/xfs/scrub/alloc.c | 2 fs/xfs/scrub/inode.c | 10 + fs/xfs/scrub/inode_repair.c | 774 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/repair.c | 32 ++ fs/xfs/scrub/repair.h | 19 + fs/xfs/scrub/scrub.c | 2 fs/xfs/scrub/trace.h | 129 +++++++ 9 files changed, 969 insertions(+), 3 deletions(-) create mode 100644 fs/xfs/scrub/inode_repair.c
fs/xfs/Makefile +1 -0
@@ -181,6 +181,7 @@ xfs-y += $(addprefix scrub/, \ agheader_repair.o \ alloc_repair.o \ ialloc_repair.o \ + inode_repair.o \ newbt.o \ reap.o \ refcount_repair.o \
fs/xfs/libxfs/xfs_format.h +2 -1
@@ -996,7 +996,8 @@ enum xfs_dinode_fmt {#define XFS_DFORK_APTR (dip) \ (XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip))#define XFS_DFORK_PTR (dip,w) \ - ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip)) + ((void *)((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : \ + XFS_DFORK_APTR(dip)))#define XFS_DFORK_FORMAT (dip,w) \ ((w) == XFS_DATA_FORK ? \
fs/xfs/scrub/alloc.c +2 -0
@@ -9,6 +9,8 @@#include "xfs_format.h" #include "xfs_trans_resv.h" #include "xfs_mount.h" +#include "xfs_log_format.h" +#include "xfs_trans.h" #include "xfs_btree.h" #include "xfs_alloc.h" #include "xfs_rmap.h"
fs/xfs/scrub/inode.c +9 -1
@@ -24,6 +24,7 @@#include "scrub/common.h" #include "scrub/btree.h" #include "scrub/trace.h" +#include "scrub/repair.h" /* Prepare the attached inode for scrubbing. */ static inline int
@@ -184,8 +185,11 @@ xchk_setup_inode(* saying the inode is allocated and the icache being unable to load * the inode until we can flag the corruption in xchk_inode. The * scrub function has to note the corruption, since we're not really -* supposed to do that from the setup function. +* supposed to do that from the setup function. Save the mapping to +* make repairs to the ondisk inode buffer. */ +if (xchk_could_repair (sc)) +xrep_setup_inode (sc, &imap);return 0 ; out_cancel:
@@ -341,6 +345,10 @@ xchk_inode_flags2(if (xfs_dinode_has_bigtime (dip) && !xfs_has_bigtime (mp)) goto bad; +/* no large extent counts without the filesystem feature */ +if ((flags2 &XFS_DIFLAG2_NREXT64 ) && !xfs_has_large_extent_counts (mp)) + goto bad; +return ; bad:xchk_ino_set_corrupt (sc, ino);
fs/xfs/scrub/inode_repair.c new file +774 -0
774 lines not on this page · raw message
fs/xfs/scrub/repair.c +32 -0
@@ -741,6 +741,38 @@ xrep_ino_dqattach( }#endif /* CONFIG_XFS_QUOTA */ +/* +* Ensure that the inode being repaired is ready to handle a certain number of +* extents, or return EFSCORRUPTED. Caller must hold the ILOCK of the inode +* being repaired and have joined it to the scrub transaction. +*/ +int +xrep_ino_ensure_extent_count ( +struct xfs_scrub *sc, +int whichfork, +xfs_extnum_t nextents) +{ +xfs_extnum_t max_extents; +bool large_extcount; + + large_extcount =xfs_inode_has_large_extent_counts (sc->ip); + max_extents =xfs_iext_max_nextents (large_extcount, whichfork); +if (nextents <= max_extents) +return 0 ; +if (large_extcount) +return -EFSCORRUPTED ; +if (!xfs_has_large_extent_counts (sc->mp)) +return -EFSCORRUPTED ; + + max_extents =xfs_iext_max_nextents (true, whichfork); +if (nextents > max_extents) +return -EFSCORRUPTED ; + + sc->ip->i_diflags2 |=XFS_DIFLAG2_NREXT64 ; +xfs_trans_log_inode (sc->tp, sc->ip,XFS_ILOG_CORE ); +return 0 ; +} +/* Initialize all the btree cursors for an AG repair. */ void xrep_ag_btcur_init(
fs/xfs/scrub/repair.h +19 -0
@@ -26,6 +26,16 @@ bool xrep_ag_has_space(struct xfs_perag *pag, xfs_extlen_t nr_blocks, enum xfs_ag_resv_type type);xfs_extlen_t xrep_calc_ag_resblks (struct xfs_scrub *sc); +static inline int +xrep_trans_commit ( +struct xfs_scrub *sc) +{ +int error =xfs_trans_commit (sc->tp); + + sc->tp =NULL ; +return error; +} +struct xbitmap ;struct xagb_bitmap ;
@@ -57,11 +67,16 @@ int xrep_ino_dqattach(struct xfs_scrub *sc);# define xrep_ino_dqattach (sc) (0)#endif /* CONFIG_XFS_QUOTA */ +int xrep_ino_ensure_extent_count (struct xfs_scrub *sc,int whichfork, +xfs_extnum_t nextents);int xrep_reset_perag_resv (struct xfs_scrub *sc);/* Repair setup functions */ int xrep_setup_ag_allocbt (struct xfs_scrub *sc); +struct xfs_imap ; +int xrep_setup_inode (struct xfs_scrub *sc,struct xfs_imap *imap); +void xrep_ag_btcur_init (struct xfs_scrub *sc,struct xchk_ag *sa);/* Metadata revalidators */
@@ -79,6 +94,7 @@ int xrep_agi(struct xfs_scrub *sc);int xrep_allocbt (struct xfs_scrub *sc);int xrep_iallocbt (struct xfs_scrub *sc);int xrep_refcountbt (struct xfs_scrub *sc); +int xrep_inode (struct xfs_scrub *sc);int xrep_reinit_pagf (struct xfs_scrub *sc);int xrep_reinit_pagi (struct xfs_scrub *sc);
@@ -123,6 +139,8 @@ xrep_setup_nothing( }#define xrep_setup_ag_allocbt xrep_setup_nothing +#define xrep_setup_inode (sc, imap) ((void)0) +#define xrep_revalidate_allocbt (NULL)#define xrep_revalidate_iallocbt (NULL)
@@ -134,6 +152,7 @@ xrep_setup_nothing(#define xrep_allocbt xrep_notsupported#define xrep_iallocbt xrep_notsupported#define xrep_refcountbt xrep_notsupported +#define xrep_inode xrep_notsupported#endif /* CONFIG_XFS_ONLINE_REPAIR */
fs/xfs/scrub/scrub.c +1 -1
@@ -281,7 +281,7 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .type = ST_INODE, .setup = xchk_setup_inode, .scrub = xchk_inode, - .repair = xrep_notsupported, + .repair = xrep_inode, }, [XFS_SCRUB_TYPE_BMBTD] = { /* inode data fork */ .type = ST_INODE,
fs/xfs/scrub/trace.h +129 -0
135 lines not on this page · raw message
PATCH 4/6 xfs: zap broken inode forks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Determine if inode fork damage is responsible for the inode being unable to pass the ifork verifiers in xfs_iget and zap the fork contents if this is true. Once this is done the fork will be empty but we'll be able to construct an in-core inode, and a subsequent call to the inode fork repair ioctl will search the rmapbt to rebuild the records that were in the fork.
--- fs/xfs/libxfs/xfs_attr_leaf.c | 32 +- fs/xfs/libxfs/xfs_attr_leaf.h | 2 fs/xfs/libxfs/xfs_bmap.c | 22 + fs/xfs/libxfs/xfs_bmap.h | 2 fs/xfs/libxfs/xfs_dir2_priv.h | 2 fs/xfs/libxfs/xfs_dir2_sf.c | 29 +- fs/xfs/libxfs/xfs_shared.h | 1 fs/xfs/libxfs/xfs_symlink_remote.c | 21 + fs/xfs/scrub/inode_repair.c | 688 ++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/trace.h | 42 ++ 10 files changed, 804 insertions(+), 37 deletions(-)
fs/xfs/libxfs/xfs_attr_leaf.c +21 -11
@@ -1040,23 +1040,16 @@ xfs_attr_shortform_allfit(return xfs_attr_shortform_bytesfit (dp, bytes); } -/* Verify the consistency of an inline attribute fork. */ +/* Verify the consistency of a raw inline attribute fork. */ xfs_failaddr_t -xfs_attr_shortform_verify ( -struct xfs_inode *ip) +xfs_attr_shortform_verify_struct ( +struct xfs_attr_shortform *sfp, +size_t size) { -struct xfs_attr_shortform *sfp;struct xfs_attr_sf_entry *sfep;struct xfs_attr_sf_entry *next_sfep;char *endp; -struct xfs_ifork *ifp;int i; -int64_t size; - -ASSERT (ip->i_af.if_format ==XFS_DINODE_FMT_LOCAL ); - ifp =xfs_ifork_ptr (ip,XFS_ATTR_FORK ); - sfp = (struct xfs_attr_shortform *)ifp->if_u1.if_data; - size = ifp->if_bytes;/* * Give up if the attribute is way too short.
@@ -1116,6 +1109,23 @@ xfs_attr_shortform_verify(return NULL ; } +/* Verify the consistency of an inline attribute fork. */ +xfs_failaddr_t +xfs_attr_shortform_verify ( +struct xfs_inode *ip) +{ +struct xfs_attr_shortform *sfp; +struct xfs_ifork *ifp; +int64_t size; + +ASSERT (ip->i_af.if_format ==XFS_DINODE_FMT_LOCAL ); + ifp =xfs_ifork_ptr (ip,XFS_ATTR_FORK ); + sfp = (struct xfs_attr_shortform *)ifp->if_u1.if_data; + size = ifp->if_bytes; + +return xfs_attr_shortform_verify_struct (sfp, size); +} +/* * Convert a leaf attribute list to shortform attribute list */
fs/xfs/libxfs/xfs_attr_leaf.h +2 -0
@@ -56,6 +56,8 @@ int xfs_attr_sf_findname(struct xfs_da_args *args, unsigned int *basep);int xfs_attr_shortform_allfit (struct xfs_buf *bp,struct xfs_inode *dp);int xfs_attr_shortform_bytesfit (struct xfs_inode *dp,int bytes); +xfs_failaddr_t xfs_attr_shortform_verify_struct (struct xfs_attr_shortform *sfp, +size_t size);xfs_failaddr_t xfs_attr_shortform_verify (struct xfs_inode *ip);void xfs_attr_fork_remove (struct xfs_inode *ip,struct xfs_trans *tp);
fs/xfs/libxfs/xfs_bmap.c +16 -6
@@ -6188,19 +6188,18 @@ xfs_bmap_finish_one(return error; } -/* Check that an inode's extent does not have invalid flags or bad ranges. */ +/* Check that an extent does not have invalid flags or bad ranges. */ xfs_failaddr_t -xfs_bmap_validate_extent ( -struct xfs_inode *ip, +xfs_bmap_validate_extent_raw ( +struct xfs_mount *mp, +bool rtfile,int whichfork,struct xfs_bmbt_irec *irec) { -struct xfs_mount *mp = ip->i_mount; -if (!xfs_verify_fileext (mp, irec->br_startoff, irec->br_blockcount))return __this_address; -if (XFS_IS_REALTIME_INODE (ip) && whichfork ==XFS_DATA_FORK ) { +if (rtfile && whichfork ==XFS_DATA_FORK ) {if (!xfs_verify_rtext (mp, irec->br_startblock, irec->br_blockcount))return __this_address;
@@ -6230,3 +6229,14 @@ xfs_bmap_intent_destroy_cache(void)kmem_cache_destroy (xfs_bmap_intent_cache); xfs_bmap_intent_cache =NULL ; } + +/* Check that an inode's extent does not have invalid flags or bad ranges. */ +xfs_failaddr_t +xfs_bmap_validate_extent ( +struct xfs_inode *ip, +int whichfork, +struct xfs_bmbt_irec *irec) +{ +return xfs_bmap_validate_extent_raw (ip->i_mount, +XFS_IS_REALTIME_INODE (ip), whichfork, irec); +}
fs/xfs/libxfs/xfs_bmap.h +2 -0
@@ -263,6 +263,8 @@ static inline uint32_t xfs_bmap_fork_to_state(int whichfork) } } +xfs_failaddr_t xfs_bmap_validate_extent_raw (struct xfs_mount *mp,bool rtfile, +int whichfork,struct xfs_bmbt_irec *irec);xfs_failaddr_t xfs_bmap_validate_extent (struct xfs_inode *ip,int whichfork,struct xfs_bmbt_irec *irec); int xfs_bmap_complain_bad_rec(struct xfs_inode *ip, int whichfork,
fs/xfs/libxfs/xfs_dir2_priv.h +2 -0
@@ -175,6 +175,8 @@ extern int xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino);extern int xfs_dir2_sf_lookup (struct xfs_da_args *args);extern int xfs_dir2_sf_removename (struct xfs_da_args *args);extern int xfs_dir2_sf_replace (struct xfs_da_args *args); +extern xfs_failaddr_t xfs_dir2_sf_verify_struct (struct xfs_mount *mp, +struct xfs_dir2_sf_hdr *sfp,int64_t size);extern xfs_failaddr_t xfs_dir2_sf_verify (struct xfs_inode *ip);int xfs_dir2_sf_entsize (struct xfs_mount *mp,struct xfs_dir2_sf_hdr *hdr,int len);
fs/xfs/libxfs/xfs_dir2_sf.c +18 -11
@@ -706,12 +706,11 @@ xfs_dir2_sf_check(/* Verify the consistency of an inline directory. */ xfs_failaddr_t -xfs_dir2_sf_verify ( -struct xfs_inode *ip) +xfs_dir2_sf_verify_struct ( +struct xfs_mount *mp, +struct xfs_dir2_sf_hdr *sfp, +int64_t size) { -struct xfs_mount *mp = ip->i_mount; -struct xfs_ifork *ifp =xfs_ifork_ptr (ip,XFS_DATA_FORK ); -struct xfs_dir2_sf_hdr *sfp;struct xfs_dir2_sf_entry *sfep;struct xfs_dir2_sf_entry *next_sfep;char *endp;
@@ -719,15 +718,9 @@ xfs_dir2_sf_verify(int i;int i8count;int offset; -int64_t size;int error;uint8_t filetype; -ASSERT (ifp->if_format ==XFS_DINODE_FMT_LOCAL ); - - sfp = (struct xfs_dir2_sf_hdr *)ifp->if_u1.if_data; - size = ifp->if_bytes; -/* * Give up if the directory is way too short. */
@@ -803,6 +796,20 @@ xfs_dir2_sf_verify(return NULL ; } +xfs_failaddr_t +xfs_dir2_sf_verify ( +struct xfs_inode *ip) +{ +struct xfs_mount *mp = ip->i_mount; +struct xfs_ifork *ifp =xfs_ifork_ptr (ip,XFS_DATA_FORK ); +struct xfs_dir2_sf_hdr *sfp; + +ASSERT (ifp->if_format ==XFS_DINODE_FMT_LOCAL ); + + sfp = (struct xfs_dir2_sf_hdr *)ifp->if_u1.if_data; +return xfs_dir2_sf_verify_struct (mp, sfp, ifp->if_bytes); +} +/* * Create a new (shortform) directory. */
fs/xfs/libxfs/xfs_shared.h +1 -0
@@ -139,6 +139,7 @@ bool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset, uint32_t size, struct xfs_buf *bp);void xfs_symlink_local_to_remote (struct xfs_trans *tp,struct xfs_buf *bp,struct xfs_inode *ip,struct xfs_ifork *ifp); +xfs_failaddr_t xfs_symlink_sf_verify_struct (void *sfp,int64_t size);xfs_failaddr_t xfs_symlink_shortform_verify (struct xfs_inode *ip);/* Computed inode geometry for the filesystem. */
fs/xfs/libxfs/xfs_symlink_remote.c +14 -7
@@ -201,16 +201,12 @@ xfs_symlink_local_to_remote(* does not do on-disk format checks. */ xfs_failaddr_t -xfs_symlink_shortform_verify ( -struct xfs_inode *ip) +xfs_symlink_sf_verify_struct ( +void *sfp, +int64_t size) { -struct xfs_ifork *ifp =xfs_ifork_ptr (ip,XFS_DATA_FORK ); -char *sfp = (char *)ifp->if_u1.if_data; -int size = ifp->if_bytes;char *endp = sfp + size; -ASSERT (ifp->if_format ==XFS_DINODE_FMT_LOCAL ); -/* * Zero length symlinks should never occur in memory as they are * never allowed to exist on disk.
@@ -231,3 +227,14 @@ xfs_symlink_shortform_verify(return __this_address;return NULL ; } + +xfs_failaddr_t +xfs_symlink_shortform_verify ( +struct xfs_inode *ip) +{ +struct xfs_ifork *ifp =xfs_ifork_ptr (ip,XFS_DATA_FORK ); + +ASSERT (ifp->if_format ==XFS_DINODE_FMT_LOCAL ); + +return xfs_symlink_sf_verify_struct (ifp->if_u1.if_data, ifp->if_bytes); +}
fs/xfs/scrub/inode_repair.c +686 -2
740 lines not on this page · raw message
fs/xfs/scrub/trace.h +42 -0
54 lines not on this page · raw message
PATCH 5/6 xfs: abort directory parent scrub scans if we encounter a zapped directory
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In the previous patch, we added some code to perform sufficient repairs to an ondisk inode record such that the inode cache would be willing to load the inode. If the broken inode was a shortform directory, it will reset the directory to something plausible, which is to say an empty subdirectory of the root. The telltale signs that something is seriously wrong is the broken link count.
Such directories look clean, but they shouldn't participate in a filesystem scan to find or confirm a directory parent pointer. Create a predicate that identifies such directories and abort the scrub.
Found by fuzzing xfs/1554 with multithreaded xfs_scrub enabled and u3.bmx[0].startblock = zeroes.
--- fs/xfs/scrub/common.c | 1 + fs/xfs/scrub/common.h | 2 ++ fs/xfs/scrub/dir.c | 21 +++++++++++++++++++++ fs/xfs/scrub/parent.c | 10 ++++++++++ 4 files changed, 34 insertions(+)
fs/xfs/scrub/common.c +1 -0
@@ -26,6 +26,7 @@#include "xfs_trans_priv.h" #include "xfs_da_format.h" #include "xfs_da_btree.h" +#include "xfs_dir2_priv.h" #include "xfs_attr.h" #include "xfs_reflink.h" #include "xfs_ag.h"
fs/xfs/scrub/common.h +2 -0
@@ -173,6 +173,8 @@ static inline bool xchk_skip_xref(struct xfs_scrub_metadata *sm) XFS_SCRUB_OFLAG_XCORRUPT); } +bool xchk_dir_looks_zapped (struct xfs_inode *dp); +#ifdef CONFIG_XFS_ONLINE_REPAIR /* Decide if a repair is required. */ static inline bool xchk_needs_repair (const struct xfs_scrub_metadata *sm)
fs/xfs/scrub/dir.c +21 -0
@@ -788,3 +788,24 @@ xchk_directory( error =0 ;return error; } + +/* +* Decide if this directory has been zapped to satisfy the inode and ifork +* verifiers. Checking and repairing should be postponed until the directory +* is fixed. +*/ +bool +xchk_dir_looks_zapped ( +struct xfs_inode *dp) +{ +/* +* If the dinode repair found a bad data fork, it will reset the fork +* to extents format with zero records and wait for the bmapbtd +* scrubber to reconstruct the block mappings. Directories always +* contain some content, so this is a clear sign of a zapped directory. +*/ +if (dp->i_df.if_format ==XFS_DINODE_FMT_EXTENTS ) +return dp->i_df.if_nextents ==0 ; + +return false; +}
fs/xfs/scrub/parent.c +10 -0
@@ -156,6 +156,16 @@ xchk_parent_validate( goto out_rele; } +/* +* We cannot yet validate this parent pointer if the directory looks as +* though it has been zapped by the inode record repair code. +*/ +if (xchk_dir_looks_zapped (dp)) { + error = -EFSCORRUPTED ; +xchk_set_incomplete (sc); + goto out_unlock; + } +/* Look for a directory entry in the parent pointing to the child. */ error =xchk_dir_walk (sc, dp, xchk_parent_actor, &spc);if (!xchk_fblock_xref_process_error (sc,XFS_DATA_FORK ,0 , &error))
PATCH 6/6 xfs: repair obviously broken inode modes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Building off the rmap scanner that we added in the previous patch, we can now find block 0 and try to use the information contained inside of it to guess the mode of an inode if it's totally improper.
--- fs/xfs/scrub/inode_repair.c | 170 ++++++++++++++++++++++++++++++++++++++++++- fs/xfs/scrub/trace.h | 11 ++- 2 files changed, 172 insertions(+), 9 deletions(-)
fs/xfs/scrub/inode_repair.c +165 -5
@@ -74,6 +74,9 @@ struct xrep_inode {/* Blocks in use by the attr fork. */ xfs_rfsblock_t attr_blocks; +/* Physical block containing data block 0. */ +xfs_fsblock_t block0; +/* Number of data device extents for the data fork. */ xfs_extnum_t data_extents;
@@ -113,6 +116,7 @@ xrep_setup_inode( ri = sc->buf;memcpy (&ri->imap, imap,sizeof (struct xfs_imap )); ri->sc = sc; + ri->block0 =NULLFSBLOCK ;return 0 ; }
@@ -188,12 +192,159 @@ xrep_dinode_header( dip->di_gen =cpu_to_be32 (sc->sm->sm_gen); } +/* Parse enough of the directory block header to guess if this is a dir. */ +static inline bool +xrep_dinode_is_dir ( +xfs_ino_t ino, +xfs_daddr_t daddr, +struct xfs_buf *bp) +{ +struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; +struct xfs_dir2_data_free *bf; +struct xfs_mount *mp = bp->b_mount; +xfs_lsn_t lsn =be64_to_cpu (hdr3->lsn); + +/* Does the dir3 header match the filesystem? */ +if (hdr3->magic !=cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC ) && + hdr3->magic !=cpu_to_be32 (XFS_DIR3_DATA_MAGIC )) +return false; + +if (be64_to_cpu (hdr3->owner) != ino) +return false; + +if (!uuid_equal (&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) +return false; + +if (be64_to_cpu (hdr3->blkno) != daddr) +return false; + +/* Directory blocks are always logged and must have a valid LSN. */ +if (lsn ==NULLCOMMITLSN ) +return false; +if (!xlog_valid_lsn (mp->m_log, lsn)) +return false; + +/* +* bestfree information lives immediately after the end of the header, +* so we won't run off the end of the buffer. +*/ + bf =xfs_dir2_data_bestfree_p (mp, bp->b_addr); +if (!bf[0 ].length && bf[0 ].offset) +return false; +if (!bf[1 ].length && bf[1 ].offset) +return false; +if (!bf[2 ].length && bf[2 ].offset) +return false; + +if (be16_to_cpu (bf[0 ].length) <be16_to_cpu (bf[1 ].length)) +return false; +if (be16_to_cpu (bf[1 ].length) <be16_to_cpu (bf[2 ].length)) +return false; + +return true; +} + +/* Guess the mode of this file from the contents. */ +STATIC uint16_t +xrep_dinode_guess_mode ( +struct xrep_inode *ri, +struct xfs_dinode *dip) +{ +struct xfs_buf *bp; +struct xfs_mount *mp = ri->sc->mp; +xfs_daddr_t daddr; +uint64_t fsize =be64_to_cpu (dip->di_size); +unsigned int dfork_sz =XFS_DFORK_DSIZE (dip, mp); +uint16_t mode =S_IFREG ; +int error; + +switch (dip->di_format) { +case XFS_DINODE_FMT_LOCAL : +/* +* If the data fork is local format, the size of the data area +* is reasonable and is big enough to contain the entire file, +* we can guess the file type from the local data. +* +* If there are no nulls, guess this is a symbolic link. +* Otherwise, this is probably a shortform directory. +*/ +if (dfork_sz <=XFS_LITINO (mp) && dfork_sz >= fsize) { +if (!memchr (XFS_DFORK_DPTR (dip),0 , fsize)) +return S_IFLNK ; +return S_IFDIR ; + } + +/* By default, we guess regular file. */ +return S_IFREG ; +case XFS_DINODE_FMT_DEV : +/* +* If the data fork is dev format, the size of the data area is +* reasonable and large enough to store a dev_t, and the file +* size is zero, this could be a blockdev, a chardev, a fifo, +* or a socket. There is no solid way to distinguish between +* those choices, so we guess blockdev if the device number is +* nonzero and chardev if it's zero (aka whiteout). +*/ +if (dfork_sz <=XFS_LITINO (mp) && + dfork_sz >=sizeof (__be32) && fsize ==0 ) { +xfs_dev_t dev =xfs_dinode_get_rdev (dip); + +return dev !=0 ?S_IFBLK :S_IFCHR ; + } + +/* By default, we guess regular file. */ +return S_IFREG ; +case XFS_DINODE_FMT_EXTENTS : +case XFS_DINODE_FMT_BTREE : +/* There are data blocks to examine below. */ +break ; +default : +/* Everything else is considered a regular file. */ +return S_IFREG ; + } + +/* There are no zero-length directories. */ +if (fsize ==0 ) +return S_IFREG ; + +/* +* If we didn't find a written mapping for file block zero, we'll guess +* that it's a sparse regular file. +*/ +if (ri->block0 ==NULLFSBLOCK ) +return S_IFREG ; + +/* Directories can't have rt extents. */ +if (ri->rt_extents >0 ) +return S_IFREG ; + +/* +* Read the first block of the file. Since we have no idea what kind +* of file geometry (e.g. dirblock size) we might be reading into, use +* an uncached buffer so that we don't pollute the buffer cache. We +* can't do uncached mapped buffers, so the best we can do is guess +* from the directory header. +*/ + daddr =XFS_FSB_TO_DADDR (mp, ri->block0); + error =xfs_buf_read_uncached (mp->m_ddev_targp, daddr, +XFS_FSS_TO_BB (mp,1 ),0 , &bp,NULL ); +if (error) +return S_IFREG ; + +if (xrep_dinode_is_dir (ri->sc->sm->sm_ino, daddr, bp)) + mode =S_IFDIR ; + +xfs_buf_relse (bp); +return mode; +} +/* Turn di_mode into /something/ recognizable. */ STATIC voidxrep_dinode_mode ( -struct xfs_scrub *sc, +struct xrep_inode *ri,struct xfs_dinode *dip) { +struct xfs_scrub *sc = ri->sc;uint16_t mode;trace_xrep_dinode_mode (sc, dip);
@@ -203,7 +354,7 @@ xrep_dinode_mode(return ;/* bad mode, so we set it to a file that only root can read */ - mode =S_IFREG ; + mode =xrep_dinode_guess_mode (ri, dip); dip->di_mode =cpu_to_be16 (mode); dip->di_uid =0 ; dip->di_gid =0 ;
@@ -412,9 +563,17 @@ xrep_dinode_walk_rmap( } ri->data_blocks += rec->rm_blockcount; -if (!(rec->rm_flags &XFS_RMAP_BMBT_BLOCK )) +if (!(rec->rm_flags &XFS_RMAP_BMBT_BLOCK )) { ri->data_extents++; +if (rec->rm_offset ==0 && + !(rec->rm_flags &XFS_RMAP_UNWRITTEN )) { +if (ri->block0 !=NULLFSBLOCK ) +return -EFSCORRUPTED ; + ri->block0 = rec->rm_startblock; + } + } +return 0 ; }
@@ -465,7 +624,8 @@ xrep_dinode_count_rmaps(trace_xrep_dinode_count_rmaps (ri->sc, ri->data_blocks, ri->rt_blocks, ri->attr_blocks, - ri->data_extents, ri->rt_extents, ri->attr_extents); + ri->data_extents, ri->rt_extents, ri->attr_extents, + ri->block0);return 0 ; }
@@ -1072,7 +1232,7 @@ xrep_dinode_core(/* Fix everything the verifier will complain about. */ dip =xfs_buf_offset (bp, ri->imap.im_boffset);xrep_dinode_header (sc, dip); -xrep_dinode_mode (sc, dip); +xrep_dinode_mode (ri, dip);xrep_dinode_flags (sc, dip, ri->rt_extents >0 );xrep_dinode_size (sc, dip);xrep_dinode_extsize_hints (sc, dip);
fs/xfs/scrub/trace.h +7 -4
@@ -1483,9 +1483,9 @@ TRACE_EVENT(xrep_dinode_count_rmaps, TP_PROTO(struct xfs_scrub *sc, xfs_rfsblock_t data_blocks, xfs_rfsblock_t rt_blocks, xfs_rfsblock_t attr_blocks, xfs_extnum_t data_extents, xfs_extnum_t rt_extents, - xfs_aextnum_t attr_extents), + xfs_aextnum_t attr_extents, xfs_fsblock_t block0),TP_ARGS (sc, data_blocks, rt_blocks, attr_blocks, data_extents, - rt_extents, attr_extents), + rt_extents, attr_extents, block0), TP_STRUCT__entry( __field(dev_t, dev) __field(xfs_ino_t, ino)
@@ -1495,6 +1495,7 @@ TRACE_EVENT(xrep_dinode_count_rmaps, __field(xfs_extnum_t, data_extents) __field(xfs_extnum_t, rt_extents) __field(xfs_aextnum_t, attr_extents) +__field (xfs_fsblock_t, block0) ),TP_fast_assign ( __entry->dev = sc->mp->m_super->s_dev;
@@ -1505,8 +1506,9 @@ TRACE_EVENT(xrep_dinode_count_rmaps, __entry->data_extents = data_extents; __entry->rt_extents = rt_extents; __entry->attr_extents = attr_extents; + __entry->block0 = block0; ), - TP_printk("dev %d:%d ino 0x%llx dblocks 0x%llx rtblocks 0x%llx ablocks 0x%llx dextents %llu rtextents %llu aextents %u", + TP_printk("dev %d:%d ino 0x%llx dblocks 0x%llx rtblocks 0x%llx ablocks 0x%llx dextents %llu rtextents %llu aextents %u startblock0 0x%llx", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, __entry->data_blocks,
@@ -1514,7 +1516,8 @@ TRACE_EVENT(xrep_dinode_count_rmaps, __entry->attr_blocks, __entry->data_extents, __entry->rt_extents, - __entry->attr_extents) + __entry->attr_extents, + __entry->block0) );#endif /* IS_ENABLED(CONFIG_XFS_ONLINE_REPAIR) */
cover xfs: online repair of file fork mappings
In reply to Darrick J. WongHi all,
In this series, online repair gains the ability to rebuild data and attr fork mappings from the reverse mapping information. It is at this point where we reintroduce the ability to reap file extents.
Repair of CoW forks is a little different -- on disk, CoW staging extents are owned by the refcount btree and cannot be mapped back to individual files. Hence we can only detect staging extents that don't quite look right (missing reverse mappings, shared staging extents) and replace them with fresh allocations.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-file-mappings
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-file-mappings
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=repair-file-mappings
--- fs/xfs/Makefile | 2 fs/xfs/libxfs/xfs_bmap_btree.c | 112 +++++ fs/xfs/libxfs/xfs_bmap_btree.h | 5 fs/xfs/libxfs/xfs_btree_staging.c | 11 - fs/xfs/libxfs/xfs_btree_staging.h | 2 fs/xfs/libxfs/xfs_iext_tree.c | 23 + fs/xfs/libxfs/xfs_inode_fork.c | 1 fs/xfs/libxfs/xfs_inode_fork.h | 3 fs/xfs/libxfs/xfs_refcount.c | 41 ++ fs/xfs/libxfs/xfs_refcount.h | 10 fs/xfs/scrub/bitmap.h | 28 + fs/xfs/scrub/bmap.c | 18 + fs/xfs/scrub/bmap_repair.c | 776 +++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/cow_repair.c | 609 +++++++++++++++++++++++++++++ fs/xfs/scrub/reap.c | 145 +++++++ fs/xfs/scrub/reap.h | 2 fs/xfs/scrub/repair.c | 50 ++ fs/xfs/scrub/repair.h | 11 + fs/xfs/scrub/scrub.c | 20 - fs/xfs/scrub/trace.h | 118 ++++++ fs/xfs/xfs_trans.c | 95 +++++ fs/xfs/xfs_trans.h | 4 22 files changed, 2041 insertions(+), 45 deletions(-) create mode 100644 fs/xfs/scrub/bmap_repair.c create mode 100644 fs/xfs/scrub/cow_repair.c
PATCH 1/5 xfs: reintroduce reaping of file metadata blocks to xrep_reap_extents
From: Darrick J. Wong <[email protected]>
Reintroduce to xrep_reap_extents the ability to reap extents from any AG. We dropped this before because it was buggy, but in the next patch we will gain the ability to reap old bmap btrees, which can have blocks in any AG. To do this, we require that sc->sa is uninitialized, so that we can use it to hold all the per-AG context for a given extent.
--- fs/xfs/scrub/bitmap.h | 28 +++++++++++ fs/xfs/scrub/reap.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++-- fs/xfs/scrub/reap.h | 2 + fs/xfs/scrub/repair.h | 1 4 files changed, 147 insertions(+), 4 deletions(-)
fs/xfs/scrub/bitmap.h +28 -0
@@ -105,4 +105,32 @@ int xagb_bitmap_set_btblocks(struct xagb_bitmap *bitmap,int xagb_bitmap_set_btcur_path (struct xagb_bitmap *bitmap,struct xfs_btree_cur *cur); +/* Bitmaps, but for type-checked for xfs_fsblock_t */ + +struct xfsb_bitmap { +struct xbitmap fsbitmap; +}; + +static inline void xfsb_bitmap_init (struct xfsb_bitmap *bitmap) +{ +xbitmap_init (&bitmap->fsbitmap); +} + +static inline void xfsb_bitmap_destroy (struct xfsb_bitmap *bitmap) +{ +xbitmap_destroy (&bitmap->fsbitmap); +} + +static inline int xfsb_bitmap_set (struct xfsb_bitmap *bitmap, +xfs_fsblock_t start,xfs_filblks_t len) +{ +return xbitmap_set (&bitmap->fsbitmap, start, len); +} + +static inline int xfsb_bitmap_walk (struct xfsb_bitmap *bitmap, +xbitmap_walk_fn fn,void *priv) +{ +return xbitmap_walk (&bitmap->fsbitmap, fn, priv); +} +#endif /* __XFS_SCRUB_BITMAP_H__ */
fs/xfs/scrub/reap.c +116 -4
129 lines not on this page · raw message
fs/xfs/scrub/reap.h +2 -0
@@ -8,5 +8,7 @@int xrep_reap_agblocks (struct xfs_scrub *sc,struct xagb_bitmap *bitmap,const struct xfs_owner_info *oinfo,enum xfs_ag_resv_type type); +int xrep_reap_fsblocks (struct xfs_scrub *sc,struct xfsb_bitmap *bitmap, +const struct xfs_owner_info *oinfo);#endif /* __XFS_SCRUB_REAP_H__ */
fs/xfs/scrub/repair.h +1 -0
@@ -38,6 +38,7 @@ xrep_trans_commit(struct xbitmap ;struct xagb_bitmap ; +struct xfsb_bitmap ;int xrep_fix_freelist (struct xfs_scrub *sc,bool can_shrink);
PATCH 2/5 xfs: repair inode fork block mapping data structures
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Use the reverse-mapping btree information to rebuild an inode block map. Update the btree bulk loading code as necessary to support inode rooted btrees and fix some bitrot problems.
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_bmap_btree.c | 112 +++++ fs/xfs/libxfs/xfs_bmap_btree.h | 5 fs/xfs/libxfs/xfs_btree_staging.c | 11 - fs/xfs/libxfs/xfs_btree_staging.h | 2 fs/xfs/libxfs/xfs_iext_tree.c | 23 + fs/xfs/libxfs/xfs_inode_fork.c | 1 fs/xfs/libxfs/xfs_inode_fork.h | 3 fs/xfs/scrub/bmap.c | 18 + fs/xfs/scrub/bmap_repair.c | 776 +++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/repair.c | 28 + fs/xfs/scrub/repair.h | 6 fs/xfs/scrub/scrub.c | 4 fs/xfs/scrub/trace.h | 34 ++ fs/xfs/xfs_trans.c | 95 +++++ fs/xfs/xfs_trans.h | 4 16 files changed, 1096 insertions(+), 27 deletions(-) create mode 100644 fs/xfs/scrub/bmap_repair.c
fs/xfs/Makefile +1 -0
@@ -180,6 +180,7 @@ ifeq ($(CONFIG_XFS_ONLINE_REPAIR),y) xfs-y += $(addprefix scrub/, \ agheader_repair.o \ alloc_repair.o \ + bmap_repair.o \ ialloc_repair.o \ inode_repair.o \ newbt.o \
fs/xfs/libxfs/xfs_bmap_btree.c +98 -14
160 lines not on this page · raw message
fs/xfs/libxfs/xfs_bmap_btree.h +5 -0
@@ -11,6 +11,7 @@ struct xfs_btree_block;struct xfs_mount ;struct xfs_inode ;struct xfs_trans ; +struct xbtree_ifakeroot ;/* * Btree block header size depends on a superblock flag.
@@ -106,6 +107,10 @@ extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,extern struct xfs_btree_cur *xfs_bmbt_init_cursor (struct xfs_mount *,struct xfs_trans *,struct xfs_inode *,int ); +struct xfs_btree_cur *xfs_bmbt_stage_cursor (struct xfs_mount *mp, +struct xfs_inode *ip,struct xbtree_ifakeroot *ifake); +void xfs_bmbt_commit_staged_btree (struct xfs_btree_cur *cur, +struct xfs_trans *tp,int whichfork);extern unsigned long long xfs_bmbt_calc_size (struct xfs_mount *mp,unsigned long long len);
fs/xfs/libxfs/xfs_btree_staging.c +9 -2
@@ -399,7 +399,7 @@ xfs_btree_bload_prep_block(ASSERT (*bpp ==NULL );/* Allocate a new incore btree root block. */ - new_size = bbl->iroot_size (cur, nr_this_block, priv); + new_size = bbl->iroot_size (cur, level, nr_this_block, priv); ifp->if_broot =kmem_zalloc (new_size,0 ); ifp->if_broot_bytes = (int )new_size;
@@ -585,7 +585,14 @@ xfs_btree_bload_level_geometry(unsigned int desired_npb;unsigned int maxnr; - maxnr = cur->bc_ops->get_maxrecs (cur, level); +/* +* Compute the absolute maximum number of records that we can store in +* the ondisk block or inode root. +*/ +if (cur->bc_ops->get_dmaxrecs) + maxnr = cur->bc_ops->get_dmaxrecs (cur, level); +else + maxnr = cur->bc_ops->get_maxrecs (cur, level);/* * Compute the number of blocks we need to fill each block with the
fs/xfs/libxfs/xfs_btree_staging.h +1 -1
@@ -56,7 +56,7 @@ typedef int (*xfs_btree_bload_get_records_fn)(struct xfs_btree_cur *cur,typedef int (*xfs_btree_bload_claim_block_fn )(struct xfs_btree_cur *cur,union xfs_btree_ptr *ptr,void *priv);typedef size_t (*xfs_btree_bload_iroot_size_fn )(struct xfs_btree_cur *cur, -unsigned int nr_this_level,void *priv); +unsigned int level,unsigned int nr_this_level,void *priv);struct xfs_btree_bload {/*
fs/xfs/libxfs/xfs_iext_tree.c +16 -7
@@ -622,13 +622,11 @@ static inline void xfs_iext_inc_seq(struct xfs_ifork *ifp) }void -xfs_iext_insert ( -struct xfs_inode *ip, +xfs_iext_insert_raw ( +struct xfs_ifork *ifp,struct xfs_iext_cursor *cur, -struct xfs_bmbt_irec *irec, -int state) +struct xfs_bmbt_irec *irec) { -struct xfs_ifork *ifp =xfs_iext_state_to_fork (ip, state);xfs_fileoff_t offset = irec->br_startoff;struct xfs_iext_leaf *new =NULL ;int nr_entries, i;
@@ -662,12 +660,23 @@ xfs_iext_insert(xfs_iext_set (cur_rec (cur), irec); ifp->if_bytes +=sizeof (struct xfs_iext_rec ); -trace_xfs_iext_insert (ip, cur, state, _RET_IP_); -if (new)xfs_iext_insert_node (ifp,xfs_iext_leaf_key (new,0 ), new,2 ); } +void +xfs_iext_insert ( +struct xfs_inode *ip, +struct xfs_iext_cursor *cur, +struct xfs_bmbt_irec *irec, +int state) +{ +struct xfs_ifork *ifp =xfs_iext_state_to_fork (ip, state); + +xfs_iext_insert_raw (ifp, cur, irec); +trace_xfs_iext_insert (ip, cur, state, _RET_IP_); +} +static struct xfs_iext_node * xfs_iext_rebalance_node( struct xfs_iext_node *parent,
fs/xfs/libxfs/xfs_inode_fork.c +1 -0
@@ -520,6 +520,7 @@ xfs_idata_realloc( ifp->if_bytes = new_size; } +/* Free all memory and reset a fork back to its initial state. */ void xfs_idestroy_fork (struct xfs_ifork *ifp)
fs/xfs/libxfs/xfs_inode_fork.h +3 -0
@@ -180,6 +180,9 @@ void xfs_init_local_fork(struct xfs_inode *ip, int whichfork, const void *data, int64_t size);xfs_extnum_t xfs_iext_count (struct xfs_ifork *ifp); +void xfs_iext_insert_raw (struct xfs_ifork *ifp, +struct xfs_iext_cursor *cur, +struct xfs_bmbt_irec *irec);void xfs_iext_insert (struct xfs_inode *,struct xfs_iext_cursor *cur,struct xfs_bmbt_irec *,int ); void xfs_iext_remove(struct xfs_inode *, struct xfs_iext_cursor *,
fs/xfs/scrub/bmap.c +18 -0
@@ -48,9 +48,18 @@ xchk_setup_inode_bmap(if (S_ISREG (VFS_I (sc->ip)->i_mode) && sc->sm->sm_type !=XFS_SCRUB_TYPE_BMBTA ) {struct address_space *mapping =VFS_I (sc->ip)->i_mapping; +bool is_repair =xchk_could_repair (sc);xchk_ilock (sc,XFS_MMAPLOCK_EXCL ); +/* Break all our leases, we're going to mess with things. */ +if (is_repair) { + error =xfs_break_layouts (VFS_I (sc->ip), + &sc->ilock_flags,BREAK_WRITE ); +if (error) + goto out; + } +inode_dio_wait (VFS_I (sc->ip));/*
@@ -71,6 +80,15 @@ xchk_setup_inode_bmap( error =filemap_fdatawait_keep_errors (mapping);if (error && (error != -ENOSPC && error != -EIO )) goto out; + +/* Drop the page cache if we're repairing block mappings. */ +if (is_repair) { + error =invalidate_inode_pages2 ( +VFS_I (sc->ip)->i_mapping); +if (error) + goto out; + } + }/* Got the inode, lock it and we're ready to go. */
fs/xfs/scrub/bmap_repair.c new file +776 -0
776 lines not on this page · raw message
fs/xfs/scrub/repair.c +28 -0
@@ -871,6 +871,34 @@ xrep_reinit_pagi(return 0 ; } +/* +* Given an active reference to a perag structure, load AG headers and cursors. +* This should only be called to scan an AG while repairing file-based metadata. +*/ +int +xrep_ag_init ( +struct xfs_scrub *sc, +struct xfs_perag *pag, +struct xchk_ag *sa) +{ +int error; + +ASSERT (!sa->pag); + + error =xfs_ialloc_read_agi (pag, sc->tp, &sa->agi_bp); +if (error) +return error; + + error =xfs_alloc_read_agf (pag, sc->tp,0 , &sa->agf_bp); +if (error) +return error; + +/* Grab our own passive reference from the caller's ref. */ + sa->pag =xfs_perag_hold (pag); +xrep_ag_btcur_init (sc, sa); +return 0 ; +} +/* Reinitialize the per-AG block reservation for the AG we just fixed. */ int xrep_reset_perag_resv(
fs/xfs/scrub/repair.h +6 -0
@@ -79,6 +79,8 @@ struct xfs_imap;int xrep_setup_inode (struct xfs_scrub *sc,struct xfs_imap *imap);void xrep_ag_btcur_init (struct xfs_scrub *sc,struct xchk_ag *sa); +int xrep_ag_init (struct xfs_scrub *sc,struct xfs_perag *pag, +struct xchk_ag *sa);/* Metadata revalidators */
@@ -96,6 +98,8 @@ int xrep_allocbt(struct xfs_scrub *sc);int xrep_iallocbt (struct xfs_scrub *sc);int xrep_refcountbt (struct xfs_scrub *sc);int xrep_inode (struct xfs_scrub *sc); +int xrep_bmap_data (struct xfs_scrub *sc); +int xrep_bmap_attr (struct xfs_scrub *sc);int xrep_reinit_pagf (struct xfs_scrub *sc);int xrep_reinit_pagi (struct xfs_scrub *sc);
@@ -154,6 +158,8 @@ xrep_setup_nothing(#define xrep_iallocbt xrep_notsupported#define xrep_refcountbt xrep_notsupported#define xrep_inode xrep_notsupported +#define xrep_bmap_data xrep_notsupported +#define xrep_bmap_attr xrep_notsupported#endif /* CONFIG_XFS_ONLINE_REPAIR */
fs/xfs/scrub/scrub.c +2 -2
@@ -287,13 +287,13 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .type = ST_INODE, .setup = xchk_setup_inode_bmap, .scrub = xchk_bmap_data, - .repair = xrep_notsupported, + .repair = xrep_bmap_data, }, [XFS_SCRUB_TYPE_BMBTA] = { /* inode attr fork */ .type = ST_INODE, .setup = xchk_setup_inode_bmap, .scrub = xchk_bmap_attr, - .repair = xrep_notsupported, + .repair = xrep_bmap_attr, }, [XFS_SCRUB_TYPE_BMBTC] = { /* inode CoW fork */ .type = ST_INODE,
fs/xfs/scrub/trace.h +33 -1
@@ -1128,7 +1128,7 @@ DEFINE_EVENT(xrep_rmap_class, name, \ TP_ARGS(mp, agno, agbno, len, owner, offset, flags))DEFINE_REPAIR_RMAP_EVENT (xrep_ibt_walk_rmap);DEFINE_REPAIR_RMAP_EVENT (xrep_rmap_extent_fn); -DEFINE_REPAIR_RMAP_EVENT (xrep_bmap_extent_fn); +DEFINE_REPAIR_RMAP_EVENT (xrep_bmap_walk_rmap); TRACE_EVENT(xrep_abt_found, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno,
@@ -1213,6 +1213,38 @@ TRACE_EVENT(xrep_refc_found, __entry->refcount) ) +TRACE_EVENT (xrep_bmap_found, + TP_PROTO(struct xfs_inode *ip, int whichfork, + struct xfs_bmbt_irec *irec), +TP_ARGS (ip, whichfork, irec), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(xfs_ino_t, ino) + __field(int, whichfork) + __field(xfs_fileoff_t, lblk) + __field(xfs_filblks_t, len) + __field(xfs_fsblock_t, pblk) +__field (int, state) + ), +TP_fast_assign ( + __entry->dev = VFS_I(ip)->i_sb->s_dev; + __entry->ino = ip->i_ino; + __entry->whichfork = whichfork; + __entry->lblk = irec->br_startoff; + __entry->len = irec->br_blockcount; + __entry->pblk = irec->br_startblock; + __entry->state = irec->br_state; + ), +TP_printk ("dev %d:%d ino 0x%llx whichfork %s fileoff 0x%llx fsbcount 0x%llx startblock 0x%llx state %d" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->ino, +__print_symbolic (__entry->whichfork,XFS_WHICHFORK_STRINGS ), + __entry->lblk, + __entry->len, + __entry->pblk, + __entry->state) +); + TRACE_EVENT(xrep_findroot_block, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, xfs_agblock_t agbno, uint32_t magic, uint16_t level),
fs/xfs/xfs_trans.c +95 -0
107 lines not on this page · raw message
fs/xfs/xfs_trans.h +4 -0
@@ -168,6 +168,8 @@ typedef struct xfs_trans {int xfs_trans_alloc (struct xfs_mount *mp,struct xfs_trans_res *resp,uint blocks,uint rtextents,uint flags,struct xfs_trans **tpp); +int xfs_trans_reserve_more (struct xfs_trans *tp, +unsigned int blocks,unsigned int rtextents);int xfs_trans_alloc_empty (struct xfs_mount *mp,struct xfs_trans **tpp);void xfs_trans_mod_sb (xfs_trans_t *,uint ,int64_t );
@@ -260,6 +262,8 @@ struct xfs_dquot;int xfs_trans_alloc_inode (struct xfs_inode *ip,struct xfs_trans_res *resv,unsigned int dblocks,unsigned int rblocks,bool force,struct xfs_trans **tpp); +int xfs_trans_reserve_more_inode (struct xfs_trans *tp,struct xfs_inode *ip, +unsigned int dblocks,unsigned int rblocks,bool force_quota); int xfs_trans_alloc_icreate(struct xfs_mount *mp, struct xfs_trans_res *resv, struct xfs_dquot *udqp, struct xfs_dquot *gdqp, struct xfs_dquot *pdqp, unsigned int dblocks,
PATCH 3/5 xfs: refactor repair forcing tests into a repair.c helper
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
There are a couple of conditions that userspace can set to force repairs of metadata. These really belong in the repair code and not open-coded into the check code, so refactor them into a helper.
--- fs/xfs/scrub/repair.c | 22 ++++++++++++++++++++++ fs/xfs/scrub/repair.h | 2 ++ fs/xfs/scrub/scrub.c | 14 +------------- 3 files changed, 25 insertions(+), 13 deletions(-)
fs/xfs/scrub/repair.c +22 -0
@@ -27,6 +27,8 @@#include "xfs_quota.h" #include "xfs_qm.h" #include "xfs_defer.h" +#include "xfs_errortag.h" +#include "xfs_error.h" #include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/trace.h"
@@ -928,3 +930,23 @@ xrep_reset_perag_resv( out:return error; } + +/* Decide if we are going to call the repair function for a scrub type. */ +bool +xrep_will_attempt ( +struct xfs_scrub *sc) +{ +/* Userspace asked us to rebuild the structure regardless. */ +if (sc->sm->sm_flags &XFS_SCRUB_IFLAG_FORCE_REBUILD ) +return true; + +/* Let debug users force us into the repair routines. */ +if (XFS_TEST_ERROR (false, sc->mp,XFS_ERRTAG_FORCE_SCRUB_REPAIR )) +return true; + +/* Metadata is corrupt or failed cross-referencing. */ +if (xchk_needs_repair (sc->sm)) +return true; + +return false; +}
fs/xfs/scrub/repair.h +2 -0
@@ -18,6 +18,7 @@ static inline int xrep_notsupported(struct xfs_scrub *sc)/* Repair helpers */ int xrep_attempt (struct xfs_scrub *sc); +bool xrep_will_attempt (struct xfs_scrub *sc);void xrep_failure (struct xfs_mount *mp);int xrep_roll_ag_trans (struct xfs_scrub *sc);int xrep_roll_trans (struct xfs_scrub *sc);
@@ -107,6 +108,7 @@ int xrep_reinit_pagi(struct xfs_scrub *sc);#else #define xrep_ino_dqattach (sc) (0) +#define xrep_will_attempt (sc) (false)static inline int xrep_attempt(
fs/xfs/scrub/scrub.c +1 -13
@@ -14,8 +14,6 @@#include "xfs_inode.h" #include "xfs_quota.h" #include "xfs_qm.h" -#include "xfs_errortag.h" -#include "xfs_error.h" #include "xfs_scrub.h" #include "xfs_btree.h" #include "xfs_btree_staging.h"
@@ -543,21 +541,11 @@ xfs_scrub_metadata(xchk_update_health (sc);if (xchk_could_repair (sc)) { -bool needs_fix =xchk_needs_repair (sc->sm); - -/* Userspace asked us to rebuild the structure regardless. */ -if (sc->sm->sm_flags &XFS_SCRUB_IFLAG_FORCE_REBUILD ) - needs_fix = true; - -/* Let debug users force us into the repair routines. */ -if (XFS_TEST_ERROR (needs_fix, mp,XFS_ERRTAG_FORCE_SCRUB_REPAIR )) - needs_fix = true; -/* * If userspace asked for a repair but it wasn't necessary, * report that back to userspace. */ -if (!needs_fix) { +if (!xrep_will_attempt (sc)) { sc->sm->sm_flags |=XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED ; goto out_nofix; }
PATCH 4/5 xfs: create a ranged query function for refcount btrees
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Implement ranged queries for refcount records. The next patch will use this to scan refcount data.
--- fs/xfs/libxfs/xfs_refcount.c | 41 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_refcount.h | 10 ++++++++++ 2 files changed, 51 insertions(+)
fs/xfs/libxfs/xfs_refcount.c +41 -0
@@ -2029,6 +2029,47 @@ xfs_refcount_has_records(return xfs_btree_has_records (cur, &low, &high,NULL , outcome); } +struct xfs_refcount_query_range_info { +xfs_refcount_query_range_fn fn; +void *priv; +}; + +/* Format btree record and pass to our callback. */ +STATIC int +xfs_refcount_query_range_helper ( +struct xfs_btree_cur *cur, +const union xfs_btree_rec *rec, +void *priv) +{ +struct xfs_refcount_query_range_info *query = priv; +struct xfs_refcount_irec irec; +xfs_failaddr_t fa; + +xfs_refcount_btrec_to_irec (rec, &irec); + fa =xfs_refcount_check_irec (cur, &irec); +if (fa) +return xfs_refcount_complain_bad_rec (cur, fa, &irec); + +return query->fn (cur, &irec, query->priv); +} + +/* Find all refcount records between two keys. */ +int +xfs_refcount_query_range ( +struct xfs_btree_cur *cur, +const struct xfs_refcount_irec *low_rec, +const struct xfs_refcount_irec *high_rec, +xfs_refcount_query_range_fn fn, +void *priv) +{ +union xfs_btree_irec low_brec = { .rc = *low_rec }; +union xfs_btree_irec high_brec = { .rc = *high_rec }; +struct xfs_refcount_query_range_info query = { .priv = priv, .fn = fn }; + +return xfs_btree_query_range (cur, &low_brec, &high_brec, + xfs_refcount_query_range_helper, &query); +} +int __init xfs_refcount_intent_init_cache (void ) {
fs/xfs/libxfs/xfs_refcount.h +10 -0
@@ -129,4 +129,14 @@ extern struct kmem_cache *xfs_refcount_intent_cache;int __init xfs_refcount_intent_init_cache (void );void xfs_refcount_intent_destroy_cache (void ); +typedef int (*xfs_refcount_query_range_fn )( +struct xfs_btree_cur *cur, +const struct xfs_refcount_irec *rec, +void *priv); + +int xfs_refcount_query_range (struct xfs_btree_cur *cur, +const struct xfs_refcount_irec *low_rec, +const struct xfs_refcount_irec *high_rec, +xfs_refcount_query_range_fn fn,void *priv); +#endif /* __XFS_REFCOUNT_H__ */
PATCH 5/5 xfs: repair problems in CoW forks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Try to repair errors that we see in file CoW forks so that we don't do stupid things like remap garbage into a file. There's not a lot we can do with the COW fork -- the ondisk metadata record only that the COW staging extents are owned by the refcount btree, which effectively means that we can't reconstruct this incore structure from scratch.
Actually, this is even worse -- we can't touch written extents, because those map space that are actively under writeback, and there's not much to do with delalloc reservations. Hence we can only detect crosslinked unwritten extents and fix them by punching out the problematic parts and replacing them with delalloc extents.
--- fs/xfs/Makefile | 1 fs/xfs/scrub/cow_repair.c | 609 +++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/reap.c | 25 ++ fs/xfs/scrub/repair.h | 2 fs/xfs/scrub/scrub.c | 2 fs/xfs/scrub/trace.h | 84 ++++++ 6 files changed, 722 insertions(+), 1 deletion(-) create mode 100644 fs/xfs/scrub/cow_repair.c
fs/xfs/Makefile +1 -0
@@ -181,6 +181,7 @@ xfs-y += $(addprefix scrub/, \ agheader_repair.o \ alloc_repair.o \ bmap_repair.o \ + cow_repair.o \ ialloc_repair.o \ inode_repair.o \ newbt.o \
fs/xfs/scrub/cow_repair.c new file +609 -0
609 lines not on this page · raw message
fs/xfs/scrub/reap.c +25 -0
@@ -20,6 +20,7 @@#include "xfs_ialloc_btree.h" #include "xfs_rmap.h" #include "xfs_rmap_btree.h" +#include "xfs_refcount.h" #include "xfs_refcount_btree.h" #include "xfs_extent_busy.h" #include "xfs_ag.h"
@@ -313,6 +314,14 @@ xreap_agextent(trace_xreap_dispose_unmap_extent (sc->sa.pag, agbno, *aglenp); rs->force_roll = true; +if (rs->oinfo == &XFS_RMAP_OINFO_COW ) { +/* +* If we're unmapping CoW staging extents, remove the +* records from the refcountbt as well. +*/ +xfs_refcount_free_cow_extent (sc->tp, fsbno, *aglenp); +return 0 ; + }return xfs_rmap_free (sc->tp, sc->sa.agf_bp, sc->sa.pag, agbno, *aglenp, rs->oinfo); }
@@ -331,6 +340,22 @@ xreap_agextent(return 0 ; } +/* +* If we're getting rid of CoW staging extents, use deferred work items +* to remove the refcountbt records (which removes the rmap records) +* and free the extent. We're not worried about the system going down +* here because log recovery walks the refcount btree to clean out the +* CoW staging extents. +*/ +if (rs->oinfo == &XFS_RMAP_OINFO_COW ) { +ASSERT (rs->resv ==XFS_AG_RESV_NONE ); + + rs->force_roll = true; +xfs_refcount_free_cow_extent (sc->tp, fsbno, *aglenp); +__xfs_free_extent_later (sc->tp, fsbno, *aglenp,NULL , true); +return 0 ; + } +switch (rs->resv) {case XFS_AG_RESV_AGFL :ASSERT (*aglenp ==1 );
fs/xfs/scrub/repair.h +2 -0
@@ -101,6 +101,7 @@ int xrep_refcountbt(struct xfs_scrub *sc);int xrep_inode (struct xfs_scrub *sc);int xrep_bmap_data (struct xfs_scrub *sc);int xrep_bmap_attr (struct xfs_scrub *sc); +int xrep_bmap_cow (struct xfs_scrub *sc);int xrep_reinit_pagf (struct xfs_scrub *sc);int xrep_reinit_pagi (struct xfs_scrub *sc);
@@ -162,6 +163,7 @@ xrep_setup_nothing(#define xrep_inode xrep_notsupported#define xrep_bmap_data xrep_notsupported#define xrep_bmap_attr xrep_notsupported +#define xrep_bmap_cow xrep_notsupported#endif /* CONFIG_XFS_ONLINE_REPAIR */
fs/xfs/scrub/scrub.c +1 -1
@@ -297,7 +297,7 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .type = ST_INODE, .setup = xchk_setup_inode_bmap, .scrub = xchk_bmap_cow, - .repair = xrep_notsupported, + .repair = xrep_bmap_cow, }, [XFS_SCRUB_TYPE_DIR] = { /* directory */ .type = ST_INODE,
fs/xfs/scrub/trace.h +84 -0
90 lines not on this page · raw message
cover xfs: online repair of quota and rt metadata files
In reply to Darrick J. WongHi all,
XFS stores quota records and free space bitmap information in files. Add the necessary infrastructure to enable repairing metadata inodes and their forks, and then make it so that we can repair the file metadata for the rtbitmap. Repairing the bitmap contents (and the summary file) is left for subsequent patchsets.
We also add the ability to repair file metadata the quota files. As part of these repairs, we also reinitialize the ondisk dquot records as necessary to get the incore dquots working. We can also correct obviously bad dquot record attributes, but we leave checking the resource usage counts for the next patchsets.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=repair-quota
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=repair-quota
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=repair-quota
--- fs/xfs/Makefile | 8 + fs/xfs/libxfs/xfs_bmap.c | 39 ++++ fs/xfs/libxfs/xfs_bmap.h | 2 fs/xfs/scrub/bmap_repair.c | 17 +- fs/xfs/scrub/quota.c | 11 + fs/xfs/scrub/quota.h | 11 + fs/xfs/scrub/quota_repair.c | 405 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/repair.c | 151 +++++++++++++++ fs/xfs/scrub/repair.h | 22 ++ fs/xfs/scrub/rtbitmap.c | 10 + fs/xfs/scrub/rtbitmap_repair.c | 56 ++++++ fs/xfs/scrub/scrub.c | 8 - fs/xfs/scrub/trace.c | 1 fs/xfs/scrub/trace.h | 28 +++ fs/xfs/xfs_inode.c | 24 -- 15 files changed, 761 insertions(+), 32 deletions(-) create mode 100644 fs/xfs/scrub/quota.h create mode 100644 fs/xfs/scrub/quota_repair.c create mode 100644 fs/xfs/scrub/rtbitmap_repair.c
PATCH 1/4 xfs: repair the inode core and forks of a metadata inode
From: Darrick J. Wong <[email protected]>
Add a helper function to repair the core and forks of a metadata inode, so that we can get move onto the task of repairing higher level metadata that lives in an inode.
--- fs/xfs/scrub/bmap_repair.c | 17 ++++- fs/xfs/scrub/repair.c | 151 ++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/repair.h | 2 + 3 files changed, 166 insertions(+), 4 deletions(-)
fs/xfs/scrub/bmap_repair.c +13 -4
@@ -74,6 +74,9 @@ struct xrep_bmap {/* Which fork are we fixing? */ int whichfork; + +/* Do we allow unwritten extents? */ +bool allow_unwritten; };/* Remember this reverse-mapping as a series of bmap records. */
@@ -213,6 +216,10 @@ xrep_bmap_walk_rmap( !(rec->rm_flags & XFS_RMAP_ATTR_FORK))return 0 ; +/* Reject unwritten extents if we don't allow those. */ +if ((rec->rm_flags &XFS_RMAP_UNWRITTEN ) && !rb->allow_unwritten) +return -EFSCORRUPTED ; + fsbno =XFS_AGB_TO_FSB (mp, cur->bc_ag.pag->pag_agno, rec->rm_startblock);
@@ -705,10 +712,11 @@ xrep_bmap_check_inputs( }/* Repair an inode fork. */ -STATIC int +int xrep_bmap (struct xfs_scrub *sc, -int whichfork) +int whichfork, +bool allow_unwritten) {struct xrep_bmap *rb;unsigned int max_bmbt_recs;
@@ -726,6 +734,7 @@ xrep_bmap(return -ENOMEM ; rb->sc = sc; rb->whichfork = whichfork; + rb->allow_unwritten = allow_unwritten;/* Set up enough storage to handle the max records for this fork. */ large_extcount =xfs_has_large_extent_counts (sc->mp);
@@ -764,7 +773,7 @@ intxrep_bmap_data ( struct xfs_scrub *sc) { -return xrep_bmap (sc,XFS_DATA_FORK ); +return xrep_bmap (sc,XFS_DATA_FORK , true); }/* Repair an inode's attr fork. */
@@ -772,5 +781,5 @@ intxrep_bmap_attr ( struct xfs_scrub *sc) { -return xrep_bmap (sc,XFS_ATTR_FORK ); +return xrep_bmap (sc,XFS_ATTR_FORK , false); }
fs/xfs/scrub/repair.c +151 -0
160 lines not on this page · raw message
fs/xfs/scrub/repair.h +2 -0
@@ -72,6 +72,8 @@ int xrep_ino_dqattach(struct xfs_scrub *sc);int xrep_ino_ensure_extent_count (struct xfs_scrub *sc,int whichfork,xfs_extnum_t nextents);int xrep_reset_perag_resv (struct xfs_scrub *sc); +int xrep_bmap (struct xfs_scrub *sc,int whichfork,bool allow_unwritten); +int xrep_metadata_inode_forks (struct xfs_scrub *sc);/* Repair setup functions */ int xrep_setup_ag_allocbt (struct xfs_scrub *sc);
PATCH 2/4 xfs: create a new inode fork block unmap helper
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a new helper to unmap blocks from an inode's fork.
--- fs/xfs/libxfs/xfs_bmap.c | 39 +++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_bmap.h | 2 ++ fs/xfs/xfs_inode.c | 24 ++++-------------------- 3 files changed, 45 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +39 -0
@@ -6240,3 +6240,42 @@ xfs_bmap_validate_extent(return xfs_bmap_validate_extent_raw (ip->i_mount,XFS_IS_REALTIME_INODE (ip), whichfork, irec); } + +/* +* Used in xfs_itruncate_extents(). This is the maximum number of extents +* freed from a file in a single transaction. +*/ +#define XFS_ITRUNC_MAX_EXTENTS 2 + +/* +* Unmap every extent in part of an inode's fork. We don't do any higher level +* invalidation work at all. +*/ +int +xfs_bunmapi_range ( +struct xfs_trans **tpp, +struct xfs_inode *ip, +uint32_t flags, +xfs_fileoff_t startoff, +xfs_fileoff_t endoff) +{ +xfs_filblks_t unmap_len = endoff - startoff +1 ; +int error =0 ; + +ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); + +while (unmap_len >0 ) { +ASSERT ((*tpp)->t_highest_agno ==NULLAGNUMBER ); + error =__xfs_bunmapi (*tpp, ip, startoff, &unmap_len, flags, +XFS_ITRUNC_MAX_EXTENTS ); +if (error) + goto out; + +/* free the just unmapped extents */ + error =xfs_defer_finish (tpp); +if (error) + goto out; + } +out: +return error; +}
fs/xfs/libxfs/xfs_bmap.h +2 -0
@@ -273,6 +273,8 @@ int xfs_bmap_complain_bad_rec(struct xfs_inode *ip, int whichfork,int xfs_bmapi_remap (struct xfs_trans *tp,struct xfs_inode *ip,xfs_fileoff_t bno,xfs_filblks_t len,xfs_fsblock_t startblock,uint32_t flags); +int xfs_bunmapi_range (struct xfs_trans **tpp,struct xfs_inode *ip, +uint32_t flags,xfs_fileoff_t startoff,xfs_fileoff_t endoff);extern struct kmem_cache *xfs_bmap_intent_cache;
fs/xfs/xfs_inode.c +4 -20
@@ -40,12 +40,6 @@struct kmem_cache *xfs_inode_cache; -/* -* Used in xfs_itruncate_extents(). This is the maximum number of extents -* freed from a file in a single transaction. -*/ -#define XFS_ITRUNC_MAX_EXTENTS 2 - STATIC int xfs_iunlink(struct xfs_trans *, struct xfs_inode *); STATIC int xfs_iunlink_remove(struct xfs_trans *tp, struct xfs_perag *pag,struct xfs_inode *);
@@ -1333,7 +1327,6 @@ xfs_itruncate_extents_flags(struct xfs_mount *mp = ip->i_mount;struct xfs_trans *tp = *tpp;xfs_fileoff_t first_unmap_block; -xfs_filblks_t unmap_len;int error =0 ;ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL ));
@@ -1365,19 +1358,10 @@ xfs_itruncate_extents_flags(return 0 ; } - unmap_len =XFS_MAX_FILEOFF - first_unmap_block +1 ; -while (unmap_len >0 ) { -ASSERT (tp->t_highest_agno ==NULLAGNUMBER ); - error =__xfs_bunmapi (tp, ip, first_unmap_block, &unmap_len, - flags,XFS_ITRUNC_MAX_EXTENTS ); -if (error) - goto out; - -/* free the just unmapped extents */ - error =xfs_defer_finish (&tp); -if (error) - goto out; - } + error =xfs_bunmapi_range (&tp, ip, flags, first_unmap_block, +XFS_MAX_FILEOFF ); +if (error) + goto out;if (whichfork ==XFS_DATA_FORK ) {/* Remove all pending CoW reservations. */
PATCH 3/4 xfs: online repair of realtime bitmaps
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Rebuild the realtime bitmap from the realtime rmap btree.
--- fs/xfs/Makefile | 4 +++ fs/xfs/scrub/repair.h | 13 +++++++++ fs/xfs/scrub/rtbitmap.c | 10 ++++++- fs/xfs/scrub/rtbitmap_repair.c | 56 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/scrub.c | 2 + 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 fs/xfs/scrub/rtbitmap_repair.c
fs/xfs/Makefile +4 -0
@@ -189,5 +189,9 @@ xfs-y += $(addprefix scrub/, \ refcount_repair.o \ repair.o \ ) + +xfs-$(CONFIG_XFS_RT) += $(addprefix scrub/, \ + rtbitmap_repair.o \ + ) endif endif
fs/xfs/scrub/repair.h +13 -0
@@ -80,6 +80,7 @@ int xrep_setup_ag_allocbt(struct xfs_scrub *sc);struct xfs_imap ;int xrep_setup_inode (struct xfs_scrub *sc,struct xfs_imap *imap); +int xrep_setup_rtbitmap (struct xfs_scrub *sc,unsigned int *resblks);void xrep_ag_btcur_init (struct xfs_scrub *sc,struct xchk_ag *sa); int xrep_ag_init(struct xfs_scrub *sc, struct xfs_perag *pag,
@@ -105,6 +106,12 @@ int xrep_bmap_data(struct xfs_scrub *sc);int xrep_bmap_attr (struct xfs_scrub *sc);int xrep_bmap_cow (struct xfs_scrub *sc); +#ifdef CONFIG_XFS_RT +int xrep_rtbitmap (struct xfs_scrub *sc); +#else +# define xrep_rtbitmap xrep_notsupported +#endif /* CONFIG_XFS_RT */ +int xrep_reinit_pagf (struct xfs_scrub *sc);int xrep_reinit_pagi (struct xfs_scrub *sc);
@@ -151,6 +158,11 @@ xrep_setup_nothing(#define xrep_setup_inode (sc, imap) ((void)0) +static inline int xrep_setup_rtbitmap (struct xfs_scrub *sc,unsigned int *x) +{ +return 0 ; +} +#define xrep_revalidate_allocbt (NULL)#define xrep_revalidate_iallocbt (NULL)
@@ -166,6 +178,7 @@ xrep_setup_nothing(#define xrep_bmap_data xrep_notsupported#define xrep_bmap_attr xrep_notsupported#define xrep_bmap_cow xrep_notsupported +#define xrep_rtbitmap xrep_notsupported#endif /* CONFIG_XFS_ONLINE_REPAIR */
fs/xfs/scrub/rtbitmap.c +9 -1
@@ -16,15 +16,23 @@#include "xfs_bmap.h" #include "scrub/scrub.h" #include "scrub/common.h" +#include "scrub/repair.h" /* Set us up with the realtime metadata locked. */ int xchk_setup_rtbitmap (struct xfs_scrub *sc) { +unsigned int resblks =0 ;int error; - error =xchk_trans_alloc (sc,0 ); +if (xchk_could_repair (sc)) { + error =xrep_setup_rtbitmap (sc, &resblks); +if (error) +return error; + } + + error =xchk_trans_alloc (sc, resblks);if (error)return error;
fs/xfs/scrub/rtbitmap_repair.c new file +56 -0
56 lines not on this page · raw message
fs/xfs/scrub/scrub.c +1 -1
@@ -328,7 +328,7 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .setup = xchk_setup_rtbitmap, .scrub = xchk_rtbitmap, .has = xfs_has_realtime, - .repair = xrep_notsupported, + .repair = xrep_rtbitmap, }, [XFS_SCRUB_TYPE_RTSUM] = { /* realtime summary */ .type = ST_FS,
PATCH 4/4 xfs: repair quotas
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Fix anything that causes the quota verifiers to fail.
--- fs/xfs/Makefile | 4 fs/xfs/scrub/quota.c | 11 + fs/xfs/scrub/quota.h | 11 + fs/xfs/scrub/quota_repair.c | 405 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/repair.h | 7 + fs/xfs/scrub/scrub.c | 6 - fs/xfs/scrub/trace.c | 1 fs/xfs/scrub/trace.h | 28 +++ 8 files changed, 467 insertions(+), 6 deletions(-) create mode 100644 fs/xfs/scrub/quota.h create mode 100644 fs/xfs/scrub/quota_repair.c
fs/xfs/Makefile +4 -0
@@ -193,5 +193,9 @@ xfs-y += $(addprefix scrub/, \ xfs-$(CONFIG_XFS_RT) += $(addprefix scrub/, \ rtbitmap_repair.o \ ) + +xfs-$(CONFIG_XFS_QUOTA) += $(addprefix scrub/, \ + quota_repair.o \ + ) endif endif
fs/xfs/scrub/quota.c +8 -3
@@ -17,9 +17,10 @@#include "xfs_bmap.h" #include "scrub/scrub.h" #include "scrub/common.h" +#include "scrub/quota.h" /* Convert a scrub type code to a DQ flag, or return 0 if error. */ -static inline xfs_dqtype_t +xfs_dqtype_t xchk_quota_to_dqtype (struct xfs_scrub *sc) {
@@ -226,7 +227,10 @@ xchk_quota( dqtype =xchk_quota_to_dqtype (sc); -/* Look for problem extents. */ +/* +* Look for problem extents. Leave the quota inode ILOCKd if we find +* any. +*/ error =xchk_quota_data_fork (sc);if (error) goto out;
@@ -239,10 +243,11 @@ xchk_quota(* functions. */ xchk_iunlock (sc, sc->ilock_flags); + +/* Now look for things that the quota verifiers won't complain about. */ sqi.sc = sc; sqi.last_id =0 ; error =xfs_qm_dqiterate (mp, dqtype, xchk_quota_item, &sqi); -xchk_ilock (sc,XFS_ILOCK_EXCL );if (error == -ECANCELED ) error =0 ; if (!xchk_fblock_process_error(sc, XFS_DATA_FORK,
fs/xfs/scrub/quota.h new file +11 -0
@@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2018-2023 Oracle. All Rights Reserved. +* Author: Darrick J. Wong <[email protected]> +*/ +#ifndef __XFS_SCRUB_QUOTA_H__ +#define __XFS_SCRUB_QUOTA_H__ + +xfs_dqtype_t xchk_quota_to_dqtype (struct xfs_scrub *sc); + +#endif /* __XFS_SCRUB_QUOTA_H__ */
fs/xfs/scrub/quota_repair.c new file +405 -0
405 lines not on this page · raw message
fs/xfs/scrub/repair.h +7 -0
@@ -112,6 +112,12 @@ int xrep_rtbitmap(struct xfs_scrub *sc);# define xrep_rtbitmap xrep_notsupported#endif /* CONFIG_XFS_RT */ +#ifdef CONFIG_XFS_QUOTA +int xrep_quota (struct xfs_scrub *sc); +#else +# define xrep_quota xrep_notsupported +#endif /* CONFIG_XFS_QUOTA */ +int xrep_reinit_pagf (struct xfs_scrub *sc);int xrep_reinit_pagi (struct xfs_scrub *sc);
@@ -179,6 +185,7 @@ static inline int xrep_setup_rtbitmap(struct xfs_scrub *sc, unsigned int *x)#define xrep_bmap_attr xrep_notsupported#define xrep_bmap_cow xrep_notsupported#define xrep_rtbitmap xrep_notsupported +#define xrep_quota xrep_notsupported#endif /* CONFIG_XFS_ONLINE_REPAIR */
fs/xfs/scrub/scrub.c +3 -3
@@ -341,19 +341,19 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .type = ST_FS, .setup = xchk_setup_quota, .scrub = xchk_quota, - .repair = xrep_notsupported, + .repair = xrep_quota, }, [XFS_SCRUB_TYPE_GQUOTA] = { /* group quota */ .type = ST_FS, .setup = xchk_setup_quota, .scrub = xchk_quota, - .repair = xrep_notsupported, + .repair = xrep_quota, }, [XFS_SCRUB_TYPE_PQUOTA] = { /* project quota */ .type = ST_FS, .setup = xchk_setup_quota, .scrub = xchk_quota, - .repair = xrep_notsupported, + .repair = xrep_quota, }, [XFS_SCRUB_TYPE_FSCOUNTERS] = { /* fs summary counters */ .type = ST_FS,
fs/xfs/scrub/trace.c +1 -0
@@ -13,6 +13,7 @@#include "xfs_inode.h" #include "xfs_btree.h" #include "xfs_ag.h" +#include "xfs_quota_defs.h" #include "scrub/scrub.h" #include "scrub/xfile.h" #include "scrub/xfarray.h"
fs/xfs/scrub/trace.h +28 -0
@@ -1636,6 +1636,34 @@ TRACE_EVENT(xrep_cow_free_staging, __entry->blockcount) ); +#ifdef CONFIG_XFS_QUOTA +DECLARE_EVENT_CLASS (xrep_dquot_class, + TP_PROTO(struct xfs_mount *mp, uint8_t type, uint32_t id), +TP_ARGS (mp, type, id), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(uint8_t, type) +__field (uint32_t, id) + ), +TP_fast_assign ( + __entry->dev = mp->m_super->s_dev; + __entry->id = id; + __entry->type = type; + ), +TP_printk ("dev %d:%d type %s id 0x%x" , +MAJOR (__entry->dev),MINOR (__entry->dev), +__print_flags (__entry->type,"|" ,XFS_DQTYPE_STRINGS ), + __entry->id) +); + +#define DEFINE_XREP_DQUOT_EVENT (name) \ +DEFINE_EVENT(xrep_dquot_class, name, \ + TP_PROTO(struct xfs_mount *mp, uint8_t type, uint32_t id), \ + TP_ARGS(mp, type, id)) +DEFINE_XREP_DQUOT_EVENT (xrep_dquot_item); +DEFINE_XREP_DQUOT_EVENT (xrep_disk_dquot); +#endif /* CONFIG_XFS_QUOTA */ +#endif /* IS_ENABLED(CONFIG_XFS_ONLINE_REPAIR) */ #endif /* _TRACE_XFS_SCRUB_TRACE_H */
cover xfs: live inode scans for online fsck
In reply to Darrick J. WongHi all,
The design document discusses the need for a specialized inode scan cursor to manage walking every file on a live filesystem to build replacement metadata objects while receiving updates about the files already scanned. This series adds two pieces of infrastructure -- the scan cursor, and live hooks to deliver information about updates going on in other parts of the filesystem.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=scrub-iscan
--- fs/xfs/Kconfig | 37 ++++ fs/xfs/Makefile | 6 + fs/xfs/scrub/iscan.c | 498 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/iscan.h | 63 ++++++ fs/xfs/scrub/trace.c | 1 fs/xfs/scrub/trace.h | 106 +++++++++++ fs/xfs/xfs_hooks.c | 94 +++++++++ fs/xfs/xfs_hooks.h | 72 +++++++ fs/xfs/xfs_iwalk.c | 13 - fs/xfs/xfs_linux.h | 1 10 files changed, 879 insertions(+), 12 deletions(-) create mode 100644 fs/xfs/scrub/iscan.c create mode 100644 fs/xfs/scrub/iscan.h create mode 100644 fs/xfs/xfs_hooks.c create mode 100644 fs/xfs/xfs_hooks.h
PATCH 1/4 xfs: speed up xfs_iwalk_adjust_start a little bit
From: Darrick J. Wong <[email protected]>
Replace the open-coded loop that recomputes freecount with a single call to a bit weight function.
--- fs/xfs/xfs_iwalk.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
fs/xfs/xfs_iwalk.c +2 -11
@@ -22,6 +22,7 @@#include "xfs_trans.h" #include "xfs_pwork.h" #include "xfs_ag.h" +#include "xfs_bit.h" /* * Walking Inodes in the Filesystem
@@ -131,21 +132,11 @@ xfs_iwalk_adjust_start( struct xfs_inobt_rec_incore *irec) /* btree record */ {int idx;/* index into inode chunk */ -int i; idx = agino - irec->ir_startino; -/* -* We got a right chunk with some left inodes allocated at it. Grab -* the chunk record. Mark all the uninteresting inodes free because -* they're before our start point. -*/ -for (i =0 ; i < idx; i++) { -if (XFS_INOBT_MASK (i) & ~irec->ir_free) - irec->ir_freecount++; - } - irec->ir_free |=xfs_inobt_maskn (0 , idx); + irec->ir_freecount =hweight64 (irec->ir_free); }/* Allocate memory for a walk. */
PATCH 2/4 xfs: implement live inode scan for scrub
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
This patch implements a live file scanner for online fsck functions that require the ability to walk a filesystem to gather metadata records and stay informed about metadata changes to files that have already been visited.
The iscan structure consists of two inode number cursors: one to track which inode we want to visit next, and a second one to track which inodes have already been visited. This second cursor is key to capturing live updates to files previously scanned while the main thread continues scanning -- any inode greater than this value hasn't been scanned and can go on its way; any other update must be incorporated into the collected data. It is critical for the scanning thraad to hold exclusive access on the inode until after marking the inode visited.
This new code is a separate patch from the patchsets adding callers for the sake of enabling the author to move patches around his tree with ease. The intended usage model for this code is roughly:
xchk_iscan_start(iscan, 0, 0);
while ((error = xchk_iscan_iter(sc, iscan, &ip)) == 1) {
xfs_ilock(ip, ...);
/* capture inode metadata */
xchk_iscan_mark_visited(iscan, ip);
xfs_iunlock(ip, ...);
xfs_irele(ip);
}
xchk_iscan_stop(iscan);
if (error)
return error;Hook functions for live updates can then do:
if (xchk_iscan_want_live_update(...)) /* update the captured inode metadata */
--- fs/xfs/Makefile | 5 - fs/xfs/scrub/iscan.c | 498 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/iscan.h | 63 ++++++ fs/xfs/scrub/trace.c | 1 fs/xfs/scrub/trace.h | 106 +++++++++++ 5 files changed, 672 insertions(+), 1 deletion(-) create mode 100644 fs/xfs/scrub/iscan.c create mode 100644 fs/xfs/scrub/iscan.h
fs/xfs/Makefile +4 -1
@@ -173,7 +173,10 @@ xfs-$(CONFIG_XFS_RT) += $(addprefix scrub/, \ rtsummary.o \ ) -xfs-$(CONFIG_XFS_QUOTA) += scrub/quota.o +xfs-$(CONFIG_XFS_QUOTA) += $(addprefix scrub/, \ + iscan.o \ + quota.o \ + ) # online repair ifeq ($(CONFIG_XFS_ONLINE_REPAIR),y)
fs/xfs/scrub/iscan.c new file +498 -0
498 lines not on this page · raw message
fs/xfs/scrub/iscan.h new file +63 -0
63 lines not on this page · raw message
fs/xfs/scrub/trace.c +1 -0
@@ -17,6 +17,7 @@#include "scrub/scrub.h" #include "scrub/xfile.h" #include "scrub/xfarray.h" +#include "scrub/iscan.h" /* Figure out which block the btree cursor was pointing to. */ static inline xfs_fsblock_t
fs/xfs/scrub/trace.h +106 -0
121 lines not on this page · raw message
PATCH 3/4 xfs: allow scrub to hook metadata updates in other writers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Certain types of filesystem metadata can only be checked by scanning every file in the entire filesystem. Specific examples of this include quota counts, file link counts, and reverse mappings of file extents. Directory and parent pointer reconstruction may also fall into this category. File scanning is much trickier than scanning AG metadata because we have to take inode locks in the same order as the rest of [VX]FS, we can't be holding buffer locks when we do that, and scanning the whole filesystem takes time.
Earlier versions of the online repair patchset relied heavily on fsfreeze as a means to quiesce the filesystem so that we could take locks in the proper order without worrying about concurrent updates from other writers. Reviewers of those patches opined that freezing the entire fs to check and repair something was not sufficiently better than unmounting to run fsck offline. I don't agree with that 100%, but the message was clear: find a way to repair things that minimizes the quiet period where nobody can write to the filesystem.
Generally, building btree indexes online can be split into two phases: a collection phase where we compute the records that will be put into the new btree; and a construction phase, where we construct the physical btree blocks and persist them. While it's simple to hold resource locks for the entirety of the two phases to ensure that the new index is consistent with the rest of the system, we don't need to hold resource locks during the collection phase if we have a means to receive live updates of other work going on elsewhere in the system.
The goal of this patch, then, is to enable online fsck to learn about metadata updates going on in other threads while it constructs a shadow copy of the metadata records to verify or correct the real metadata. To minimize the overhead when online fsck isn't running, we use srcu notifiers because they prioritize fast access to the notifier call chain (particularly when the chain is empty) at a cost to configuring notifiers. Online fsck should be relatively infrequent, so this is acceptable.
The intended usage model is fairly simple. Code that modifies a metadata structure of interest should declare a xfs_hook_chain structure in some well defined place, and call xfs_hook_call whenever an update happens. Online fsck code should define a struct notifier_block and use xfs_hook_add to attach the block to the chain, along with a function to be called. This function should synchronize with the fsck scanner to update whatever in-memory data the scanner is collecting. When finished, xfs_hook_del removes the notifier from the list and waits for them all to complete.
On the author's computer, calling an empty srcu notifier chain was observed to have an overhead averaging ~40ns with a maximum of 60ns. Adding a no-op notifier function increased the average to ~58ns and 66ns. When the quotacheck live update notifier is attached, the average increases to ~322ns with a max of 372ns to update scrub's in-memory observation data, assuming no lock contention.
With jump labels enabled, calls to empty srcu notifier chains are elided from the call sites when there are no hooks registered, which means that the overhead is 0.36ns when fsck is not running. For compilers that do not support jump labels (all major architectures do), the overhead of a no-op notifier call is less bad (on a many-cpu system) than the atomic counter ops, so we make the hook switch itself a nop.
Note: This new code is also split out as a separate patch from its initial user so that the author can move patches around his tree with ease.
--- fs/xfs/Kconfig | 6 +++++ fs/xfs/Makefile | 1 + fs/xfs/xfs_hooks.c | 53 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_hooks.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_linux.h | 1 + 5 files changed, 129 insertions(+) create mode 100644 fs/xfs/xfs_hooks.c create mode 100644 fs/xfs/xfs_hooks.h
fs/xfs/Kconfig +6 -0
@@ -124,11 +124,17 @@ config XFS_DRAIN_INTENTS bool select JUMP_LABEL if HAVE_ARCH_JUMP_LABEL +config XFS_LIVE_HOOKS + bool + select JUMP_LABEL if HAVE_ARCH_JUMP_LABEL + config XFS_ONLINE_SCRUB bool "XFS online metadata check support" default n depends on XFS_FS depends on TMPFS && SHMEM + depends on SRCU + select XFS_LIVE_HOOKS select XFS_DRAIN_INTENTS help If you say Y here you will be able to check metadata on a
fs/xfs/Makefile +1 -0
@@ -137,6 +137,7 @@ xfs-$(CONFIG_FS_DAX) += xfs_notify_failure.o endif xfs-$(CONFIG_XFS_DRAIN_INTENTS) += xfs_drain.o +xfs-$(CONFIG_XFS_LIVE_HOOKS) += xfs_hooks.o # online scrub/repair ifeq ($(CONFIG_XFS_ONLINE_SCRUB),y)
fs/xfs/xfs_hooks.c new file +53 -0
53 lines not on this page · raw message
fs/xfs/xfs_hooks.h new file +68 -0
68 lines not on this page · raw message
fs/xfs/xfs_linux.h +1 -0
@@ -81,6 +81,7 @@ typedef __u32 xfs_nlink_t;#include "xfs_buf.h" #include "xfs_message.h" #include "xfs_drain.h" +#include "xfs_hooks.h" #ifdef __BIG_ENDIAN#define XFS_NATIVE_HOST 1
PATCH 4/4 xfs: allow blocking notifier chains with filesystem hooks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make it so that we can switch between notifier chain implementations for testing purposes. On the author's test system, calling an empty srcu notifier chain cost about 19ns per call, vs. 4ns for a blocking notifier chain. Hm. Might we actually want regular blocking notifiers?
--- fs/xfs/Kconfig | 33 ++++++++++++++++++++++++++++++++- fs/xfs/xfs_hooks.c | 41 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_hooks.h | 6 +++++- 3 files changed, 78 insertions(+), 2 deletions(-)
fs/xfs/Kconfig +32 -1
@@ -133,7 +133,6 @@ config XFS_ONLINE_SCRUB default n depends on XFS_FS depends on TMPFS && SHMEM - depends on SRCU select XFS_LIVE_HOOKS select XFS_DRAIN_INTENTS help
@@ -149,6 +148,38 @@ config XFS_ONLINE_SCRUB If unsure, say N. +choice + prompt "XFS hook implementation" + depends on XFS_FS && XFS_LIVE_HOOKS && XFS_ONLINE_SCRUB + default XFS_LIVE_HOOKS_BLOCKING if HAVE_ARCH_JUMP_LABEL + default XFS_LIVE_HOOKS_SRCU if !HAVE_ARCH_JUMP_LABEL + help + Pick one + +config XFS_LIVE_HOOKS_SRCU + bool "SRCU notifier chains" + depends on SRCU + help + Use SRCU notifier chains for filesystem hooks. These have very low + overhead for event initiators (the main filesystem) and higher + overhead for chain modifiers (scrub waits for RCU grace). This is + the best option when jump labels are not supported or there are many + CPUs in the system. + + This may cause problems with CPU hotplug invoking reclaim invoking + XFS. + +config XFS_LIVE_HOOKS_BLOCKING + bool "Blocking notifier chains" + help + Use blocking notifier chains for filesystem hooks. These have medium + overhead for event initiators (the main fs) and chain modifiers + (scrub) due to their use of rwsems. This is the best option when + jump labels can be used to eliminate overhead for the filesystem when + scrub is not running. + +endchoice + config XFS_ONLINE_REPAIR bool "XFS online metadata repair support" default n
fs/xfs/xfs_hooks.c +41 -0
50 lines not on this page · raw message
fs/xfs/xfs_hooks.h +5 -1
@@ -6,10 +6,14 @@#ifndef XFS_HOOKS_H_ #define XFS_HOOKS_H_ -#ifdef CONFIG_XFS_LIVE_HOOKS +#if defined(CONFIG_XFS_LIVE_HOOKS_SRCU )struct xfs_hooks {struct srcu_notifier_head head; }; +#elif defined(CONFIG_XFS_LIVE_HOOKS_BLOCKING ) +struct xfs_hooks { +struct blocking_notifier_head head; +};#else struct xfs_hooks {/* empty */ };#endif