mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-04 18:09:57 +00:00
btrfs: factor out helper for counting data stripes
Factor the sequence of ifs to a helper, the 'data stripes' here means the number of stripes without redundancy and parity. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
44b28adafd
commit
946c9256c6
1 changed files with 15 additions and 10 deletions
|
@ -3474,6 +3474,18 @@ static int chunk_devid_filter(struct extent_buffer *leaf,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static u64 calc_data_stripes(u64 type, int num_stripes)
|
||||||
|
{
|
||||||
|
const int index = btrfs_bg_flags_to_raid_index(type);
|
||||||
|
const int ncopies = btrfs_raid_array[index].ncopies;
|
||||||
|
const int nparity = btrfs_raid_array[index].nparity;
|
||||||
|
|
||||||
|
if (nparity)
|
||||||
|
return num_stripes - nparity;
|
||||||
|
else
|
||||||
|
return num_stripes / ncopies;
|
||||||
|
}
|
||||||
|
|
||||||
/* [pstart, pend) */
|
/* [pstart, pend) */
|
||||||
static int chunk_drange_filter(struct extent_buffer *leaf,
|
static int chunk_drange_filter(struct extent_buffer *leaf,
|
||||||
struct btrfs_chunk *chunk,
|
struct btrfs_chunk *chunk,
|
||||||
|
@ -3483,22 +3495,15 @@ static int chunk_drange_filter(struct extent_buffer *leaf,
|
||||||
int num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
|
int num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
|
||||||
u64 stripe_offset;
|
u64 stripe_offset;
|
||||||
u64 stripe_length;
|
u64 stripe_length;
|
||||||
|
u64 type;
|
||||||
int factor;
|
int factor;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!(bargs->flags & BTRFS_BALANCE_ARGS_DEVID))
|
if (!(bargs->flags & BTRFS_BALANCE_ARGS_DEVID))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (btrfs_chunk_type(leaf, chunk) & (BTRFS_BLOCK_GROUP_DUP |
|
type = btrfs_chunk_type(leaf, chunk);
|
||||||
BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10)) {
|
factor = calc_data_stripes(type, num_stripes);
|
||||||
factor = num_stripes / 2;
|
|
||||||
} else if (btrfs_chunk_type(leaf, chunk) & BTRFS_BLOCK_GROUP_RAID5) {
|
|
||||||
factor = num_stripes - 1;
|
|
||||||
} else if (btrfs_chunk_type(leaf, chunk) & BTRFS_BLOCK_GROUP_RAID6) {
|
|
||||||
factor = num_stripes - 2;
|
|
||||||
} else {
|
|
||||||
factor = num_stripes;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < num_stripes; i++) {
|
for (i = 0; i < num_stripes; i++) {
|
||||||
stripe = btrfs_stripe_nr(chunk, i);
|
stripe = btrfs_stripe_nr(chunk, i);
|
||||||
|
|
Loading…
Reference in a new issue