diff options
author | David Sterba <dsterba@suse.cz> | 2015-01-16 11:26:13 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2015-03-03 11:24:00 -0500 |
commit | b8b93addde1e0192b045da8995e296fc1e40c80f (patch) | |
tree | d78234932a05c824c0feac2ada9bd0a3fce42f72 /fs | |
parent | 3284da7b7b585e6e8e98f374a51d234d14c7a0a2 (diff) |
btrfs: cleanup 64bit/32bit divs, provably bounded values
The divisor is derived from nodesize or PAGE_SIZE, fits into 32bit type.
Get rid of a few more do_div instances.
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/extent-tree.c | 4 | ||||
-rw-r--r-- | fs/btrfs/free-space-cache.c | 10 | ||||
-rw-r--r-- | fs/btrfs/ioctl.c | 2 | ||||
-rw-r--r-- | fs/btrfs/scrub.c | 8 | ||||
-rw-r--r-- | fs/btrfs/volumes.c | 26 |
5 files changed, 24 insertions, 26 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 2cb32bc45bcc..4ccc3397c644 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -5032,7 +5032,7 @@ static u64 calc_csum_metadata_size(struct inode *inode, u64 num_bytes, | |||
5032 | BTRFS_I(inode)->csum_bytes == 0) | 5032 | BTRFS_I(inode)->csum_bytes == 0) |
5033 | return 0; | 5033 | return 0; |
5034 | 5034 | ||
5035 | old_csums = (int)div64_u64(BTRFS_I(inode)->csum_bytes, root->sectorsize); | 5035 | old_csums = (int)div_u64(BTRFS_I(inode)->csum_bytes, root->sectorsize); |
5036 | if (reserve) | 5036 | if (reserve) |
5037 | BTRFS_I(inode)->csum_bytes += num_bytes; | 5037 | BTRFS_I(inode)->csum_bytes += num_bytes; |
5038 | else | 5038 | else |
@@ -5041,7 +5041,7 @@ static u64 calc_csum_metadata_size(struct inode *inode, u64 num_bytes, | |||
5041 | num_csums_per_leaf = (int)div_u64(csum_size, | 5041 | num_csums_per_leaf = (int)div_u64(csum_size, |
5042 | sizeof(struct btrfs_csum_item) + | 5042 | sizeof(struct btrfs_csum_item) + |
5043 | sizeof(struct btrfs_disk_key)); | 5043 | sizeof(struct btrfs_disk_key)); |
5044 | num_csums = (int)div64_u64(BTRFS_I(inode)->csum_bytes, root->sectorsize); | 5044 | num_csums = (int)div_u64(BTRFS_I(inode)->csum_bytes, root->sectorsize); |
5045 | num_csums = num_csums + num_csums_per_leaf - 1; | 5045 | num_csums = num_csums + num_csums_per_leaf - 1; |
5046 | num_csums = num_csums / num_csums_per_leaf; | 5046 | num_csums = num_csums / num_csums_per_leaf; |
5047 | 5047 | ||
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 6e5d0abec6f9..13c9b46d4727 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -1298,11 +1298,11 @@ static inline u64 offset_to_bitmap(struct btrfs_free_space_ctl *ctl, | |||
1298 | u64 offset) | 1298 | u64 offset) |
1299 | { | 1299 | { |
1300 | u64 bitmap_start; | 1300 | u64 bitmap_start; |
1301 | u64 bytes_per_bitmap; | 1301 | u32 bytes_per_bitmap; |
1302 | 1302 | ||
1303 | bytes_per_bitmap = BITS_PER_BITMAP * ctl->unit; | 1303 | bytes_per_bitmap = BITS_PER_BITMAP * ctl->unit; |
1304 | bitmap_start = offset - ctl->start; | 1304 | bitmap_start = offset - ctl->start; |
1305 | bitmap_start = div64_u64(bitmap_start, bytes_per_bitmap); | 1305 | bitmap_start = div_u64(bitmap_start, bytes_per_bitmap); |
1306 | bitmap_start *= bytes_per_bitmap; | 1306 | bitmap_start *= bytes_per_bitmap; |
1307 | bitmap_start += ctl->start; | 1307 | bitmap_start += ctl->start; |
1308 | 1308 | ||
@@ -1521,10 +1521,10 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl) | |||
1521 | u64 bitmap_bytes; | 1521 | u64 bitmap_bytes; |
1522 | u64 extent_bytes; | 1522 | u64 extent_bytes; |
1523 | u64 size = block_group->key.offset; | 1523 | u64 size = block_group->key.offset; |
1524 | u64 bytes_per_bg = BITS_PER_BITMAP * ctl->unit; | 1524 | u32 bytes_per_bg = BITS_PER_BITMAP * ctl->unit; |
1525 | int max_bitmaps = div64_u64(size + bytes_per_bg - 1, bytes_per_bg); | 1525 | u32 max_bitmaps = div_u64(size + bytes_per_bg - 1, bytes_per_bg); |
1526 | 1526 | ||
1527 | max_bitmaps = max(max_bitmaps, 1); | 1527 | max_bitmaps = max_t(u32, max_bitmaps, 1); |
1528 | 1528 | ||
1529 | ASSERT(ctl->total_bitmaps <= max_bitmaps); | 1529 | ASSERT(ctl->total_bitmaps <= max_bitmaps); |
1530 | 1530 | ||
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 0a9fe214deeb..4a5524c2713a 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -1564,7 +1564,7 @@ static noinline int btrfs_ioctl_resize(struct file *file, | |||
1564 | goto out_free; | 1564 | goto out_free; |
1565 | } | 1565 | } |
1566 | 1566 | ||
1567 | do_div(new_size, root->sectorsize); | 1567 | new_size = div_u64(new_size, root->sectorsize); |
1568 | new_size *= root->sectorsize; | 1568 | new_size *= root->sectorsize; |
1569 | 1569 | ||
1570 | printk_in_rcu(KERN_INFO "BTRFS: new size for %s is %llu\n", | 1570 | printk_in_rcu(KERN_INFO "BTRFS: new size for %s is %llu\n", |
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 5a7d63cd9c25..293262163daf 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c | |||
@@ -2623,9 +2623,8 @@ static int get_raid56_logic_offset(u64 physical, int num, | |||
2623 | for (i = 0; i < nr_data_stripes(map); i++) { | 2623 | for (i = 0; i < nr_data_stripes(map); i++) { |
2624 | *offset = last_offset + i * map->stripe_len; | 2624 | *offset = last_offset + i * map->stripe_len; |
2625 | 2625 | ||
2626 | stripe_nr = *offset; | 2626 | stripe_nr = div_u64(*offset, map->stripe_len); |
2627 | do_div(stripe_nr, map->stripe_len); | 2627 | stripe_nr = div_u64(stripe_nr, nr_data_stripes(map)); |
2628 | do_div(stripe_nr, nr_data_stripes(map)); | ||
2629 | 2628 | ||
2630 | /* Work out the disk rotation on this stripe-set */ | 2629 | /* Work out the disk rotation on this stripe-set */ |
2631 | rot = do_div(stripe_nr, map->num_stripes); | 2630 | rot = do_div(stripe_nr, map->num_stripes); |
@@ -2994,10 +2993,9 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx, | |||
2994 | int extent_mirror_num; | 2993 | int extent_mirror_num; |
2995 | int stop_loop = 0; | 2994 | int stop_loop = 0; |
2996 | 2995 | ||
2997 | nstripes = length; | ||
2998 | physical = map->stripes[num].physical; | 2996 | physical = map->stripes[num].physical; |
2999 | offset = 0; | 2997 | offset = 0; |
3000 | do_div(nstripes, map->stripe_len); | 2998 | nstripes = div_u64(length, map->stripe_len); |
3001 | if (map->type & BTRFS_BLOCK_GROUP_RAID0) { | 2999 | if (map->type & BTRFS_BLOCK_GROUP_RAID0) { |
3002 | offset = map->stripe_len * num; | 3000 | offset = map->stripe_len * num; |
3003 | increment = map->stripe_len * map->num_stripes; | 3001 | increment = map->stripe_len * map->num_stripes; |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 5b77982ab6b1..d712c46c0a6b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -3021,7 +3021,7 @@ static int chunk_drange_filter(struct extent_buffer *leaf, | |||
3021 | 3021 | ||
3022 | stripe_offset = btrfs_stripe_offset(leaf, stripe); | 3022 | stripe_offset = btrfs_stripe_offset(leaf, stripe); |
3023 | stripe_length = btrfs_chunk_length(leaf, chunk); | 3023 | stripe_length = btrfs_chunk_length(leaf, chunk); |
3024 | do_div(stripe_length, factor); | 3024 | stripe_length = div_u64(stripe_length, factor); |
3025 | 3025 | ||
3026 | if (stripe_offset < bargs->pend && | 3026 | if (stripe_offset < bargs->pend && |
3027 | stripe_offset + stripe_length > bargs->pstart) | 3027 | stripe_offset + stripe_length > bargs->pstart) |
@@ -4399,8 +4399,8 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, | |||
4399 | */ | 4399 | */ |
4400 | if (stripe_size * data_stripes > max_chunk_size) { | 4400 | if (stripe_size * data_stripes > max_chunk_size) { |
4401 | u64 mask = (1ULL << 24) - 1; | 4401 | u64 mask = (1ULL << 24) - 1; |
4402 | stripe_size = max_chunk_size; | 4402 | |
4403 | do_div(stripe_size, data_stripes); | 4403 | stripe_size = div_u64(max_chunk_size, data_stripes); |
4404 | 4404 | ||
4405 | /* bump the answer up to a 16MB boundary */ | 4405 | /* bump the answer up to a 16MB boundary */ |
4406 | stripe_size = (stripe_size + mask) & ~mask; | 4406 | stripe_size = (stripe_size + mask) & ~mask; |
@@ -4412,10 +4412,10 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, | |||
4412 | stripe_size = devices_info[ndevs-1].max_avail; | 4412 | stripe_size = devices_info[ndevs-1].max_avail; |
4413 | } | 4413 | } |
4414 | 4414 | ||
4415 | do_div(stripe_size, dev_stripes); | 4415 | stripe_size = div_u64(stripe_size, dev_stripes); |
4416 | 4416 | ||
4417 | /* align to BTRFS_STRIPE_LEN */ | 4417 | /* align to BTRFS_STRIPE_LEN */ |
4418 | do_div(stripe_size, raid_stripe_len); | 4418 | stripe_size = div_u64(stripe_size, raid_stripe_len); |
4419 | stripe_size *= raid_stripe_len; | 4419 | stripe_size *= raid_stripe_len; |
4420 | 4420 | ||
4421 | map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS); | 4421 | map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS); |
@@ -5135,7 +5135,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, | |||
5135 | stripe_index = 0; | 5135 | stripe_index = 0; |
5136 | stripe_nr_orig = stripe_nr; | 5136 | stripe_nr_orig = stripe_nr; |
5137 | stripe_nr_end = ALIGN(offset + *length, map->stripe_len); | 5137 | stripe_nr_end = ALIGN(offset + *length, map->stripe_len); |
5138 | do_div(stripe_nr_end, map->stripe_len); | 5138 | stripe_nr_end = div_u64(stripe_nr_end, map->stripe_len); |
5139 | stripe_end_offset = stripe_nr_end * map->stripe_len - | 5139 | stripe_end_offset = stripe_nr_end * map->stripe_len - |
5140 | (offset + *length); | 5140 | (offset + *length); |
5141 | 5141 | ||
@@ -5197,8 +5197,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, | |||
5197 | ((rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) || | 5197 | ((rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) || |
5198 | mirror_num > 1)) { | 5198 | mirror_num > 1)) { |
5199 | /* push stripe_nr back to the start of the full stripe */ | 5199 | /* push stripe_nr back to the start of the full stripe */ |
5200 | stripe_nr = raid56_full_stripe_start; | 5200 | stripe_nr = div_u64(raid56_full_stripe_start, |
5201 | do_div(stripe_nr, stripe_len * nr_data_stripes(map)); | 5201 | stripe_len * nr_data_stripes(map)); |
5202 | 5202 | ||
5203 | /* RAID[56] write or recovery. Return all stripes */ | 5203 | /* RAID[56] write or recovery. Return all stripes */ |
5204 | num_stripes = map->num_stripes; | 5204 | num_stripes = map->num_stripes; |
@@ -5534,11 +5534,11 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree, | |||
5534 | rmap_len = map->stripe_len; | 5534 | rmap_len = map->stripe_len; |
5535 | 5535 | ||
5536 | if (map->type & BTRFS_BLOCK_GROUP_RAID10) | 5536 | if (map->type & BTRFS_BLOCK_GROUP_RAID10) |
5537 | do_div(length, map->num_stripes / map->sub_stripes); | 5537 | length = div_u64(length, map->num_stripes / map->sub_stripes); |
5538 | else if (map->type & BTRFS_BLOCK_GROUP_RAID0) | 5538 | else if (map->type & BTRFS_BLOCK_GROUP_RAID0) |
5539 | do_div(length, map->num_stripes); | 5539 | length = div_u64(length, map->num_stripes); |
5540 | else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { | 5540 | else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { |
5541 | do_div(length, nr_data_stripes(map)); | 5541 | length = div_u64(length, nr_data_stripes(map)); |
5542 | rmap_len = map->stripe_len * nr_data_stripes(map); | 5542 | rmap_len = map->stripe_len * nr_data_stripes(map); |
5543 | } | 5543 | } |
5544 | 5544 | ||
@@ -5553,11 +5553,11 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree, | |||
5553 | continue; | 5553 | continue; |
5554 | 5554 | ||
5555 | stripe_nr = physical - map->stripes[i].physical; | 5555 | stripe_nr = physical - map->stripes[i].physical; |
5556 | do_div(stripe_nr, map->stripe_len); | 5556 | stripe_nr = div_u64(stripe_nr, map->stripe_len); |
5557 | 5557 | ||
5558 | if (map->type & BTRFS_BLOCK_GROUP_RAID10) { | 5558 | if (map->type & BTRFS_BLOCK_GROUP_RAID10) { |
5559 | stripe_nr = stripe_nr * map->num_stripes + i; | 5559 | stripe_nr = stripe_nr * map->num_stripes + i; |
5560 | do_div(stripe_nr, map->sub_stripes); | 5560 | stripe_nr = div_u64(stripe_nr, map->sub_stripes); |
5561 | } else if (map->type & BTRFS_BLOCK_GROUP_RAID0) { | 5561 | } else if (map->type & BTRFS_BLOCK_GROUP_RAID0) { |
5562 | stripe_nr = stripe_nr * map->num_stripes + i; | 5562 | stripe_nr = stripe_nr * map->num_stripes + i; |
5563 | } /* else if RAID[56], multiply by nr_data_stripes(). | 5563 | } /* else if RAID[56], multiply by nr_data_stripes(). |