From patchwork Thu Mar 6 05:54:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 3781521 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 EA13DBF540 for ; Thu, 6 Mar 2014 05:56:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1D01A201D3 for ; Thu, 6 Mar 2014 05:56:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 38F56201CE for ; Thu, 6 Mar 2014 05:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751878AbaCFF4G (ORCPT ); Thu, 6 Mar 2014 00:56:06 -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 S1751124AbaCFF4D (ORCPT ); Thu, 6 Mar 2014 00:56:03 -0500 X-IronPort-AV: E=Sophos;i="4.97,598,1389715200"; d="scan'208";a="9652963" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 06 Mar 2014 13:52:09 +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 s265tv8Z010090 for ; Thu, 6 Mar 2014 13:56:00 +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 2014030613532378-441953 ; Thu, 6 Mar 2014 13:53:23 +0800 From: Wang Shilong To: linux-btrfs@vger.kernel.org Subject: [PATCH 5/5] Btrfs-progs: fsck: handle case that we can not lookup extent info Date: Thu, 6 Mar 2014 13:54:00 +0800 Message-Id: <1394085240-23520-5-git-send-email-wangsl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1394085240-23520-1-git-send-email-wangsl.fnst@cn.fujitsu.com> References: <1394085240-23520-1-git-send-email-wangsl.fnst@cn.fujitsu.com> 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:27, Serialize complete at 2014/03/06 13:53:27 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 Previously, --init-extent-tree works just because btrfs_lookup_extent_info() blindly return 0, and this make it work if there are not any *FULL BACKREF* mode in broken filesystem. It is just a coincidence that --init-extent-tree option works, let's do it in the right way firstly. For now, we have not supported to rebuild extent tree if there are any *FULL BACKREF* mode which means if there are snapshots with broken filesystem, avoid using --init-extent-tree option now. Signed-off-by: Wang Shilong --- cmds-check.c | 36 ++++++++++++++++++++++++++---------- extent-tree.c | 2 +- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index ae611d1..d1cafe1 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -52,6 +52,7 @@ static LIST_HEAD(duplicate_extents); static LIST_HEAD(delete_items); static int repair = 0; static int no_holes = 0; +static int init_extent_tree = 0; struct extent_backref { struct list_head list; @@ -3915,11 +3916,19 @@ static int run_next_block(struct btrfs_trans_handle *trans, nritems = btrfs_header_nritems(buf); - ret = btrfs_lookup_extent_info(NULL, root, bytenr, + /* + * FIXME, this only works only if we don't have any full + * backref mode. + */ + if (!init_extent_tree) { + ret = btrfs_lookup_extent_info(NULL, root, bytenr, btrfs_header_level(buf), 1, NULL, &flags); - if (ret < 0) - flags = BTRFS_BLOCK_FLAG_FULL_BACKREF; + if (ret < 0) + flags = 0; + } else { + flags = 0; + } if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) { parent = bytenr; @@ -5102,12 +5111,20 @@ static int fixup_extent_refs(struct btrfs_trans_handle *trans, int allocated = 0; u64 flags = 0; - /* remember our flags for recreating the extent */ - ret = btrfs_lookup_extent_info(NULL, info->extent_root, rec->start, - rec->max_size, rec->metadata, NULL, - &flags); - if (ret < 0) - flags = BTRFS_BLOCK_FLAG_FULL_BACKREF; + /* + * remember our flags for recreating the extent. + * FIXME, if we have cleared extent tree, we can not + * lookup extent info in extent tree. + */ + if (!init_extent_tree) { + ret = btrfs_lookup_extent_info(NULL, info->extent_root, + rec->start, rec->max_size, + rec->metadata, NULL, &flags); + if (ret < 0) + flags = 0; + } else { + flags = 0; + } path = btrfs_alloc_path(); if (!path) @@ -6438,7 +6455,6 @@ int cmd_check(int argc, char **argv) u64 num; int option_index = 0; int init_csum_tree = 0; - int init_extent_tree = 0; enum btrfs_open_ctree_flags ctree_flags = OPEN_CTREE_PARTIAL | OPEN_CTREE_EXCLUSIVE; diff --git a/extent-tree.c b/extent-tree.c index 7860d1d..7979457 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -1560,7 +1560,7 @@ again: *flags = extent_flags; out: btrfs_free_path(path); - return 0; + return ret; } int btrfs_set_block_flags(struct btrfs_trans_handle *trans,