Skip to contentSkip to conversation

Btrfs: fix 64 bit divide problem

PATCH In review Josef Bacik 2 participants 2 messages Aug 20, 2011 – Aug 21, 2011 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: fix 64 bit divide problem

This fixes a regression introduced by

cdcb725c05fe0cb71777c66ddc2445fedbbb3c59

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,

---
 fs/btrfs/extent-tree.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
fs/btrfs/extent-tree.c +7 -5
index 44a3107..99ab571 100644
@@ -6727,9 +6727,9 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
 	struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
 	struct btrfs_device *device;
 	u64 min_free;
+	u64 dev_min = 1;
+	u64 dev_nr = 0;
 	int index;
-	int dev_nr = 0;
-	int dev_min = 1;
 	int full = 0;
 	int ret = 0;
 
@@ -6788,14 +6788,16 @@ int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr)
 	index = get_block_group_index(block_group);
 	if (index == 0) {
 		dev_min = 4;
-		min_free /= 2;
+		/* Divide by 2 */
+		min_free >>= 1;
 	} else if (index == 1) {
 		dev_min = 2;
 	} else if (index == 2) {
-		min_free *= 2;
+		/* Multiply by 2 */
+		min_free <<= 1;
 	} else if (index == 3) {
 		dev_min = fs_devices->rw_devices;
-		min_free /= dev_min;
+		do_div(min_free, dev_min);
 	}
 
 	mutex_lock(&root->fs_info->chunk_mutex);
Signature · 1 line
1.7.5.2
#1 lore raw
Quoted 9 lines · Josef Bacik

This fixes a regression introduced by

cdcb725c05fe0cb71777c66ddc2445fedbbb3c59

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,

Thanks,

Ingo