Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Mar 2021 00:21:25 GMT
From:      Kirk McKusick <mckusick@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 7848b25edd2a - main - Fix fsck_ffs -R finds unfixed duplicate block errors when rerunning.
Message-ID:  <202103250021.12P0LP9x034263@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=7848b25edd2a513f115de6d91f0a5a8d8fa1aa58

commit 7848b25edd2a513f115de6d91f0a5a8d8fa1aa58
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2021-03-25 00:23:33 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
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));



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103250021.12P0LP9x034263>