btrfs-progs: use round_down for allocation calcs

Several calculations in the chunk allocation process use this pattern.

    x /= y;
    x *= y;

Replace this pattern with round_down().

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Naohiro Aota 2021-04-06 17:05:51 +09:00 committed by David Sterba
parent 907c5fd7a4
commit 2d3b31d604
1 changed files with 6 additions and 6 deletions

View File

@ -1098,15 +1098,13 @@ static int decide_stripe_size_regular(struct alloc_chunk_ctl *ctl)
if (chunk_size > ctl->max_chunk_size) {
ctl->calc_size = ctl->max_chunk_size;
ctl->calc_size /= ctl->num_stripes;
ctl->calc_size /= ctl->stripe_len;
ctl->calc_size *= ctl->stripe_len;
ctl->calc_size = round_down(ctl->calc_size, ctl->stripe_len);
}
/* We don't want tiny stripes */
ctl->calc_size = max_t(u64, ctl->calc_size, ctl->min_stripe_size);
/* Align to the stripe length */
ctl->calc_size /= ctl->stripe_len;
ctl->calc_size *= ctl->stripe_len;
ctl->calc_size = round_down(ctl->calc_size, ctl->stripe_len);
return 0;
}
@ -1315,8 +1313,10 @@ again:
if (index >= ctl.min_stripes) {
ctl.num_stripes = index;
if (type & (BTRFS_BLOCK_GROUP_RAID10)) {
ctl.num_stripes /= ctl.sub_stripes;
ctl.num_stripes *= ctl.sub_stripes;
/* We know this should be 2, but just in case */
ASSERT(is_power_of_2(ctl.sub_stripes));
ctl.num_stripes = round_down(ctl.num_stripes,
ctl.sub_stripes);
}
looped = 1;
goto again;