Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1327163pxu; Mon, 23 Nov 2020 18:41:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUbFE/ZyLhy4ybRpOx+Sg9YEtAdGTsZDPOZvsmZxzCiI8588QG3PAYIKoIKsSXYZPimyO4 X-Received: by 2002:a17:906:af6b:: with SMTP id os11mr2321086ejb.270.1606185661703; Mon, 23 Nov 2020 18:41:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606185661; cv=none; d=google.com; s=arc-20160816; b=SI4HR1GicSycnHKOojpddEBnrvWl/c2BKS2gK2DmO6uKU+lFkBoiksO+sIiNSDmUgK YP3KXTXF6LLTR+8rnbnmRmxQfnvhkqcm86r5+4QQUQ/wZthPvcv1dfNo6UNZXX+q3/yX Rds1UfPUReYNKRIJYczI0sCVL3Vb02OPl8Ju0naOQTbFO2NWAnAqkBfkaEhEHPK4jNbJ Xv4zwESYnOUq7b4IY/IcJXhnBHX4eU7NErbhzPz9H5QNJt9oPh1exHt1MWWse8spdKRw 6Bx6nkLEXsnNCiJi/ojL8ZCLxWJDwiaHxwId85dfdMO0DUaoYT07GjHO1nLoktjaqY4j uTZA== 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=tCFGVyqs1zD62uEKE8+DY60oHJRZTedtt4fdTLRkNLZe8T9WfhTcSg0Kji9FTXRqaL h+LLCvHwh9VAF9NZP/KOrTcCVh1HWaC9nRiLx4kreRYs7CXgFkNcow2q493Dg+DJFLB6 4b8G8GirnL6+9bE8i8LyvF7v4GHCoUDI5XUW+SKTy8DmCc3Q6/wmsnxXJfiJI9Ivkt56 RUZq0QK9t6Xawv+BiEHE2yGQdNb+KPMhUspc1L2mVk6Lc9gZFxwshUq/wG8A/bIh7aLz ssa4cBtALkjuIHfJCnf4u0EBacoTKGG3A4wXfLBK2PPjptARYQjX19bt7WbYKoESuHsd AdjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P4JU5UZr; 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 t25si5959342eje.719.2020.11.23.18.40.38; Mon, 23 Nov 2020 18:41:01 -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=P4JU5UZr; 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 S2387682AbgKWNJs (ORCPT + 99 others); Mon, 23 Nov 2020 08:09:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:33628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732832AbgKWMsk (ORCPT ); Mon, 23 Nov 2020 07:48:40 -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 DBD352168B; Mon, 23 Nov 2020 12:48:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135688; bh=Q00tPwNHBkRAF65fZ9qVOUkTiu+Zlk3ZANn06colzNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P4JU5UZrkm45Z/k/F8u99tBLcc6UjWiQptfolwF67FmN1kzuJ6W2ccWIJY0BykvZn XdCuEnT49cpEHFTe94ewVBIhkPPiLK42+R6tnvCh9bRkbKAD9Y7sruqa+NISVGRhsZ kw5s8GBRSBYEi32qEalb0H+wX1biItqEbwxH14mE= 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.9 160/252] xfs: fix the minrecs logic when dealing with inode root child blocks Date: Mon, 23 Nov 2020 13:21:50 +0100 Message-Id: <20201123121843.311564983@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121835.580259631@linuxfoundation.org> References: <20201123121835.580259631@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