public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: bodonnel@redhat.com
To: linux-xfs@vger.kernel.org
Cc: djwong@kernel.org, sandeen@sandeen.net,
	Bill O'Donnell <bodonnel@redhat.com>
Subject: [PATCH] xfs_repair: handling a block with bad crc, bad uuid, and bad magic number needs fixing
Date: Thu, 20 Mar 2025 15:25:18 -0500	[thread overview]
Message-ID: <20250320202518.644182-1-bodonnel@redhat.com> (raw)

From: Bill O'Donnell <bodonnel@redhat.com>

In certain cases, if a block is so messed up that crc, uuid and magic number are all
bad, we need to not only detect in phase3 but fix it properly in phase6. In the
current code, the mechanism doesn't work in that it only pays attention to one of the
parameters.

Note: in this case, the nlink inode link count drops to 1, but re-running xfs_repair
fixes it back to 2. This is a side effect that should probably be handled in
update_inode_nlinks() with separate patch. Regardless, running xfs_repair twice
fixes the issue. Also, this patch fixes the issue with v5, but not v4 xfs.

Signed-off-by: Bill O'Donnell <bodonnel@redhat.com>
---
 repair/phase6.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/repair/phase6.c b/repair/phase6.c
index 4064a84b2450..677505d45357 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -2336,6 +2336,7 @@ longform_dir2_entry_check(
 	int			fixit = 0;
 	struct xfs_da_args	args;
 	int			error;
+	int			wantmagic;
 
 	*need_dot = 1;
 	freetab = malloc(FREETAB_SIZE(ip->i_disk_size / mp->m_dir_geo->blksize));
@@ -2364,7 +2365,6 @@ longform_dir2_entry_check(
 	     da_bno = (xfs_dablk_t)next_da_bno) {
 		const struct xfs_buf_ops *ops;
 		int			 error;
-		struct xfs_dir2_data_hdr *d;
 
 		next_da_bno = da_bno + mp->m_dir_geo->fsbcount - 1;
 		if (bmap_next_offset(ip, &next_da_bno)) {
@@ -2404,9 +2404,11 @@ longform_dir2_entry_check(
 		}
 
 		/* check v5 metadata */
-		d = bp->b_addr;
-		if (be32_to_cpu(d->magic) == XFS_DIR3_BLOCK_MAGIC ||
-		    be32_to_cpu(d->magic) == XFS_DIR3_DATA_MAGIC) {
+		if (xfs_has_crc(mp))
+			wantmagic = XFS_DIR3_BLOCK_MAGIC;
+		else
+			wantmagic = XFS_DIR2_BLOCK_MAGIC;
+		if (wantmagic == XFS_DIR3_BLOCK_MAGIC) {
 			error = check_dir3_header(mp, bp, ino);
 			if (error) {
 				fixit++;
-- 
2.48.1


             reply	other threads:[~2025-03-20 20:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-20 20:25 bodonnel [this message]
2025-03-20 22:21 ` [PATCH] xfs_repair: handling a block with bad crc, bad uuid, and bad magic number needs fixing Eric Sandeen
2025-03-21  7:32   ` Christoph Hellwig
2025-03-20 23:28 ` Eric Sandeen
2025-03-21  7:35   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250320202518.644182-1-bodonnel@redhat.com \
    --to=bodonnel@redhat.com \
    --cc=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox