btrfs: replace remaining do_div calls with div_u64 variants
authorDavid Sterba <dsterba@suse.cz>
Fri, 20 Feb 2015 17:43:47 +0000 (18:43 +0100)
committerDavid Sterba <dsterba@suse.cz>
Tue, 3 Mar 2015 16:09:41 +0000 (17:09 +0100)
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>
fs/btrfs/extent-tree.c
fs/btrfs/free-space-cache.c
fs/btrfs/scrub.c
fs/btrfs/volumes.c

index 4ccc3397c644dfa3d3701dcd771fa60bb627c86f..5840afe5e5f90e19c2bad7cc026cf1666676569e 100644 (file)
@@ -8670,7 +8670,7 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
                min_free <<= 1;
        } else if (index == BTRFS_RAID_RAID0) {
                dev_min = fs_devices->rw_devices;
-               do_div(min_free, dev_min);
+               min_free = div64_u64(min_free, dev_min);
        }
 
        /* We need to do this so that we can look at pending chunks */
index f371aac91a90e97c31d17e646bc50e192bd3fe1b..740beed2aec5a8e5804db1cede5b4e4b20144cd6 100644 (file)
@@ -1673,7 +1673,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes,
                 */
                if (*bytes >= align) {
                        tmp = entry->offset - ctl->start + align - 1;
-                       do_div(tmp, align);
+                       tmp = div64_u64(tmp, align);
                        tmp = tmp * align + ctl->start;
                        align_off = tmp - entry->offset;
                } else {
index 07be15d4ce7b6465eac122995354cde0c08522ec..4cdf739c7a4799bd6e01efbd53cdbd954584260a 100644 (file)
@@ -2329,7 +2329,7 @@ static inline void __scrub_mark_bitmap(struct scrub_parity *sparity,
        }
 
        start -= sparity->logic_start;
-       offset = (int)do_div(start, sparity->stripe_len);
+       start = div_u64_rem(start, sparity->stripe_len, &offset);
        offset /= sectorsize;
        nsectors = (int)len / sectorsize;
 
@@ -2628,7 +2628,7 @@ static int get_raid56_logic_offset(u64 physical, int num,
                stripe_nr = div_u64(stripe_nr, nr_data_stripes(map));
 
                /* Work out the disk rotation on this stripe-set */
-               rot = do_div(stripe_nr, map->num_stripes);
+               stripe_nr = div_u64_rem(stripe_nr, map->num_stripes, &rot);
                /* calculate which stripe this data locates */
                rot += i;
                stripe_index = rot % map->num_stripes;
index 36c9c1a8923223c84a7e0dfcf1ff54d4dd19696b..e79eee9c127e0f4c7b05b6a0dd1cfa66c7fca8b4 100644 (file)
@@ -4995,7 +4995,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
         * stripe_nr counts the total number of stripes we have to stride
         * to get to this block
         */
-       do_div(stripe_nr, stripe_len);
+       stripe_nr = div64_u64(stripe_nr, stripe_len);
 
        stripe_offset = stripe_nr * stripe_len;
        BUG_ON(offset < stripe_offset);
@@ -5011,7 +5011,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                /* allow a write of a full stripe, but make sure we don't
                 * allow straddling of stripes
                 */
-               do_div(raid56_full_stripe_start, full_stripe_len);
+               raid56_full_stripe_start = div64_u64(raid56_full_stripe_start,
+                               full_stripe_len);
                raid56_full_stripe_start *= full_stripe_len;
        }
 
@@ -5144,7 +5145,8 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                if (rw & REQ_DISCARD)
                        num_stripes = min_t(u64, map->num_stripes,
                                            stripe_nr_end - stripe_nr_orig);
-               stripe_index = do_div(stripe_nr, map->num_stripes);
+               stripe_nr = div_u64_rem(stripe_nr, map->num_stripes,
+                               &stripe_index);
                if (!(rw & (REQ_WRITE | REQ_DISCARD | REQ_GET_READ_MIRRORS)))
                        mirror_num = 1;
        } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
@@ -5172,7 +5174,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
        } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
                int factor = map->num_stripes / map->sub_stripes;
 
-               stripe_index = do_div(stripe_nr, factor);
+               stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index);
                stripe_index *= map->sub_stripes;
 
                if (rw & (REQ_WRITE | REQ_GET_READ_MIRRORS))
@@ -5209,32 +5211,32 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                        stripe_index = 0;
                        stripe_offset = 0;
                } else {
-                       u64 tmp;
-
                        /*
                         * Mirror #0 or #1 means the original data block.
                         * Mirror #2 is RAID5 parity block.
                         * Mirror #3 is RAID6 Q block.
                         */
-                       stripe_index = do_div(stripe_nr, nr_data_stripes(map));
+                       stripe_nr = div_u64_rem(stripe_nr,
+                                       nr_data_stripes(map), &stripe_index);
                        if (mirror_num > 1)
                                stripe_index = nr_data_stripes(map) +
                                                mirror_num - 2;
 
                        /* We distribute the parity blocks across stripes */
-                       tmp = stripe_nr + stripe_index;
-                       stripe_index = do_div(tmp, map->num_stripes);
+                       div_u64_rem(stripe_nr + stripe_index, map->num_stripes,
+                                       &stripe_index);
                        if (!(rw & (REQ_WRITE | REQ_DISCARD |
                                    REQ_GET_READ_MIRRORS)) && mirror_num <= 1)
                                mirror_num = 1;
                }
        } else {
                /*
-                * after this do_div call, stripe_nr is the number of stripes
-                * on this device we have to walk to find the data, and
-                * stripe_index is the number of our device in the stripe array
+                * after this, stripe_nr is the number of stripes on this
+                * device we have to walk to find the data, and stripe_index is
+                * the number of our device in the stripe array
                 */
-               stripe_index = do_div(stripe_nr, map->num_stripes);
+               stripe_nr = div_u64_rem(stripe_nr, map->num_stripes,
+                               &stripe_index);
                mirror_num = stripe_index + 1;
        }
        BUG_ON(stripe_index >= map->num_stripes);
@@ -5269,8 +5271,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                                 sizeof(int) * tgtdev_indexes);
 
                /* Work out the disk rotation on this stripe-set */
-               tmp = stripe_nr;
-               rot = do_div(tmp, num_stripes);
+               div_u64_rem(stripe_nr, num_stripes, &rot);
 
                /* Fill in the logical address of each stripe */
                tmp = stripe_nr * nr_data_stripes(map);