lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231004-rst-updates-v3-1-7729c4474ade@wdc.com>
Date:   Wed, 04 Oct 2023 00:56:16 -0700
From:   Johannes Thumshirn <johannes.thumshirn@....com>
To:     Chris Mason <clm@...com>, Josef Bacik <josef@...icpanda.com>,
        David Sterba <dsterba@...e.com>
Cc:     Qu Wenru <wqu@...e.com>, Damien Le Moal <dlemoal@...nel.org>,
        Naohiro Aota <naohiro.aota@....com>,
        linux-btrfs@...r.kernel.org, linux-kernel@...r.kernel.org,
        Johannes Thumshirn <johannes.thumshirn@....com>
Subject: [PATCH v3 1/4] btrfs: change RST write

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@....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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ