From nobody Wed Jun 07 22:35:10 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 4Qc2Gk6yM4z4bZhN; Wed, 7 Jun 2023 22:35:10 +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 4Qc2Gk6M22z4MY1; Wed, 7 Jun 2023 22:35:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686177310; 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=VbyyFD1jHmSYJSaPxzLtOcbQh/h6jojz71idngLWrN8=; b=CvqX+bsxFY1saWJ2GBWKUwEznD04BVQAGv8cqjlceGob9TPfsTw5+y2ZdkZMTzr0ZHOMjX Dim+t2QRr3DikMpYEIakd3D0PkIaJVuLFvjmd3YgFaxi6yPFs9b9OhjK/RaGbOnfn7DnwI ZGwzOiR2BIgghs+MUdUmAPBeyoy2q68T/9euLWu68GQ3S1dxoDSXoFSv9R3XCn2PqiZ+U6 APkthNhzInn2mmLaemIiKyFco5CuPuncuG+FnRw6rpvkLsdWOXKLyLZ/TAeF0ey1SoKOPJ ZFXXOTBskyH8hizdq7cZ3Jj2vFKEfu/13CS6Bydhls6lzd1SQ912BdAbSRl1QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686177310; 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=VbyyFD1jHmSYJSaPxzLtOcbQh/h6jojz71idngLWrN8=; b=AoJIWKVwGQfVyG75Ly6C0SnSwEURCESLlb+gL9kaL98eHnruxdxfXyFPuqFGk17i8oJODO SposaC8D3tkbKu9Z6o83I0Jnvfpj5zQupvny1Hh1OI/xnprjXT8Ve7XfCYd7Ty4IZi2ANO 7AWMUEXH9HWofYdwm7Nyog3jWDUG9+qsb3CK30kGUKyC5jrw0xAFfVbf5ZqifUkJGWHFbN bgv03rC2yCL1fOgGJafuI3pXbqHQAGM0BLk060hJnByo+qsz5BZbxdKmcEffBqZq3z1iPl 9gfKP9K+Q7/ZCubhe2lDNDJiu59xgCXWlU9jTzSE9DNbFTWfnFYFZWUiV66U1g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686177310; a=rsa-sha256; cv=none; b=t/u8GpMHVZN9MiGV1gUhWEVbRqGbXuw0SA4l4ZHNifFTsWfcCTaoKVjtGlSOSweSypHsxG 1QI4kJiFXZxYTmWu6MQ34k+8SnmvVgZtznD4ddO4Exrgpd2VgEEWZtAU9hgsMJwdNwE1Sm 7ycd4eNuRMkyKFxLRa170WW3muly0ZUnFYJKtLKGGr7cckseOJSfYLPBlqd31dl7u6gW7F REae2UjldeyHTtr3/6XvhV4XG6Q1JUHcDbsOfSMQ++DywVJQ//xT50X1XJ9UTmGRKeM3As ++j85m7uHCYDEmdpX4c/2bKagdEtWsr10Y0fe0krSq9ZLG3ywOML+dsZ/Nhuhg== 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 4Qc2Gk56hWzVDQ; Wed, 7 Jun 2023 22:35:10 +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 357MZAKS081839; Wed, 7 Jun 2023 22:35:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 357MZALh081838; Wed, 7 Jun 2023 22:35:10 GMT (envelope-from git) Date: Wed, 7 Jun 2023 22:35:10 GMT Message-Id: <202306072235.357MZALh081838@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: 007322a94cee - stable/13 - Add the ability to adjust directory depths to background fsck_ffs(8). 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: 007322a94ceeca654c3bb3bf1fdf6e2bea30d683 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=007322a94ceeca654c3bb3bf1fdf6e2bea30d683 commit 007322a94ceeca654c3bb3bf1fdf6e2bea30d683 Author: Kirk McKusick AuthorDate: 2023-05-26 02:27:04 +0000 Commit: Kirk McKusick CommitDate: 2023-06-07 22:34:39 +0000 Add the ability to adjust directory depths to background fsck_ffs(8). Sponsored by: The FreeBSD Foundation (cherry picked from commit e4a905d1e0d94ddb8e15de50d37e67f13e058047) --- sbin/fsck_ffs/dir.c | 26 +++++++++++++++++++++----- sbin/fsck_ffs/fsck.h | 1 + sbin/fsck_ffs/globs.c | 2 ++ sys/ufs/ffs/ffs_alloc.c | 28 ++++++++++++++++++++++++++++ sys/ufs/ffs/fs.h | 3 ++- 5 files changed, 54 insertions(+), 6 deletions(-) diff --git a/sbin/fsck_ffs/dir.c b/sbin/fsck_ffs/dir.c index cc5305c390a4..e5f0e1e7e7f4 100644 --- a/sbin/fsck_ffs/dir.c +++ b/sbin/fsck_ffs/dir.c @@ -105,6 +105,7 @@ check_dirdepth(struct inoinfo *inp) struct inode ip; union dinode *dp; int saveresolved; + size_t size; static int updateasked, dirdepthupdate; if ((parentinp = getinoinfo(inp->i_parent)) == NULL) { @@ -141,9 +142,11 @@ check_dirdepth(struct inoinfo *inp) } } /* - * If we are not converting, nothing more to do. + * If we are not converting or we are running in no-write mode + * there is nothing more to do. */ - if (inp->i_depth == 0 && dirdepthupdate == 0) + if ((inp->i_depth == 0 && dirdepthupdate == 0) || + (fswritefd < 0 && bkgrdflag == 0)) return; /* * Individual directory at wrong depth. Report it and correct if @@ -174,8 +177,20 @@ check_dirdepth(struct inoinfo *inp) printf(" (ADJUSTED)\n"); } inp->i_depth = parentinp->i_depth + 1; - DIP_SET(dp, di_dirdepth, inp->i_depth); - inodirty(&ip); + if (bkgrdflag == 0) { + DIP_SET(dp, di_dirdepth, inp->i_depth); + inodirty(&ip); + } else { + cmd.value = inp->i_number; + cmd.size = (int64_t)inp->i_depth - DIP(dp, di_dirdepth); + if (debug) + printf("adjdepth ino %ld amt %jd\n", (long)cmd.value, + (intmax_t)cmd.size); + size = MIBSIZE; + if (sysctlnametomib("vfs.ffs.adjdepth", adjdepth, &size) < 0 || + sysctl(adjdepth, MIBSIZE, 0, 0, &cmd, sizeof cmd) == -1) + rwerror("ADJUST INODE DEPTH", cmd.value); + } irelse(&ip); } @@ -506,7 +521,8 @@ adjust(struct inodesc *idesc, int lcnt) (long long)cmd.size); if (sysctl(adjrefcnt, MIBSIZE, 0, 0, &cmd, sizeof cmd) == -1) - rwerror("ADJUST INODE", cmd.value); + rwerror("ADJUST INODE LINK COUNT", + cmd.value); } } } diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h index 4e5878b0b12f..9f9b1e0a8857 100644 --- a/sbin/fsck_ffs/fsck.h +++ b/sbin/fsck_ffs/fsck.h @@ -333,6 +333,7 @@ extern int adjnbfree[MIBSIZE]; /* MIB cmd to adjust number of free blocks */ extern int adjnifree[MIBSIZE]; /* MIB cmd to adjust number of free inodes */ extern int adjnffree[MIBSIZE]; /* MIB cmd to adjust number of free frags */ extern int adjnumclusters[MIBSIZE]; /* MIB cmd adjust number of free clusters */ +extern int adjdepth[MIBSIZE]; /* MIB cmd to adjust directory depth count */ extern int freefiles[MIBSIZE]; /* MIB cmd to free a set of files */ extern int freedirs[MIBSIZE]; /* MIB cmd to free a set of directories */ extern int freeblks[MIBSIZE]; /* MIB cmd to free a set of data blocks */ diff --git a/sbin/fsck_ffs/globs.c b/sbin/fsck_ffs/globs.c index 92e77b61f9d4..2340636fe3a9 100644 --- a/sbin/fsck_ffs/globs.c +++ b/sbin/fsck_ffs/globs.c @@ -68,6 +68,7 @@ int adjnbfree[MIBSIZE]; /* MIB command to adjust number of free blocks */ int adjnifree[MIBSIZE]; /* MIB command to adjust number of free inodes */ int adjnffree[MIBSIZE]; /* MIB command to adjust number of free frags */ int adjnumclusters[MIBSIZE]; /* MIB command to adjust number of free clusters */ +int adjdepth[MIBSIZE]; /* MIB cmd to adjust directory depth count */ int freefiles[MIBSIZE]; /* MIB command to free a set of files */ int freedirs[MIBSIZE]; /* MIB command to free a set of directories */ int freeblks[MIBSIZE]; /* MIB command to free a set of data blocks */ @@ -141,6 +142,7 @@ fsckinit(void) bzero(adjnifree, sizeof(int) * MIBSIZE); bzero(adjnffree, sizeof(int) * MIBSIZE); bzero(adjnumclusters, sizeof(int) * MIBSIZE); + bzero(adjdepth, sizeof(int) * MIBSIZE); bzero(freefiles, sizeof(int) * MIBSIZE); bzero(freedirs, sizeof(int) * MIBSIZE); bzero(freeblks, sizeof(int) * MIBSIZE); diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index 6d37afcfadf6..195ba9f8a299 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -3108,6 +3108,8 @@ ffs_fserr(struct fs *fs, * the count to zero will cause the inode to be freed. * adjblkcnt(inode, amt) - adjust the number of blocks used by the * inode by the specified amount. + * adjdepth(inode, amt) - adjust the depth of the specified directory + * inode by the specified amount. * setsize(inode, size) - set the size of the inode to the * specified size. * adjndir, adjbfree, adjifree, adjffree, adjnumclusters(amt) - @@ -3142,6 +3144,10 @@ static SYSCTL_NODE(_vfs_ffs, FFS_ADJ_BLKCNT, adjblkcnt, CTLFLAG_WR | CTLFLAG_NEEDGIANT, sysctl_ffs_fsck, "Adjust Inode Used Blocks Count"); +static SYSCTL_NODE(_vfs_ffs, FFS_ADJ_DEPTH, adjdepth, + CTLFLAG_WR | CTLFLAG_NEEDGIANT, sysctl_ffs_fsck, + "Adjust Directory Inode Depth"); + static SYSCTL_NODE(_vfs_ffs, FFS_SET_SIZE, setsize, CTLFLAG_WR | CTLFLAG_NEEDGIANT, sysctl_ffs_fsck, "Set the inode size"); @@ -3299,6 +3305,28 @@ sysctl_ffs_fsck(SYSCTL_HANDLER_ARGS) vput(vp); break; + case FFS_ADJ_DEPTH: +#ifdef DIAGNOSTIC + if (fsckcmds) { + printf("%s: adjust directory inode %jd depth by %jd\n", + mp->mnt_stat.f_mntonname, (intmax_t)cmd.value, + (intmax_t)cmd.size); + } +#endif /* DIAGNOSTIC */ + if ((error = ffs_vget(mp, (ino_t)cmd.value, LK_EXCLUSIVE, &vp))) + break; + if (vp->v_type != VDIR) { + vput(vp); + error = ENOTDIR; + break; + } + ip = VTOI(vp); + DIP_SET(ip, i_dirdepth, DIP(ip, i_dirdepth) + cmd.size); + UFS_INODE_SET_FLAG(ip, IN_CHANGE | IN_MODIFIED); + error = ffs_update(vp, 1); + vput(vp); + break; + case FFS_SET_SIZE: #ifdef DIAGNOSTIC if (fsckcmds) { diff --git a/sys/ufs/ffs/fs.h b/sys/ufs/ffs/fs.h index b2ed2051471c..70e24242b01b 100644 --- a/sys/ufs/ffs/fs.h +++ b/sys/ufs/ffs/fs.h @@ -224,7 +224,8 @@ /* Was FFS_SET_INODE 15 */ /* Was FFS_SET_BUFOUTPUT 16 */ #define FFS_SET_SIZE 17 /* set inode size */ -#define FFS_MAXID 17 /* number of valid ffs ids */ +#define FFS_ADJ_DEPTH 18 /* adjust directory inode depth */ +#define FFS_MAXID 18 /* number of valid ffs ids */ /* * Command structure passed in to the filesystem to adjust filesystem values.