From patchwork Thu Mar 6 05:53:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 3781541 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 4D74A9F375 for ; Thu, 6 Mar 2014 05:56:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 89756201CE for ; Thu, 6 Mar 2014 05:56:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 05786201DC for ; Thu, 6 Mar 2014 05:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751831AbaCFF4E (ORCPT ); Thu, 6 Mar 2014 00:56:04 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:19939 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751076AbaCFF4C (ORCPT ); Thu, 6 Mar 2014 00:56:02 -0500 X-IronPort-AV: E=Sophos;i="4.97,598,1389715200"; d="scan'208";a="9652962" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 06 Mar 2014 13:52:08 +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 s265tv8Y010090 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 2014030613532375-441951 ; Thu, 6 Mar 2014 13:53:23 +0800 From: Wang Shilong To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/5] Btrfs-progs: fsck: insert root dir into reloc data tree when reiniting it Date: Thu, 6 Mar 2014 13:53:58 +0800 Message-Id: <1394085240-23520-3-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:26, Serialize complete at 2014/03/06 13:53:26 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 There are two bugs when resetting balance: 1.we will skip reinitting reloc data tree if no reloc root found, however this is not right because we don't pin reloc data tree before. 2.we should insert root dir into reloc data tree,otherwise we will fail to fsck. Fix problems by forcely reiniting reloc data root and inserting root dir. Signed-off-by: Wang Shilong --- cmds-check.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmds-check.c b/cmds-check.c index 8a3f2cd..4b2a8f0 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -6128,7 +6128,10 @@ static int reset_balance(struct btrfs_trans_handle *trans, if (ret) { if (ret > 0) ret = 0; - goto out; + if (!ret) + goto reinit_data_reloc; + else + goto out; } ret = btrfs_del_item(trans, root, path); @@ -6190,6 +6193,7 @@ static int reset_balance(struct btrfs_trans_handle *trans, } btrfs_release_path(path); +reinit_data_reloc: key.objectid = BTRFS_DATA_RELOC_TREE_OBJECTID; key.type = BTRFS_ROOT_ITEM_KEY; key.offset = (u64)-1; @@ -6205,6 +6209,9 @@ static int reset_balance(struct btrfs_trans_handle *trans, extent_buffer_get(root->node); } ret = btrfs_fsck_reinit_root(trans, root, 0); + if (ret) + goto out; + ret = btrfs_make_root_dir(trans, root, BTRFS_FIRST_FREE_OBJECTID); out: btrfs_free_path(path); return ret;