From patchwork Wed May 28 11:20:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 4254631 X-Patchwork-Delegate: dave@jikos.cz Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 980FD9F336 for ; Wed, 28 May 2014 11:24:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA74E201FA for ; Wed, 28 May 2014 11:24:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EE45E2027D for ; Wed, 28 May 2014 11:24:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753109AbaE1LY0 (ORCPT ); Wed, 28 May 2014 07:24:26 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:21000 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752921AbaE1LYZ (ORCPT ); Wed, 28 May 2014 07:24:25 -0400 X-IronPort-AV: E=Sophos;i="4.98,927,1392134400"; d="scan'208";a="31126818" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 28 May 2014 19:21:48 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s4SBONVh029422 for ; Wed, 28 May 2014 19:24:23 +0800 Received: from wangs.fnst.cn.fujitsu.com (10.167.226.104) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.146.2; Wed, 28 May 2014 19:24:30 +0800 From: Wang Shilong To: Subject: [PATCH 2/4] Btrfs-progs: fsck: disallow partial opening if critical roots corrupted Date: Wed, 28 May 2014 19:20:39 +0800 Message-ID: <1401276041-18349-2-git-send-email-wangsl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1401276041-18349-1-git-send-email-wangsl.fnst@cn.fujitsu.com> References: <1401276041-18349-1-git-send-email-wangsl.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.104] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If btrfs tree root is corrupted, fsck will hit the following segmentation. enabling repair mode Check tree block failed, want=29376512, have=0 Check tree block failed, want=29376512, have=0 Check tree block failed, want=29376512, have=0 Check tree block failed, want=29376512, have=0 Check tree block failed, want=29376512, have=0 read block failed check_tree_block Couldn't read tree root Checking filesystem on /dev/sda9 UUID: 0e1a754d-04a5-4256-ae79-0f769751803e Critical roots corrupted, unable to fsck the FS Segmentation fault (core dumped) In btrfs_setup_all_roots(), we could tolerate some trees(extent tree, csum tree) corrupted, and we have did careful check inside that function, it will return NULL if critial roots corrupt(for example tree root). The problem is that we check @OPEN_CTREE_PARTIAL flag again after calling btrfs_setup_all_roots() which will successfully return @fs_info though critial roots corrupted. Fix this problem by removing @OPEN_CTREE_PARTIAL flag check outsize btrfs_setup_all_roots(). Signed-off-by: Wang Shilong Tested-by: Qu Wenruo --- disk-io.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/disk-io.c b/disk-io.c index 58f3f07..63e153d 100644 --- a/disk-io.c +++ b/disk-io.c @@ -1134,13 +1134,10 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, ret = btrfs_setup_all_roots(fs_info, root_tree_bytenr, flags); if (ret) - goto out_failed; + goto out_chunk; return fs_info; -out_failed: - if (flags & OPEN_CTREE_PARTIAL) - return fs_info; out_chunk: btrfs_release_all_roots(fs_info); btrfs_cleanup_all_caches(fs_info);