From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A26ECC43387 for ; Tue, 15 Jan 2019 17:02:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 634D620675 for ; Tue, 15 Jan 2019 17:02:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547571722; bh=AFph+3DnTGJ8KVB6uAkRLpjnK2AhBmxFoO9KX+bRHBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=H2czhG70brSg2/h178ULu3FbwG3z4oBrMlr7OkS/P/1wkkKYrbAPu8pQUfiUbcQ29 /xF7NIRj0oWQHe9m5lRl1OSgkscVWgaliFQ25GN1MBc+yGCbJQR1uN+HW1XloeiF+A +abJbOb+iHZ1Ht7oGEcicbr6U3oYk6bE1/ewv5Ho= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731766AbfAOQhO (ORCPT ); Tue, 15 Jan 2019 11:37:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:52592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731776AbfAOQhM (ORCPT ); Tue, 15 Jan 2019 11:37:12 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 47B3A20859; Tue, 15 Jan 2019 16:37:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547570231; bh=AFph+3DnTGJ8KVB6uAkRLpjnK2AhBmxFoO9KX+bRHBI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VqQ9K8q0FEMvcDE0gyhFwcjVkXB4EljHk8JjjAPT8+FRw0wF5TkzJKc7AloAPzoKB SbWHCPSrQ6OTu03XehanXAtVhswZi5aXRwlZxlNYCs6AzaJBdm3+ZWSyVUc7yP+xEw JV7zQoBHDc+hFDTHMDMQbfmdjlRJVi9LilkGggD4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liu Bo , David Sterba , Ben Hutchings Subject: [PATCH 4.4 05/51] Btrfs: check inconsistence between chunk and block group Date: Tue, 15 Jan 2019 17:35:01 +0100 Message-Id: <20190115154847.722648865@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190115154846.928796000@linuxfoundation.org> References: <20190115154846.928796000@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Liu Bo commit 6fb37b756acce6d6e045f79c3764206033f617b4 upstream. With btrfs-corrupt-block, one can drop one chunk item and mounting will end up with a panic in btrfs_full_stripe_len(). This doesn't not remove the BUG_ON, but instead checks it a bit earlier when we find the block group item. Signed-off-by: Liu Bo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/extent-tree.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -9502,7 +9502,22 @@ static int find_first_block_group(struct if (found_key.objectid >= key->objectid && found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) { - ret = 0; + struct extent_map_tree *em_tree; + struct extent_map *em; + + em_tree = &root->fs_info->mapping_tree.map_tree; + read_lock(&em_tree->lock); + em = lookup_extent_mapping(em_tree, found_key.objectid, + found_key.offset); + read_unlock(&em_tree->lock); + if (!em) { + btrfs_err(root->fs_info, + "logical %llu len %llu found bg but no related chunk", + found_key.objectid, found_key.offset); + ret = -ENOENT; + } else { + ret = 0; + } goto out; } path->slots[0]++;