Commit d58ede8d authored by David Sterba's avatar David Sterba

btrfs: simplify data stripe calculation helpers

There are two helpers doing the same calculations based on nparity and
ncopies. calc_data_stripes can be simplified into one expression, so far
we don't have profile with both copies and parity, so there's no
effective change. calc_stripe_length should reuse the helper and not
repeat the same calculation.
Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent fe4f46d4
...@@ -3568,10 +3568,7 @@ static u64 calc_data_stripes(u64 type, int num_stripes) ...@@ -3568,10 +3568,7 @@ static u64 calc_data_stripes(u64 type, int num_stripes)
const int ncopies = btrfs_raid_array[index].ncopies; const int ncopies = btrfs_raid_array[index].ncopies;
const int nparity = btrfs_raid_array[index].nparity; const int nparity = btrfs_raid_array[index].nparity;
if (nparity) return (num_stripes - nparity) / ncopies;
return num_stripes - nparity;
else
return num_stripes / ncopies;
} }
/* [pstart, pend) */ /* [pstart, pend) */
...@@ -6879,15 +6876,7 @@ static void btrfs_report_missing_device(struct btrfs_fs_info *fs_info, ...@@ -6879,15 +6876,7 @@ static void btrfs_report_missing_device(struct btrfs_fs_info *fs_info,
static u64 calc_stripe_length(u64 type, u64 chunk_len, int num_stripes) static u64 calc_stripe_length(u64 type, u64 chunk_len, int num_stripes)
{ {
int index = btrfs_bg_flags_to_raid_index(type); const int data_stripes = calc_data_stripes(type, num_stripes);
int ncopies = btrfs_raid_array[index].ncopies;
const int nparity = btrfs_raid_array[index].nparity;
int data_stripes;
if (nparity)
data_stripes = num_stripes - nparity;
else
data_stripes = num_stripes / ncopies;
return div_u64(chunk_len, data_stripes); return div_u64(chunk_len, data_stripes);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment