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 | |
parent | 39279cc3d2704cfbf9c35dcb5bdd392159ae4625 (diff) |
Btrfs: 64 bit div fixes
Signed-off-by: Chris Mason <chris.mason@oracle.com>
-rw-r--r-- | fs/btrfs/extent-tree.c | 43 | ||||
-rw-r--r-- | fs/btrfs/file-item.c | 3 | ||||
-rw-r--r-- | fs/btrfs/file.c | 7 | ||||
-rw-r--r-- | fs/btrfs/root-tree.c | 2 |
4 files changed, 31 insertions, 24 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); |
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 0782e924ddeb..fb8c214160c1 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c | |||
@@ -239,7 +239,8 @@ int btrfs_csum_truncate(struct btrfs_trans_handle *trans, | |||
239 | if (isize <= key.offset) | 239 | if (isize <= key.offset) |
240 | return 0; | 240 | return 0; |
241 | new_item_span = isize - key.offset; | 241 | new_item_span = isize - key.offset; |
242 | blocks = (new_item_span + root->blocksize - 1) / root->blocksize; | 242 | blocks = (new_item_span + root->blocksize - 1) >> |
243 | root->fs_info->sb->s_blocksize_bits; | ||
243 | new_item_size = blocks * BTRFS_CRC32_SIZE; | 244 | new_item_size = blocks * BTRFS_CRC32_SIZE; |
244 | if (new_item_size >= btrfs_item_size(leaf->items + slot)) | 245 | if (new_item_size >= btrfs_item_size(leaf->items + slot)) |
245 | return 0; | 246 | return 0; |
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 7f8e3035d99e..0325dc038592 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -82,7 +82,7 @@ static int dirty_and_release_pages(struct btrfs_trans_handle *trans, | |||
82 | 82 | ||
83 | for (i = 0; i < num_pages; i++) { | 83 | for (i = 0; i < num_pages; i++) { |
84 | offset = pos & (PAGE_CACHE_SIZE -1); | 84 | offset = pos & (PAGE_CACHE_SIZE -1); |
85 | this_write = min(PAGE_CACHE_SIZE - offset, write_bytes); | 85 | this_write = min((size_t)PAGE_CACHE_SIZE - offset, write_bytes); |
86 | /* FIXME, one block at a time */ | 86 | /* FIXME, one block at a time */ |
87 | 87 | ||
88 | mutex_lock(&root->fs_info->fs_mutex); | 88 | mutex_lock(&root->fs_info->fs_mutex); |
@@ -395,7 +395,7 @@ static int prepare_pages(struct btrfs_root *root, | |||
395 | cancel_dirty_page(pages[i], PAGE_CACHE_SIZE); | 395 | cancel_dirty_page(pages[i], PAGE_CACHE_SIZE); |
396 | wait_on_page_writeback(pages[i]); | 396 | wait_on_page_writeback(pages[i]); |
397 | offset = pos & (PAGE_CACHE_SIZE -1); | 397 | offset = pos & (PAGE_CACHE_SIZE -1); |
398 | this_write = min(PAGE_CACHE_SIZE - offset, write_bytes); | 398 | this_write = min((size_t)PAGE_CACHE_SIZE - offset, write_bytes); |
399 | if (!page_has_buffers(pages[i])) { | 399 | if (!page_has_buffers(pages[i])) { |
400 | create_empty_buffers(pages[i], | 400 | create_empty_buffers(pages[i], |
401 | root->fs_info->sb->s_blocksize, | 401 | root->fs_info->sb->s_blocksize, |
@@ -567,7 +567,8 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, | |||
567 | 567 | ||
568 | while(count > 0) { | 568 | while(count > 0) { |
569 | size_t offset = pos & (PAGE_CACHE_SIZE - 1); | 569 | size_t offset = pos & (PAGE_CACHE_SIZE - 1); |
570 | size_t write_bytes = min(count, PAGE_CACHE_SIZE - offset); | 570 | size_t write_bytes = min(count, |
571 | (size_t)PAGE_CACHE_SIZE - offset); | ||
571 | size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >> | 572 | size_t num_pages = (write_bytes + PAGE_CACHE_SIZE - 1) >> |
572 | PAGE_CACHE_SHIFT; | 573 | PAGE_CACHE_SHIFT; |
573 | 574 | ||
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c index a42943bd9179..0564a73bb2e2 100644 --- a/fs/btrfs/root-tree.c +++ b/fs/btrfs/root-tree.c | |||
@@ -102,7 +102,7 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
102 | ret = btrfs_del_item(trans, root, path); | 102 | ret = btrfs_del_item(trans, root, path); |
103 | } else { | 103 | } else { |
104 | btrfs_set_root_refs(ri, refs - 1); | 104 | btrfs_set_root_refs(ri, refs - 1); |
105 | printk("ref now %u root %Lu %Lu %u\n", refs -1, key->objectid, key->offset, key->flags); | 105 | printk("ref now %u root %llu %Lu %u\n", refs -1, key->objectid, key->offset, key->flags); |
106 | mark_buffer_dirty(path->nodes[0]); | 106 | mark_buffer_dirty(path->nodes[0]); |
107 | } | 107 | } |
108 | out: | 108 | out: |