From patchwork Wed May 28 11:20:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 4254641 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 848C69F358 for ; Wed, 28 May 2014 11:24:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A3C43201FA for ; Wed, 28 May 2014 11:24:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CBB7120212 for ; Wed, 28 May 2014 11:24:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753116AbaE1LY2 (ORCPT ); Wed, 28 May 2014 07:24:28 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:42230 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753106AbaE1LY1 (ORCPT ); Wed, 28 May 2014 07:24:27 -0400 X-IronPort-AV: E=Sophos;i="4.98,927,1392134400"; d="scan'208";a="31126820" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 28 May 2014 19:21:50 +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 s4SBOPUS029428 for ; Wed, 28 May 2014 19:24:25 +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:32 +0800 From: Wang Shilong To: Subject: [PATCH 4/4] Btrfs-progs: fsck: fix wrong check for btrfs_read_fs_root() Date: Wed, 28 May 2014 19:20:41 +0800 Message-ID: <1401276041-18349-4-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 When encountering a corrupted fs root node, fsck hit following message: Check tree block failed, want=29360128, have=0 Check tree block failed, want=29360128, have=0 Check tree block failed, want=29360128, have=0 Check tree block failed, want=29360128, have=0 Check tree block failed, want=29360128, have=0 read block failed check_tree_block Checking filesystem on /dev/sda9 UUID: 0d295d80-bae2-45f2-a106-120dbfd0e173 checking extents Segmentation fault (core dumped) This is because in btrfs_setup_all_roots(), we check btrfs_read_fs_root() return value by verifing whether it is NULL pointer, this is wrong since btrfs_read_fs_root() return PTR_ERR(ret), fix it. Signed-off-by: Wang Shilong --- btrfs-calc-size.c | 2 +- disk-io.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/btrfs-calc-size.c b/btrfs-calc-size.c index a832ee0..5eabdfc 100644 --- a/btrfs-calc-size.c +++ b/btrfs-calc-size.c @@ -326,7 +326,7 @@ static int calc_root_size(struct btrfs_root *tree_root, struct btrfs_key *key, int size_fail = 0; root = btrfs_read_fs_root(tree_root->fs_info, key); - if (!root) { + if (IS_ERR(root)) { fprintf(stderr, "Failed to read root %Lu\n", key->objectid); return 1; } diff --git a/disk-io.c b/disk-io.c index bbfd8e7..c1c5b70 100644 --- a/disk-io.c +++ b/disk-io.c @@ -946,7 +946,7 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr, key.offset = (u64)-1; fs_info->fs_root = btrfs_read_fs_root(fs_info, &key); - if (!fs_info->fs_root) + if (IS_ERR(fs_info->fs_root)) return -EIO; return 0; }