Lines Matching refs:trans
77 static int update_block_group(struct btrfs_trans_handle *trans,
80 static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
89 static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
94 static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
99 static int do_chunk_alloc(struct btrfs_trans_handle *trans,
805 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, in btrfs_lookup_extent_info() argument
833 if (!trans) { in btrfs_lookup_extent_info()
846 ret = btrfs_search_slot(trans, root->fs_info->extent_root, in btrfs_lookup_extent_info()
891 if (!trans) in btrfs_lookup_extent_info()
894 delayed_refs = &trans->transaction->delayed_refs; in btrfs_lookup_extent_info()
896 head = btrfs_find_delayed_ref_head(trans, bytenr); in btrfs_lookup_extent_info()
1042 static int convert_extent_item_v0(struct btrfs_trans_handle *trans, in convert_extent_item_v0() argument
1094 ret = btrfs_search_slot(trans, root, &key, path, in convert_extent_item_v0()
1158 static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans, in lookup_extent_data_ref() argument
1184 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in lookup_extent_data_ref()
1196 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in lookup_extent_data_ref()
1245 static noinline int insert_extent_data_ref(struct btrfs_trans_handle *trans, in insert_extent_data_ref() argument
1270 ret = btrfs_insert_empty_item(trans, root, path, &key, size); in insert_extent_data_ref()
1296 ret = btrfs_insert_empty_item(trans, root, path, &key, in insert_extent_data_ref()
1324 static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans, in remove_extent_data_ref() argument
1362 ret = btrfs_del_item(trans, root, path); in remove_extent_data_ref()
1423 static noinline int lookup_tree_block_ref(struct btrfs_trans_handle *trans, in lookup_tree_block_ref() argument
1441 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in lookup_tree_block_ref()
1448 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in lookup_tree_block_ref()
1456 static noinline int insert_tree_block_ref(struct btrfs_trans_handle *trans, in insert_tree_block_ref() argument
1474 ret = btrfs_insert_empty_item(trans, root, path, &key, 0); in insert_tree_block_ref()
1531 int lookup_inline_extent_backref(struct btrfs_trans_handle *trans, in lookup_inline_extent_backref() argument
1576 ret = btrfs_search_slot(trans, root, &key, path, extra_size, 1); in lookup_inline_extent_backref()
1622 ret = convert_extent_item_v0(trans, root, path, owner, in lookup_inline_extent_backref()
1784 static int lookup_extent_backref(struct btrfs_trans_handle *trans, in lookup_extent_backref() argument
1793 ret = lookup_inline_extent_backref(trans, root, path, ref_ret, in lookup_extent_backref()
1803 ret = lookup_tree_block_ref(trans, root, path, bytenr, parent, in lookup_extent_backref()
1806 ret = lookup_extent_data_ref(trans, root, path, bytenr, parent, in lookup_extent_backref()
1880 int insert_inline_extent_backref(struct btrfs_trans_handle *trans, in insert_inline_extent_backref() argument
1891 ret = lookup_inline_extent_backref(trans, root, path, &iref, in insert_inline_extent_backref()
1907 static int insert_extent_backref(struct btrfs_trans_handle *trans, in insert_extent_backref() argument
1916 ret = insert_tree_block_ref(trans, root, path, bytenr, in insert_extent_backref()
1919 ret = insert_extent_data_ref(trans, root, path, bytenr, in insert_extent_backref()
1926 static int remove_extent_backref(struct btrfs_trans_handle *trans, in remove_extent_backref() argument
1939 ret = remove_extent_data_ref(trans, root, path, refs_to_drop, in remove_extent_backref()
1943 ret = btrfs_del_item(trans, root, path); in remove_extent_backref()
2072 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, in btrfs_inc_extent_ref() argument
2084 ret = btrfs_add_delayed_tree_ref(fs_info, trans, bytenr, in btrfs_inc_extent_ref()
2089 ret = btrfs_add_delayed_data_ref(fs_info, trans, bytenr, in btrfs_inc_extent_ref()
2097 static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, in __btrfs_inc_extent_ref() argument
2121 ret = insert_inline_extent_backref(trans, fs_info->extent_root, path, in __btrfs_inc_extent_ref()
2147 ret = insert_extent_backref(trans, root->fs_info->extent_root, in __btrfs_inc_extent_ref()
2151 btrfs_abort_transaction(trans, root, ret); in __btrfs_inc_extent_ref()
2157 static int run_delayed_data_ref(struct btrfs_trans_handle *trans, in run_delayed_data_ref() argument
2184 ret = alloc_reserved_file_extent(trans, root, in run_delayed_data_ref()
2189 ret = __btrfs_inc_extent_ref(trans, root, node, parent, in run_delayed_data_ref()
2194 ret = __btrfs_free_extent(trans, root, node, parent, in run_delayed_data_ref()
2222 static int run_delayed_extent_op(struct btrfs_trans_handle *trans, in run_delayed_extent_op() argument
2236 if (trans->aborted) in run_delayed_extent_op()
2259 ret = btrfs_search_slot(trans, root->fs_info->extent_root, &key, in run_delayed_extent_op()
2295 ret = convert_extent_item_v0(trans, root->fs_info->extent_root, in run_delayed_extent_op()
2315 static int run_delayed_tree_ref(struct btrfs_trans_handle *trans, in run_delayed_tree_ref() argument
2348 ret = alloc_reserved_tree_block(trans, root, in run_delayed_tree_ref()
2354 ret = __btrfs_inc_extent_ref(trans, root, node, in run_delayed_tree_ref()
2359 ret = __btrfs_free_extent(trans, root, node, in run_delayed_tree_ref()
2369 static int run_one_delayed_ref(struct btrfs_trans_handle *trans, in run_one_delayed_ref() argument
2377 if (trans->aborted) { in run_one_delayed_ref()
2400 ret = btrfs_del_csums(trans, root, in run_one_delayed_ref()
2415 ret = run_delayed_tree_ref(trans, root, node, extent_op, in run_one_delayed_ref()
2419 ret = run_delayed_data_ref(trans, root, node, extent_op, in run_one_delayed_ref()
2453 static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, in __btrfs_run_delayed_refs() argument
2468 delayed_refs = &trans->transaction->delayed_refs; in __btrfs_run_delayed_refs()
2475 locked_ref = btrfs_select_ref_head(trans); in __btrfs_run_delayed_refs()
2483 ret = btrfs_delayed_ref_lock(trans, locked_ref); in __btrfs_run_delayed_refs()
2511 btrfs_merge_delayed_refs(trans, fs_info, delayed_refs, in __btrfs_run_delayed_refs()
2560 ret = run_delayed_extent_op(trans, root, in __btrfs_run_delayed_refs()
2626 ret = run_one_delayed_ref(trans, root, ref, extent_op, in __btrfs_run_delayed_refs()
2758 int btrfs_check_space_for_delayed_refs(struct btrfs_trans_handle *trans, in btrfs_check_space_for_delayed_refs() argument
2762 u64 num_heads = trans->transaction->delayed_refs.num_heads_ready; in btrfs_check_space_for_delayed_refs()
2763 u64 csum_bytes = trans->transaction->delayed_refs.pending_csums; in btrfs_check_space_for_delayed_refs()
2764 u64 num_dirty_bgs = trans->transaction->num_dirty_bgs; in btrfs_check_space_for_delayed_refs()
2794 int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans, in btrfs_should_throttle_delayed_refs() argument
2799 atomic_read(&trans->transaction->delayed_refs.num_entries); in btrfs_should_throttle_delayed_refs()
2811 return btrfs_check_space_for_delayed_refs(trans, root); in btrfs_should_throttle_delayed_refs()
2826 struct btrfs_trans_handle *trans; in delayed_ref_async_start() local
2831 trans = btrfs_join_transaction(async->root); in delayed_ref_async_start()
2832 if (IS_ERR(trans)) { in delayed_ref_async_start()
2833 async->error = PTR_ERR(trans); in delayed_ref_async_start()
2841 trans->sync = true; in delayed_ref_async_start()
2842 ret = btrfs_run_delayed_refs(trans, async->root, async->count); in delayed_ref_async_start()
2846 ret = btrfs_end_transaction(trans, async->root); in delayed_ref_async_start()
2899 int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, in btrfs_run_delayed_refs() argument
2907 bool can_flush_pending_bgs = trans->can_flush_pending_bgs; in btrfs_run_delayed_refs()
2910 if (trans->aborted) in btrfs_run_delayed_refs()
2916 delayed_refs = &trans->transaction->delayed_refs; in btrfs_run_delayed_refs()
2924 trans->can_flush_pending_bgs = false; in btrfs_run_delayed_refs()
2925 ret = __btrfs_run_delayed_refs(trans, root, count); in btrfs_run_delayed_refs()
2927 btrfs_abort_transaction(trans, root, ret); in btrfs_run_delayed_refs()
2932 if (!list_empty(&trans->new_bgs)) in btrfs_run_delayed_refs()
2933 btrfs_create_pending_block_groups(trans, root); in btrfs_run_delayed_refs()
2973 assert_qgroups_uptodate(trans); in btrfs_run_delayed_refs()
2974 trans->can_flush_pending_bgs = can_flush_pending_bgs; in btrfs_run_delayed_refs()
2978 int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, in btrfs_set_disk_extent_flags() argument
2996 ret = btrfs_add_delayed_extent_op(root->fs_info, trans, bytenr, in btrfs_set_disk_extent_flags()
3003 static noinline int check_delayed_ref(struct btrfs_trans_handle *trans, in check_delayed_ref() argument
3014 delayed_refs = &trans->transaction->delayed_refs; in check_delayed_ref()
3016 head = btrfs_find_delayed_ref_head(trans, bytenr); in check_delayed_ref()
3065 static noinline int check_committed_ref(struct btrfs_trans_handle *trans, in check_committed_ref() argument
3136 int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans, in btrfs_cross_ref_exist() argument
3149 ret = check_committed_ref(trans, root, path, objectid, in btrfs_cross_ref_exist()
3154 ret2 = check_delayed_ref(trans, root, path, objectid, in btrfs_cross_ref_exist()
3172 static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, in __btrfs_mod_ref() argument
3227 ret = process_func(trans, root, bytenr, num_bytes, in __btrfs_mod_ref()
3235 ret = process_func(trans, root, bytenr, num_bytes, in __btrfs_mod_ref()
3246 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, in btrfs_inc_ref() argument
3249 return __btrfs_mod_ref(trans, root, buf, full_backref, 1); in btrfs_inc_ref()
3252 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, in btrfs_dec_ref() argument
3255 return __btrfs_mod_ref(trans, root, buf, full_backref, 0); in btrfs_dec_ref()
3258 static int write_one_cache_group(struct btrfs_trans_handle *trans, in write_one_cache_group() argument
3268 ret = btrfs_search_slot(trans, extent_root, &cache->key, path, 0, 1); in write_one_cache_group()
3316 struct btrfs_trans_handle *trans, in cache_save_setup() argument
3338 if (trans->aborted) in cache_save_setup()
3355 ret = create_free_space_inode(root, trans, block_group, path); in cache_save_setup()
3362 if (block_group->cache_generation == trans->transid && in cache_save_setup()
3374 ret = btrfs_update_inode(trans, root, inode); in cache_save_setup()
3386 btrfs_abort_transaction(trans, root, ret); in cache_save_setup()
3397 ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode); in cache_save_setup()
3420 if (test_bit(BTRFS_TRANS_CACHE_ENOSPC, &trans->transaction->flags)) { in cache_save_setup()
3442 ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, num_pages, in cache_save_setup()
3456 set_bit(BTRFS_TRANS_CACHE_ENOSPC, &trans->transaction->flags); in cache_save_setup()
3466 block_group->cache_generation = trans->transid; in cache_save_setup()
3473 int btrfs_setup_space_cache(struct btrfs_trans_handle *trans, in btrfs_setup_space_cache() argument
3477 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_setup_space_cache()
3492 cache_save_setup(cache, trans, path); in btrfs_setup_space_cache()
3511 int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans, in btrfs_start_dirty_block_groups() argument
3515 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_start_dirty_block_groups()
3537 btrfs_create_pending_block_groups(trans, root); in btrfs_start_dirty_block_groups()
3550 mutex_lock(&trans->transaction->cache_write_mutex); in btrfs_start_dirty_block_groups()
3562 btrfs_wait_cache_io(root, trans, cache, in btrfs_start_dirty_block_groups()
3583 cache_save_setup(cache, trans, path); in btrfs_start_dirty_block_groups()
3587 ret = btrfs_write_out_cache(root, trans, cache, path); in btrfs_start_dirty_block_groups()
3606 ret = write_one_cache_group(trans, root, path, cache); in btrfs_start_dirty_block_groups()
3626 btrfs_abort_transaction(trans, root, ret); in btrfs_start_dirty_block_groups()
3642 mutex_unlock(&trans->transaction->cache_write_mutex); in btrfs_start_dirty_block_groups()
3643 mutex_lock(&trans->transaction->cache_write_mutex); in btrfs_start_dirty_block_groups()
3645 mutex_unlock(&trans->transaction->cache_write_mutex); in btrfs_start_dirty_block_groups()
3651 ret = btrfs_run_delayed_refs(trans, root, 0); in btrfs_start_dirty_block_groups()
3671 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, in btrfs_write_dirty_block_groups() argument
3675 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_write_dirty_block_groups()
3704 btrfs_wait_cache_io(root, trans, cache, in btrfs_write_dirty_block_groups()
3717 cache_save_setup(cache, trans, path); in btrfs_write_dirty_block_groups()
3720 ret = btrfs_run_delayed_refs(trans, root, (unsigned long) -1); in btrfs_write_dirty_block_groups()
3724 ret = btrfs_write_out_cache(root, trans, cache, path); in btrfs_write_dirty_block_groups()
3738 ret = write_one_cache_group(trans, root, path, cache); in btrfs_write_dirty_block_groups()
3740 btrfs_abort_transaction(trans, root, ret); in btrfs_write_dirty_block_groups()
3752 btrfs_wait_cache_io(root, trans, cache, in btrfs_write_dirty_block_groups()
4027 struct btrfs_trans_handle *trans; in btrfs_alloc_data_chunk_ondemand() local
4050 trans = btrfs_join_transaction(root); in btrfs_alloc_data_chunk_ondemand()
4051 if (IS_ERR(trans)) in btrfs_alloc_data_chunk_ondemand()
4052 return PTR_ERR(trans); in btrfs_alloc_data_chunk_ondemand()
4054 ret = do_chunk_alloc(trans, root->fs_info->extent_root, in btrfs_alloc_data_chunk_ondemand()
4057 btrfs_end_transaction(trans, root); in btrfs_alloc_data_chunk_ondemand()
4094 trans = btrfs_join_transaction(root); in btrfs_alloc_data_chunk_ondemand()
4095 if (IS_ERR(trans)) in btrfs_alloc_data_chunk_ondemand()
4096 return PTR_ERR(trans); in btrfs_alloc_data_chunk_ondemand()
4099 &trans->transaction->flags) || in btrfs_alloc_data_chunk_ondemand()
4101 ret = btrfs_commit_transaction(trans, root); in btrfs_alloc_data_chunk_ondemand()
4113 btrfs_end_transaction(trans, root); in btrfs_alloc_data_chunk_ondemand()
4279 void check_system_chunk(struct btrfs_trans_handle *trans, in check_system_chunk() argument
4324 ret = btrfs_alloc_chunk(trans, root, flags); in check_system_chunk()
4332 trans->chunk_bytes_reserved += thresh; in check_system_chunk()
4336 static int do_chunk_alloc(struct btrfs_trans_handle *trans, in do_chunk_alloc() argument
4345 if (trans->allocating_chunk) in do_chunk_alloc()
4394 trans->allocating_chunk = true; in do_chunk_alloc()
4419 check_system_chunk(trans, extent_root, flags); in do_chunk_alloc()
4421 ret = btrfs_alloc_chunk(trans, extent_root, flags); in do_chunk_alloc()
4422 trans->allocating_chunk = false; in do_chunk_alloc()
4451 if (trans->can_flush_pending_bgs && in do_chunk_alloc()
4452 trans->chunk_bytes_reserved >= (2 * 1024 * 1024ull)) { in do_chunk_alloc()
4453 btrfs_create_pending_block_groups(trans, trans->root); in do_chunk_alloc()
4454 btrfs_trans_release_chunk_metadata(trans); in do_chunk_alloc()
4560 struct btrfs_trans_handle *trans; in shrink_delalloc() local
4573 trans = (struct btrfs_trans_handle *)current->journal_info; in shrink_delalloc()
4580 if (trans) in shrink_delalloc()
4609 if (!trans) in shrink_delalloc()
4621 if (wait_ordered && !trans) { in shrink_delalloc()
4648 struct btrfs_trans_handle *trans; in may_commit_transaction() local
4650 trans = (struct btrfs_trans_handle *)current->journal_info; in may_commit_transaction()
4651 if (trans) in may_commit_transaction()
4678 trans = btrfs_join_transaction(root); in may_commit_transaction()
4679 if (IS_ERR(trans)) in may_commit_transaction()
4682 return btrfs_commit_transaction(trans, root); in may_commit_transaction()
4698 struct btrfs_trans_handle *trans; in flush_space() local
4710 trans = btrfs_join_transaction(root); in flush_space()
4711 if (IS_ERR(trans)) { in flush_space()
4712 ret = PTR_ERR(trans); in flush_space()
4715 ret = btrfs_run_delayed_items_nr(trans, root, nr); in flush_space()
4716 btrfs_end_transaction(trans, root); in flush_space()
4724 trans = btrfs_join_transaction(root); in flush_space()
4725 if (IS_ERR(trans)) { in flush_space()
4726 ret = PTR_ERR(trans); in flush_space()
4729 ret = do_chunk_alloc(trans, root->fs_info->extent_root, in flush_space()
4732 btrfs_end_transaction(trans, root); in flush_space()
5028 const struct btrfs_trans_handle *trans, in get_block_rsv() argument
5034 (root == root->fs_info->csum_root && trans->adding_csums) || in get_block_rsv()
5036 block_rsv = trans->block_rsv; in get_block_rsv()
5390 void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans, in btrfs_trans_release_metadata() argument
5393 if (!trans->block_rsv) in btrfs_trans_release_metadata()
5396 if (!trans->bytes_reserved) in btrfs_trans_release_metadata()
5400 trans->transid, trans->bytes_reserved, 0); in btrfs_trans_release_metadata()
5401 btrfs_block_rsv_release(root, trans->block_rsv, trans->bytes_reserved); in btrfs_trans_release_metadata()
5402 trans->bytes_reserved = 0; in btrfs_trans_release_metadata()
5409 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_chunk_metadata() argument
5411 struct btrfs_fs_info *fs_info = trans->root->fs_info; in btrfs_trans_release_chunk_metadata()
5413 if (!trans->chunk_bytes_reserved) in btrfs_trans_release_chunk_metadata()
5416 WARN_ON_ONCE(!list_empty(&trans->new_bgs)); in btrfs_trans_release_chunk_metadata()
5419 trans->chunk_bytes_reserved); in btrfs_trans_release_chunk_metadata()
5420 trans->chunk_bytes_reserved = 0; in btrfs_trans_release_chunk_metadata()
5424 int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans, in btrfs_orphan_reserve_metadata() argument
5428 struct btrfs_block_rsv *src_rsv = get_block_rsv(trans, root); in btrfs_orphan_reserve_metadata()
5847 static int update_block_group(struct btrfs_trans_handle *trans, in update_block_group() argument
5923 spin_lock(&trans->transaction->dirty_bgs_lock); in update_block_group()
5926 &trans->transaction->dirty_bgs); in update_block_group()
5927 trans->transaction->num_dirty_bgs++; in update_block_group()
5930 spin_unlock(&trans->transaction->dirty_bgs_lock); in update_block_group()
6180 void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans, in btrfs_prepare_extent_commit() argument
6326 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, in btrfs_finish_extent_commit() argument
6342 while (!trans->aborted) { in btrfs_finish_extent_commit()
6366 deleted_bgs = &trans->transaction->deleted_bgs; in btrfs_finish_extent_commit()
6371 if (!trans->aborted) in btrfs_finish_extent_commit()
6413 static int __btrfs_free_extent(struct btrfs_trans_handle *trans, in __btrfs_free_extent() argument
6453 ret = lookup_extent_backref(trans, extent_root, path, &iref, in __btrfs_free_extent()
6485 ret = remove_extent_backref(trans, extent_root, path, in __btrfs_free_extent()
6489 btrfs_abort_transaction(trans, extent_root, ret); in __btrfs_free_extent()
6504 ret = btrfs_search_slot(trans, extent_root, in __btrfs_free_extent()
6526 ret = btrfs_search_slot(trans, extent_root, in __btrfs_free_extent()
6538 btrfs_abort_transaction(trans, extent_root, ret); in __btrfs_free_extent()
6549 btrfs_abort_transaction(trans, extent_root, ret); in __btrfs_free_extent()
6552 btrfs_abort_transaction(trans, extent_root, ret); in __btrfs_free_extent()
6561 ret = convert_extent_item_v0(trans, extent_root, path, in __btrfs_free_extent()
6564 btrfs_abort_transaction(trans, extent_root, ret); in __btrfs_free_extent()
6575 ret = btrfs_search_slot(trans, extent_root, &key, path, in __btrfs_free_extent()
6583 btrfs_abort_transaction(trans, extent_root, ret); in __btrfs_free_extent()
6608 btrfs_abort_transaction(trans, extent_root, ret); in __btrfs_free_extent()
6627 ret = remove_extent_backref(trans, extent_root, path, in __btrfs_free_extent()
6631 btrfs_abort_transaction(trans, extent_root, ret); in __btrfs_free_extent()
6651 ret = btrfs_del_items(trans, extent_root, path, path->slots[0], in __btrfs_free_extent()
6654 btrfs_abort_transaction(trans, extent_root, ret); in __btrfs_free_extent()
6660 ret = btrfs_del_csums(trans, root, bytenr, num_bytes); in __btrfs_free_extent()
6662 btrfs_abort_transaction(trans, extent_root, ret); in __btrfs_free_extent()
6667 ret = update_block_group(trans, root, bytenr, num_bytes, 0); in __btrfs_free_extent()
6669 btrfs_abort_transaction(trans, extent_root, ret); in __btrfs_free_extent()
6686 static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, in check_ref_cleanup() argument
6693 delayed_refs = &trans->transaction->delayed_refs; in check_ref_cleanup()
6695 head = btrfs_find_delayed_ref_head(trans, bytenr); in check_ref_cleanup()
6752 void btrfs_free_tree_block(struct btrfs_trans_handle *trans, in btrfs_free_tree_block() argument
6761 ret = btrfs_add_delayed_tree_ref(root->fs_info, trans, in btrfs_free_tree_block()
6772 if (btrfs_header_generation(buf) == trans->transid) { in btrfs_free_tree_block()
6776 ret = check_ref_cleanup(trans, root, buf->start); in btrfs_free_tree_block()
6811 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root, in btrfs_free_extent() argument
6833 ret = btrfs_add_delayed_tree_ref(fs_info, trans, bytenr, in btrfs_free_extent()
6838 ret = btrfs_add_delayed_data_ref(fs_info, trans, bytenr, in btrfs_free_extent()
7423 struct btrfs_trans_handle *trans; in find_free_extent() local
7426 trans = current->journal_info; in find_free_extent()
7427 if (trans) in find_free_extent()
7430 trans = btrfs_join_transaction(root); in find_free_extent()
7432 if (IS_ERR(trans)) { in find_free_extent()
7433 ret = PTR_ERR(trans); in find_free_extent()
7437 ret = do_chunk_alloc(trans, root, flags, in find_free_extent()
7453 btrfs_abort_transaction(trans, in find_free_extent()
7458 btrfs_end_transaction(trans, root); in find_free_extent()
7617 static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans, in alloc_reserved_file_extent() argument
7644 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, in alloc_reserved_file_extent()
7655 btrfs_set_extent_generation(leaf, extent_item, trans->transid); in alloc_reserved_file_extent()
7678 ret = update_block_group(trans, root, ins->objectid, ins->offset, 1); in alloc_reserved_file_extent()
7688 static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, in alloc_reserved_tree_block() argument
7717 ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, in alloc_reserved_tree_block()
7730 btrfs_set_extent_generation(leaf, extent_item, trans->transid); in alloc_reserved_tree_block()
7758 ret = update_block_group(trans, root, ins->objectid, root->nodesize, in alloc_reserved_tree_block()
7770 int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, in btrfs_alloc_reserved_file_extent() argument
7780 ret = btrfs_add_delayed_data_ref(root->fs_info, trans, ins->objectid, in btrfs_alloc_reserved_file_extent()
7793 int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans, in btrfs_alloc_logged_file_extent() argument
7818 ret = alloc_reserved_file_extent(trans, root, 0, root_objectid, in btrfs_alloc_logged_file_extent()
7825 btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root, in btrfs_init_new_buffer() argument
7833 btrfs_set_header_generation(buf, trans->transid); in btrfs_init_new_buffer()
7836 clean_tree_block(trans, root->fs_info, buf); in btrfs_init_new_buffer()
7856 set_extent_dirty(&trans->transaction->dirty_pages, buf->start, in btrfs_init_new_buffer()
7859 trans->blocks_used++; in btrfs_init_new_buffer()
7865 use_block_rsv(struct btrfs_trans_handle *trans, in use_block_rsv() argument
7873 block_rsv = get_block_rsv(trans, root); in use_block_rsv()
7929 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, in btrfs_alloc_tree_block() argument
7946 buf = btrfs_init_new_buffer(trans, root, root->alloc_bytenr, in btrfs_alloc_tree_block()
7953 block_rsv = use_block_rsv(trans, root, blocksize); in btrfs_alloc_tree_block()
7962 buf = btrfs_init_new_buffer(trans, root, ins.objectid, level); in btrfs_alloc_tree_block()
7994 ret = btrfs_add_delayed_tree_ref(root->fs_info, trans, in btrfs_alloc_tree_block()
8032 static noinline void reada_walk_down(struct btrfs_trans_handle *trans, in reada_walk_down() argument
8078 ret = btrfs_lookup_extent_info(trans, root, bytenr, in reada_walk_down()
8117 static int record_one_subtree_extent(struct btrfs_trans_handle *trans, in record_one_subtree_extent() argument
8132 delayed_refs = &trans->transaction->delayed_refs; in record_one_subtree_extent()
8141 static int account_leaf_items(struct btrfs_trans_handle *trans, in account_leaf_items() argument
8174 ret = record_one_subtree_extent(trans, root, bytenr, num_bytes); in account_leaf_items()
8246 static int account_shared_subtree(struct btrfs_trans_handle *trans, in account_shared_subtree() argument
8270 ret = account_leaf_items(trans, root, root_eb); in account_shared_subtree()
8323 ret = record_one_subtree_extent(trans, root, child_bytenr, in account_shared_subtree()
8330 ret = account_leaf_items(trans, root, path->nodes[level]); in account_shared_subtree()
8361 static noinline int walk_down_proc(struct btrfs_trans_handle *trans, in walk_down_proc() argument
8383 ret = btrfs_lookup_extent_info(trans, root, in walk_down_proc()
8407 ret = btrfs_inc_ref(trans, root, eb, 1); in walk_down_proc()
8409 ret = btrfs_dec_ref(trans, root, eb, 0); in walk_down_proc()
8411 ret = btrfs_set_disk_extent_flags(trans, root, eb->start, in walk_down_proc()
8442 static noinline int do_walk_down(struct btrfs_trans_handle *trans, in do_walk_down() argument
8486 ret = btrfs_lookup_extent_info(trans, root, bytenr, level - 1, 1, in do_walk_down()
8535 reada_walk_down(trans, root, wc, path); in do_walk_down()
8569 ret = account_shared_subtree(trans, root, next, in do_walk_down()
8579 ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent, in do_walk_down()
8601 static noinline int walk_up_proc(struct btrfs_trans_handle *trans, in walk_up_proc() argument
8635 ret = btrfs_lookup_extent_info(trans, root, in walk_up_proc()
8659 ret = btrfs_dec_ref(trans, root, eb, 1); in walk_up_proc()
8661 ret = btrfs_dec_ref(trans, root, eb, 0); in walk_up_proc()
8663 ret = account_leaf_items(trans, root, eb); in walk_up_proc()
8674 btrfs_header_generation(eb) == trans->transid) { in walk_up_proc()
8679 clean_tree_block(trans, root->fs_info, eb); in walk_up_proc()
8696 btrfs_free_tree_block(trans, root, eb, parent, wc->refs[level] == 1); in walk_up_proc()
8703 static noinline int walk_down_tree(struct btrfs_trans_handle *trans, in walk_down_tree() argument
8713 ret = walk_down_proc(trans, root, path, wc, lookup_info); in walk_down_tree()
8724 ret = do_walk_down(trans, root, path, wc, &lookup_info); in walk_down_tree()
8735 static noinline int walk_up_tree(struct btrfs_trans_handle *trans, in walk_up_tree() argument
8751 ret = walk_up_proc(trans, root, path, wc); in walk_up_tree()
8786 struct btrfs_trans_handle *trans; in btrfs_drop_snapshot() local
8811 trans = btrfs_start_transaction(tree_root, 0); in btrfs_drop_snapshot()
8812 if (IS_ERR(trans)) { in btrfs_drop_snapshot()
8813 err = PTR_ERR(trans); in btrfs_drop_snapshot()
8818 trans->block_rsv = block_rsv; in btrfs_drop_snapshot()
8856 ret = btrfs_lookup_extent_info(trans, root, in btrfs_drop_snapshot()
8886 ret = walk_down_tree(trans, root, path, wc); in btrfs_drop_snapshot()
8892 ret = walk_up_tree(trans, root, path, wc, BTRFS_MAX_LEVEL); in btrfs_drop_snapshot()
8912 if (btrfs_should_end_transaction(trans, tree_root) || in btrfs_drop_snapshot()
8914 ret = btrfs_update_root(trans, tree_root, in btrfs_drop_snapshot()
8918 btrfs_abort_transaction(trans, tree_root, ret); in btrfs_drop_snapshot()
8923 btrfs_end_transaction_throttle(trans, tree_root); in btrfs_drop_snapshot()
8930 trans = btrfs_start_transaction(tree_root, 0); in btrfs_drop_snapshot()
8931 if (IS_ERR(trans)) { in btrfs_drop_snapshot()
8932 err = PTR_ERR(trans); in btrfs_drop_snapshot()
8936 trans->block_rsv = block_rsv; in btrfs_drop_snapshot()
8943 ret = btrfs_del_root(trans, tree_root, &root->root_key); in btrfs_drop_snapshot()
8945 btrfs_abort_transaction(trans, tree_root, ret); in btrfs_drop_snapshot()
8953 btrfs_abort_transaction(trans, tree_root, ret); in btrfs_drop_snapshot()
8962 btrfs_del_orphan_item(trans, tree_root, in btrfs_drop_snapshot()
8968 btrfs_add_dropped_root(trans, root); in btrfs_drop_snapshot()
8976 btrfs_end_transaction_throttle(trans, tree_root); in btrfs_drop_snapshot()
9001 int btrfs_drop_subtree(struct btrfs_trans_handle *trans, in btrfs_drop_subtree() argument
9048 wret = walk_down_tree(trans, root, path, wc); in btrfs_drop_subtree()
9054 wret = walk_up_tree(trans, root, path, wc, parent_level); in btrfs_drop_subtree()
9164 struct btrfs_trans_handle *trans; in btrfs_inc_block_group_ro() local
9169 trans = btrfs_join_transaction(root); in btrfs_inc_block_group_ro()
9170 if (IS_ERR(trans)) in btrfs_inc_block_group_ro()
9171 return PTR_ERR(trans); in btrfs_inc_block_group_ro()
9179 if (test_bit(BTRFS_TRANS_DIRTY_BG_RUN, &trans->transaction->flags)) { in btrfs_inc_block_group_ro()
9180 u64 transid = trans->transid; in btrfs_inc_block_group_ro()
9183 btrfs_end_transaction(trans, root); in btrfs_inc_block_group_ro()
9197 ret = do_chunk_alloc(trans, root, alloc_flags, in btrfs_inc_block_group_ro()
9214 ret = do_chunk_alloc(trans, root, alloc_flags, in btrfs_inc_block_group_ro()
9223 check_system_chunk(trans, root, alloc_flags); in btrfs_inc_block_group_ro()
9228 btrfs_end_transaction(trans, root); in btrfs_inc_block_group_ro()
9232 int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, in btrfs_force_chunk_alloc() argument
9236 return do_chunk_alloc(trans, root, alloc_flags, in btrfs_force_chunk_alloc()
9314 struct btrfs_trans_handle *trans; in btrfs_can_relocate() local
9402 trans = btrfs_join_transaction(root); in btrfs_can_relocate()
9403 if (IS_ERR(trans)) { in btrfs_can_relocate()
9404 ret = PTR_ERR(trans); in btrfs_can_relocate()
9418 ret = find_free_dev_extent(trans, device, min_free, in btrfs_can_relocate()
9430 btrfs_end_transaction(trans, root); in btrfs_can_relocate()
9855 void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans, in btrfs_create_pending_block_groups() argument
9863 bool can_flush_pending_bgs = trans->can_flush_pending_bgs; in btrfs_create_pending_block_groups()
9865 trans->can_flush_pending_bgs = false; in btrfs_create_pending_block_groups()
9866 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { in btrfs_create_pending_block_groups()
9875 ret = btrfs_insert_item(trans, extent_root, &key, &item, in btrfs_create_pending_block_groups()
9878 btrfs_abort_transaction(trans, extent_root, ret); in btrfs_create_pending_block_groups()
9879 ret = btrfs_finish_chunk_alloc(trans, extent_root, in btrfs_create_pending_block_groups()
9882 btrfs_abort_transaction(trans, extent_root, ret); in btrfs_create_pending_block_groups()
9886 trans->can_flush_pending_bgs = can_flush_pending_bgs; in btrfs_create_pending_block_groups()
9889 int btrfs_make_block_group(struct btrfs_trans_handle *trans, in btrfs_make_block_group() argument
9900 btrfs_set_log_full_commit(root->fs_info, trans); in btrfs_make_block_group()
9981 list_add_tail(&cache->bg_list, &trans->new_bgs); in btrfs_make_block_group()
10003 int btrfs_remove_block_group(struct btrfs_trans_handle *trans, in btrfs_remove_block_group() argument
10068 mutex_lock(&trans->transaction->cache_write_mutex); in btrfs_remove_block_group()
10073 spin_lock(&trans->transaction->dirty_bgs_lock); in btrfs_remove_block_group()
10079 spin_unlock(&trans->transaction->dirty_bgs_lock); in btrfs_remove_block_group()
10080 btrfs_wait_cache_io(root, trans, block_group, in btrfs_remove_block_group()
10084 spin_lock(&trans->transaction->dirty_bgs_lock); in btrfs_remove_block_group()
10091 spin_unlock(&trans->transaction->dirty_bgs_lock); in btrfs_remove_block_group()
10092 mutex_unlock(&trans->transaction->cache_write_mutex); in btrfs_remove_block_group()
10095 ret = btrfs_orphan_add(trans, inode); in btrfs_remove_block_group()
10119 ret = btrfs_search_slot(trans, tree_root, &key, path, -1, 1); in btrfs_remove_block_group()
10125 ret = btrfs_del_item(trans, tree_root, path); in btrfs_remove_block_group()
10184 spin_lock(&trans->transaction->dirty_bgs_lock); in btrfs_remove_block_group()
10191 spin_unlock(&trans->transaction->dirty_bgs_lock); in btrfs_remove_block_group()
10286 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in btrfs_remove_block_group()
10292 ret = btrfs_del_item(trans, root, path); in btrfs_remove_block_group()
10348 struct btrfs_trans_handle *trans; in btrfs_delete_unused_bgs() local
10405 trans = btrfs_start_trans_remove_block_group(fs_info, in btrfs_delete_unused_bgs()
10407 if (IS_ERR(trans)) { in btrfs_delete_unused_bgs()
10409 ret = PTR_ERR(trans); in btrfs_delete_unused_bgs()
10471 ret = btrfs_remove_chunk(trans, root, in btrfs_delete_unused_bgs()
10493 &trans->transaction->deleted_bgs); in btrfs_delete_unused_bgs()
10498 btrfs_end_transaction(trans, root); in btrfs_delete_unused_bgs()
10588 struct btrfs_transaction *trans; in btrfs_trim_free_extents() local
10598 trans = fs_info->running_transaction; in btrfs_trim_free_extents()
10599 if (trans) in btrfs_trim_free_extents()
10600 atomic_inc(&trans->use_count); in btrfs_trim_free_extents()
10603 ret = find_free_dev_extent_start(trans, device, minlen, start, in btrfs_trim_free_extents()
10605 if (trans) in btrfs_trim_free_extents()
10606 btrfs_put_transaction(trans); in btrfs_trim_free_extents()