From nobody Wed Aug 24 06:50:07 2022 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 4MCGtm04xtz4ZQjj; Wed, 24 Aug 2022 06:50:08 +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 4MCGtl6kyrz3PTJ; Wed, 24 Aug 2022 06:50:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661323807; 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=LcERZ+RxCKzs+TzkCFN8bUErHzH7JMaNZTgxp6Biu3Q=; b=oF89D9/mAG2giyZNUSnNRuiJ25I7hjFWKqA3WR/Z7OR4zfLNZXLgjEiilyUOs6bQW8HkQh LdWtMCIF6i/rgtKSZ7xdhM27UFmmarTYM/GgIKpQ2zVYXiyA9z4rkGY0Ux7/T8P6Xx9fmB mJbXcFlM7+0II3P4bV+V9rWBz7fccdMBbQ+wrw9IT8+LsIJqaBjtYgehunlQIsOGaTVyRp 7FDXOwX7fWHYJUMIHrOdDxr70PGN6ksnufO2QE8oNcuEa5b5WTX+VpCrAiPbq2xGfZHrhU x7r2OXld/4UdGXZNMGScz8ZYdGwryxtNwH0azZSQDCPT7OtfgmQEerY5adMehA== 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 4MCGtl5nGlz10YB; Wed, 24 Aug 2022 06:50:07 +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 27O6o7Yr097741; Wed, 24 Aug 2022 06:50:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27O6o7wC097738; Wed, 24 Aug 2022 06:50:07 GMT (envelope-from git) Date: Wed, 24 Aug 2022 06:50:07 GMT Message-Id: <202208240650.27O6o7wC097738@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: 345bfec10905 - main - Provide cache coherency between getnextinode() and ginode() 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: 345bfec1090571ea219263c99eed29de27e143c8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661323807; 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=LcERZ+RxCKzs+TzkCFN8bUErHzH7JMaNZTgxp6Biu3Q=; b=QZFLd2nkycPnZT0h5BSMQ6f+XsLGscHrWmMxcF84aiMDy1UDMGsZ9tLQyzNOmUtn1zVFa2 5iAA8qEo3RQOtHPRWaGJkLccsAV6dZwYWx/vOOTgEtzGS8jThhQqw9BWR4ZW4csuMlJE2N gFRTfo+BVk73WEB4e+sDJ3XDMyNdnK+j4/o7sMHoz65sURrUTzsVpHpY1UQOZLtOqy6gLP U6c29E/08/C/VrlxasPd2DT3lSjCBdPCdMiCS6uvnHko0nUSaoa64V72cAhZR5IuI3DBT4 f5og7MX+AkecYYlOJiRGg2OmkRiatVlcIgmUAUeLBbkgSIMXQQVjrlrbG1r+GQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661323807; a=rsa-sha256; cv=none; b=tKuv4oQsbwYNe56X5atGXSyvu0IRoebNgKYnbmssZeFtf5WcOu9JL5s3NeMEfwRRYK6HsQ BRvkqP4iGlfkyw3E1wRSvLahiKfD/Z0E0kzs1k9DzffI5n+HQDTNZDYkmuCfrPVZLDoC+p 0KTZc1x6SQ33R2sfVp6zdViDjA7ocW5UC/+vrc+bZN//i1c4w8bz1ggJ/Gwu5+qHFb9Pn5 i8FQFvXOEf52ufj22aWzY96QzdW1g0DTeS1naKnWK9ba3q/x6xfmElKunaLgTRMlOWoEPQ ob1+HQ0hSrRsSXnyr8wDZDcZFfNlfZjrgwgRGmCEToIA8Ofzvqoi9Y6672iFwQ== 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=345bfec1090571ea219263c99eed29de27e143c8 commit 345bfec1090571ea219263c99eed29de27e143c8 Author: Kirk McKusick AuthorDate: 2022-08-24 06:48:40 +0000 Commit: Kirk McKusick CommitDate: 2022-08-24 06:48:40 +0000 Provide cache coherency between getnextinode() and ginode() The fsck_ffs(8) utility has two subsystems for reading and writing inodes. The getnextinode() interface is used in Pass 1 (and Pass 1b if needed) to sequentially walk through all the inodes in the filesystem. The ginode() interface is used to read and write individual inodes. Pass 1 uses a mix of both interfaces. This change ensures that ginode() returns a pointer to the inode in the cache maintained by getnextinode() when that interface holds the requested inode so that all modifications to the inode are made in a single place and are all written to the disk together. Reported by: Peter Holm Tested by: Peter Holm Sponsored by: The FreeBSD Foundation --- sbin/fsck_ffs/inode.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index 8a93ad092a4a..ae7124784415 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -415,21 +415,35 @@ chkrange(ufs2_daddr_t blk, int cnt) /* * General purpose interface for reading inodes. + * + * firstinum and lastinum track contents of getnextino() cache (below). */ +static ino_t firstinum, lastinum; +static struct bufarea inobuf; + void ginode(ino_t inumber, struct inode *ip) { ufs2_daddr_t iblk; + ino_t numinodes; if (inumber < UFS_ROOTINO || inumber > maxino) errx(EEXIT, "bad inode number %ju to ginode", (uintmax_t)inumber); ip->i_number = inumber; - if (icachebp != NULL && + if (inumber >= firstinum && inumber < lastinum) { + /* contents in getnextino() cache */ + ip->i_bp = &inobuf; + inobuf.b_refcnt++; + inobuf.b_index = firstinum; + numinodes = lastinum - firstinum; + } else if (icachebp != NULL && inumber >= icachebp->b_index && inumber < icachebp->b_index + INOPB(&sblock)) { /* take an additional reference for the returned inode */ icachebp->b_refcnt++; + ip->i_bp = icachebp; + numinodes = INOPB(&sblock); } else { iblk = ino_to_fsba(&sblock, inumber); /* release our cache-hold reference on old icachebp */ @@ -445,15 +459,16 @@ ginode(ino_t inumber, struct inode *ip) /* take a cache-hold reference on new icachebp */ icachebp->b_refcnt++; icachebp->b_index = rounddown(inumber, INOPB(&sblock)); + ip->i_bp = icachebp; + numinodes = INOPB(&sblock); } - ip->i_bp = icachebp; if (sblock.fs_magic == FS_UFS1_MAGIC) { ip->i_dp = (union dinode *) - &icachebp->b_un.b_dinode1[inumber % INOPB(&sblock)]; + &ip->i_bp->b_un.b_dinode1[inumber % numinodes]; return; } ip->i_dp = (union dinode *) - &icachebp->b_un.b_dinode2[inumber % INOPB(&sblock)]; + &ip->i_bp->b_un.b_dinode2[inumber % numinodes]; if (ffs_verify_dinode_ckhash(&sblock, (struct ufs2_dinode *)ip->i_dp)) { pwarn("INODE CHECK-HASH FAILED"); prtinode(ip); @@ -487,9 +502,8 @@ irelse(struct inode *ip) * Special purpose version of ginode used to optimize first pass * over all the inodes in numerical order. */ -static ino_t nextino, lastinum, lastvalidinum; +static ino_t nextinum, lastvalidinum; static long readcount, readpercg, fullcnt, inobufsize, partialcnt, partialsize; -static struct bufarea inobuf; union dinode * getnextinode(ino_t inumber, int rebuildcg) @@ -502,11 +516,12 @@ getnextinode(ino_t inumber, int rebuildcg) struct inode ip; static caddr_t nextinop; - if (inumber != nextino++ || inumber > lastvalidinum) + if (inumber != nextinum++ || inumber > lastvalidinum) errx(EEXIT, "bad inode number %ju to nextinode", (uintmax_t)inumber); if (inumber >= lastinum) { readcount++; + firstinum = lastinum; blk = ino_to_fsba(&sblock, lastinum); if (readcount % readpercg == 0) { size = partialsize; @@ -520,6 +535,9 @@ getnextinode(ino_t inumber, int rebuildcg) * If getblk encounters an error, it will already have zeroed * out the buffer, so we do not need to do so here. */ + if (inobuf.b_refcnt != 0) + pfatal("Non-zero getnextinode() ref count %d\n", + inobuf.b_refcnt); flush(fswritefd, &inobuf); getblk(&inobuf, blk, size); nextinop = inobuf.b_un.b_buf; @@ -604,7 +622,7 @@ setinodebuf(int cg, ino_t inosused) inum = cg * sblock.fs_ipg; lastvalidinum = inum + inosused - 1; - nextino = inum; + nextinum = inum; lastinum = inum; readcount = 0; /* Flush old contents in case they have been updated */ @@ -674,6 +692,7 @@ freeinodebuf(void) if (inobuf.b_un.b_buf != NULL) free((char *)inobuf.b_un.b_buf); inobuf.b_un.b_buf = NULL; + firstinum = lastinum = 0; } /*