From nobody Sun Jan 02 22:19:39 2022 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 07907192FEEF; Sun, 2 Jan 2022 22:19:40 +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 4JRtbJ1cGZz3mc3; Sun, 2 Jan 2022 22:19:40 +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 AD6BB19DDE; Sun, 2 Jan 2022 22:19:39 +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 202MJdj9011523; Sun, 2 Jan 2022 22:19:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 202MJd37011522; Sun, 2 Jan 2022 22:19:39 GMT (envelope-from git) Date: Sun, 2 Jan 2022 22:19:39 GMT Message-Id: <202201022219.202MJd37011522@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kirk McKusick Subject: git: fe7121ec5b8b - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: fe7121ec5b8b1c98c2933902be7aef1850030154 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641161980; 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=+ej0UDRQiUgE6/jSCmugocAcp+0X21OWcPjlTcLhVjU=; b=I5ViTqCMa8Z31Ox0Z4N+J0HKbXBplHgSNFaGOc3E1365jOPylKj+TUPNuoUXsL5UoeAcce B3wk1mbgeBtQ2pP5QXJZSCNEwdy/Q8tlsXCloV9EJZCydj40TfMh1HeeNCRIqhNEwSnOs7 OIleW8Eo3BMdAGkWwMsiw3npC3/Sb3z37mIzkvClHi880DebnAnaD8/8d883NihLaDn00D VFBIA/UoeCMjSnuph0bI8PtIdv05XiP6t+OdCp2NN/7TuK+BDHM/x7W8MR5GXojjTFMuzE /lot1o7Fu5dAR8QqfZU7r9kR69Dtddw43t9s1R8UusVH+o6xfSLL1gj9LPL0VA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641161980; a=rsa-sha256; cv=none; b=s4ydIKTxSK8L7SsXw9m69EfxXKgxo8kJgE5RxoN0Kn5UyHQzouMciOkRpv1wpNQoKryean dUUjV8KebvcqlExLbrt1gYBrGx3vIypJJ5/JJzEUpn7j1h8wJeqCvi5OwXH05iBWtzp9Vd aROVNfj1EMA9e6nIAdkEH3gT7kesZofsHhPRXX6mwVBSW+bKEonrCR19US35nSzLzPlI60 H8cR7x7eZ6/9/drZJbLbJ+ULZyXyFtHftyazgvDFPJKcn7H8JbB6uMBEAaBXXXNinSV3jo uCAr5RrxWrsqZXsaJjDXeMIcA796f5BS/hVfgmEFvoxqVSL305Mkui36G9npxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=fe7121ec5b8b1c98c2933902be7aef1850030154 commit fe7121ec5b8b1c98c2933902be7aef1850030154 Author: Kirk McKusick AuthorDate: 2021-12-16 00:51:55 +0000 Commit: Kirk McKusick CommitDate: 2022-01-02 22:12:14 +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. PR: 246201 Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D33424 (cherry picked from commit c72372c693b36058b58a525981e833515ce8e441) --- 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); }