From owner-dev-commits-src-all@freebsd.org Thu Mar 25 00:21:25 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 536B457CB74; Thu, 25 Mar 2021 00:21:25 +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 4F5Qks1rLCz3js3; Thu, 25 Mar 2021 00:21:25 +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 322A11D6CA; Thu, 25 Mar 2021 00:21:25 +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 12P0LPCi034264; Thu, 25 Mar 2021 00:21:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 12P0LP9x034263; Thu, 25 Mar 2021 00:21:25 GMT (envelope-from git) Date: Thu, 25 Mar 2021 00:21:25 GMT Message-Id: <202103250021.12P0LP9x034263@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: 7848b25edd2a - main - Fix fsck_ffs -R finds unfixed duplicate block errors when rerunning. 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: 7848b25edd2a513f115de6d91f0a5a8d8fa1aa58 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Mar 2021 00:21:25 -0000 The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=7848b25edd2a513f115de6d91f0a5a8d8fa1aa58 commit 7848b25edd2a513f115de6d91f0a5a8d8fa1aa58 Author: Kirk McKusick AuthorDate: 2021-03-25 00:23:33 +0000 Commit: Kirk McKusick CommitDate: 2021-03-25 00:24:41 +0000 Fix fsck_ffs -R finds unfixed duplicate block errors when rerunning. This fixes a long-standing but very obscure bug in fsck_ffs when it is run with the -R (rerun after unexpected errors). It only occurs if fsck_ffs finds duplicate blocks and they are all contained in inodes that reside in the first block of inodes (typically among the first 128 inodes). Rather than use the usual ginode() interface to walk through the inodes in pass1, there is a special optimized `getnextinode()' routine for walking through all the inodes. It has its own private buffer for reading the inode blocks. If pass 1 finds duplicate blocks it runs pass 1b to find all the inodes that contain these duplicate blocks. Pass 1b also uses the `getnextinode()' to search for the inodes with duplicate blocks. Pass 1b stops when all the duplicate blocks have been found. If all the duplicate blocks are found in the first block of inodes, then the getnextinode cache holds this block of bad inodes. The subsequent cleanup of the inodes in passes 2-5 is done using ginode() which uses the regular fsck_ffs cache. When fsck_ffs restarts, pass1() calls setinodebuf() to point at the first block of inodes. When it calls getnextinode() to get inode 2, getnextino() sees that its private cache already has the first set of inodes loaded and starts using them. They are of course the trashed inodes left over from the previous run of pass1b(). The fix is to always invalidate the getnextinode cache when calling setinodebuf(). Reported by: Chuck Silvers Tested by: Chuck Silvers MFC after: 3 days Sponsored by: Netflix --- sbin/fsck_ffs/inode.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index 60019425c825..020a69dd72f8 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -600,6 +600,9 @@ setinodebuf(int cg, ino_t inosused) nextino = inum; lastinum = inum; readcount = 0; + /* Flush old contents in case they have been updated */ + flush(fswritefd, &inobuf); + inobuf.b_bno = 0; if (inobuf.b_un.b_buf == NULL) { inobufsize = blkroundup(&sblock, MAX(INOBUFSIZE, sblock.fs_bsize));