From nobody Mon May 08 18:34:04 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QFVLN3DQkz4BD7C; Mon, 8 May 2023 18:34:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QFVLN2JZFz3wKM; Mon, 8 May 2023 18:34:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683570844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iCqAmx8MoC9v7J3+USjUi93lIUl3UaVkkw6Eg89cUlA=; b=dcZgb/hJYgUURduEp2XX2RovFO2ksNzJ/VUFiDLwgwp/Nk9C2wCFUPcTYLQh7ZDCAUnMB4 9eFTFfJHQle7D2YYBH3PGfNjX4u7jgtHmfLthBight2xIuyL6Hu8UssoYe5IgUxvpaD8Sl 7LboFUk/mNR4lq0NySu7SUbGgA+RGyApxqAONM3P56lYvrfcKxSKSSk/KHTh2eNjd87Tx9 +BcgZFRa1Yql3P7WEU6J69s2JsiRyICJbbmGHaDW/j6uKM8oFbTEE8fYwb6S2JaDjffCEo 0XLAy2rV73Zik6mwcwx71WWmkRL/eXoAhCRnpXrwZyMBuNViziqk7832TK8Kaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683570844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iCqAmx8MoC9v7J3+USjUi93lIUl3UaVkkw6Eg89cUlA=; b=MesCHSCnwPRAFUMvh0UYNQyAAXaCzNP0I1SmX5Wd/qgEXKt1vy6hb4Nz6Pic2U2RS3ILiu mjHl/zcPWtEFEFJ72TqYS8Xvf/GTYMLnF6qd5su+9jWLx8Yq+wn77GbioxnIHyGH2ug435 aK3zmlBT9JRosUwKZRo1AiDWf7QzLd0RGAtFE/XfBsfzVNmf0OfG2PXrH4NKrcRQuZ9q19 DMvHkdjlYpMMAPJ6AY2LbHp+NpmNrTlPtN3Ovb6BEk8k9b0rXvTC37ICRsxEcxh0jIDM2V V7+XuBs5wK8e1PKvDxCHt2N9xh0KxrOFfpAmhXJYIczfMY8mIZQ9pQDmHFvRGg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683570844; a=rsa-sha256; cv=none; b=wWRCCE73sdHzcPj06RfXvulVpNYRp+BaRJjPzoX2V3YyZ0TTUOqpdNg6F7hgxj3jJqatAr xqz0oVTGYyaBu+gWRtcmCVpL5U6LXGu+z/2YLiKQVfyJhCEN5cvaD8OvuYFD6DEoBq/zFY PREskfjgXupI8FrAG2VtxOdh+dgmLFT3otthSI51ruMX/BJ0EwYGUNx3yrbxQIzZQgexPx Z+Yy+oidKhQoZTisZQ28BbS6iBC2coJ9sVAdXWXCnPpKychki1UMDDHBAO8hXHe8JiOiwg DobUyisF7p0/8GrCYN1YIi1qPqr7BQ7lSAKE8XkS0tvNRLorn5Rh0Ksey/ENyA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QFVLN1NK8z19lM; Mon, 8 May 2023 18:34:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 348IY4jg056128; Mon, 8 May 2023 18:34:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 348IY4Mi056127; Mon, 8 May 2023 18:34:04 GMT (envelope-from git) Date: Mon, 8 May 2023 18:34:04 GMT Message-Id: <202305081834.348IY4Mi056127@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Chuck Silvers Subject: git: db1a4d9c4569 - stable/13 - fsck_ffs: fix the previous change that skipped pass 5 in some cases List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: chs X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: db1a4d9c45698daf19e2d6372083820a1a09d4da Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by chs: URL: https://cgit.FreeBSD.org/src/commit/?id=db1a4d9c45698daf19e2d6372083820a1a09d4da commit db1a4d9c45698daf19e2d6372083820a1a09d4da Author: Chuck Silvers AuthorDate: 2023-05-03 20:21:19 +0000 Commit: Chuck Silvers CommitDate: 2023-05-08 17:57:16 +0000 fsck_ffs: fix the previous change that skipped pass 5 in some cases The previous change involved calling check_cgmagic() twice in a row for the same CG in order to differentiate when the CG was already ok vs. when the CG was rebuilt, but that doesn't work because the second call (which was supposed to rebuild the CG) returns 0 (indicating that the CG was not rebuilt) due to the prevfailcg check causing an early failure return. Fix this by moving the rebuild part of check_cgmagic() out into a separate function which is called by pass1() when it wants to rebuild a CG. Fixes: da86e7a20dc4a4b17e8d9e7630ed9b675cf71702 Reported by: pho Discussed with: mckusick Sponsored by: Netflix (cherry picked from commit 406475581246360faa7af9891dc8ad2423284e18) --- sbin/fsck_ffs/fsck.h | 3 ++- sbin/fsck_ffs/fsutil.c | 28 +++++++++++++--------------- sbin/fsck_ffs/gjournal.c | 2 +- sbin/fsck_ffs/inode.c | 2 +- sbin/fsck_ffs/main.c | 2 +- sbin/fsck_ffs/pass1.c | 12 +++++++++--- sbin/fsck_ffs/suj.c | 4 ++-- 7 files changed, 29 insertions(+), 24 deletions(-) diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h index 12a06e69b5fc..4e5878b0b12f 100644 --- a/sbin/fsck_ffs/fsck.h +++ b/sbin/fsck_ffs/fsck.h @@ -467,7 +467,8 @@ void cgdirty(struct bufarea *); struct bufarea *cglookup(int cg); int changeino(ino_t dir, const char *name, ino_t newnum, int depth); void check_blkcnt(struct inode *ip); -int check_cgmagic(int cg, struct bufarea *cgbp, int requestrebuild); +int check_cgmagic(int cg, struct bufarea *cgbp); +void rebuild_cg(int cg, struct bufarea *cgbp); void check_dirdepth(struct inoinfo *inp); int chkrange(ufs2_daddr_t blk, int cnt); void ckfini(int markclean); diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c index 974dba4be79b..b5ca478fbc46 100644 --- a/sbin/fsck_ffs/fsutil.c +++ b/sbin/fsck_ffs/fsutil.c @@ -988,9 +988,7 @@ 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. * - * Return 1 if the cylinder group is good or if repair is requested - * and is completed successfully. Return 0 if it is bad or if a repair - * has been requested but is not completed successfully. + * Return 1 if the cylinder group is good or return 0 if it is bad. */ #undef CHK #define CHK(lhs, op, rhs, fmt) \ @@ -1002,7 +1000,7 @@ blzero(int fd, ufs2_daddr_t blk, long size) error = 1; \ } int -check_cgmagic(int cg, struct bufarea *cgbp, int request_rebuild) +check_cgmagic(int cg, struct bufarea *cgbp) { struct cg *cgp = cgbp->b_un.b_cg; uint32_t cghash, calchash; @@ -1076,15 +1074,16 @@ check_cgmagic(int cg, struct bufarea *cgbp, int request_rebuild) return (0); prevfailcg = cg; pfatal("CYLINDER GROUP %d: INTEGRITY CHECK FAILED", cg); - if (!request_rebuild) { - printf("\n"); - return (0); - } - if (!reply("REBUILD CYLINDER GROUP")) { - printf("YOU WILL NEED TO RERUN FSCK.\n"); - rerun = 1; - return (0); - } + printf("\n"); + return (0); +} + +void +rebuild_cg(int cg, struct bufarea *cgbp) +{ + struct cg *cgp = cgbp->b_un.b_cg; + long start; + /* * Zero out the cylinder group and then initialize critical fields. * Bit maps and summaries will be recalculated by later passes. @@ -1126,7 +1125,6 @@ check_cgmagic(int cg, struct bufarea *cgbp, int request_rebuild) } cgp->cg_ckhash = calculate_crc32c(~0L, (void *)cgp, sblock.fs_cgsize); cgdirty(cgbp); - return (1); } /* @@ -1190,7 +1188,7 @@ std_checkblkavail(ufs2_daddr_t blkno, long frags) cg = dtog(&sblock, blkno + j); cgbp = cglookup(cg); cgp = cgbp->b_un.b_cg; - if (!check_cgmagic(cg, cgbp, 0)) + if (!check_cgmagic(cg, cgbp)) return (-((cg + 1) * sblock.fs_fpg - sblock.fs_frag)); baseblk = dtogd(&sblock, blkno + j); for (k = 0; k < frags; k++) { diff --git a/sbin/fsck_ffs/gjournal.c b/sbin/fsck_ffs/gjournal.c index b65589b5bd08..cd2c9df878a8 100644 --- a/sbin/fsck_ffs/gjournal.c +++ b/sbin/fsck_ffs/gjournal.c @@ -97,7 +97,7 @@ gjournal_check(const char *filesys) } cgbp = cglookup(cg); cgp = cgbp->b_un.b_cg; - if (!check_cgmagic(cg, cgbp, 0)) { + if (!check_cgmagic(cg, cgbp)) { rerun = 1; ckfini(0); return; diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index 2d563f617a56..04891447254e 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -1394,7 +1394,7 @@ retry: cg = ino_to_cg(&sblock, ino); cgbp = cglookup(cg); cgp = cgbp->b_un.b_cg; - if (!check_cgmagic(cg, cgbp, 0)) { + if (!check_cgmagic(cg, cgbp)) { if (anyino == 0) return (0); request = (cg + 1) * sblock.fs_ipg; diff --git a/sbin/fsck_ffs/main.c b/sbin/fsck_ffs/main.c index e559f6cb4ea6..df86cb5fb107 100644 --- a/sbin/fsck_ffs/main.c +++ b/sbin/fsck_ffs/main.c @@ -492,7 +492,7 @@ checkfilesys(char *filesys) snapflush(std_checkblkavail); if (cgheader_corrupt) { printf("PHASE 5 SKIPPED DUE TO CORRUPT CYLINDER GROUP " - "HEADER(S)\n"); + "HEADER(S)\n\n"); } else { pass5(); IOstats("Pass5"); diff --git a/sbin/fsck_ffs/pass1.c b/sbin/fsck_ffs/pass1.c index 55233e0bc4f4..e784fd29dc1c 100644 --- a/sbin/fsck_ffs/pass1.c +++ b/sbin/fsck_ffs/pass1.c @@ -100,11 +100,17 @@ pass1(void) cgbp = cglookup(c); cgp = cgbp->b_un.b_cg; rebuiltcg = 0; - if (!check_cgmagic(c, cgbp, 0)) { - if (!check_cgmagic(c, cgbp, 1)) + if (!check_cgmagic(c, cgbp)) { + if (!reply("REBUILD CYLINDER GROUP")) { cgheader_corrupt = 1; - else + if (!nflag) { + printf("YOU WILL NEED TO RERUN FSCK.\n"); + rerun = 1; + } + } else { + rebuild_cg(c, cgbp); rebuiltcg = 1; + } } if (!rebuiltcg && sblock.fs_magic == FS_UFS2_MAGIC) { inosused = cgp->cg_initediblk; diff --git a/sbin/fsck_ffs/suj.c b/sbin/fsck_ffs/suj.c index a1d624392fcf..8bcee7c54c85 100644 --- a/sbin/fsck_ffs/suj.c +++ b/sbin/fsck_ffs/suj.c @@ -181,7 +181,7 @@ cg_lookup(int cgx) if (lastcg && lastcg->sc_cgx == cgx) return (lastcg); cgbp = cglookup(cgx); - if (!check_cgmagic(cgx, cgbp, 0)) + if (!check_cgmagic(cgx, cgbp)) err_suj("UNABLE TO REBUILD CYLINDER GROUP %d", cgx); hd = &cghash[HASH(cgx)]; LIST_FOREACH(sc, hd, sc_next) @@ -394,7 +394,7 @@ suj_checkblkavail(ufs2_daddr_t blkno, long frags) cg = dtog(&sblock, blkno); cgbp = cglookup(cg); cgp = cgbp->b_un.b_cg; - if (!check_cgmagic(cg, cgbp, 0)) + if (!check_cgmagic(cg, cgbp)) return (-((cg + 1) * sblock.fs_fpg - sblock.fs_frag)); baseblk = dtogd(&sblock, blkno); for (j = 0; j <= sblock.fs_frag - frags; j++) {