Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1238994pxu; Mon, 23 Nov 2020 15:37:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRMRtJXdvcnh247S77gygEAur1Of2p8/tCc4v0rSSCrDL9tdX2Ncd4vQKp1ek14WZnczpU X-Received: by 2002:aa7:c889:: with SMTP id p9mr1495548eds.110.1606174676710; Mon, 23 Nov 2020 15:37:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606174676; cv=none; d=google.com; s=arc-20160816; b=kg9630aP8ZLVhMPLAogMzKTzUrRnr8/YrKJzHbFyCeO3fCq7nSW4lgvrvBsVbYSlhf 1GC9i28w/D822x4HgS1efMwE9cVvR/uWn3K0Uj1N2lJ/sK1KqFrW/NtUeOp5eQC+s7Dd ZEl3tqx/Wyz94sLm+pLV+suOOMrexg79v+Ifu2yV1vj+Q9GaA9pS6+RGM9yNYIjc199u 6XvUoRRV3KAMvZPU6isksEYg6Up5xTyJDXBAxASsBngnSM6111dDdd0jc3m2QsilNqps o16MBPrwzFXFC87kkLVEYkHntAy7Fnzt9umNu+Q6tefKiPRkZGZMNbQhIbH36WP++0Ag miFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7O4VmGwhfX+q9IDVi4KpmVfWpNrei1h7pYjfiGRr210=; b=F9Db0jU6WxpuGc/B7I4VphTF56NBuNItOScL73mQgjBA12G93ifrNMPH5rrWz4p84A Xfd0xeLWGi30efURLSs/xYGlynq3xjpJvBVOf4bea/CIczGGtpmdEqYlZtHOK5ijrGvk FIyOyqahGesLX275LQ82fuAqqejJLhlR3tGXZTRpvnsU0qNR0HX9Y/OgC5J8yilqzdaV TC9uNXhQg2q+E/A0PhGEfV+ZVmOfEMrpd6ejO4ejoL8R00mZBGSymMosQ+9EDdjsCS6Q do+jhQucpIVVpZSKflnd2yZbWZ8yl0u6QnF1g3skKxaJyT3lcwc8E8eRJi78pkmnoJpy 7w0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="jwIcJu/8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y23si7237080eju.563.2020.11.23.15.37.34; Mon, 23 Nov 2020 15:37:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="jwIcJu/8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732110AbgKWMif (ORCPT + 99 others); Mon, 23 Nov 2020 07:38:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:50602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732063AbgKWMiK (ORCPT ); Mon, 23 Nov 2020 07:38:10 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 498992065E; Mon, 23 Nov 2020 12:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135089; bh=Q00tPwNHBkRAF65fZ9qVOUkTiu+Zlk3ZANn06colzNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jwIcJu/8T9+ga+0Y9YZ/TsdGul+wCUXVlZMy6nx7mapk//CRDoVzCn11cSzZD43AO poxHRJ61Gcc1glDzcRHh7Qtd14dFeWwcxNMTv/aLmu1QvsVkYfHblbAE5ytaR/gEtJ tLnRWQMGVFejioQziMtn86rN+EmW0usz/gHE1udg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Chandan Babu R , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.4 101/158] xfs: fix the minrecs logic when dealing with inode root child blocks Date: Mon, 23 Nov 2020 13:22:09 +0100 Message-Id: <20201123121824.806829580@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Darrick J. Wong [ Upstream commit e95b6c3ef1311dd7b20467d932a24b6d0fd88395 ] The comment and logic in xchk_btree_check_minrecs for dealing with inode-rooted btrees isn't quite correct. While the direct children of the inode root are allowed to have fewer records than what would normally be allowed for a regular ondisk btree block, this is only true if there is only one child block and the number of records don't fit in the inode root. Fixes: 08a3a692ef58 ("xfs: btree scrub should check minrecs") Signed-off-by: Darrick J. Wong Reviewed-by: Chandan Babu R Reviewed-by: Christoph Hellwig Signed-off-by: Sasha Levin --- fs/xfs/scrub/btree.c | 45 ++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/fs/xfs/scrub/btree.c b/fs/xfs/scrub/btree.c index f52a7b8256f96..debf392e05156 100644 --- a/fs/xfs/scrub/btree.c +++ b/fs/xfs/scrub/btree.c @@ -452,32 +452,41 @@ xchk_btree_check_minrecs( int level, struct xfs_btree_block *block) { - unsigned int numrecs; - int ok_level; - - numrecs = be16_to_cpu(block->bb_numrecs); + struct xfs_btree_cur *cur = bs->cur; + unsigned int root_level = cur->bc_nlevels - 1; + unsigned int numrecs = be16_to_cpu(block->bb_numrecs); /* More records than minrecs means the block is ok. */ - if (numrecs >= bs->cur->bc_ops->get_minrecs(bs->cur, level)) + if (numrecs >= cur->bc_ops->get_minrecs(cur, level)) return; /* - * Certain btree blocks /can/ have fewer than minrecs records. Any - * level greater than or equal to the level of the highest dedicated - * btree block are allowed to violate this constraint. - * - * For a btree rooted in a block, the btree root can have fewer than - * minrecs records. If the btree is rooted in an inode and does not - * store records in the root, the direct children of the root and the - * root itself can have fewer than minrecs records. + * For btrees rooted in the inode, it's possible that the root block + * contents spilled into a regular ondisk block because there wasn't + * enough space in the inode root. The number of records in that + * child block might be less than the standard minrecs, but that's ok + * provided that there's only one direct child of the root. */ - ok_level = bs->cur->bc_nlevels - 1; - if (bs->cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) - ok_level--; - if (level >= ok_level) + if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && + level == cur->bc_nlevels - 2) { + struct xfs_btree_block *root_block; + struct xfs_buf *root_bp; + int root_maxrecs; + + root_block = xfs_btree_get_block(cur, root_level, &root_bp); + root_maxrecs = cur->bc_ops->get_dmaxrecs(cur, root_level); + if (be16_to_cpu(root_block->bb_numrecs) != 1 || + numrecs <= root_maxrecs) + xchk_btree_set_corrupt(bs->sc, cur, level); return; + } - xchk_btree_set_corrupt(bs->sc, bs->cur, level); + /* + * Otherwise, only the root level is allowed to have fewer than minrecs + * records or keyptrs. + */ + if (level < root_level) + xchk_btree_set_corrupt(bs->sc, cur, level); } /* -- 2.27.0