From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>
Cc: Qu Wenru <wqu@suse.com>, Damien Le Moal <dlemoal@kernel.org>,
Naohiro Aota <naohiro.aota@wdc.com>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: [PATCH v3 1/4] btrfs: change RST write
Date: Wed, 04 Oct 2023 00:56:16 -0700 [thread overview]
Message-ID: <20231004-rst-updates-v3-1-7729c4474ade@wdc.com> (raw)
In-Reply-To: <20231004-rst-updates-v3-0-7729c4474ade@wdc.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
fs/btrfs/raid-stripe-tree.c | 165 ++------------------------------------------
1 file changed, 5 insertions(+), 160 deletions(-)
diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c
index 8a38f07a3246..248e048810d3 100644
--- a/fs/btrfs/raid-stripe-tree.c
+++ b/fs/btrfs/raid-stripe-tree.c
@@ -75,12 +75,12 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
}
static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans,
- int num_stripes,
struct btrfs_io_context *bioc)
{
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_key stripe_key;
struct btrfs_root *stripe_root = fs_info->stripe_root;
+ const int num_stripes = btrfs_bg_type_to_factor(bioc->map_type);
u8 encoding = btrfs_bg_flags_to_raid_index(bioc->map_type);
struct btrfs_stripe_extent *stripe_extent;
const size_t item_size = struct_size(stripe_extent, strides, num_stripes);
@@ -107,7 +107,6 @@ static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans,
btrfs_set_stack_raid_stride_devid(raid_stride, devid);
btrfs_set_stack_raid_stride_physical(raid_stride, physical);
- btrfs_set_stack_raid_stride_length(raid_stride, length);
}
stripe_key.objectid = bioc->logical;
@@ -124,173 +123,19 @@ static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans,
return ret;
}
-static int btrfs_insert_mirrored_raid_extents(struct btrfs_trans_handle *trans,
- struct btrfs_ordered_extent *ordered,
- u64 map_type)
-{
- int num_stripes = btrfs_bg_type_to_factor(map_type);
- struct btrfs_io_context *bioc;
- int ret;
-
- list_for_each_entry(bioc, &ordered->bioc_list, rst_ordered_entry) {
- ret = btrfs_insert_one_raid_extent(trans, num_stripes, bioc);
- if (ret)
- return ret;
- }
-
- return 0;
-}
-
-static int btrfs_insert_striped_mirrored_raid_extents(
- struct btrfs_trans_handle *trans,
- struct btrfs_ordered_extent *ordered,
- u64 map_type)
-{
- struct btrfs_io_context *bioc;
- struct btrfs_io_context *rbioc;
- const size_t nstripes = list_count_nodes(&ordered->bioc_list);
- const enum btrfs_raid_types index = btrfs_bg_flags_to_raid_index(map_type);
- const int substripes = btrfs_raid_array[index].sub_stripes;
- const int max_stripes = div_u64(trans->fs_info->fs_devices->rw_devices,
- substripes);
- int left = nstripes;
- int i;
- int ret = 0;
- u64 stripe_end;
- u64 prev_end;
- int stripe;
-
- if (nstripes == 1)
- return btrfs_insert_mirrored_raid_extents(trans, ordered, map_type);
-
- rbioc = kzalloc(struct_size(rbioc, stripes, nstripes * substripes), GFP_NOFS);
- if (!rbioc)
- return -ENOMEM;
-
- rbioc->map_type = map_type;
- rbioc->logical = list_first_entry(&ordered->bioc_list, typeof(*rbioc),
- rst_ordered_entry)->logical;
-
- stripe_end = rbioc->logical;
- prev_end = stripe_end;
- i = 0;
- stripe = 0;
- list_for_each_entry(bioc, &ordered->bioc_list, rst_ordered_entry) {
- rbioc->size += bioc->size;
- for (int j = 0; j < substripes; j++) {
- stripe = i + j;
- rbioc->stripes[stripe].dev = bioc->stripes[j].dev;
- rbioc->stripes[stripe].physical = bioc->stripes[j].physical;
- rbioc->stripes[stripe].length = bioc->size;
- }
-
- stripe_end += rbioc->size;
- if (i >= nstripes ||
- (stripe_end - prev_end >= max_stripes * BTRFS_STRIPE_LEN)) {
- ret = btrfs_insert_one_raid_extent(trans, stripe + 1, rbioc);
- if (ret)
- goto out;
-
- left -= stripe + 1;
- if (left <= 0)
- break;
-
- i = 0;
- rbioc->logical += rbioc->size;
- rbioc->size = 0;
- } else {
- i += substripes;
- prev_end = stripe_end;
- }
- }
-
- if (left > 0) {
- bioc = list_prev_entry(bioc, rst_ordered_entry);
- ret = btrfs_insert_one_raid_extent(trans, substripes, bioc);
- }
-
-out:
- kfree(rbioc);
- return ret;
-}
-
-static int btrfs_insert_striped_raid_extents(struct btrfs_trans_handle *trans,
- struct btrfs_ordered_extent *ordered,
- u64 map_type)
-{
- struct btrfs_io_context *bioc;
- struct btrfs_io_context *rbioc;
- const size_t nstripes = list_count_nodes(&ordered->bioc_list);
- int i;
- int ret = 0;
-
- rbioc = kzalloc(struct_size(rbioc, stripes, nstripes), GFP_NOFS);
- if (!rbioc)
- return -ENOMEM;
- rbioc->map_type = map_type;
- rbioc->logical = list_first_entry(&ordered->bioc_list, typeof(*rbioc),
- rst_ordered_entry)->logical;
-
- i = 0;
- list_for_each_entry(bioc, &ordered->bioc_list, rst_ordered_entry) {
- rbioc->size += bioc->size;
- rbioc->stripes[i].dev = bioc->stripes[0].dev;
- rbioc->stripes[i].physical = bioc->stripes[0].physical;
- rbioc->stripes[i].length = bioc->size;
-
- if (i == nstripes - 1) {
- ret = btrfs_insert_one_raid_extent(trans, nstripes, rbioc);
- if (ret)
- goto out;
-
- i = 0;
- rbioc->logical += rbioc->size;
- rbioc->size = 0;
- } else {
- i++;
- }
- }
-
- if (i && i < nstripes - 1)
- ret = btrfs_insert_one_raid_extent(trans, i, rbioc);
-
-out:
- kfree(rbioc);
- return ret;
-}
-
int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans,
struct btrfs_ordered_extent *ordered_extent)
{
struct btrfs_io_context *bioc;
- u64 map_type;
int ret;
if (!btrfs_fs_incompat(trans->fs_info, RAID_STRIPE_TREE))
return 0;
- map_type = list_first_entry(&ordered_extent->bioc_list, typeof(*bioc),
- rst_ordered_entry)->map_type;
-
- switch (map_type & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
- case BTRFS_BLOCK_GROUP_DUP:
- case BTRFS_BLOCK_GROUP_RAID1:
- case BTRFS_BLOCK_GROUP_RAID1C3:
- case BTRFS_BLOCK_GROUP_RAID1C4:
- ret = btrfs_insert_mirrored_raid_extents(trans, ordered_extent, map_type);
- break;
- case BTRFS_BLOCK_GROUP_RAID0:
- ret = btrfs_insert_striped_raid_extents(trans, ordered_extent, map_type);
- break;
- case BTRFS_BLOCK_GROUP_RAID10:
- ret = btrfs_insert_striped_mirrored_raid_extents(trans, ordered_extent,
- map_type);
- break;
- default:
- btrfs_err(trans->fs_info, "trying to insert unknown block group profile %lld",
- map_type & BTRFS_BLOCK_GROUP_PROFILE_MASK);
- ret = -EINVAL;
- break;
+ list_for_each_entry(bioc, &ordered_extent->bioc_list, rst_ordered_entry) {
+ ret = btrfs_insert_one_raid_extent(trans, bioc);
+ if (ret)
+ return ret;
}
while (!list_empty(&ordered_extent->bioc_list)) {
--
2.41.0
next prev parent reply other threads:[~2023-10-04 7:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-04 7:56 [PATCH v3 0/4] btrfs: RAID stripe tree updates Johannes Thumshirn
2023-10-04 7:56 ` Johannes Thumshirn [this message]
2023-10-04 12:43 ` [PATCH v3 1/4] btrfs: change RST write Johannes Thumshirn
2023-10-04 7:56 ` [PATCH v3 2/4] btrfs: remove stride length check on read Johannes Thumshirn
2023-10-04 12:43 ` Johannes Thumshirn
2023-10-04 7:56 ` [PATCH v3 3/4] btrfs: remove raid stride length in tree printer Johannes Thumshirn
2023-10-04 12:44 ` Johannes Thumshirn
2023-10-04 7:56 ` [PATCH v3 4/4] btrfs: remove stride length from on-disk format Johannes Thumshirn
2023-10-04 12:45 ` Johannes Thumshirn
2023-10-04 8:25 ` [PATCH v3 0/4] btrfs: RAID stripe tree updates Qu Wenruo
2023-10-04 8:36 ` Johannes Thumshirn
2023-10-04 13:14 ` 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=20231004-rst-updates-v3-1-7729c4474ade@wdc.com \
--to=johannes.thumshirn@wdc.com \
--cc=clm@fb.com \
--cc=dlemoal@kernel.org \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=naohiro.aota@wdc.com \
--cc=wqu@suse.com \
/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).