diff options
author | David Sterba <dsterba@suse.cz> | 2015-02-20 12:43:47 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2015-03-03 11:24:01 -0500 |
commit | 47c5713f4737e460a3b2535abb8ae2e2afe2d2d0 (patch) | |
tree | 918e1930e0de0e607736cd7845fc4d3db92d24aa /fs/btrfs | |
parent | b8b93addde1e0192b045da8995e296fc1e40c80f (diff) |
btrfs: replace remaining do_div calls with div_u64 variants
Switch to div_u64_rem that does type checking and has more obvious
semantics than do_div.
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/extent-tree.c | 2 | ||||
-rw-r--r-- | fs/btrfs/free-space-cache.c | 2 | ||||
-rw-r--r-- | fs/btrfs/scrub.c | 4 | ||||
-rw-r--r-- | fs/btrfs/volumes.c | 31 |
4 files changed, 20 insertions, 19 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 4ccc3397c644..5840afe5e5f9 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -8670,7 +8670,7 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr) | |||
8670 | min_free <<= 1; | 8670 | min_free <<= 1; |
8671 | } else if (index == BTRFS_RAID_RAID0) { | 8671 | } else if (index == BTRFS_RAID_RAID0) { |
8672 | dev_min = fs_devices->rw_devices; | 8672 | dev_min = fs_devices->rw_devices; |
8673 | do_div(min_free, dev_min); | 8673 | min_free = div64_u64(min_free, dev_min); |
8674 | } | 8674 | } |
8675 | 8675 | ||
8676 | /* We need to do this so that we can look at pending chunks */ | 8676 | /* We need to do this so that we can look at pending chunks */ |
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 13c9b46d4727..764528a4f6fd 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c | |||
@@ -1673,7 +1673,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, | |||
1673 | */ | 1673 | */ |
1674 | if (*bytes >= align) { | 1674 | if (*bytes >= align) { |
1675 | tmp = entry->offset - ctl->start + align - 1; | 1675 | tmp = entry->offset - ctl->start + align - 1; |
1676 | do_div(tmp, align); | 1676 | tmp = div64_u64(tmp, align); |
1677 | tmp = tmp * align + ctl->start; | 1677 | tmp = tmp * align + ctl->start; |
1678 | align_off = tmp - entry->offset; | 1678 | align_off = tmp - entry->offset; |
1679 | } else { | 1679 | } else { |
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 293262163daf..c21581e0be7a 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c | |||
@@ -2328,7 +2328,7 @@ static inline void __scrub_mark_bitmap(struct scrub_parity *sparity, | |||
2328 | } | 2328 | } |
2329 | 2329 | ||
2330 | start -= sparity->logic_start; | 2330 | start -= sparity->logic_start; |
2331 | offset = (int)do_div(start, sparity->stripe_len); | 2331 | start = div_u64_rem(start, sparity->stripe_len, &offset); |
2332 | offset /= sectorsize; | 2332 | offset /= sectorsize; |
2333 | nsectors = (int)len / sectorsize; | 2333 | nsectors = (int)len / sectorsize; |
2334 | 2334 | ||
@@ -2627,7 +2627,7 @@ static int get_raid56_logic_offset(u64 physical, int num, | |||
2627 | stripe_nr = div_u64(stripe_nr, nr_data_stripes(map)); | 2627 | stripe_nr = div_u64(stripe_nr, nr_data_stripes(map)); |
2628 | 2628 | ||
2629 | /* Work out the disk rotation on this stripe-set */ | 2629 | /* Work out the disk rotation on this stripe-set */ |
2630 | rot = do_div(stripe_nr, map->num_stripes); | 2630 | stripe_nr = div_u64_rem(stripe_nr, map->num_stripes, &rot); |
2631 | /* calculate which stripe this data locates */ | 2631 | /* calculate which stripe this data locates */ |
2632 | rot += i; | 2632 | rot += i; |
2633 | stripe_index = rot % map->num_stripes; | 2633 | stripe_index = rot % map->num_stripes; |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index d712c46c0a6b..bf38ed09810a 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -4994,7 +4994,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, | |||
4994 | * stripe_nr counts the total number of stripes we have to stride | 4994 | * stripe_nr counts the total number of stripes we have to stride |
4995 | * to get to this block | 4995 | * to get to this block |
4996 | */ | 4996 | */ |
4997 | do_div(stripe_nr, stripe_len); | 4997 | stripe_nr = div64_u64(stripe_nr, stripe_len); |
4998 | 4998 | ||
4999 | stripe_offset = stripe_nr * stripe_len; | 4999 | stripe_offset = stripe_nr * stripe_len; |
5000 | BUG_ON(offset < stripe_offset); | 5000 | BUG_ON(offset < stripe_offset); |
@@ -5010,7 +5010,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, | |||
5010 | /* allow a write of a full stripe, but make sure we don't | 5010 | /* allow a write of a full stripe, but make sure we don't |
5011 | * allow straddling of stripes | 5011 | * allow straddling of stripes |
5012 | */ | 5012 | */ |
5013 | do_div(raid56_full_stripe_start, full_stripe_len); | 5013 | raid56_full_stripe_start = div64_u64(raid56_full_stripe_start, |
5014 | full_stripe_len); | ||
5014 | raid56_full_stripe_start *= full_stripe_len; | 5015 | raid56_full_stripe_start *= full_stripe_len; |
5015 | } | 5016 | } |
5016 | 5017 | ||
@@ -5143,7 +5144,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, | |||
5143 | if (rw & REQ_DISCARD) | 5144 | if (rw & REQ_DISCARD) |
5144 | num_stripes = min_t(u64, map->num_stripes, | 5145 | num_stripes = min_t(u64, map->num_stripes, |
5145 | stripe_nr_end - stripe_nr_orig); | 5146 | stripe_nr_end - stripe_nr_orig); |
5146 | stripe_index = do_div(stripe_nr, map->num_stripes); | 5147 | stripe_nr = div_u64_rem(stripe_nr, map->num_stripes, |
5148 | &stripe_index); | ||
5147 | if (!(rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS))) | 5149 | if (!(rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS))) |
5148 | mirror_num = 1; | 5150 | mirror_num = 1; |
5149 | } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) { | 5151 | } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) { |
@@ -5171,7 +5173,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, | |||
5171 | } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { | 5173 | } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { |
5172 | int factor = map->num_stripes / map->sub_stripes; | 5174 | int factor = map->num_stripes / map->sub_stripes; |
5173 | 5175 | ||
5174 | stripe_index = do_div(stripe_nr, factor); | 5176 | stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index); |
5175 | stripe_index *= map->sub_stripes; | 5177 | stripe_index *= map->sub_stripes; |
5176 | 5178 | ||
5177 | if (rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) | 5179 | if (rw & (REQ_WRITE | REQ_GET_READ_MIRRORS)) |
@@ -5208,32 +5210,32 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, | |||
5208 | stripe_index = 0; | 5210 | stripe_index = 0; |
5209 | stripe_offset = 0; | 5211 | stripe_offset = 0; |
5210 | } else { | 5212 | } else { |
5211 | u64 tmp; | ||
5212 | |||
5213 | /* | 5213 | /* |
5214 | * Mirror #0 or #1 means the original data block. | 5214 | * Mirror #0 or #1 means the original data block. |
5215 | * Mirror #2 is RAID5 parity block. | 5215 | * Mirror #2 is RAID5 parity block. |
5216 | * Mirror #3 is RAID6 Q block. | 5216 | * Mirror #3 is RAID6 Q block. |
5217 | */ | 5217 | */ |
5218 | stripe_index = do_div(stripe_nr, nr_data_stripes(map)); | 5218 | stripe_nr = div_u64_rem(stripe_nr, |
5219 | nr_data_stripes(map), &stripe_index); | ||
5219 | if (mirror_num > 1) | 5220 | if (mirror_num > 1) |
5220 | stripe_index = nr_data_stripes(map) + | 5221 | stripe_index = nr_data_stripes(map) + |
5221 | mirror_num - 2; | 5222 | mirror_num - 2; |
5222 | 5223 | ||
5223 | /* We distribute the parity blocks across stripes */ | 5224 | /* We distribute the parity blocks across stripes */ |
5224 | tmp = stripe_nr + stripe_index; | 5225 | div_u64_rem(stripe_nr + stripe_index, map->num_stripes, |
5225 | stripe_index = do_div(tmp, map->num_stripes); | 5226 | &stripe_index); |
5226 | if (!(rw & (REQ_WRITE | REQ_DISCARD | | 5227 | if (!(rw & (REQ_WRITE | REQ_DISCARD | |
5227 | REQ_GET_READ_MIRRORS)) && mirror_num <= 1) | 5228 | REQ_GET_READ_MIRRORS)) && mirror_num <= 1) |
5228 | mirror_num = 1; | 5229 | mirror_num = 1; |
5229 | } | 5230 | } |
5230 | } else { | 5231 | } else { |
5231 | /* | 5232 | /* |
5232 | * after this do_div call, stripe_nr is the number of stripes | 5233 | * after this, stripe_nr is the number of stripes on this |
5233 | * on this device we have to walk to find the data, and | 5234 | * device we have to walk to find the data, and stripe_index is |
5234 | * stripe_index is the number of our device in the stripe array | 5235 | * the number of our device in the stripe array |
5235 | */ | 5236 | */ |
5236 | stripe_index = do_div(stripe_nr, map->num_stripes); | 5237 | stripe_nr = div_u64_rem(stripe_nr, map->num_stripes, |
5238 | &stripe_index); | ||
5237 | mirror_num = stripe_index + 1; | 5239 | mirror_num = stripe_index + 1; |
5238 | } | 5240 | } |
5239 | BUG_ON(stripe_index >= map->num_stripes); | 5241 | BUG_ON(stripe_index >= map->num_stripes); |
@@ -5268,8 +5270,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, | |||
5268 | sizeof(int) * tgtdev_indexes); | 5270 | sizeof(int) * tgtdev_indexes); |
5269 | 5271 | ||
5270 | /* Work out the disk rotation on this stripe-set */ | 5272 | /* Work out the disk rotation on this stripe-set */ |
5271 | tmp = stripe_nr; | 5273 | div_u64_rem(stripe_nr, num_stripes, &rot); |
5272 | rot = do_div(tmp, num_stripes); | ||
5273 | 5274 | ||
5274 | /* Fill in the logical address of each stripe */ | 5275 | /* Fill in the logical address of each stripe */ |
5275 | tmp = stripe_nr * nr_data_stripes(map); | 5276 | tmp = stripe_nr * nr_data_stripes(map); |