From patchwork Thu May 29 09:59:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 4263761 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 A69339F485 for ; Thu, 29 May 2014 10:03:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CF870201FA for ; Thu, 29 May 2014 10:03:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EEC0720306 for ; Thu, 29 May 2014 10:03:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756539AbaE2KDd (ORCPT ); Thu, 29 May 2014 06:03:33 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:20719 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1756558AbaE2KDc (ORCPT ); Thu, 29 May 2014 06:03:32 -0400 X-IronPort-AV: E=Sophos;i="4.98,933,1392134400"; d="scan'208";a="31187225" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 29 May 2014 18:00:56 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s4TA3Ujc005185 for ; Thu, 29 May 2014 18:03:31 +0800 Received: from wangs.fnst.cn.fujitsu.com (10.167.226.104) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.146.2; Thu, 29 May 2014 18:03:30 +0800 From: Wang Shilong To: Subject: [PATCH v2 3/4] Btrfs-progs: fsck: deal with corrupted csum root Date: Thu, 29 May 2014 17:59:57 +0800 Message-ID: <1401357597-9494-2-git-send-email-wangsl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1401357597-9494-1-git-send-email-wangsl.fnst@cn.fujitsu.com> References: <1401357597-9494-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 checksum root is corrupted, fsck will get segmentation. This is because if we fail to load checksum root, root's node is NULL which cause NULL pointer deferences later. To fix this problem, we just did something like extent tree rebuilding. Allocate a new one and clear uptodate flag. We will do sanity check before fsck going on. Signed-off-by: Wang Shilong --- v1->v2: fix typo for output message. --- cmds-check.c | 5 +++++ disk-io.c | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index 0e4e042..ad5514e 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -6963,6 +6963,11 @@ int cmd_check(int argc, char **argv) ret = -EIO; goto close_out; } + if (!extent_buffer_uptodate(info->csum_root->node)) { + fprintf(stderr, "Checksum root corrupted, rerun with --init-csum-tree option\n"); + ret = -EIO; + goto close_out; + } fprintf(stderr, "checking extents\n"); ret = check_chunks_and_extents(root); diff --git a/disk-io.c b/disk-io.c index 63e153d..bbfd8e7 100644 --- a/disk-io.c +++ b/disk-io.c @@ -914,6 +914,13 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr, printk("Couldn't setup csum tree\n"); if (!(flags & OPEN_CTREE_PARTIAL)) return -EIO; + /* do the same thing as extent tree rebuilding */ + fs_info->csum_root->node = + btrfs_find_create_tree_block(fs_info->extent_root, 0, + leafsize); + if (!fs_info->csum_root->node) + return -ENOMEM; + clear_extent_buffer_uptodate(NULL, fs_info->csum_root->node); } fs_info->csum_root->track_dirty = 1;