Commit 6719db6a23d4b7f1e5052eedae394135e3aef9c1
Committed by
Linus Torvalds
1 parent
c063d8a60f
Exists in
master
and in
4 other branches
Btrfs: fix 64 bit divide problem
This fixes a regression introduced by commit cdcb725c05fe ("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: Josef Bacik <josef@redhat.com> Acked-and-tested-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 7 additions and 5 deletions Side-by-side Diff
fs/btrfs/extent-tree.c
... | ... | @@ -6735,9 +6735,9 @@ |
6735 | 6735 | struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; |
6736 | 6736 | struct btrfs_device *device; |
6737 | 6737 | u64 min_free; |
6738 | + u64 dev_min = 1; | |
6739 | + u64 dev_nr = 0; | |
6738 | 6740 | int index; |
6739 | - int dev_nr = 0; | |
6740 | - int dev_min = 1; | |
6741 | 6741 | int full = 0; |
6742 | 6742 | int ret = 0; |
6743 | 6743 | |
6744 | 6744 | |
6745 | 6745 | |
... | ... | @@ -6796,14 +6796,16 @@ |
6796 | 6796 | index = get_block_group_index(block_group); |
6797 | 6797 | if (index == 0) { |
6798 | 6798 | dev_min = 4; |
6799 | - min_free /= 2; | |
6799 | + /* Divide by 2 */ | |
6800 | + min_free >>= 1; | |
6800 | 6801 | } else if (index == 1) { |
6801 | 6802 | dev_min = 2; |
6802 | 6803 | } else if (index == 2) { |
6803 | - min_free *= 2; | |
6804 | + /* Multiply by 2 */ | |
6805 | + min_free <<= 1; | |
6804 | 6806 | } else if (index == 3) { |
6805 | 6807 | dev_min = fs_devices->rw_devices; |
6806 | - min_free /= dev_min; | |
6808 | + do_div(min_free, dev_min); | |
6807 | 6809 | } |
6808 | 6810 | |
6809 | 6811 | mutex_lock(&root->fs_info->chunk_mutex); |