From patchwork Thu Mar 6 05:53:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 3781511 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 599E0BF540 for ; Thu, 6 Mar 2014 05:56:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8F137201D3 for ; Thu, 6 Mar 2014 05:56:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B6B02201CE for ; Thu, 6 Mar 2014 05:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751812AbaCFF4B (ORCPT ); Thu, 6 Mar 2014 00:56:01 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:52580 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751076AbaCFF4A (ORCPT ); Thu, 6 Mar 2014 00:56:00 -0500 X-IronPort-AV: E=Sophos;i="4.97,598,1389715200"; d="scan'208";a="9652960" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 06 Mar 2014 13:52:06 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s265tv8W010090 for ; Thu, 6 Mar 2014 13:55:58 +0800 Received: from wangs.fnst.cn.fujitsu.com ([10.167.226.104]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2014030613532372-441949 ; Thu, 6 Mar 2014 13:53:23 +0800 From: Wang Shilong To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/5] Btrfs-progs: fsck: deal with really corrupted extent tree Date: Thu, 6 Mar 2014 13:53:56 +0800 Message-Id: <1394085240-23520-1-git-send-email-wangsl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.0 X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/03/06 13:53:23, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/03/06 13:53:24, Serialize complete at 2014/03/06 13:53:24 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 To reinit extent root, we need find a free extent, however, we may have a really corrupted extent tree, so we can't rely on existed extent tree to cache block group any more. During test, we fail to reinit extent tree which is because we can not find a free extent so let's make block group cache ourselves firstly. Signed-off-by: Wang Shilong --- cmds-check.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index 98199ce..3cf59b6 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -6030,11 +6030,13 @@ static int pin_metadata_blocks(struct btrfs_fs_info *fs_info) static int reset_block_groups(struct btrfs_fs_info *fs_info) { + struct btrfs_block_group_cache *cache; struct btrfs_path *path; struct extent_buffer *leaf; struct btrfs_chunk *chunk; struct btrfs_key key; int ret; + u64 start; path = btrfs_alloc_path(); if (!path) @@ -6085,8 +6087,19 @@ static int reset_block_groups(struct btrfs_fs_info *fs_info) btrfs_chunk_type(leaf, chunk), key.objectid, key.offset, btrfs_chunk_length(leaf, chunk)); + set_extent_dirty(&fs_info->free_space_cache, key.offset, + key.offset + btrfs_chunk_length(leaf, chunk), + GFP_NOFS); path->slots[0]++; } + start = 0; + while (1) { + cache = btrfs_lookup_first_block_group(fs_info, start); + if (!cache) + break; + cache->cached = 1; + start = cache->key.objectid + cache->key.offset; + } btrfs_free_path(path); return 0;