From patchwork Wed Dec 7 14:22:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13067222 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 079D2C352A1 for ; Wed, 7 Dec 2022 14:23:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230156AbiLGOXC (ORCPT ); Wed, 7 Dec 2022 09:23:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230304AbiLGOWd (ORCPT ); Wed, 7 Dec 2022 09:22:33 -0500 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29C825D680 for ; Wed, 7 Dec 2022 06:22:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1670422949; x=1701958949; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2JLPjyhI+JfRKihnABLAJNw5B4az/VCG8tUUYMk9MC0=; b=Pgm7nRsDl6e3erPzjXzfRXQ/gCJCMQSGnYLqiVYfNu/3+cJe8iM3BrQR bsJLi9knG6zyoJYl8bNhbVdo7ydSRKq0jeJ0hfsUbsTwCgI23VvTik1PX 9ooAFVIZYDvEzA/nJDDZQuT7q0hp0vXlf0TvTY2FOw3StzRXti5tvc4BD 6YEvFrGlPIDfYIMRq8YRqLLiAwbt5vaeKRjM73zOkfzE9e1HvsMlltKHe KoYXo/n7qIkf3IqXzbf6Tx/t4e7TJfzVzrDzCV3eSBnQORRdM0SI1BiWc UD7JTjX8csMTDb7zRbzF4U5fnthemisqF7dg7Z7NeG/RVxHrDdS+sEf6R A==; X-IronPort-AV: E=Sophos;i="5.96,225,1665417600"; d="scan'208";a="218099478" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 07 Dec 2022 22:22:28 +0800 IronPort-SDR: JuPouqinJ1+VAq9UgBgHtmxE959uJJCZJ2fx0FdpE43lGw3ZivfYi7NBKipgSyallQa/uhOvbF CaMF9npVEaV4K1aqv9QLv3xIewXSi3fcmPuq8Hspmhsd5kO2qS926iIV7fghKORoKlN1FaB6rQ a3rikMSJSdJkpb7VQBo8s7Ozeu4LW5eoSaTpX7p3i2sUC44IpaYrodJQikHZ/apA0qPxfEEwgZ 2BPjwz0OZuGLVtF9dqNSxjdNr3ZM+I9mZ72YBqUuNMmNGSQFMkxkyzbqH63PMhziWWRcZj0oat jz4= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 07 Dec 2022 05:35:15 -0800 IronPort-SDR: LFAqk3j9YD7wabEddLknrpXYbeamQuwRjTkdNCKQkobf6YXKv5FlSfRpjJpIPLc1xF4QpgFhnP 3HZkimoclQndL/X8gcZoufEoyQOfe7l4WzjkQ666y9owhktWLqw9qrnKeg0yMfsmmo+/DqqLCS on2OPT8w2llmA0Qv2jrGMuAX6DvpExC7sO8NBMOscZtPeVCzEt92Jp0kOnI7u7XGiyt4LJtl7b Wu2TXOlR6uozj7+4bBr+17NSVz1QjbZjqMul1+oHrPoY+vvYH0h2pG8BFSJVZrimrjhaz3Lk7r qoI= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 07 Dec 2022 06:22:28 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik , Naohiro Aota Subject: [PATCH v4 2/9] btrfs: read raid-stripe-tree from disk Date: Wed, 7 Dec 2022 06:22:11 -0800 Message-Id: <2262ab233985a1fbed23b7ef5760f38f9318d156.1670422590.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If we find a raid-stripe-tree on mount, read it from disk. Signed-off-by: Johannes Thumshirn --- fs/btrfs/block-rsv.c | 1 + fs/btrfs/disk-io.c | 19 +++++++++++++++++++ fs/btrfs/disk-io.h | 5 +++++ fs/btrfs/fs.h | 4 +++- include/uapi/linux/btrfs.h | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index 5367a14d44d2..384987343a64 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -402,6 +402,7 @@ void btrfs_init_root_block_rsv(struct btrfs_root *root) case BTRFS_EXTENT_TREE_OBJECTID: case BTRFS_FREE_SPACE_TREE_OBJECTID: case BTRFS_BLOCK_GROUP_TREE_OBJECTID: + case BTRFS_RAID_STRIPE_TREE_OBJECTID: root->block_rsv = &fs_info->delayed_refs_rsv; break; case BTRFS_ROOT_TREE_OBJECTID: diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index f10b946454d7..5784c850a3ec 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1444,6 +1444,9 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info, return btrfs_grab_root(root) ? root : ERR_PTR(-ENOENT); } + if (objectid == BTRFS_RAID_STRIPE_TREE_OBJECTID) + return btrfs_grab_root(fs_info->stripe_root) ? + fs_info->stripe_root : ERR_PTR(-ENOENT); return NULL; } @@ -1522,6 +1525,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info) btrfs_put_root(fs_info->fs_root); btrfs_put_root(fs_info->data_reloc_root); btrfs_put_root(fs_info->block_group_root); + btrfs_put_root(fs_info->stripe_root); btrfs_check_leaked_roots(fs_info); btrfs_extent_buffer_leak_debug_check(fs_info); kfree(fs_info->super_copy); @@ -2054,6 +2058,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, bool free_chunk_root) free_root_extent_buffers(info->fs_root); free_root_extent_buffers(info->data_reloc_root); free_root_extent_buffers(info->block_group_root); + free_root_extent_buffers(info->stripe_root); if (free_chunk_root) free_root_extent_buffers(info->chunk_root); } @@ -2506,6 +2511,20 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) fs_info->uuid_root = root; } + if (btrfs_fs_incompat(fs_info, RAID_STRIPE_TREE)) { + location.objectid = BTRFS_RAID_STRIPE_TREE_OBJECTID; + root = btrfs_read_tree_root(tree_root, &location); + if (IS_ERR(root)) { + if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { + ret = PTR_ERR(root); + goto out; + } + } else { + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); + fs_info->stripe_root = root; + } + } + return 0; out: btrfs_warn(fs_info, "failed to read root (objectid=%llu): %d", diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index bc686de7eb80..e10f942c0a37 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -106,6 +106,11 @@ static inline struct btrfs_root *btrfs_grab_root(struct btrfs_root *root) return NULL; } +static inline struct btrfs_root *btrfs_stripe_tree_root(struct btrfs_fs_info *fs_info) +{ + return fs_info->stripe_root; +} + void btrfs_put_root(struct btrfs_root *root); void btrfs_mark_buffer_dirty(struct extent_buffer *buf); int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid, diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index d5224df7468b..f08b59320645 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -202,7 +202,8 @@ enum { BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \ BTRFS_FEATURE_INCOMPAT_RAID1C34 | \ BTRFS_FEATURE_INCOMPAT_ZONED | \ - BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2) + BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2 | \ + BTRFS_FEATURE_INCOMPAT_RAID_STRIPE_TREE) #else #define BTRFS_FEATURE_INCOMPAT_SUPP \ (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \ @@ -355,6 +356,7 @@ struct btrfs_fs_info { struct btrfs_root *uuid_root; struct btrfs_root *data_reloc_root; struct btrfs_root *block_group_root; + struct btrfs_root *stripe_root; /* The log root tree is a directory of all the other log roots */ struct btrfs_root *log_root_tree; diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index b4f0f9531119..593fb7930a37 100644 --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h @@ -322,6 +322,7 @@ struct btrfs_ioctl_fs_info_args { #define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11) #define BTRFS_FEATURE_INCOMPAT_ZONED (1ULL << 12) #define BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2 (1ULL << 13) +#define BTRFS_FEATURE_INCOMPAT_RAID_STRIPE_TREE (1ULL << 14) struct btrfs_ioctl_feature_flags { __u64 compat_flags;