diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-06-12 07:43:08 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-06-12 07:43:08 -0400 |
commit | 84f54cfa78c81991e087309a9b379f25f1ffdb10 (patch) | |
tree | 2f2576ea31a276504e99090473e2c6829d1a9024 /fs/btrfs/extent-tree.c | |
parent | 39279cc3d2704cfbf9c35dcb5bdd392159ae4625 (diff) |
Btrfs: 64 bit div fixes
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r-- | fs/btrfs/extent-tree.c | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index f509ffa38d03..6949eebc9dc1 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -65,7 +65,6 @@ static int cache_block_group(struct btrfs_root *root, | |||
65 | path = btrfs_alloc_path(); | 65 | path = btrfs_alloc_path(); |
66 | if (!path) | 66 | if (!path) |
67 | return -ENOMEM; | 67 | return -ENOMEM; |
68 | printk("cache block group %Lu\n", block_group->key.objectid); | ||
69 | key.objectid = block_group->key.objectid; | 68 | key.objectid = block_group->key.objectid; |
70 | key.flags = 0; | 69 | key.flags = 0; |
71 | key.offset = 0; | 70 | key.offset = 0; |
@@ -164,8 +163,8 @@ struct btrfs_block_group_cache *btrfs_lookup_block_group(struct | |||
164 | static u64 leaf_range(struct btrfs_root *root) | 163 | static u64 leaf_range(struct btrfs_root *root) |
165 | { | 164 | { |
166 | u64 size = BTRFS_LEAF_DATA_SIZE(root); | 165 | u64 size = BTRFS_LEAF_DATA_SIZE(root); |
167 | size = size / (sizeof(struct btrfs_extent_item) + | 166 | do_div(size, sizeof(struct btrfs_extent_item) + |
168 | sizeof(struct btrfs_item)); | 167 | sizeof(struct btrfs_item)); |
169 | return size; | 168 | return size; |
170 | } | 169 | } |
171 | 170 | ||
@@ -219,6 +218,13 @@ new_group: | |||
219 | goto again; | 218 | goto again; |
220 | } | 219 | } |
221 | 220 | ||
221 | static u64 div_factor(u64 num, int factor) | ||
222 | { | ||
223 | num *= factor; | ||
224 | do_div(num, 10); | ||
225 | return num; | ||
226 | } | ||
227 | |||
222 | struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root, | 228 | struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root, |
223 | struct btrfs_block_group_cache | 229 | struct btrfs_block_group_cache |
224 | *hint, u64 search_start, | 230 | *hint, u64 search_start, |
@@ -255,17 +261,18 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root, | |||
255 | if (shint->data == data) { | 261 | if (shint->data == data) { |
256 | used = btrfs_block_group_used(&shint->item); | 262 | used = btrfs_block_group_used(&shint->item); |
257 | if (used + shint->pinned < | 263 | if (used + shint->pinned < |
258 | (shint->key.offset * factor) / 10) { | 264 | div_factor(shint->key.offset, factor)) { |
259 | return shint; | 265 | return shint; |
260 | } | 266 | } |
261 | } | 267 | } |
262 | } | 268 | } |
263 | if (hint && hint->data == data) { | 269 | if (hint && hint->data == data) { |
264 | used = btrfs_block_group_used(&hint->item); | 270 | used = btrfs_block_group_used(&hint->item); |
265 | if (used + hint->pinned < (hint->key.offset * factor) / 10) { | 271 | if (used + hint->pinned < |
272 | div_factor(hint->key.offset, factor)) { | ||
266 | return hint; | 273 | return hint; |
267 | } | 274 | } |
268 | if (used >= (hint->key.offset * 8) / 10) { | 275 | if (used >= div_factor(hint->key.offset, 8)) { |
269 | radix_tree_tag_clear(radix, | 276 | radix_tree_tag_clear(radix, |
270 | hint->key.objectid + | 277 | hint->key.objectid + |
271 | hint->key.offset - 1, | 278 | hint->key.offset - 1, |
@@ -297,11 +304,11 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root, | |||
297 | cache[i]->key.offset; | 304 | cache[i]->key.offset; |
298 | used = btrfs_block_group_used(&cache[i]->item); | 305 | used = btrfs_block_group_used(&cache[i]->item); |
299 | if (used + cache[i]->pinned < | 306 | if (used + cache[i]->pinned < |
300 | (cache[i]->key.offset * factor) / 10) { | 307 | div_factor(cache[i]->key.offset, factor)) { |
301 | found_group = cache[i]; | 308 | found_group = cache[i]; |
302 | goto found; | 309 | goto found; |
303 | } | 310 | } |
304 | if (used >= (cache[i]->key.offset * 8) / 10) { | 311 | if (used >= div_factor(cache[i]->key.offset, 8)) { |
305 | radix_tree_tag_clear(radix, | 312 | radix_tree_tag_clear(radix, |
306 | cache[i]->key.objectid + | 313 | cache[i]->key.objectid + |
307 | cache[i]->key.offset - 1, | 314 | cache[i]->key.offset - 1, |
@@ -348,7 +355,6 @@ again: | |||
348 | goto again; | 355 | goto again; |
349 | } | 356 | } |
350 | if (!found_group) { | 357 | if (!found_group) { |
351 | printk("find block group bailing to zero data %d\n", data); | ||
352 | ret = radix_tree_gang_lookup(radix, | 358 | ret = radix_tree_gang_lookup(radix, |
353 | (void **)&found_group, 0, 1); | 359 | (void **)&found_group, 0, 1); |
354 | if (ret == 0) { | 360 | if (ret == 0) { |
@@ -386,7 +392,6 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, | |||
386 | ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, path, | 392 | ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, path, |
387 | 0, 1); | 393 | 0, 1); |
388 | if (ret != 0) { | 394 | if (ret != 0) { |
389 | printk("can't find block %Lu %Lu\n", blocknr, num_blocks); | ||
390 | BUG(); | 395 | BUG(); |
391 | } | 396 | } |
392 | BUG_ON(ret != 0); | 397 | BUG_ON(ret != 0); |
@@ -601,8 +606,7 @@ static int update_block_group(struct btrfs_trans_handle *trans, | |||
601 | } | 606 | } |
602 | } | 607 | } |
603 | if (cache->data != data && | 608 | if (cache->data != data && |
604 | old_val < cache->key.offset / 2) { | 609 | old_val < (cache->key.offset >> 1)) { |
605 | printk("changing block group %Lu from %d to %d\n", cache->key.objectid, cache->data, data); | ||
606 | cache->data = data; | 610 | cache->data = data; |
607 | radix_tree_delete(cache->radix, | 611 | radix_tree_delete(cache->radix, |
608 | cache->key.objectid + | 612 | cache->key.objectid + |
@@ -634,9 +638,8 @@ printk("changing block group %Lu from %d to %d\n", cache->key.objectid, cache->d | |||
634 | blocknr + i); | 638 | blocknr + i); |
635 | } | 639 | } |
636 | } | 640 | } |
637 | if (old_val < cache->key.offset / 2 && | 641 | if (old_val < (cache->key.offset >> 1) && |
638 | old_val + num >= cache->key.offset / 2) { | 642 | old_val + num >= (cache->key.offset >> 1)) { |
639 | printk("group %Lu now available\n", cache->key.objectid); | ||
640 | radix_tree_tag_set(cache->radix, | 643 | radix_tree_tag_set(cache->radix, |
641 | cache->key.objectid + | 644 | cache->key.objectid + |
642 | cache->key.offset - 1, | 645 | cache->key.offset - 1, |
@@ -1000,10 +1003,10 @@ check_failed: | |||
1000 | } | 1003 | } |
1001 | if (start_found) | 1004 | if (start_found) |
1002 | limit = last_block + | 1005 | limit = last_block + |
1003 | block_group->key.offset / 2; | 1006 | (block_group->key.offset >> 1); |
1004 | else | 1007 | else |
1005 | limit = search_start + | 1008 | limit = search_start + |
1006 | block_group->key.offset / 2; | 1009 | (block_group->key.offset >> 1); |
1007 | ret = btrfs_next_leaf(root, path); | 1010 | ret = btrfs_next_leaf(root, path); |
1008 | if (ret == 0) | 1011 | if (ret == 0) |
1009 | continue; | 1012 | continue; |
@@ -1534,9 +1537,11 @@ int btrfs_read_block_groups(struct btrfs_root *root) | |||
1534 | struct btrfs_key key; | 1537 | struct btrfs_key key; |
1535 | struct btrfs_key found_key; | 1538 | struct btrfs_key found_key; |
1536 | struct btrfs_leaf *leaf; | 1539 | struct btrfs_leaf *leaf; |
1537 | u64 group_size_blocks = BTRFS_BLOCK_GROUP_SIZE / root->blocksize; | 1540 | u64 group_size_blocks; |
1538 | u64 used; | 1541 | u64 used; |
1539 | 1542 | ||
1543 | group_size_blocks = BTRFS_BLOCK_GROUP_SIZE >> | ||
1544 | root->fs_info->sb->s_blocksize_bits; | ||
1540 | root = info->extent_root; | 1545 | root = info->extent_root; |
1541 | key.objectid = 0; | 1546 | key.objectid = 0; |
1542 | key.offset = group_size_blocks; | 1547 | key.offset = group_size_blocks; |
@@ -1590,7 +1595,7 @@ int btrfs_read_block_groups(struct btrfs_root *root) | |||
1590 | (void *)cache); | 1595 | (void *)cache); |
1591 | BUG_ON(ret); | 1596 | BUG_ON(ret); |
1592 | used = btrfs_block_group_used(bi); | 1597 | used = btrfs_block_group_used(bi); |
1593 | if (used < (key.offset * 8) / 10) { | 1598 | if (used < div_factor(key.offset, 8)) { |
1594 | radix_tree_tag_set(radix, found_key.objectid + | 1599 | radix_tree_tag_set(radix, found_key.objectid + |
1595 | found_key.offset - 1, | 1600 | found_key.offset - 1, |
1596 | BTRFS_BLOCK_GROUP_AVAIL); | 1601 | BTRFS_BLOCK_GROUP_AVAIL); |