Skip to contentSkip to conversation

xfs_repair: fix link counts update following repair of a bad block

PATCH In review [email protected] 3 participants 3 messages Apr 15, 2025 – Apr 16, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 xfs_repair: fix link counts update following repair of a bad block

From: Bill O'Donnell <[email protected]>

Updating nlinks, following repair of a bad block needs a bit of work. In unique cases, 2 runs of xfs_repair is needed to adjust the count to the proper value. This patch modifies location of longform_dir2_entry_check, to handle both longform and shortform directory cases. This results in the hashtab to be correctly filled and those entries don't end up in lost+found, and nlinks is properly adjusted on the first xfs_repair pass.

---

v3: fix logic to cover the shortform directory case, and fix the description
v2: attempt to cover the case where header indicates shortform directory v1:

 repair/phase6.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
repair/phase6.c +5 -3
index dbc090a54139..4a3fafab3522 100644
@@ -2424,6 +2424,11 @@ longform_dir2_entry_check(
 			continue;
 		}
 
+		/* salvage any dirents that look ok */
+		longform_dir2_entry_check_data(mp, ip, num_illegal, need_dot,
+				irec, ino_offset, bp, hashtab,
+				&freetab, da_bno, fmt == XFS_DIR2_FMT_BLOCK);
+
 		/* check v5 metadata */
 		if (xfs_has_crc(mp)) {
 			error = check_dir3_header(mp, bp, ino);
@@ -2438,9 +2443,6 @@ longform_dir2_entry_check(
 			}
 		}
 
-		longform_dir2_entry_check_data(mp, ip, num_illegal, need_dot,
-				irec, ino_offset, bp, hashtab,
-				&freetab, da_bno, fmt == XFS_DIR2_FMT_BLOCK);
 		if (fmt == XFS_DIR2_FMT_BLOCK)
 			break;
 
Signature · 1 line
2.49.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 6 lines · On 4/15/25 1:48 PM, [email protected] wrote:

From: Bill O'Donnell <[email protected]>

Updating nlinks, following repair of a bad block needs a bit of work. In unique cases, 2 runs of xfs_repair is needed to adjust the count to the proper value. This patch modifies location of longform_dir2_entry_check, to handle both longform and shortform directory cases.

This is not accurate; short form directories are not generally in play here. They only arise due to the directory rebuild orphaning all entries without the prior scan, yielding an empty directory.

Quoted 3 lines

This results in the
hashtab to be correctly filled and those entries don't end up in lost+found, and nlinks is properly adjusted on the first xfs_repair pass.

Changelog suggestion:

xfs_repair: phase6: scan longform entries before header check

In longform_dir2_entry_check, if check_dir3_header() fails for v5 metadata, we immediately go to out_fix: and try to rebuild the directory via longform_dir2_rebuild. But because we haven't yet called longform_dir2_entry_check_data, the *hashtab used to rebuild the directory is empty, which results in all existing entries getting moved to lost+found, and an empty rebuilt directory. On top of that, the empty directory is now short form, so its nlinks come out wrong and this requires another repair run to fix.

Scan the entries before checking the header, so that we have a decent chance of properly rebuilding the dir if the header is corrupt, rather than orphaning all the entries and moving them to lost+found.

Quoted 3 lines

Other than the commit log,

Quoted 37 lines

---

v3: fix logic to cover the shortform directory case, and fix the description
v2: attempt to cover the case where header indicates shortform directory v1:

 repair/phase6.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
repair/phase6.c +5 -3
index dbc090a54139..4a3fafab3522 100644
@@ -2424,6 +2424,11 @@ longform_dir2_entry_check(
 			continue;
 		}
 
+		/* salvage any dirents that look ok */
+		longform_dir2_entry_check_data(mp, ip, num_illegal, need_dot,
+				irec, ino_offset, bp, hashtab,
+				&freetab, da_bno, fmt == XFS_DIR2_FMT_BLOCK);
+
 		/* check v5 metadata */
 		if (xfs_has_crc(mp)) {
 			error = check_dir3_header(mp, bp, ino);
@@ -2438,9 +2443,6 @@ longform_dir2_entry_check(
 			}
 		}
 
-		longform_dir2_entry_check_data(mp, ip, num_illegal, need_dot,
-				irec, ino_offset, bp, hashtab,
-				&freetab, da_bno, fmt == XFS_DIR2_FMT_BLOCK);
 		if (fmt == XFS_DIR2_FMT_BLOCK)
 			break;
 
Reviewed-by
#2 lore raw
Quoted 33 lines · Eric Sandeen
Quoted 6 lines · On 4/15/25 1:48 PM, [email protected] wrote:

From: Bill O'Donnell <[email protected]>

Updating nlinks, following repair of a bad block needs a bit of work. In unique cases, 2 runs of xfs_repair is needed to adjust the count to the proper value. This patch modifies location of longform_dir2_entry_check, to handle both longform and shortform directory cases.

This is not accurate; short form directories are not generally in play here. They only arise due to the directory rebuild orphaning all entries without the prior scan, yielding an empty directory.

Quoted 3 lines

This results in the
hashtab to be correctly filled and those entries don't end up in lost+found, and nlinks is properly adjusted on the first xfs_repair pass.

Changelog suggestion:

xfs_repair: phase6: scan longform entries before header check

In longform_dir2_entry_check, if check_dir3_header() fails for v5 metadata, we immediately go to out_fix: and try to rebuild the directory via longform_dir2_rebuild. But because we haven't yet called longform_dir2_entry_check_data, the *hashtab used to rebuild the directory is empty, which results in all existing entries getting moved to lost+found, and an empty rebuilt directory. On top of that, the empty directory is now short form, so its nlinks come out wrong and this requires another repair run to fix.

Scan the entries before checking the header, so that we have a decent chance of properly rebuilding the dir if the header is corrupt, rather than orphaning all the entries and moving them to lost+found.

Quoted 7 lines
Quoted 3 lines

Other than the commit log,

With the changelog amended,

--D

Quoted 40 lines
Quoted 38 lines

---

v3: fix logic to cover the shortform directory case, and fix the description
v2: attempt to cover the case where header indicates shortform directory v1:

 repair/phase6.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
repair/phase6.c +5 -3
index dbc090a54139..4a3fafab3522 100644
@@ -2424,6 +2424,11 @@ longform_dir2_entry_check(
 			continue;
 		}
 
+		/* salvage any dirents that look ok */
+		longform_dir2_entry_check_data(mp, ip, num_illegal, need_dot,
+				irec, ino_offset, bp, hashtab,
+				&freetab, da_bno, fmt == XFS_DIR2_FMT_BLOCK);
+
 		/* check v5 metadata */
 		if (xfs_has_crc(mp)) {
 			error = check_dir3_header(mp, bp, ino);
@@ -2438,9 +2443,6 @@ longform_dir2_entry_check(
 			}
 		}
 
-		longform_dir2_entry_check_data(mp, ip, num_illegal, need_dot,
-				irec, ino_offset, bp, hashtab,
-				&freetab, da_bno, fmt == XFS_DIR2_FMT_BLOCK);
 		if (fmt == XFS_DIR2_FMT_BLOCK)
 			break;