| .. | .. |
|---|
| 11 | 11 | #include "free-space-cache.h" |
|---|
| 12 | 12 | #include "inode-map.h" |
|---|
| 13 | 13 | #include "transaction.h" |
|---|
| 14 | +#include "delalloc-space.h" |
|---|
| 14 | 15 | |
|---|
| 15 | 16 | static void fail_caching_thread(struct btrfs_root *root) |
|---|
| 16 | 17 | { |
|---|
| .. | .. |
|---|
| 106 | 107 | |
|---|
| 107 | 108 | if (last != (u64)-1 && last + 1 != key.objectid) { |
|---|
| 108 | 109 | __btrfs_add_free_space(fs_info, ctl, last + 1, |
|---|
| 109 | | - key.objectid - last - 1); |
|---|
| 110 | + key.objectid - last - 1, 0); |
|---|
| 110 | 111 | wake_up(&root->ino_cache_wait); |
|---|
| 111 | 112 | } |
|---|
| 112 | 113 | |
|---|
| .. | .. |
|---|
| 117 | 118 | |
|---|
| 118 | 119 | if (last < root->highest_objectid - 1) { |
|---|
| 119 | 120 | __btrfs_add_free_space(fs_info, ctl, last + 1, |
|---|
| 120 | | - root->highest_objectid - last - 1); |
|---|
| 121 | + root->highest_objectid - last - 1, 0); |
|---|
| 121 | 122 | } |
|---|
| 122 | 123 | |
|---|
| 123 | 124 | spin_lock(&root->ino_cache_lock); |
|---|
| .. | .. |
|---|
| 174 | 175 | ret = btrfs_find_free_objectid(root, &objectid); |
|---|
| 175 | 176 | if (!ret && objectid <= BTRFS_LAST_FREE_OBJECTID) { |
|---|
| 176 | 177 | __btrfs_add_free_space(fs_info, ctl, objectid, |
|---|
| 177 | | - BTRFS_LAST_FREE_OBJECTID - objectid + 1); |
|---|
| 178 | + BTRFS_LAST_FREE_OBJECTID - objectid + 1, |
|---|
| 179 | + 0); |
|---|
| 180 | + wake_up(&root->ino_cache_wait); |
|---|
| 178 | 181 | } |
|---|
| 179 | 182 | |
|---|
| 180 | 183 | tsk = kthread_run(caching_kthread, root, "btrfs-ino-cache-%llu", |
|---|
| .. | .. |
|---|
| 219 | 222 | return; |
|---|
| 220 | 223 | again: |
|---|
| 221 | 224 | if (root->ino_cache_state == BTRFS_CACHE_FINISHED) { |
|---|
| 222 | | - __btrfs_add_free_space(fs_info, pinned, objectid, 1); |
|---|
| 225 | + __btrfs_add_free_space(fs_info, pinned, objectid, 1, 0); |
|---|
| 223 | 226 | } else { |
|---|
| 224 | 227 | down_write(&fs_info->commit_root_sem); |
|---|
| 225 | 228 | spin_lock(&root->ino_cache_lock); |
|---|
| .. | .. |
|---|
| 232 | 235 | |
|---|
| 233 | 236 | start_caching(root); |
|---|
| 234 | 237 | |
|---|
| 235 | | - __btrfs_add_free_space(fs_info, pinned, objectid, 1); |
|---|
| 238 | + __btrfs_add_free_space(fs_info, pinned, objectid, 1, 0); |
|---|
| 236 | 239 | |
|---|
| 237 | 240 | up_write(&fs_info->commit_root_sem); |
|---|
| 238 | 241 | } |
|---|
| .. | .. |
|---|
| 279 | 282 | spin_unlock(rbroot_lock); |
|---|
| 280 | 283 | if (count) |
|---|
| 281 | 284 | __btrfs_add_free_space(root->fs_info, ctl, |
|---|
| 282 | | - info->offset, count); |
|---|
| 285 | + info->offset, count, 0); |
|---|
| 283 | 286 | kmem_cache_free(btrfs_free_space_cachep, info); |
|---|
| 284 | 287 | } |
|---|
| 285 | 288 | } |
|---|
| .. | .. |
|---|
| 434 | 437 | * 1 item for free space object |
|---|
| 435 | 438 | * 3 items for pre-allocation |
|---|
| 436 | 439 | */ |
|---|
| 437 | | - trans->bytes_reserved = btrfs_calc_trans_metadata_size(fs_info, 10); |
|---|
| 440 | + trans->bytes_reserved = btrfs_calc_insert_metadata_size(fs_info, 10); |
|---|
| 438 | 441 | ret = btrfs_block_rsv_add(root, trans->block_rsv, |
|---|
| 439 | 442 | trans->bytes_reserved, |
|---|
| 440 | 443 | BTRFS_RESERVE_NO_FLUSH); |
|---|
| .. | .. |
|---|
| 492 | 495 | /* Just to make sure we have enough space */ |
|---|
| 493 | 496 | prealloc += 8 * PAGE_SIZE; |
|---|
| 494 | 497 | |
|---|
| 495 | | - ret = btrfs_delalloc_reserve_space(inode, &data_reserved, 0, prealloc); |
|---|
| 498 | + ret = btrfs_delalloc_reserve_space(BTRFS_I(inode), &data_reserved, 0, |
|---|
| 499 | + prealloc); |
|---|
| 496 | 500 | if (ret) |
|---|
| 497 | 501 | goto out_put; |
|---|
| 498 | 502 | |
|---|
| .. | .. |
|---|
| 512 | 516 | trace_btrfs_space_reservation(fs_info, "ino_cache", trans->transid, |
|---|
| 513 | 517 | trans->bytes_reserved, 0); |
|---|
| 514 | 518 | btrfs_block_rsv_release(fs_info, trans->block_rsv, |
|---|
| 515 | | - trans->bytes_reserved); |
|---|
| 519 | + trans->bytes_reserved, NULL); |
|---|
| 516 | 520 | out: |
|---|
| 517 | 521 | trans->block_rsv = rsv; |
|---|
| 518 | 522 | trans->bytes_reserved = num_bytes; |
|---|
| 519 | 523 | |
|---|
| 520 | 524 | btrfs_free_path(path); |
|---|
| 521 | 525 | extent_changeset_free(data_reserved); |
|---|
| 522 | | - return ret; |
|---|
| 523 | | -} |
|---|
| 524 | | - |
|---|
| 525 | | -int btrfs_find_highest_objectid(struct btrfs_root *root, u64 *objectid) |
|---|
| 526 | | -{ |
|---|
| 527 | | - struct btrfs_path *path; |
|---|
| 528 | | - int ret; |
|---|
| 529 | | - struct extent_buffer *l; |
|---|
| 530 | | - struct btrfs_key search_key; |
|---|
| 531 | | - struct btrfs_key found_key; |
|---|
| 532 | | - int slot; |
|---|
| 533 | | - |
|---|
| 534 | | - path = btrfs_alloc_path(); |
|---|
| 535 | | - if (!path) |
|---|
| 536 | | - return -ENOMEM; |
|---|
| 537 | | - |
|---|
| 538 | | - search_key.objectid = BTRFS_LAST_FREE_OBJECTID; |
|---|
| 539 | | - search_key.type = -1; |
|---|
| 540 | | - search_key.offset = (u64)-1; |
|---|
| 541 | | - ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); |
|---|
| 542 | | - if (ret < 0) |
|---|
| 543 | | - goto error; |
|---|
| 544 | | - BUG_ON(ret == 0); /* Corruption */ |
|---|
| 545 | | - if (path->slots[0] > 0) { |
|---|
| 546 | | - slot = path->slots[0] - 1; |
|---|
| 547 | | - l = path->nodes[0]; |
|---|
| 548 | | - btrfs_item_key_to_cpu(l, &found_key, slot); |
|---|
| 549 | | - *objectid = max_t(u64, found_key.objectid, |
|---|
| 550 | | - BTRFS_FIRST_FREE_OBJECTID - 1); |
|---|
| 551 | | - } else { |
|---|
| 552 | | - *objectid = BTRFS_FIRST_FREE_OBJECTID - 1; |
|---|
| 553 | | - } |
|---|
| 554 | | - ret = 0; |
|---|
| 555 | | -error: |
|---|
| 556 | | - btrfs_free_path(path); |
|---|
| 557 | | - return ret; |
|---|
| 558 | | -} |
|---|
| 559 | | - |
|---|
| 560 | | -int btrfs_find_free_objectid(struct btrfs_root *root, u64 *objectid) |
|---|
| 561 | | -{ |
|---|
| 562 | | - int ret; |
|---|
| 563 | | - mutex_lock(&root->objectid_mutex); |
|---|
| 564 | | - |
|---|
| 565 | | - if (unlikely(root->highest_objectid >= BTRFS_LAST_FREE_OBJECTID)) { |
|---|
| 566 | | - btrfs_warn(root->fs_info, |
|---|
| 567 | | - "the objectid of root %llu reaches its highest value", |
|---|
| 568 | | - root->root_key.objectid); |
|---|
| 569 | | - ret = -ENOSPC; |
|---|
| 570 | | - goto out; |
|---|
| 571 | | - } |
|---|
| 572 | | - |
|---|
| 573 | | - *objectid = ++root->highest_objectid; |
|---|
| 574 | | - ret = 0; |
|---|
| 575 | | -out: |
|---|
| 576 | | - mutex_unlock(&root->objectid_mutex); |
|---|
| 577 | 526 | return ret; |
|---|
| 578 | 527 | } |
|---|