From owner-svn-src-head@freebsd.org Thu Oct 24 19:47:19 2019 Return-Path: Delivered-To: svn-src-head@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 898A515889C; Thu, 24 Oct 2019 19:47:19 +0000 (UTC) (envelope-from mckusick@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46zd7C346Cz4X5G; Thu, 24 Oct 2019 19:47:19 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 498B41B2B9; Thu, 24 Oct 2019 19:47:19 +0000 (UTC) (envelope-from mckusick@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9OJlJ04025606; Thu, 24 Oct 2019 19:47:19 GMT (envelope-from mckusick@FreeBSD.org) Received: (from mckusick@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9OJlJQp025605; Thu, 24 Oct 2019 19:47:19 GMT (envelope-from mckusick@FreeBSD.org) Message-Id: <201910241947.x9OJlJQp025605@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mckusick set sender to mckusick@FreeBSD.org using -f From: Kirk McKusick Date: Thu, 24 Oct 2019 19:47:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354036 - head/sys/ufs/ffs X-SVN-Group: head X-SVN-Commit-Author: mckusick X-SVN-Commit-Paths: head/sys/ufs/ffs X-SVN-Commit-Revision: 354036 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Oct 2019 19:47:19 -0000 Author: mckusick Date: Thu Oct 24 19:47:18 2019 New Revision: 354036 URL: https://svnweb.freebsd.org/changeset/base/354036 Log: Soft updates needs to keep an on-disk linked list of inodes that have been unlinked, but are still referenced by open file descriptors. These inodes cannot be freed until the final file descriptor reference has been closed. If the system crashes while they are still being referenced, these inodes and their referenced blocks need to be freed by fsck. By having them on a linked list with the head pointer in the superblock, fsck can quickly find and process them rather than having to check every inode in the filesystem to see if it is unreferenced. When updating the head pointer of this list of unlinked inodes in the superblock, the superblock check-hash was not getting updated. If the system crashed with the incorrect superblock check-hash, the superblock would appear to be corrupted. This patch ensures that the superblock check-hash is updated when updating the head pointer of the unlinked inodes list. There is no need to MFC as superblock check hashes first appeared in 13.0. Tested by: Peter Holm Sponsored by: Netflix Modified: head/sys/ufs/ffs/ffs_softdep.c Modified: head/sys/ufs/ffs/ffs_softdep.c ============================================================================== --- head/sys/ufs/ffs/ffs_softdep.c Thu Oct 24 19:18:49 2019 (r354035) +++ head/sys/ufs/ffs/ffs_softdep.c Thu Oct 24 19:47:18 2019 (r354036) @@ -9587,6 +9587,11 @@ initiate_write_sbdep(sbdep) } else fs->fs_sujfree = 0; bpfs->fs_sujfree = fs->fs_sujfree; + /* + * Because we have made changes to the superblock, we need to + * recompute its check-hash. + */ + bpfs->fs_ckhash = ffs_calc_sbhash(bpfs); } /* @@ -9665,7 +9670,7 @@ clear_unlinked_inodedep(inodedep) struct ufsmount *ump; struct inodedep *idp; struct inodedep *idn; - struct fs *fs; + struct fs *fs, *bpfs; struct buf *bp; ino_t ino; ino_t nino; @@ -9762,9 +9767,14 @@ clear_unlinked_inodedep(inodedep) */ if (pino == 0) { bcopy((caddr_t)fs, bp->b_data, (u_int)fs->fs_sbsize); - ffs_oldfscompat_write((struct fs *)bp->b_data, ump); - softdep_setup_sbupdate(ump, (struct fs *)bp->b_data, - bp); + bpfs = (struct fs *)bp->b_data; + ffs_oldfscompat_write(bpfs, ump); + softdep_setup_sbupdate(ump, bpfs, bp); + /* + * Because we may have made changes to the superblock, + * we need to recompute its check-hash. + */ + bpfs->fs_ckhash = ffs_calc_sbhash(bpfs); } else if (fs->fs_magic == FS_UFS1_MAGIC) { ((struct ufs1_dinode *)bp->b_data + ino_to_fsbo(fs, pino))->di_freelink = nino; @@ -9789,9 +9799,14 @@ clear_unlinked_inodedep(inodedep) bp = getblk(ump->um_devvp, btodb(fs->fs_sblockloc), (int)fs->fs_sbsize, 0, 0, 0); bcopy((caddr_t)fs, bp->b_data, (u_int)fs->fs_sbsize); - ffs_oldfscompat_write((struct fs *)bp->b_data, ump); - softdep_setup_sbupdate(ump, (struct fs *)bp->b_data, - bp); + bpfs = (struct fs *)bp->b_data; + ffs_oldfscompat_write(bpfs, ump); + softdep_setup_sbupdate(ump, bpfs, bp); + /* + * Because we may have made changes to the superblock, + * we need to recompute its check-hash. + */ + bpfs->fs_ckhash = ffs_calc_sbhash(bpfs); bwrite(bp); ACQUIRE_LOCK(ump); }