All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
To: David Sterba <dsterba@suse.cz>
Cc: linux-btrfs@vger.kernel.org,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: [PATCH 13/15] btrfs-progs: introduce init_alloc_chunk_ctl
Date: Wed, 10 Jun 2020 21:32:56 +0900	[thread overview]
Message-ID: <20200610123258.12382-14-johannes.thumshirn@wdc.com> (raw)
In-Reply-To: <20200610123258.12382-1-johannes.thumshirn@wdc.com>

Factor out setting of alloc_chuk_ctl fileds in a separate function
init_alloc_chunk_ctl.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 volumes.c | 70 +++++++++++++++++++++++++++++++------------------------
 1 file changed, 40 insertions(+), 30 deletions(-)

diff --git a/volumes.c b/volumes.c
index 57d0db5463ef..aacff6e0656b 100644
--- a/volumes.c
+++ b/volumes.c
@@ -1067,6 +1067,44 @@ static const struct btrfs_raid_profile {
 	},
 };
 
+static void init_alloc_chunk_ctl(struct btrfs_fs_info *info,
+				 struct alloc_chunk_ctl *ctl)
+{
+	int type = ctl->type;
+
+	ctl->num_stripes = btrfs_raid_profile_table[type].num_stripes;
+	ctl->min_stripes = btrfs_raid_profile_table[type].min_stripes;
+	ctl->sub_stripes = btrfs_raid_profile_table[type].sub_stripes;
+	ctl->stripe_len = BTRFS_STRIPE_LEN;
+
+	switch (type) {
+	case BTRFS_RAID_RAID1:
+	case BTRFS_RAID_RAID1C3:
+	case BTRFS_RAID_RAID1C4:
+		ctl->num_stripes = min(ctl->min_stripes, ctl->total_devs);
+		break;
+	case BTRFS_RAID_RAID0:
+		ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs);
+		break;
+	case BTRFS_RAID_RAID10:
+		ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs);
+		ctl->num_stripes &= ~(u32)1;
+		break;
+	case BTRFS_RAID_RAID5:
+		ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs);
+		ctl->stripe_len = find_raid56_stripe_len(ctl->num_stripes - 1,
+				    btrfs_super_stripesize(info->super_copy));
+		break;
+	case BTRFS_RAID_RAID6:
+		ctl->num_stripes = min(ctl->max_stripes, ctl->total_devs);
+		ctl->stripe_len = find_raid56_stripe_len(ctl->num_stripes - 2,
+				    btrfs_super_stripesize(info->super_copy));
+		break;
+	default:
+		break;
+	}
+}
+
 int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 		      struct btrfs_fs_info *info, u64 *start,
 		      u64 *num_bytes, u64 type)
@@ -1100,11 +1138,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 	}
 
 	ctl.type = btrfs_bg_flags_to_raid_index(type);
-	ctl.num_stripes = btrfs_raid_profile_table[ctl.type].num_stripes;
 	ctl.max_stripes = 0;
-	ctl.min_stripes = btrfs_raid_profile_table[ctl.type].min_stripes;
-	ctl.sub_stripes = btrfs_raid_profile_table[ctl.type].sub_stripes;
-	ctl.stripe_len = BTRFS_STRIPE_LEN;
 	ctl.total_devs = btrfs_super_num_devices(info->super_copy);
 
 	if (type & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
@@ -1129,32 +1163,8 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 			ctl.max_stripes = BTRFS_MAX_DEVS(info);
 		}
 	}
-	switch (ctl.type) {
-	case BTRFS_RAID_RAID1:
-	case BTRFS_RAID_RAID1C3:
-	case BTRFS_RAID_RAID1C4:
-		ctl.num_stripes = min(ctl.min_stripes, ctl.total_devs);
-		break;
-	case BTRFS_RAID_RAID0:
-		ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs);
-		break;
-	case BTRFS_RAID_RAID10:
-		ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs);
-		ctl.num_stripes &= ~(u32)1;
-		break;
-	case BTRFS_RAID_RAID5:
-		ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs);
-		ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 1,
-				    btrfs_super_stripesize(info->super_copy));
-		break;
-	case BTRFS_RAID_RAID6:
-		ctl.num_stripes = min(ctl.max_stripes, ctl.total_devs);
-		ctl.stripe_len = find_raid56_stripe_len(ctl.num_stripes - 2,
-				    btrfs_super_stripesize(info->super_copy));
-		break;
-	default:
-		break;
-	}
+
+	init_alloc_chunk_ctl(info, &ctl);
 	if (ctl.num_stripes < ctl.min_stripes)
 		return -ENOSPC;
 
-- 
2.26.2


  parent reply	other threads:[~2020-06-10 12:33 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-10 12:32 [PATCH 00/15] btrfs-progs: simplify chunk allocation a bit Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 01/15] btrfs-progs: simplify minimal stripe number checking Johannes Thumshirn
2020-06-23  5:58   ` Qu Wenruo
2020-06-10 12:32 ` [PATCH 02/15] btrfs-progs: simplify assignment of number of RAID stripes Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 03/15] btrfs-progs: introduce alloc_chunk_ctl structure Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 04/15] btrfs-progs: cache number of devices for chunk allocation Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 05/15] btrfs-progs: pass alloc_chunk_ctl to chunk_bytes_by_type Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 06/15] btrfs-progs: introduce raid profile table for chunk allocation Johannes Thumshirn
2020-06-11 13:39   ` David Sterba
2020-06-12  7:44     ` Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 07/15] btrfs-progs: consolidate assignment of minimal stripe number Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 08/15] btrfs-progs: consolidate assignment of sub_stripes Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 09/15] btrfs-progs: consolidate setting of RAID1 stripes Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 10/15] btrfs-progs: do table lookup for simple RAID profiles' num_stripes Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 11/15] btrfs-progs: consolidate num_stripes sanity check Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 12/15] btrfs-progs: compactify num_stripe setting in btrfs_alloc_chunk Johannes Thumshirn
2020-06-10 12:32 ` Johannes Thumshirn [this message]
2020-06-23  6:02   ` [PATCH 13/15] btrfs-progs: introduce init_alloc_chunk_ctl Qu Wenruo
2020-06-10 12:32 ` [PATCH 14/15] btrfs-progs: don't pretend RAID56 has a different stripe length Johannes Thumshirn
2020-06-10 12:32 ` [PATCH 15/15] btrfs-progs: consolidate num_stripes setting for striping RAID levels Johannes Thumshirn
2020-06-11 13:44 ` [PATCH 00/15] btrfs-progs: simplify chunk allocation a bit David Sterba
2020-06-23  6:33 ` Qu Wenruo
2020-06-23  8:01   ` Johannes Thumshirn

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=20200610123258.12382-14-johannes.thumshirn@wdc.com \
    --to=johannes.thumshirn@wdc.com \
    --cc=dsterba@suse.cz \
    --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.