From nobody Thu Dec 16 00:53:58 2021 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 BAF2E18D7670; Thu, 16 Dec 2021 00:53:58 +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 4JDtsf3FCqz3LYV; Thu, 16 Dec 2021 00:53:58 +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 4F4D22674A; Thu, 16 Dec 2021 00:53:58 +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 1BG0rwH2080529; Thu, 16 Dec 2021 00:53:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BG0rwCC080528; Thu, 16 Dec 2021 00:53:58 GMT (envelope-from git) Date: Thu, 16 Dec 2021 00:53:58 GMT Message-Id: <202112160053.1BG0rwCC080528@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: c72372c693b3 - main - Update fsck(8) to ignore failures from a check program for a filesystem when the fstab(5) entry for the filesystem has the "failok" attribute. 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: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c72372c693b36058b58a525981e833515ce8e441 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639616038; 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=z+whl3dWLaqW01uya2+W/LOT+rmAdzdGWFmJf19xX2c=; b=ftGQIvd2qRPb6wEDirGnJQ5y3BEegY48mYpWHJX5gETxy9uWnCU49Q2briGBFjdAlX5D/l /dYxRiHxptO05KNhUCwFk18V+DgkMhOhInSiCGLC0YVFQjMSGMX63Og5FD+6HzLzWhGLGm J7uMbiSYLT5XVBnzafcpF+5Xcx9PfFNae57eLY763S8NXBaheJiKnwsGj2nyQpGSBiNXYy RxRfA1Fkhd0JzTOoCFGbED0t578n7p2fmCIV5DbnBUtBj4u1gcHCuWIxLYg3yYxSPVLRmU ToD8SMQ7tPDDkh5z7WVIIlwCS+n8sQPXjSugaa6ddygRN3oqUIRjQCr2HX43qQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639616038; a=rsa-sha256; cv=none; b=V0XCaARv0yD9bJRIjDleJlolmKxwZ/cW5zF8GfPpySB9lkFaDFhOtqbi9t5L01+M/7ZnWU NBKV7ZGbw7Q7cWMGfU/ehe5sNEBz+fmnp4389GYx2SPON+GseiwBujUQjEccyN1u64qJuo 2qS1TMpsGbm0JnEulXVxIVB3CN4C4GTpuBtzhk4rlOKFiwgBao7qy9m3oIsfJ+cGM9l04W 8F7g3RJQ2IzJzlT94C52Qle+1SR5387b2++0zGaN/OJPXUg4cGM6wAkLU4L2/Rr1TDZWhX x4veN17SGlDfhYGDqACMst2VYSMl1QtRyuIJcNCUk6usjcTkEpgqVEgFlOMRAg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=c72372c693b36058b58a525981e833515ce8e441 commit c72372c693b36058b58a525981e833515ce8e441 Author: Kirk McKusick AuthorDate: 2021-12-16 00:51:55 +0000 Commit: Kirk McKusick CommitDate: 2021-12-16 00:53:46 +0000 Update fsck(8) to ignore failures from a check program for a filesystem when the fstab(5) entry for the filesystem has the "failok" attribute. Reviewed by: kib PR: 246201 MFC after: 2 weeks Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D33424 --- sbin/fsck/fsck.c | 3 +++ sbin/fsck/fsutil.c | 39 +++++++++++++++++++++++++++++++++++++++ sbin/fsck/fsutil.h | 7 +++---- sbin/fsck/preen.c | 24 +++++++++++++++--------- 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/sbin/fsck/fsck.c b/sbin/fsck/fsck.c index 84d2e2fe422f..bb053fe56253 100644 --- a/sbin/fsck/fsck.c +++ b/sbin/fsck/fsck.c @@ -254,6 +254,9 @@ isok(struct fstab *fs) return (0); if (!selected(fs->fs_vfstype)) return (0); + /* If failok, always check now */ + if (getfsopt(fs, "failok")) + return (1); /* * If the -B flag has been given, then process the needed * background checks. Background checks cannot be run on diff --git a/sbin/fsck/fsutil.c b/sbin/fsck/fsutil.c index 012bd434dce6..9644697e2530 100644 --- a/sbin/fsck/fsutil.c +++ b/sbin/fsck/fsutil.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -55,6 +56,44 @@ static int preen = 0; static void vmsg(int, const char *, va_list) __printflike(2, 0); +/* + * The getfsopt() function checks whether an option is present in + * an fstab(5) fs_mntops entry. There are six possible cases: + * + * fs_mntops getfsopt result + * rw,foo foo true + * rw,nofoo nofoo true + * rw,nofoo foo false + * rw,foo nofoo false + * rw foo false + * rw nofoo false + * + * This function should be part of and documented in getfsent(3). + */ +int +getfsopt(struct fstab *fs, const char *option) +{ + int negative, found; + char *opt, *optbuf; + + if (option[0] == 'n' && option[1] == 'o') { + negative = 1; + option += 2; + } else + negative = 0; + optbuf = strdup(fs->fs_mntops); + found = 0; + for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { + if (opt[0] == 'n' && opt[1] == 'o') { + if (!strcasecmp(opt + 2, option)) + found = negative; + } else if (!strcasecmp(opt, option)) + found = !negative; + } + free(optbuf); + return (found); +} + void setcdevname(const char *cd, int pr) { diff --git a/sbin/fsck/fsutil.h b/sbin/fsck/fsutil.h index c6300a0cc0c4..8bb9ddb90d6e 100644 --- a/sbin/fsck/fsutil.h +++ b/sbin/fsck/fsutil.h @@ -28,6 +28,9 @@ * $FreeBSD$ */ +int checkfstab(int, int (*)(struct fstab *), + int (*) (const char *, const char *, const char *, const char *, pid_t *)); +int getfsopt(struct fstab *, const char *); void pfatal(const char *, ...) __printflike(1, 2); void pwarn(const char *, ...) __printflike(1, 2); void perr(const char *, ...) __printflike(1, 2); @@ -46,7 +49,3 @@ char *estrdup(const char *); #define CHECK_BACKGRD 0x0008 #define DO_BACKGRD 0x0010 #define CHECK_CLEAN 0x0020 - -struct fstab; -int checkfstab(int, int (*)(struct fstab *), - int (*) (const char *, const char *, const char *, const char *, pid_t *)); diff --git a/sbin/fsck/preen.c b/sbin/fsck/preen.c index e40ec5d4fb91..c8a36a608695 100644 --- a/sbin/fsck/preen.c +++ b/sbin/fsck/preen.c @@ -62,6 +62,7 @@ struct partentry { char *p_devname; /* device name */ char *p_mntpt; /* mount point */ char *p_type; /* file system type */ + int p_failok; /* failok option set */ }; static TAILQ_HEAD(part, partentry) badh; @@ -78,7 +79,7 @@ static TAILQ_HEAD(disk, diskentry) diskh; static int nrun = 0, ndisks = 0; static struct diskentry *finddisk(const char *); -static void addpart(const char *, const char *, const char *); +static void addpart(const char *, const char *, const char *, const int); static int startdisk(struct diskentry *, int (*)(const char *, const char *, const char *, const char *, pid_t *)); static void printpart(void); @@ -132,7 +133,6 @@ checkfstab(int flags, int (*docheck)(struct fstab *), } sumstatus = (*checkit)(fs->fs_vfstype, name, fs->fs_file, NULL, NULL); - if (sumstatus) return (sumstatus); continue; @@ -143,7 +143,8 @@ checkfstab(int flags, int (*docheck)(struct fstab *), sumstatus |= 8; continue; } - addpart(fs->fs_vfstype, name, fs->fs_file); + addpart(fs->fs_vfstype, name, fs->fs_file, + getfsopt(fs, "failok")); } if ((flags & CHECK_PREEN) == 0 || passno == 1 || @@ -172,12 +173,17 @@ checkfstab(int flags, int (*docheck)(struct fstab *), continue; } - if (WIFEXITED(status)) + p = TAILQ_FIRST(&d->d_part); + + if (WIFEXITED(status) == 0) { + retcode = 0; + } else if (p->p_failok == 0) { retcode = WEXITSTATUS(status); - else + } else { retcode = 0; - - p = TAILQ_FIRST(&d->d_part); + fprintf(stderr, "%s: failok SPECIFIED, FSCK " + "ERROR(S) IGNORED\n", p->p_devname); + } if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) (void) printf("done %s: %s (%s) = 0x%x\n", @@ -243,7 +249,6 @@ checkfstab(int flags, int (*docheck)(struct fstab *), return (0); } - static struct diskentry * finddisk(const char *name) { @@ -297,7 +302,7 @@ printpart(void) static void -addpart(const char *type, const char *dev, const char *mntpt) +addpart(const char *type, const char *dev, const char *mntpt, const int failok) { struct diskentry *d = finddisk(dev); struct partentry *p; @@ -312,6 +317,7 @@ addpart(const char *type, const char *dev, const char *mntpt) p->p_devname = estrdup(dev); p->p_mntpt = estrdup(mntpt); p->p_type = estrdup(type); + p->p_failok = failok; TAILQ_INSERT_TAIL(&d->d_part, p, p_entries); }