Lines Matching refs:trans
172 static noinline void switch_commit_roots(struct btrfs_trans_handle *trans) in switch_commit_roots() argument
174 struct btrfs_transaction *cur_trans = trans->transaction; in switch_commit_roots()
175 struct btrfs_fs_info *fs_info = trans->fs_info; in switch_commit_roots()
187 fs_info->last_reloc_trans = trans->transid; in switch_commit_roots()
205 btrfs_free_log(trans, root); in switch_commit_roots()
214 static inline void extwriter_counter_inc(struct btrfs_transaction *trans, in extwriter_counter_inc() argument
218 atomic_inc(&trans->num_extwriters); in extwriter_counter_inc()
221 static inline void extwriter_counter_dec(struct btrfs_transaction *trans, in extwriter_counter_dec() argument
225 atomic_dec(&trans->num_extwriters); in extwriter_counter_dec()
228 static inline void extwriter_counter_init(struct btrfs_transaction *trans, in extwriter_counter_init() argument
231 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0)); in extwriter_counter_init()
234 static inline int extwriter_counter_read(struct btrfs_transaction *trans) in extwriter_counter_read() argument
236 return atomic_read(&trans->num_extwriters); in extwriter_counter_read()
246 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_chunk_metadata() argument
248 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_chunk_metadata()
250 if (!trans->chunk_bytes_reserved) in btrfs_trans_release_chunk_metadata()
254 trans->chunk_bytes_reserved, NULL); in btrfs_trans_release_chunk_metadata()
255 trans->chunk_bytes_reserved = 0; in btrfs_trans_release_chunk_metadata()
399 static int record_root_in_trans(struct btrfs_trans_handle *trans, in record_root_in_trans() argument
407 btrfs_get_root_last_trans(root) < trans->transid) || force) { in record_root_in_trans()
423 if (btrfs_get_root_last_trans(root) == trans->transid && !force) { in record_root_in_trans()
431 btrfs_set_root_last_trans(root, trans->transid); in record_root_in_trans()
452 ret = btrfs_init_reloc_root(trans, root); in record_root_in_trans()
460 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans, in btrfs_add_dropped_root() argument
464 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_add_dropped_root()
479 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, in btrfs_record_root_in_trans() argument
493 if (btrfs_get_root_last_trans(root) == trans->transid && in btrfs_record_root_in_trans()
498 ret = record_root_in_trans(trans, root, 0); in btrfs_record_root_in_trans()
504 static inline int is_transaction_blocked(struct btrfs_transaction *trans) in is_transaction_blocked() argument
506 return (trans->state >= TRANS_STATE_COMMIT_START && in is_transaction_blocked()
507 trans->state < TRANS_STATE_UNBLOCKED && in is_transaction_blocked()
508 !TRANS_ABORTED(trans)); in is_transaction_blocked()
875 struct btrfs_trans_handle *trans; in btrfs_attach_transaction_barrier() local
877 trans = start_transaction(root, 0, TRANS_ATTACH, in btrfs_attach_transaction_barrier()
879 if (trans == ERR_PTR(-ENOENT)) { in btrfs_attach_transaction_barrier()
887 return trans; in btrfs_attach_transaction_barrier()
1000 bool btrfs_should_end_transaction(struct btrfs_trans_handle *trans) in btrfs_should_end_transaction() argument
1002 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
1008 if (btrfs_check_space_for_delayed_refs(trans->fs_info)) in btrfs_should_end_transaction()
1011 return !!btrfs_block_rsv_check(&trans->fs_info->global_block_rsv, 50); in btrfs_should_end_transaction()
1014 static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_metadata() argument
1017 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_metadata()
1019 if (!trans->block_rsv) { in btrfs_trans_release_metadata()
1020 ASSERT(!trans->bytes_reserved); in btrfs_trans_release_metadata()
1021 ASSERT(!trans->delayed_refs_bytes_reserved); in btrfs_trans_release_metadata()
1025 if (!trans->bytes_reserved) { in btrfs_trans_release_metadata()
1026 ASSERT(!trans->delayed_refs_bytes_reserved); in btrfs_trans_release_metadata()
1030 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv); in btrfs_trans_release_metadata()
1032 trans->transid, trans->bytes_reserved, 0); in btrfs_trans_release_metadata()
1033 btrfs_block_rsv_release(fs_info, trans->block_rsv, in btrfs_trans_release_metadata()
1034 trans->bytes_reserved, NULL); in btrfs_trans_release_metadata()
1035 trans->bytes_reserved = 0; in btrfs_trans_release_metadata()
1037 if (!trans->delayed_refs_bytes_reserved) in btrfs_trans_release_metadata()
1041 trans->transid, in btrfs_trans_release_metadata()
1042 trans->delayed_refs_bytes_reserved, 0); in btrfs_trans_release_metadata()
1043 btrfs_block_rsv_release(fs_info, &trans->delayed_rsv, in btrfs_trans_release_metadata()
1044 trans->delayed_refs_bytes_reserved, NULL); in btrfs_trans_release_metadata()
1045 trans->delayed_refs_bytes_reserved = 0; in btrfs_trans_release_metadata()
1048 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, in __btrfs_end_transaction() argument
1051 struct btrfs_fs_info *info = trans->fs_info; in __btrfs_end_transaction()
1052 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
1055 if (refcount_read(&trans->use_count) > 1) { in __btrfs_end_transaction()
1056 refcount_dec(&trans->use_count); in __btrfs_end_transaction()
1057 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
1061 btrfs_trans_release_metadata(trans); in __btrfs_end_transaction()
1062 trans->block_rsv = NULL; in __btrfs_end_transaction()
1064 btrfs_create_pending_block_groups(trans); in __btrfs_end_transaction()
1066 btrfs_trans_release_chunk_metadata(trans); in __btrfs_end_transaction()
1068 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
1074 extwriter_counter_dec(cur_trans, trans->type); in __btrfs_end_transaction()
1083 if (current->journal_info == trans) in __btrfs_end_transaction()
1089 if (TRANS_ABORTED(trans) || BTRFS_FS_ERROR(info)) { in __btrfs_end_transaction()
1091 if (TRANS_ABORTED(trans)) in __btrfs_end_transaction()
1092 ret = trans->aborted; in __btrfs_end_transaction()
1097 kmem_cache_free(btrfs_trans_handle_cachep, trans); in __btrfs_end_transaction()
1101 int btrfs_end_transaction(struct btrfs_trans_handle *trans) in btrfs_end_transaction() argument
1103 return __btrfs_end_transaction(trans, 0); in btrfs_end_transaction()
1106 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans) in btrfs_end_transaction_throttle() argument
1108 return __btrfs_end_transaction(trans, 1); in btrfs_end_transaction_throttle()
1249 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans) in btrfs_write_and_wait_transaction() argument
1253 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages; in btrfs_write_and_wait_transaction()
1254 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_write_and_wait_transaction()
1262 extent_io_tree_release(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1282 static int update_cowonly_root(struct btrfs_trans_handle *trans, in update_cowonly_root() argument
1300 ret = btrfs_update_root(trans, tree_root, in update_cowonly_root()
1319 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans) in commit_cowonly_roots() argument
1321 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_cowonly_roots()
1322 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1323 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1332 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING); in commit_cowonly_roots()
1335 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1343 ret = btrfs_run_dev_stats(trans); in commit_cowonly_roots()
1346 ret = btrfs_run_dev_replace(trans); in commit_cowonly_roots()
1349 ret = btrfs_run_qgroups(trans); in commit_cowonly_roots()
1353 ret = btrfs_setup_space_cache(trans); in commit_cowonly_roots()
1366 &trans->transaction->switch_commits); in commit_cowonly_roots()
1367 ret = update_cowonly_root(trans, root); in commit_cowonly_roots()
1373 ret = btrfs_run_delayed_refs(trans, U64_MAX); in commit_cowonly_roots()
1378 ret = btrfs_write_dirty_block_groups(trans); in commit_cowonly_roots()
1388 ret = btrfs_run_delayed_refs(trans, U64_MAX); in commit_cowonly_roots()
1455 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans) in commit_fs_roots() argument
1457 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_fs_roots()
1466 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING); in commit_fs_roots()
1494 btrfs_free_log(trans, root); in commit_fs_roots()
1495 ret2 = btrfs_update_reloc_root(trans, root); in commit_fs_roots()
1505 &trans->transaction->switch_commits); in commit_fs_roots()
1510 ret2 = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1529 static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, in qgroup_account_snapshot() argument
1551 ret = record_root_in_trans(trans, src, 1); in qgroup_account_snapshot()
1566 ret = btrfs_run_delayed_refs(trans, U64_MAX); in qgroup_account_snapshot()
1568 btrfs_abort_transaction(trans, ret); in qgroup_account_snapshot()
1572 ret = commit_fs_roots(trans); in qgroup_account_snapshot()
1575 ret = btrfs_qgroup_account_extents(trans); in qgroup_account_snapshot()
1580 ret = btrfs_qgroup_inherit(trans, btrfs_root_id(src), dst_objectid, in qgroup_account_snapshot()
1597 ret = commit_cowonly_roots(trans); in qgroup_account_snapshot()
1600 switch_commit_roots(trans); in qgroup_account_snapshot()
1601 ret = btrfs_write_and_wait_transaction(trans); in qgroup_account_snapshot()
1614 ret = record_root_in_trans(trans, parent, 1); in qgroup_account_snapshot()
1627 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, in create_pending_snapshot() argument
1631 struct btrfs_fs_info *fs_info = trans->fs_info; in create_pending_snapshot()
1679 btrfs_set_skip_qgroup(trans, objectid); in create_pending_snapshot()
1696 rsv = trans->block_rsv; in create_pending_snapshot()
1697 trans->block_rsv = &pending->block_rsv; in create_pending_snapshot()
1698 trans->bytes_reserved = trans->block_rsv->reserved; in create_pending_snapshot()
1700 trans->transid, in create_pending_snapshot()
1701 trans->bytes_reserved, 1); in create_pending_snapshot()
1703 ret = record_root_in_trans(trans, parent_root, 0); in create_pending_snapshot()
1713 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1726 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1731 ret = btrfs_create_qgroup(trans, objectid); in create_pending_snapshot()
1733 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1743 ret = btrfs_run_delayed_items(trans); in create_pending_snapshot()
1745 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1749 ret = record_root_in_trans(trans, root, 0); in create_pending_snapshot()
1751 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1754 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1766 trans->transid); in create_pending_snapshot()
1780 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1783 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old, in create_pending_snapshot()
1788 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1792 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); in create_pending_snapshot()
1797 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1806 key.offset = trans->transid; in create_pending_snapshot()
1807 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); in create_pending_snapshot()
1811 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1818 ret = btrfs_add_root_ref(trans, objectid, in create_pending_snapshot()
1823 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1832 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1836 ret = btrfs_reloc_post_snapshot(trans, pending); in create_pending_snapshot()
1838 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1849 ret = qgroup_account_snapshot(trans, root, parent_root, in create_pending_snapshot()
1852 ret = btrfs_qgroup_inherit(trans, btrfs_root_id(root), objectid, in create_pending_snapshot()
1857 ret = btrfs_insert_dir_item(trans, &fname.disk_name, in create_pending_snapshot()
1861 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1869 ret = btrfs_update_inode_fallback(trans, BTRFS_I(parent_inode)); in create_pending_snapshot()
1871 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1874 ret = btrfs_uuid_tree_add(trans, new_root_item->uuid, in create_pending_snapshot()
1878 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1882 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid, in create_pending_snapshot()
1886 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1894 trans->block_rsv = rsv; in create_pending_snapshot()
1895 trans->bytes_reserved = 0; in create_pending_snapshot()
1897 btrfs_clear_skip_qgroup(trans); in create_pending_snapshot()
1912 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans) in create_pending_snapshots() argument
1915 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1920 ret = create_pending_snapshot(trans, pending); in create_pending_snapshots()
1953 struct btrfs_transaction *trans; in btrfs_transaction_blocked() local
1957 trans = info->running_transaction; in btrfs_transaction_blocked()
1958 if (trans) in btrfs_transaction_blocked()
1959 ret = is_transaction_blocked(trans); in btrfs_transaction_blocked()
1964 void btrfs_commit_transaction_async(struct btrfs_trans_handle *trans) in btrfs_commit_transaction_async() argument
1966 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction_async()
1974 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1977 btrfs_end_transaction(trans); in btrfs_commit_transaction_async()
1997 struct btrfs_trans_handle *trans; in btrfs_commit_current_transaction() local
1999 trans = btrfs_attach_transaction_barrier(root); in btrfs_commit_current_transaction()
2000 if (IS_ERR(trans)) { in btrfs_commit_current_transaction()
2001 int ret = PTR_ERR(trans); in btrfs_commit_current_transaction()
2006 return btrfs_commit_transaction(trans); in btrfs_commit_current_transaction()
2009 static void cleanup_transaction(struct btrfs_trans_handle *trans, int err) in cleanup_transaction() argument
2011 struct btrfs_fs_info *fs_info = trans->fs_info; in cleanup_transaction()
2012 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
2014 WARN_ON(refcount_read(&trans->use_count) > 1); in cleanup_transaction()
2016 btrfs_abort_transaction(trans, err); in cleanup_transaction()
2054 btrfs_cleanup_one_transaction(trans->transaction); in cleanup_transaction()
2061 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
2068 if (current->journal_info == trans) in cleanup_transaction()
2085 kmem_cache_free(btrfs_trans_handle_cachep, trans); in cleanup_transaction()
2092 static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans) in btrfs_cleanup_pending_block_groups() argument
2094 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_cleanup_pending_block_groups()
2097 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { in btrfs_cleanup_pending_block_groups()
2141 static void add_pending_snapshot(struct btrfs_trans_handle *trans) in add_pending_snapshot() argument
2143 struct btrfs_transaction *cur_trans = trans->transaction; in add_pending_snapshot()
2145 if (!trans->pending_snapshot) in add_pending_snapshot()
2148 lockdep_assert_held(&trans->fs_info->trans_lock); in add_pending_snapshot()
2151 list_add(&trans->pending_snapshot->list, &cur_trans->pending_snapshots); in add_pending_snapshot()
2163 int btrfs_commit_transaction(struct btrfs_trans_handle *trans) in btrfs_commit_transaction() argument
2165 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction()
2166 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
2172 ASSERT(refcount_read(&trans->use_count) == 1); in btrfs_commit_transaction()
2183 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2184 trans->block_rsv = NULL; in btrfs_commit_transaction()
2196 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
2201 btrfs_create_pending_block_groups(trans); in btrfs_commit_transaction()
2226 ret = btrfs_start_dirty_block_groups(trans); in btrfs_commit_transaction()
2236 add_pending_snapshot(trans); in btrfs_commit_transaction()
2241 if (trans->in_fsync) in btrfs_commit_transaction()
2246 ret = btrfs_end_transaction(trans); in btrfs_commit_transaction()
2264 if (trans->in_fsync) in btrfs_commit_transaction()
2306 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
2312 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2327 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2351 add_pending_snapshot(trans); in btrfs_commit_transaction()
2399 ret = create_pending_snapshots(trans); in btrfs_commit_transaction()
2413 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2417 ret = btrfs_run_delayed_refs(trans, U64_MAX); in btrfs_commit_transaction()
2427 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
2429 ret = commit_fs_roots(trans); in btrfs_commit_transaction()
2436 btrfs_free_log_root_tree(trans, fs_info); in btrfs_commit_transaction()
2442 ret = btrfs_qgroup_account_extents(trans); in btrfs_commit_transaction()
2446 ret = commit_cowonly_roots(trans); in btrfs_commit_transaction()
2478 switch_commit_roots(trans); in btrfs_commit_transaction()
2494 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2520 ret = btrfs_write_and_wait_transaction(trans); in btrfs_commit_transaction()
2545 btrfs_finish_extent_commit(trans); in btrfs_commit_transaction()
2566 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2575 if (current->journal_info == trans) in btrfs_commit_transaction()
2578 kmem_cache_free(btrfs_trans_handle_cachep, trans); in btrfs_commit_transaction()
2592 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2593 btrfs_cleanup_pending_block_groups(trans); in btrfs_commit_transaction()
2594 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2595 trans->block_rsv = NULL; in btrfs_commit_transaction()
2597 if (current->journal_info == trans) in btrfs_commit_transaction()
2599 cleanup_transaction(trans, ret); in btrfs_commit_transaction()
2610 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2666 void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans, in __btrfs_abort_transaction() argument
2670 struct btrfs_fs_info *fs_info = trans->fs_info; in __btrfs_abort_transaction()
2672 WRITE_ONCE(trans->aborted, error); in __btrfs_abort_transaction()
2673 WRITE_ONCE(trans->transaction->aborted, error); in __btrfs_abort_transaction()