From patchwork Thu Mar 6 05:53:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 3781551 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 296289F369 for ; Thu, 6 Mar 2014 05:56:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 606F8201D3 for ; Thu, 6 Mar 2014 05:56:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 88A87201CE for ; Thu, 6 Mar 2014 05:56:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751885AbaCFF4M (ORCPT ); Thu, 6 Mar 2014 00:56:12 -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 S1751820AbaCFF4E (ORCPT ); Thu, 6 Mar 2014 00:56:04 -0500 X-IronPort-AV: E=Sophos;i="4.97,598,1389715200"; d="scan'208";a="9652965" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 06 Mar 2014 13:52:10 +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 s265txX3010095 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 2014030613532377-441952 ; Thu, 6 Mar 2014 13:53:23 +0800 From: Wang Shilong To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/5] Btrfs-progs: fsck: force to udate tree root for some cases Date: Thu, 6 Mar 2014 13:53:59 +0800 Message-Id: <1394085240-23520-4-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 commit roots won't update root item in tree root if it finds updated root's bytenr is same as before. However, this is not right for fsck, we need update tree root in the following case: 1.overwrite previous root node. 2.reinit reloc data tree, this is because we skip pin relo data tree before which means we can allocate same block as before. Fix this by updating tree root ourselves for the above cases. Signed-off-by: Wang Shilong --- cmds-check.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cmds-check.c b/cmds-check.c index 4b2a8f0..ae611d1 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -5906,6 +5906,7 @@ static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans, struct extent_buffer *c; struct extent_buffer *old = root->node; int level; + int ret; struct btrfs_disk_key disk_key = {0,0,0}; level = 0; @@ -5922,6 +5923,7 @@ static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans, if (IS_ERR(c)) { c = old; extent_buffer_get(c); + overwrite = 1; } init: memset_extent_buffer(c, 0, 0, sizeof(struct btrfs_header)); @@ -5939,7 +5941,26 @@ init: BTRFS_UUID_SIZE); btrfs_mark_buffer_dirty(c); - + /* + * this case can happen in the following case: + * + * 1.overwrite previous root. + * + * 2.reinit reloc data root, this is because we skip pin + * down reloc data tree before which means we can allocate + * same block bytenr here. + */ + if (old->start == c->start) { + btrfs_set_root_generation(&root->root_item, + trans->transid); + root->root_item.level = btrfs_header_level(root->node); + ret = btrfs_update_root(trans, root->fs_info->tree_root, + &root->root_key, &root->root_item); + if (ret) { + free_extent_buffer(c); + return ret; + } + } free_extent_buffer(old); root->node = c; add_root_to_dirty_list(root);