From patchwork Mon Jan 19 06:45:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5654991 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 2A418C058D for ; Mon, 19 Jan 2015 06:55:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5A3F5202B8 for ; Mon, 19 Jan 2015 06:55:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 729A8202A1 for ; Mon, 19 Jan 2015 06:55:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751494AbbASGrW (ORCPT ); Mon, 19 Jan 2015 01:47:22 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:52325 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751450AbbASGrV (ORCPT ); Mon, 19 Jan 2015 01:47:21 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="56253737" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 19 Jan 2015 14:43:51 +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 t0J6kfbJ022566 for ; Mon, 19 Jan 2015 14:46:41 +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; Mon, 19 Jan 2015 14:47:21 +0800 From: Qu Wenruo To: Subject: [PATCH v2 03/10] btrfs-progs: Add new btrfs_open_ctree_flags CHUNK_ONLY. Date: Mon, 19 Jan 2015 14:45:05 +0800 Message-ID: <1421649912-14539-4-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1421649912-14539-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1421649912-14539-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 Add new flag CHUNK_ONLY and internal used only flag __RETURN_CHUNK. CHUNK_ONLY will imply __RETURN_CHUNK, SUPPRESS_ERROR and PARTIAL, which will allow the fs to be opened with only chunk tree OK. This will improve the usability for btrfs-find-root. Signed-off-by: Qu Wenruo --- disk-io.c | 6 +++++- disk-io.h | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/disk-io.c b/disk-io.c index f08f612..71ca31f 100644 --- a/disk-io.c +++ b/disk-io.c @@ -1167,7 +1167,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, BTRFS_UUID_SIZE); ret = btrfs_setup_all_roots(fs_info, root_tree_bytenr, flags); - if (ret) + if (ret && !(flags & __RETURN_CHUNK_ROOT)) goto out_chunk; return fs_info; @@ -1212,6 +1212,8 @@ struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, info = open_ctree_fs_info(filename, sb_bytenr, 0, flags); if (!info) return NULL; + if (flags & __RETURN_CHUNK_ROOT) + return info->chunk_root; return info->fs_root; } @@ -1222,6 +1224,8 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr, info = __open_ctree_fd(fp, path, sb_bytenr, 0, flags); if (!info) return NULL; + if (flags & __RETURN_CHUNK_ROOT) + return info->chunk_root; return info->fs_root; } diff --git a/disk-io.h b/disk-io.h index 90ede6b..2d23cc3 100644 --- a/disk-io.h +++ b/disk-io.h @@ -34,6 +34,15 @@ enum btrfs_open_ctree_flags { OPEN_CTREE_NO_BLOCK_GROUPS = (1 << 5), OPEN_CTREE_EXCLUSIVE = (1 << 6), OPEN_CTREE_SUPPRESS_ERROR = (1 << 7), /* Suppress csum error */ + __RETURN_CHUNK_ROOT = (1 << 8), /* Return chunk root */ + OPEN_CTREE_CHUNK_ONLY = OPEN_CTREE_PARTIAL + + OPEN_CTREE_SUPPRESS_ERROR + + __RETURN_CHUNK_ROOT, + /* + * TODO: cleanup: Split the open_ctree_flags into more indepent + * tree bits. + * Like split PARTIAL into SKIP_CSUM/SKIP_EXTENT + */ }; static inline u64 btrfs_sb_offset(int mirror)