All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
To: linux-btrfs@vger.kernel.org
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: [PATCH v5 08/13] btrfs: zoned: allow zoned RAID
Date: Wed,  8 Feb 2023 02:57:45 -0800	[thread overview]
Message-ID: <946bf77cc07eba1b536466c6da1ce8c575865e7e.1675853489.git.johannes.thumshirn@wdc.com> (raw)
In-Reply-To: <cover.1675853489.git.johannes.thumshirn@wdc.com>

When we have a raid-stripe-tree, we can do RAID0/1/10 on zoned devices for
data block-groups. For meta-data block-groups, we don't actually need
anything special, as all meta-data I/O is protected by the
btrfs_zoned_meta_io_lock() already.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/btrfs/raid-stripe-tree.c |  4 ++++
 fs/btrfs/raid-stripe-tree.h | 10 +++++++++
 fs/btrfs/volumes.c          |  5 ++++-
 fs/btrfs/zoned.c            | 45 +++++++++++++++++++++++++++++++++++--
 4 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c
index ba7015a8012c..1eaa97378d1c 100644
--- a/fs/btrfs/raid-stripe-tree.c
+++ b/fs/btrfs/raid-stripe-tree.c
@@ -268,10 +268,12 @@ static bool btrfs_physical_from_ordered_stripe(struct btrfs_fs_info *fs_info,
 
 int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
 				 u64 logical, u64 *length, u64 map_type,
+				 u32 stripe_index,
 				 struct btrfs_io_stripe *stripe)
 {
 	struct btrfs_root *stripe_root = btrfs_stripe_tree_root(fs_info);
 	int num_stripes = btrfs_bg_type_to_factor(map_type);
+	const bool is_dup = map_type & BTRFS_BLOCK_GROUP_DUP;
 	struct btrfs_stripe_extent *stripe_extent;
 	struct btrfs_key stripe_key;
 	struct btrfs_key found_key;
@@ -343,6 +345,8 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
 			if (btrfs_raid_stride_devid_nr(leaf,
 				       stripe_extent, i) != stripe->dev->devid)
 				continue;
+			if (is_dup && (stripe_index - 1) != i)
+				continue;
 			stripe->physical = btrfs_raid_stride_physical_nr(leaf,
 						   stripe_extent, i) + offset;
 			ret = 0;
diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h
index 9359df0ca3f1..c7f6c5377aaa 100644
--- a/fs/btrfs/raid-stripe-tree.h
+++ b/fs/btrfs/raid-stripe-tree.h
@@ -24,6 +24,7 @@ struct btrfs_ordered_stripe {
 
 int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
 				 u64 logical, u64 *length, u64 map_type,
+				 u32 stripe_index,
 				 struct btrfs_io_stripe *stripe);
 int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start,
 			     u64 length);
@@ -50,9 +51,18 @@ static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info,
 	if (type != BTRFS_BLOCK_GROUP_DATA)
 		return false;
 
+	if (profile & BTRFS_BLOCK_GROUP_DUP)
+		return true;
+
 	if (profile & BTRFS_BLOCK_GROUP_RAID1_MASK)
 		return true;
 
+	if (profile & BTRFS_BLOCK_GROUP_RAID0)
+		return true;
+
+	if (profile & BTRFS_BLOCK_GROUP_RAID10)
+		return true;
+
 	return false;
 }
 
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 7a784bb511ed..ef626f932af5 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6322,7 +6322,8 @@ static int set_io_stripe(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
 	if (op == BTRFS_MAP_READ &&
 	    btrfs_need_stripe_tree_update(fs_info, map->type))
 		return btrfs_get_raid_extent_offset(fs_info, logical, length,
-						    map->type, dst);
+						    map->type, stripe_index,
+						    dst);
 
 	dst->physical = map->stripes[stripe_index].physical +
 			stripe_offset + stripe_nr * map->stripe_len;
@@ -6508,6 +6509,8 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op,
 	 * I/O context structure.
 	 */
 	if (smap && num_alloc_stripes == 1 &&
+	    !(btrfs_need_stripe_tree_update(fs_info, map->type) &&
+	      op != BTRFS_MAP_READ) &&
 	    !((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && mirror_num > 1) &&
 	    (!need_full_stripe(op) || !dev_replace_is_ongoing ||
 	     !dev_replace->tgtdev)) {
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index ed49150e6e6f..9796f76cffd6 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1476,8 +1476,9 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
 			set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &cache->runtime_flags);
 		break;
 	case BTRFS_BLOCK_GROUP_DUP:
-		if (map->type & BTRFS_BLOCK_GROUP_DATA) {
-			btrfs_err(fs_info, "zoned: profile DUP not yet supported on data bg");
+		if (map->type & BTRFS_BLOCK_GROUP_DATA &&
+		    !btrfs_stripe_tree_root(fs_info)) {
+			btrfs_err(fs_info, "zoned: data DUP profile needs stripe_root");
 			ret = -EINVAL;
 			goto out;
 		}
@@ -1515,8 +1516,48 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
 		cache->zone_capacity = min(caps[0], caps[1]);
 		break;
 	case BTRFS_BLOCK_GROUP_RAID1:
+	case BTRFS_BLOCK_GROUP_RAID1C3:
+	case BTRFS_BLOCK_GROUP_RAID1C4:
 	case BTRFS_BLOCK_GROUP_RAID0:
 	case BTRFS_BLOCK_GROUP_RAID10:
+		if (map->type & BTRFS_BLOCK_GROUP_DATA &&
+		    !btrfs_stripe_tree_root(fs_info)) {
+			btrfs_err(fs_info,
+				  "zoned: data %s needs stripe_root",
+				  btrfs_bg_type_to_raid_name(map->type));
+			ret = -EIO;
+			goto out;
+
+		}
+
+		for (i = 0; i < map->num_stripes; i++) {
+			if (alloc_offsets[i] == WP_MISSING_DEV ||
+			    alloc_offsets[i] == WP_CONVENTIONAL)
+				continue;
+
+			if (i == 0)
+				continue;
+
+			if (alloc_offsets[0] != alloc_offsets[i]) {
+				btrfs_err(fs_info,
+					  "zoned: write pointer offset mismatch of zones in RAID profile");
+				ret = -EIO;
+				goto out;
+			}
+			if (test_bit(0, active) != test_bit(i, active)) {
+				if (!btrfs_zone_activate(cache)) {
+					ret = -EIO;
+					goto out;
+				}
+			} else {
+				if (test_bit(0, active))
+					set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE,
+						&cache->runtime_flags);
+			}
+			cache->zone_capacity = min(caps[0], caps[i]);
+		}
+		cache->alloc_offset = alloc_offsets[0];
+		break;
 	case BTRFS_BLOCK_GROUP_RAID5:
 	case BTRFS_BLOCK_GROUP_RAID6:
 		/* non-single profiles are not supported yet */
-- 
2.39.0


  parent reply	other threads:[~2023-02-08 10:58 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08 10:57 [PATCH v5 00/13] btrfs: introduce RAID stripe tree Johannes Thumshirn
2023-02-08 10:57 ` [PATCH v5 01/13] btrfs: re-add trans parameter to insert_delayed_ref Johannes Thumshirn
2023-02-08 19:41   ` Josef Bacik
2023-02-08 10:57 ` [PATCH v5 02/13] btrfs: add raid stripe tree definitions Johannes Thumshirn
2023-02-08 19:42   ` Josef Bacik
2023-02-13  6:50   ` Christoph Hellwig
2023-02-13 11:10     ` Johannes Thumshirn
2023-02-13 11:34   ` Anand Jain
2023-02-08 10:57 ` [PATCH v5 03/13] btrfs: read raid-stripe-tree from disk Johannes Thumshirn
2023-02-08 19:43   ` Josef Bacik
2023-02-13 11:35   ` Anand Jain
2023-02-08 10:57 ` [PATCH v5 04/13] btrfs: add support for inserting raid stripe extents Johannes Thumshirn
2023-02-08 19:47   ` Josef Bacik
2023-02-08 19:52   ` Josef Bacik
2023-02-13  6:57   ` Christoph Hellwig
2023-02-13 10:43     ` Johannes Thumshirn
2023-02-13 13:12       ` Johannes Thumshirn
2023-02-13  7:40   ` Qu Wenruo
2023-02-13 10:49     ` Johannes Thumshirn
2023-02-13 11:12       ` Qu Wenruo
2023-02-13 11:37         ` Johannes Thumshirn
2023-02-08 10:57 ` [PATCH v5 05/13] btrfs: delete stripe extent on extent deletion Johannes Thumshirn
2023-02-08 20:00   ` Josef Bacik
2023-02-13 15:21     ` Johannes Thumshirn
2023-02-08 10:57 ` [PATCH v5 06/13] btrfs: lookup physical address from stripe extent Johannes Thumshirn
2023-02-08 20:16   ` Josef Bacik
2023-02-08 10:57 ` [PATCH v5 07/13] btrfs: add raid stripe tree pretty printer Johannes Thumshirn
2023-02-08 10:57 ` Johannes Thumshirn [this message]
2023-02-08 20:18   ` [PATCH v5 08/13] btrfs: zoned: allow zoned RAID Josef Bacik
2023-02-08 10:57 ` [PATCH v5 09/13] btrfs: check for leaks of ordered stripes on umount Johannes Thumshirn
2023-02-08 20:19   ` Josef Bacik
2023-02-08 10:57 ` [PATCH v5 10/13] btrfs: add tracepoints for ordered stripes Johannes Thumshirn
2023-02-08 10:57 ` [PATCH v5 11/13] btrfs: announce presence of raid-stripe-tree in sysfs Johannes Thumshirn
2023-02-08 20:20   ` Josef Bacik
2023-02-08 10:57 ` [PATCH v5 12/13] btrfs: consult raid-stripe-tree when scrubbing Johannes Thumshirn
2023-02-08 20:21   ` Josef Bacik
2023-02-08 10:57 ` [PATCH v5 13/13] btrfs: add raid-stripe-tree to features enabled with debug Johannes Thumshirn
2023-02-08 20:23   ` Josef Bacik
2023-02-09  0:42 ` [PATCH v5 00/13] btrfs: introduce RAID stripe tree Qu Wenruo
2023-02-09  8:47   ` Johannes Thumshirn
2023-02-09 15:57 ` Phillip Susi
2023-02-10  8:44   ` Johannes Thumshirn
2023-02-10 10:33     ` Johannes Thumshirn
2023-02-13 16:42     ` Phillip Susi
2023-02-13 17:44       ` Johannes Thumshirn
2023-02-13 17:56         ` Phillip Susi
2023-02-14  5:52           ` Christoph Hellwig
2023-02-14  5:51         ` Christoph Hellwig

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=946bf77cc07eba1b536466c6da1ce8c575865e7e.1675853489.git.johannes.thumshirn@wdc.com \
    --to=johannes.thumshirn@wdc.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.