From nobody Mon Nov 15 17:12:29 2021 X-Original-To: dev-commits-src-main@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 7A2E91898E37; Mon, 15 Nov 2021 17:12:29 +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 4HtG3134thz4kNK; Mon, 15 Nov 2021 17:12:29 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 4AAA21DB17; Mon, 15 Nov 2021 17:12:29 +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 1AFHCTvd060290; Mon, 15 Nov 2021 17:12:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AFHCTgL060289; Mon, 15 Nov 2021 17:12:29 GMT (envelope-from git) Date: Mon, 15 Nov 2021 17:12:29 GMT Message-Id: <202111151712.1AFHCTgL060289@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kirk McKusick Subject: git: f2b391528ad9 - main - Add ability to suppress UFS/FFS superblock check-hash failure messages. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f2b391528ad9b11a2089457108a55645e358e92f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=f2b391528ad9b11a2089457108a55645e358e92f commit f2b391528ad9b11a2089457108a55645e358e92f Author: Kirk McKusick AuthorDate: 2021-11-15 17:10:47 +0000 Commit: Kirk McKusick CommitDate: 2021-11-15 17:11:54 +0000 Add ability to suppress UFS/FFS superblock check-hash failure messages. When reading UFS/FFS superblocks that have check hashes, both the kernel and libufs print an error message if the check hash is incorrect. This commit adds the ability to request that the error message not be made. It is intended for use by programs like fsck that wants to print its own error message and by kernel subsystems like glabel that just wants to check for possible filesystem types. This capability will be used in followup commits. Sponsored by: Netflix --- sys/ufs/ffs/ffs_subr.c | 26 ++++++++++++++------------ sys/ufs/ffs/fs.h | 10 ++++++++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/sys/ufs/ffs/ffs_subr.c b/sys/ufs/ffs/ffs_subr.c index 60d90aac5bcc..09f03458e753 100644 --- a/sys/ufs/ffs/ffs_subr.c +++ b/sys/ufs/ffs/ffs_subr.c @@ -155,7 +155,6 @@ ffs_sbget(void *devfd, struct fs **fsp, off_t altsblock, int i, error, size, blks; uint8_t *space; int32_t *lp; - int chkhash; char *buf; fs = NULL; @@ -168,12 +167,9 @@ ffs_sbget(void *devfd, struct fs **fsp, off_t altsblock, return (error); } } else { - chkhash = 1; - if (altsblock == STDSB_NOHASHFAIL) - chkhash = 0; for (i = 0; sblock_try[i] != -1; i++) { if ((error = readsuper(devfd, &fs, sblock_try[i], 0, - chkhash, readfunc)) == 0) + altsblock, readfunc)) == 0) break; if (fs != NULL) { UFS_FREE(fs, filltype); @@ -279,6 +275,13 @@ readsuper(void *devfd, struct fs **fsp, off_t sblockloc, int isaltsblk, fs->fs_metackhash &= CK_SUPPORTED; fs->fs_flags &= FS_SUPPORTED; if (fs->fs_ckhash != (ckhash = ffs_calc_sbhash(fs))) { + if (chkhash == STDSB_NOMSG) + return (EINTEGRITY); + if (chkhash == STDSB_NOHASHFAIL_NOMSG) { + fs->fs_flags |= FS_NEEDSFSCK; + fs->fs_fmod = 1; + return (0); + } #ifdef _KERNEL res = uprintf("Superblock check-hash failed: recorded " "check-hash 0x%x != computed check-hash 0x%x%s\n", @@ -296,13 +299,12 @@ readsuper(void *devfd, struct fs **fsp, off_t sblockloc, int isaltsblk, "check-hash 0x%x != computed check-hash " "0x%x%s\n", fs->fs_ckhash, ckhash, chkhash == 0 ? " (Ignored)" : ""); - if (chkhash == 0) { - fs->fs_flags |= FS_NEEDSFSCK; - fs->fs_fmod = 1; - return (0); - } - fs->fs_fmod = 0; - return (EINTEGRITY); + if (chkhash == STDSB) + return (EINTEGRITY); + /* chkhash == STDSB_NOHASHFAIL */ + fs->fs_flags |= FS_NEEDSFSCK; + fs->fs_fmod = 1; + return (0); } /* Have to set for old filesystems that predate this field */ fs->fs_sblockactualloc = sblockloc; diff --git a/sys/ufs/ffs/fs.h b/sys/ufs/ffs/fs.h index 00c153b9684d..8c0047f17caf 100644 --- a/sys/ufs/ffs/fs.h +++ b/sys/ufs/ffs/fs.h @@ -86,9 +86,19 @@ * still return the superblock. This is used by the bootstrap code * to give the system a chance to come up so that fsck can be run * to correct the problem. + * + * STDSB_NOMSG is the same as STDSB but the kernel does not print an + * error message. It is used by programs like fsck that want to + * print their own error message. + * + * STDSB_NOHASHFAIL_NOMSG is the same as STDSB_NOHASHFAIL but the kernel + * does not print an error message. It is used by clients like glabel + * that just want to check for possible filesystem types. */ #define STDSB -1 /* Fail if check-hash is bad */ #define STDSB_NOHASHFAIL -2 /* Ignore check-hash failure */ +#define STDSB_NOMSG -3 /* STDSB with no kernel message */ +#define STDSB_NOHASHFAIL_NOMSG -4 /* STDSB_NOHASHFAIL with no message */ /* * Max number of fragments per block. This value is NOT tweakable.