Commit 6719db6a authored by Josef Bacik's avatar Josef Bacik Committed by Linus Torvalds

Btrfs: fix 64 bit divide problem

This fixes a regression introduced by commit cdcb725c ("Btrfs: check
if there is enough space for balancing smarter").  We can't do 64-bit
divides on 32-bit architectures.

In cases where we need to divide/multiply by 2 we should just left/right
shift respectively, and in cases where theres N number of devices use
do_div.  Also make the counters u64 to match up with rw_devices.
Thanks,
Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
Acked-and-tested-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c063d8a6
...@@ -6735,9 +6735,9 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr) ...@@ -6735,9 +6735,9 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
struct btrfs_device *device; struct btrfs_device *device;
u64 min_free; u64 min_free;
u64 dev_min = 1;
u64 dev_nr = 0;
int index; int index;
int dev_nr = 0;
int dev_min = 1;
int full = 0; int full = 0;
int ret = 0; int ret = 0;
...@@ -6796,14 +6796,16 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr) ...@@ -6796,14 +6796,16 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
index = get_block_group_index(block_group); index = get_block_group_index(block_group);
if (index == 0) { if (index == 0) {
dev_min = 4; dev_min = 4;
min_free /= 2; /* Divide by 2 */
min_free >>= 1;
} else if (index == 1) { } else if (index == 1) {
dev_min = 2; dev_min = 2;
} else if (index == 2) { } else if (index == 2) {
min_free *= 2; /* Multiply by 2 */
min_free <<= 1;
} else if (index == 3) { } else if (index == 3) {
dev_min = fs_devices->rw_devices; dev_min = fs_devices->rw_devices;
min_free /= dev_min; do_div(min_free, dev_min);
} }
mutex_lock(&root->fs_info->chunk_mutex); mutex_lock(&root->fs_info->chunk_mutex);
......
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