Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Dec 2022 00:38:14 GMT
From:      Kirk McKusick <mckusick@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 6d43823851ab - stable/13 - Provide better diagnostic messages for bad cylinder groups.
Message-ID:  <202212110038.2BB0cEa7003845@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=6d43823851ab7f3c9cf60b492a476c905b2b6a4a

commit 6d43823851ab7f3c9cf60b492a476c905b2b6a4a
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2022-08-26 06:56:31 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2022-12-11 00:37:17 +0000

    Provide better diagnostic messages for bad cylinder groups.
    
    (cherry picked from commit 495b1baac32774e00a9a975d4cedd2aa9f7d81b2)
    
    Sponsored by: The FreeBSD Foundation
---
 sbin/fsck_ffs/fsutil.c | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c
index dfe472ab17fb..0097ddff135e 100644
--- a/sbin/fsck_ffs/fsutil.c
+++ b/sbin/fsck_ffs/fsutil.c
@@ -948,12 +948,21 @@ blzero(int fd, ufs2_daddr_t blk, long size)
  * Verify cylinder group's magic number and other parameters.  If the
  * test fails, offer an option to rebuild the whole cylinder group.
  */
+#undef CHK
+#define CHK(lhs, op, rhs, fmt)						\
+	if (lhs op rhs) {						\
+		pwarn("UFS%d superblock failed: %s (" #fmt ") %s %s ("	\
+		    #fmt ")\n", sblock.fs_magic == FS_UFS1_MAGIC ? 1 :	\
+		    2, #lhs, (intmax_t)lhs, #op, #rhs, (intmax_t)rhs);	\
+		error = 1;						\
+	}
 int
 check_cgmagic(int cg, struct bufarea *cgbp, int request_rebuild)
 {
 	struct cg *cgp = cgbp->b_un.b_cg;
 	uint32_t cghash, calchash;
 	static int prevfailcg = -1;
+	int error;
 
 	/*
 	 * Extended cylinder group checks.
@@ -966,19 +975,20 @@ check_cgmagic(int cg, struct bufarea *cgbp, int request_rebuild)
 		calchash = calculate_crc32c(~0L, (void *)cgp, sblock.fs_cgsize);
 		cgp->cg_ckhash = cghash;
 	}
-	if (cgp->cg_ckhash == calchash &&
-	    cg_chkmagic(cgp) &&
-	    cgp->cg_cgx == cg &&
-	    ((sblock.fs_magic == FS_UFS1_MAGIC &&
-	      cgp->cg_old_niblk == sblock.fs_ipg &&
-	      cgp->cg_ndblk <= sblock.fs_fpg &&
-	      cgp->cg_old_ncyl <= sblock.fs_old_cpg) ||
-	     (sblock.fs_magic == FS_UFS2_MAGIC &&
-	      cgp->cg_niblk == sblock.fs_ipg &&
-	      cgp->cg_ndblk <= sblock.fs_fpg &&
-	      cgp->cg_initediblk <= sblock.fs_ipg))) {
-		return (1);
+	error = 0;
+	CHK(cgp->cg_ckhash, !=, calchash, "%jd");
+	CHK(cg_chkmagic(cgp), ==, 0, "%jd");
+	CHK(cgp->cg_cgx, !=, cg, "%jd");
+	CHK(cgp->cg_ndblk, >, sblock.fs_fpg, "%jd");
+	if (sblock.fs_magic == FS_UFS1_MAGIC) {
+		CHK(cgp->cg_old_niblk, !=, sblock.fs_ipg, "%jd");
+		CHK(cgp->cg_old_ncyl, >, sblock.fs_old_cpg, "%jd");
+	} else if (sblock.fs_magic == FS_UFS2_MAGIC) {
+		CHK(cgp->cg_niblk, !=, sblock.fs_ipg, "%jd");
+		CHK(cgp->cg_initediblk, >, sblock.fs_ipg, "%jd");
 	}
+	if (error == 0)
+		return (1);
 	if (prevfailcg == cg)
 		return (0);
 	prevfailcg = cg;
@@ -1029,6 +1039,7 @@ check_cgmagic(int cg, struct bufarea *cgbp, int request_rebuild)
 		cgp->cg_nextfreeoff = cgp->cg_clusteroff +
 		    howmany(fragstoblks(&sblock, sblock.fs_fpg), CHAR_BIT);
 	}
+	cgp->cg_ckhash = calculate_crc32c(~0L, (void *)cgp, sblock.fs_cgsize);
 	cgdirty(cgbp);
 	return (0);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202212110038.2BB0cEa7003845>