From nobody Wed Oct 25 22:38:31 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 4SG3jz55rrz4y7x8; Wed, 25 Oct 2023 22:38:31 +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 4SG3jz4bBKz4DwL; Wed, 25 Oct 2023 22:38:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698273511; 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=4NLPWV2PkSs5Ky+jo0jDqPZpfI05kF3pp3i+yucQKtU=; b=GVdUstmFqLTFbIYq5SIJodmyykX6BKFPITsUPpepubAk2k6HLLobowbXxmpYdK9iMn030V iJ1075oW625HqudXiYtJpfExPwJ+PsJlyDJZZVttLKfBvOceRrKbf91fEuI95G5yR/aMWO yQXNYv+D3GyfkQN2Ybh1reTLDmlFT/6nL1uebgcLoCoOz+ysM1uLLqFSnWqDnfQy7nPhdq zC79/BObI9SJQPvsUwFzmCJjN6T8gujUics5X9+yLl2NeAb/PdJiOluPPuWOLD2ECSbWXA cr/pOG6Vv1/wfi44bOVkeLs2x0ez4ry+kCa8mN9o4+HYB8CGEwyxQUbOw3ltHw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698273511; a=rsa-sha256; cv=none; b=epMxjF6E7xpiLHOPo4Q9aJMFzwQoHEbDcb7V1N50joCSSdFTTvXz6QyEFWBJ7/1xVkYm4W glultkn5c0yvu68rf0xmfyZA4XW3c20E0UPySbVyIBYqkjgVK+xC3mxEzI/WyuKAlaT9CD d459L8yOLITR4lKPyzCG3UFQ7RmFlj+v5lfcKlT5GWaXR1GyyI90UHuDckbEoXJ0L3WR4W bYahIAd0sEKCn8LfhbVolOZWw7qGqR/wpfM8IxO9lADtykxDulKsnMlo9PKoueKJkAdvdV 3wQugTT+QFKB7L8aucgW/HTx5UdeI7CoymhhD/v7kXINdMZVvrp4UcG/vLeHfQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698273511; 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=4NLPWV2PkSs5Ky+jo0jDqPZpfI05kF3pp3i+yucQKtU=; b=mVgndDGWzsTc3c2qkGeSldRbDqRIlG++LYbIRS1zS9LiTe+fY1x3WeYJLRznElsPewIJmX tzg2lZkmUBLIVHV0WwGYvdNBjdkyIKdbcCVKjfg0zoPmOUb+CJRsnuhaCH32Z6yAjRZ+WV oxXGanJ32EGG3YnXZM41pMB9fPNG/pxQQYOUA6fnG8qer3UROaSMx9ui36MTzo/TSMvBdl YLhXSPSKh++5YW+QvHcA6qom1uGP8kBnFqi4DdwswWol5QALdBGyplZiVvED4edsURiLJz 46Wt1xEryIv3/jrFhpyc6RgmqsiiRCG0/vMUGYRI5ibNu9YXWiSmdRyB1Yl13A== 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 4SG3jz3YLQz1M91; Wed, 25 Oct 2023 22:38:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39PMcVM2090260; Wed, 25 Oct 2023 22:38:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39PMcVYQ090257; Wed, 25 Oct 2023 22:38:31 GMT (envelope-from git) Date: Wed, 25 Oct 2023 22:38:31 GMT Message-Id: <202310252238.39PMcVYQ090257@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: d3a36e4b7459 - main - Delete snapshot after opening it when running fsck_ffs(9) in background. 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: d3a36e4b7459b2d62c4cd50de7a8e3195d7241c7 Auto-Submitted: auto-generated The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=d3a36e4b7459b2d62c4cd50de7a8e3195d7241c7 commit d3a36e4b7459b2d62c4cd50de7a8e3195d7241c7 Author: Kirk McKusick AuthorDate: 2023-10-25 22:36:45 +0000 Commit: Kirk McKusick CommitDate: 2023-10-25 22:38:11 +0000 Delete snapshot after opening it when running fsck_ffs(9) in background. When fsck_ffs(8) runs in background, it creates a snapshot named fsck_snapshot in the filesystem's .snap directory. The fsck_snapshot file was removed when the background fsck finished. If the system crashed or the fsck exited unexpectedly, the fsck_snapshot file would remain. The snapshot would consume ever more space as the filesystem changed over time until it was removed by a system administrator or a future run of background fsck removed it to create a new snapshot file. This commit unlinks the .snap/fsck_snapshot file immediately after opening it so that it will be reclaimed when fsck closes it at the conclusion of its run. After a system crash, it will be removed as part of the filesystem cleanup because of its zero reference count. As only a few milliseconds pass between its creation and unlinking, there is far less opportunity for it to be accidentally left behind. PR: 106107 MFC-after: 1 week --- sbin/fsck_ffs/fsck.h | 1 - sbin/fsck_ffs/fsutil.c | 1 - sbin/fsck_ffs/globs.c | 2 -- sbin/fsck_ffs/main.c | 8 +++++--- sbin/fsck_ffs/setup.c | 8 ++++---- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h index 1864ea19f4ca..3b795783f39c 100644 --- a/sbin/fsck_ffs/fsck.h +++ b/sbin/fsck_ffs/fsck.h @@ -376,7 +376,6 @@ extern long secsize; /* actual disk sector size */ extern char skipclean; /* skip clean file systems if preening */ extern int snapcnt; /* number of active snapshots */ extern struct inode snaplist[FSMAXSNAP + 1]; /* list of active snapshots */ -extern char snapname[BUFSIZ]; /* when doing snapshots, the name of the file */ extern int sujrecovery; /* 1 => doing check using the journal */ extern int surrender; /* Give up if reads fail */ extern char usedsoftdep; /* just fix soft dependency inconsistencies */ diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c index 5cf17e22fe80..2583e324e94c 100644 --- a/sbin/fsck_ffs/fsutil.c +++ b/sbin/fsck_ffs/fsutil.c @@ -616,7 +616,6 @@ ckfini(int markclean) int ofsmodified, cnt, cg; if (bkgrdflag) { - unlink(snapname); if ((!(sblock.fs_flags & FS_UNCLEAN)) != markclean) { cmd.value = FS_UNCLEAN; cmd.size = markclean ? -1 : 1; diff --git a/sbin/fsck_ffs/globs.c b/sbin/fsck_ffs/globs.c index 038fc3475742..b004dd7d48b7 100644 --- a/sbin/fsck_ffs/globs.c +++ b/sbin/fsck_ffs/globs.c @@ -71,7 +71,6 @@ int freefiles[MIBSIZE]; /* MIB cmd to free a set of files */ int freedirs[MIBSIZE]; /* MIB cmd to free a set of directories */ int freeblks[MIBSIZE]; /* MIB cmd to free a set of data blocks */ struct fsck_cmd cmd; /* sysctl file system update commands */ -char snapname[BUFSIZ]; /* when doing snapshots, the name of the file */ char *cdevname; /* name of device being checked */ long dev_bsize; /* computed value of DEV_BSIZE */ long secsize; /* actual disk sector size */ @@ -144,7 +143,6 @@ fsckinit(void) bzero(freedirs, sizeof(int) * MIBSIZE); bzero(freeblks, sizeof(int) * MIBSIZE); bzero(&cmd, sizeof(struct fsck_cmd)); - bzero(snapname, sizeof(char) * BUFSIZ); cdevname = NULL; dev_bsize = 0; secsize = 0; diff --git a/sbin/fsck_ffs/main.c b/sbin/fsck_ffs/main.c index 58e184f3581f..ee39760f4dd2 100644 --- a/sbin/fsck_ffs/main.c +++ b/sbin/fsck_ffs/main.c @@ -68,7 +68,8 @@ static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/14/95"; #include "fsck.h" -static int restarts; +static int restarts; +static char snapname[BUFSIZ]; /* when doing snapshots, the name of the file */ static void usage(void) __dead2; static intmax_t argtoimax(int flag, const char *req, const char *str, int base); @@ -664,8 +665,7 @@ setup_bkgrdchk(struct statfs *mntp, int sbreadfailed, char **filesys) "SUPPORT\n"); } /* Find or create the snapshot directory */ - snprintf(snapname, sizeof snapname, "%s/.snap", - mntp->f_mntonname); + snprintf(snapname, sizeof snapname, "%s/.snap", mntp->f_mntonname); if (stat(snapname, &snapdir) < 0) { if (errno != ENOENT) { pwarn("CANNOT FIND SNAPSHOT DIRECTORY %s: %s, CANNOT " @@ -713,6 +713,8 @@ setup_bkgrdchk(struct statfs *mntp, int sbreadfailed, char **filesys) "BACKGROUND\n", snapname, strerror(errno)); return (0); } + /* Immediately unlink snapshot so that it will be deleted when closed */ + unlink(snapname); free(sblock.fs_csp); free(sblock.fs_si); if (readsb() == 0) { diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c index d1d09d07b43a..c9aa19c7eded 100644 --- a/sbin/fsck_ffs/setup.c +++ b/sbin/fsck_ffs/setup.c @@ -380,14 +380,14 @@ openfilesys(char *dev) if ((statb.st_mode & S_IFMT) != S_IFCHR && (statb.st_mode & S_IFMT) != S_IFBLK) { if (bkgrdflag != 0 && (statb.st_flags & SF_SNAPSHOT) == 0) { - pfatal("BACKGROUND FSCK LACKS A SNAPSHOT\n"); - exit(EEXIT); + pwarn("BACKGROUND FSCK LACKS A SNAPSHOT\n"); + return (0); } if (bkgrdflag != 0) { cursnapshot = statb.st_ino; } else { - pfatal("%s IS NOT A DISK DEVICE\n", dev); - if (reply("CONTINUE") == 0) + pwarn("%s IS NOT A DISK DEVICE\n", dev); + if (preen || reply("CONTINUE") == 0) return (0); } }