From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
To: David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org,
Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: [PATCH v4 6/6] btrfs-progs: read stripe tree when mapping blocks
Date: Thu, 14 Sep 2023 09:05:37 -0700 [thread overview]
Message-ID: <20230914-raid-stripe-tree-v4-6-c921c15ec052@wdc.com> (raw)
In-Reply-To: <20230914-raid-stripe-tree-v4-0-c921c15ec052@wdc.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
kernel-shared/volumes.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 113 insertions(+), 3 deletions(-)
diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c
index 95d5930b95d8..2081f7db088f 100644
--- a/kernel-shared/volumes.c
+++ b/kernel-shared/volumes.c
@@ -1796,6 +1796,105 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
multi_ret, mirror_num, raid_map_ret);
}
+static bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info,
+ u64 map_type)
+{
+#if EXPERIMENTAL
+ const bool is_data = (map_type & BTRFS_BLOCK_GROUP_DATA);
+
+ if (!btrfs_fs_incompat(fs_info, RAID_STRIPE_TREE))
+ return false;
+
+ if (!fs_info->stripe_root)
+ return false;
+
+ if (!is_data)
+ return false;
+
+ if (map_type & BTRFS_BLOCK_GROUP_DUP)
+ return true;
+
+ if (map_type & BTRFS_BLOCK_GROUP_RAID1_MASK)
+ return true;
+
+ if (map_type & BTRFS_BLOCK_GROUP_RAID0)
+ return true;
+
+ if (map_type & BTRFS_BLOCK_GROUP_RAID10)
+ return true;
+
+#endif
+ return false;
+}
+
+static int btrfs_stripe_tree_logical_to_physical(struct btrfs_fs_info *fs_info,
+ u64 logical,
+ struct btrfs_bio_stripe *stripe)
+{
+ struct btrfs_root *root = fs_info->stripe_root;
+ struct btrfs_path path = { 0 };
+ struct btrfs_key key;
+ struct extent_buffer *leaf;
+ int slot;
+ int ret;
+
+ key.objectid = logical;
+ key.type = BTRFS_RAID_STRIPE_KEY;
+ key.offset = 0;
+
+ ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
+ if (ret < 0)
+ return ret;
+
+ while (1) {
+ struct btrfs_key found_key;
+ struct btrfs_stripe_extent *extent;
+ int num_stripes;
+ u32 item_size;
+ int i;
+
+ leaf = path.nodes[0];
+ slot = path.slots[0];
+
+ if (slot >= btrfs_header_nritems(leaf)) {
+ ret = btrfs_next_leaf(root, &path);
+ if (ret == 0)
+ continue;
+ if (ret < 0)
+ goto error;
+ break;
+ }
+
+ btrfs_item_key_to_cpu(leaf, &found_key, slot);
+
+ if (found_key.type != BTRFS_RAID_STRIPE_KEY)
+ goto next;
+
+ extent = btrfs_item_ptr(leaf, slot,
+ struct btrfs_stripe_extent);
+ item_size = btrfs_item_size(leaf, slot);
+ num_stripes = (item_size -
+ offsetof(struct btrfs_stripe_extent, strides)) /
+ sizeof(struct btrfs_raid_stride);
+
+ for (i = 0; i < num_stripes; i++) {
+ if (stripe->dev->devid !=
+ btrfs_raid_stride_devid_nr(leaf, extent, i))
+ continue;
+ stripe->physical = btrfs_raid_stride_offset_nr(leaf, extent, i);
+ btrfs_release_path(&path);
+ return 0;
+ }
+
+next:
+ path.slots[0]++;
+ }
+
+ btrfs_release_path(&path);
+error:
+ return ret;
+}
+
int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
u64 logical, u64 *length, u64 *type,
struct btrfs_multi_bio **multi_ret, int mirror_num,
@@ -1988,10 +2087,21 @@ again:
BUG_ON(stripe_index >= map->num_stripes);
for (i = 0; i < multi->num_stripes; i++) {
- multi->stripes[i].physical =
- map->stripes[stripe_index].physical + stripe_offset +
- stripe_nr * map->stripe_len;
multi->stripes[i].dev = map->stripes[stripe_index].dev;
+
+ if (stripes_allocated &&
+ btrfs_need_stripe_tree_update(fs_info, map->type)) {
+ int ret;
+
+ ret = btrfs_stripe_tree_logical_to_physical(fs_info, logical,
+ &multi->stripes[i]);
+ if (ret)
+ return ret;
+ } else {
+ multi->stripes[i].physical =
+ map->stripes[stripe_index].physical +
+ stripe_offset + stripe_nr * map->stripe_len;
+ }
stripe_index++;
}
*multi_ret = multi;
--
2.41.0
next prev parent reply other threads:[~2023-09-14 16:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-14 16:05 [PATCH v4 0/6] btrfs-progs: add support for RAID stripe tree Johannes Thumshirn
2023-09-14 16:05 ` [PATCH v4 1/6] btrfs-progs: add raid-stripe-tree definitions Johannes Thumshirn
2023-09-14 16:05 ` [PATCH v4 2/6] btrfs-progs: read fs with stripe tree from disk Johannes Thumshirn
2023-09-14 16:05 ` [PATCH v4 3/6] btrfs-progs: add dump tree support for the raid stripe tree Johannes Thumshirn
2023-09-14 16:05 ` [PATCH v4 4/6] btrfs-progs: allow zoned RAID Johannes Thumshirn
2023-09-14 16:05 ` [PATCH v4 5/6] btrfs-progs: load zone info for all zoned devices Johannes Thumshirn
2023-09-14 16:05 ` Johannes Thumshirn [this message]
2023-09-14 18:43 ` [PATCH v4 0/6] btrfs-progs: add support for RAID stripe tree David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230914-raid-stripe-tree-v4-6-c921c15ec052@wdc.com \
--to=johannes.thumshirn@wdc.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).