From patchwork Wed Feb 4 07:16:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5774771 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EC055BF440 for ; Wed, 4 Feb 2015 07:19:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 23F00202AE for ; Wed, 4 Feb 2015 07:19:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 38B2C2024F for ; Wed, 4 Feb 2015 07:19:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753477AbbBDHTv (ORCPT ); Wed, 4 Feb 2015 02:19:51 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:57071 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752239AbbBDHTt (ORCPT ); Wed, 4 Feb 2015 02:19:49 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="57098264" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Feb 2015 15:15:26 +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 t147IEb6020227 for ; Wed, 4 Feb 2015 15:18:14 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 4 Feb 2015 15:19:02 +0800 From: Qu Wenruo To: Subject: [PATCH 3/7] btrfs-progs: Allow btrfs_read_fs_root() to re-read the tree node. Date: Wed, 4 Feb 2015 15:16:47 +0800 Message-ID: <1423034213-14018-4-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1423034213-14018-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1423034213-14018-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] 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=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 With this patch, btrfs_read_fs_root() will try to re-read the tree node if it's not up to date. This will help for the tree block csum resetting function. Signed-off-by: Qu Wenruo --- disk-io.c | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/disk-io.c b/disk-io.c index cb18002..747ef15 100644 --- a/disk-io.c +++ b/disk-io.c @@ -713,20 +713,47 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root; struct rb_node *node; int ret; + int found = 0; u64 objectid = location->objectid; - if (location->objectid == BTRFS_ROOT_TREE_OBJECTID) - return fs_info->tree_root; - if (location->objectid == BTRFS_EXTENT_TREE_OBJECTID) - return fs_info->extent_root; - if (location->objectid == BTRFS_CHUNK_TREE_OBJECTID) - return fs_info->chunk_root; - if (location->objectid == BTRFS_DEV_TREE_OBJECTID) - return fs_info->dev_root; - if (location->objectid == BTRFS_CSUM_TREE_OBJECTID) - return fs_info->csum_root; - if (location->objectid == BTRFS_QUOTA_TREE_OBJECTID) - return fs_info->quota_root; + if (location->objectid == BTRFS_ROOT_TREE_OBJECTID) { + root = fs_info->tree_root; + found = 1; + } + if (location->objectid == BTRFS_EXTENT_TREE_OBJECTID) { + root = fs_info->extent_root; + found = 1; + } + if (location->objectid == BTRFS_CHUNK_TREE_OBJECTID) { + root = fs_info->chunk_root; + found = 1; + } + if (location->objectid == BTRFS_DEV_TREE_OBJECTID) { + root = fs_info->dev_root; + found = 1; + } + if (location->objectid == BTRFS_CSUM_TREE_OBJECTID) { + root = fs_info->csum_root; + found = 1; + } + if (location->objectid == BTRFS_QUOTA_TREE_OBJECTID) { + root = fs_info->quota_root; + found = 1; + } + /* + * The specified root has corruption. We should try to reread + * it since its treeblock csum may be reseted. + */ + if (found && !extent_buffer_uptodate(root->node)) { + u64 bytenr = btrfs_root_bytenr(&root->root_item); + + root->node = read_tree_block(root, bytenr, root->nodesize, 0); + if (!extent_buffer_uptodate(root->node)) { + if (IS_ERR(root->node)) + return ERR_PTR(PTR_ERR(root->node)); + return ERR_PTR(-EIO); + } + } BUG_ON(location->objectid == BTRFS_TREE_RELOC_OBJECTID || location->offset != (u64)-1);