Lines Matching refs:trans
173 static noinline void switch_commit_roots(struct btrfs_trans_handle *trans) in switch_commit_roots() argument
175 struct btrfs_transaction *cur_trans = trans->transaction; in switch_commit_roots()
176 struct btrfs_fs_info *fs_info = trans->fs_info; in switch_commit_roots()
188 fs_info->last_reloc_trans = trans->transid; in switch_commit_roots()
206 btrfs_free_log(trans, root); in switch_commit_roots()
215 static inline void extwriter_counter_inc(struct btrfs_transaction *trans, in extwriter_counter_inc() argument
219 atomic_inc(&trans->num_extwriters); in extwriter_counter_inc()
222 static inline void extwriter_counter_dec(struct btrfs_transaction *trans, in extwriter_counter_dec() argument
226 atomic_dec(&trans->num_extwriters); in extwriter_counter_dec()
229 static inline void extwriter_counter_init(struct btrfs_transaction *trans, in extwriter_counter_init() argument
232 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0)); in extwriter_counter_init()
235 static inline int extwriter_counter_read(struct btrfs_transaction *trans) in extwriter_counter_read() argument
237 return atomic_read(&trans->num_extwriters); in extwriter_counter_read()
247 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_chunk_metadata() argument
249 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_chunk_metadata()
251 if (!trans->chunk_bytes_reserved) in btrfs_trans_release_chunk_metadata()
255 trans->chunk_bytes_reserved, NULL); in btrfs_trans_release_chunk_metadata()
256 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()
876 struct btrfs_trans_handle *trans; in btrfs_attach_transaction_barrier() local
878 trans = start_transaction(root, 0, TRANS_ATTACH, in btrfs_attach_transaction_barrier()
880 if (trans == ERR_PTR(-ENOENT)) { in btrfs_attach_transaction_barrier()
888 return trans; in btrfs_attach_transaction_barrier()
1001 bool btrfs_should_end_transaction(struct btrfs_trans_handle *trans) in btrfs_should_end_transaction() argument
1003 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
1009 if (btrfs_check_space_for_delayed_refs(trans->fs_info)) in btrfs_should_end_transaction()
1012 return !!btrfs_block_rsv_check(&trans->fs_info->global_block_rsv, 50); in btrfs_should_end_transaction()
1015 static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_metadata() argument
1018 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_metadata()
1020 if (!trans->block_rsv) { in btrfs_trans_release_metadata()
1021 ASSERT(!trans->bytes_reserved); in btrfs_trans_release_metadata()
1022 ASSERT(!trans->delayed_refs_bytes_reserved); in btrfs_trans_release_metadata()
1026 if (!trans->bytes_reserved) { in btrfs_trans_release_metadata()
1027 ASSERT(!trans->delayed_refs_bytes_reserved); in btrfs_trans_release_metadata()
1031 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv); in btrfs_trans_release_metadata()
1033 trans->transid, trans->bytes_reserved, 0); in btrfs_trans_release_metadata()
1034 btrfs_block_rsv_release(fs_info, trans->block_rsv, in btrfs_trans_release_metadata()
1035 trans->bytes_reserved, NULL); in btrfs_trans_release_metadata()
1036 trans->bytes_reserved = 0; in btrfs_trans_release_metadata()
1038 if (!trans->delayed_refs_bytes_reserved) in btrfs_trans_release_metadata()
1042 trans->transid, in btrfs_trans_release_metadata()
1043 trans->delayed_refs_bytes_reserved, 0); in btrfs_trans_release_metadata()
1044 btrfs_block_rsv_release(fs_info, &trans->delayed_rsv, in btrfs_trans_release_metadata()
1045 trans->delayed_refs_bytes_reserved, NULL); in btrfs_trans_release_metadata()
1046 trans->delayed_refs_bytes_reserved = 0; in btrfs_trans_release_metadata()
1049 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, in __btrfs_end_transaction() argument
1052 struct btrfs_fs_info *info = trans->fs_info; in __btrfs_end_transaction()
1053 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
1056 if (refcount_read(&trans->use_count) > 1) { in __btrfs_end_transaction()
1057 refcount_dec(&trans->use_count); in __btrfs_end_transaction()
1058 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
1062 btrfs_trans_release_metadata(trans); in __btrfs_end_transaction()
1063 trans->block_rsv = NULL; in __btrfs_end_transaction()
1065 btrfs_create_pending_block_groups(trans); in __btrfs_end_transaction()
1067 btrfs_trans_release_chunk_metadata(trans); in __btrfs_end_transaction()
1069 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
1075 extwriter_counter_dec(cur_trans, trans->type); in __btrfs_end_transaction()
1084 if (current->journal_info == trans) in __btrfs_end_transaction()
1090 if (TRANS_ABORTED(trans) || BTRFS_FS_ERROR(info)) { in __btrfs_end_transaction()
1092 if (TRANS_ABORTED(trans)) in __btrfs_end_transaction()
1093 ret = trans->aborted; in __btrfs_end_transaction()
1098 kmem_cache_free(btrfs_trans_handle_cachep, trans); in __btrfs_end_transaction()
1102 int btrfs_end_transaction(struct btrfs_trans_handle *trans) in btrfs_end_transaction() argument
1104 return __btrfs_end_transaction(trans, 0); in btrfs_end_transaction()
1107 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans) in btrfs_end_transaction_throttle() argument
1109 return __btrfs_end_transaction(trans, 1); in btrfs_end_transaction_throttle()
1250 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans) in btrfs_write_and_wait_transaction() argument
1254 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages; in btrfs_write_and_wait_transaction()
1255 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_write_and_wait_transaction()
1263 extent_io_tree_release(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1283 static int update_cowonly_root(struct btrfs_trans_handle *trans, in update_cowonly_root() argument
1301 ret = btrfs_update_root(trans, tree_root, in update_cowonly_root()
1320 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans) in commit_cowonly_roots() argument
1322 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_cowonly_roots()
1323 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1324 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1333 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING); in commit_cowonly_roots()
1336 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1344 ret = btrfs_run_dev_stats(trans); in commit_cowonly_roots()
1347 ret = btrfs_run_dev_replace(trans); in commit_cowonly_roots()
1350 ret = btrfs_run_qgroups(trans); in commit_cowonly_roots()
1354 ret = btrfs_setup_space_cache(trans); in commit_cowonly_roots()
1367 &trans->transaction->switch_commits); in commit_cowonly_roots()
1368 ret = update_cowonly_root(trans, root); in commit_cowonly_roots()
1374 ret = btrfs_run_delayed_refs(trans, U64_MAX); in commit_cowonly_roots()
1379 ret = btrfs_write_dirty_block_groups(trans); in commit_cowonly_roots()
1389 ret = btrfs_run_delayed_refs(trans, U64_MAX); in commit_cowonly_roots()
1456 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans) in commit_fs_roots() argument
1458 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_fs_roots()
1467 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING); in commit_fs_roots()
1495 btrfs_free_log(trans, root); in commit_fs_roots()
1496 ret2 = btrfs_update_reloc_root(trans, root); in commit_fs_roots()
1506 &trans->transaction->switch_commits); in commit_fs_roots()
1511 ret2 = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1530 static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, in qgroup_account_snapshot() argument
1552 ret = record_root_in_trans(trans, src, 1); in qgroup_account_snapshot()
1567 ret = btrfs_run_delayed_refs(trans, U64_MAX); in qgroup_account_snapshot()
1569 btrfs_abort_transaction(trans, ret); in qgroup_account_snapshot()
1573 ret = commit_fs_roots(trans); in qgroup_account_snapshot()
1576 ret = btrfs_qgroup_account_extents(trans); in qgroup_account_snapshot()
1581 ret = btrfs_qgroup_inherit(trans, btrfs_root_id(src), dst_objectid, in qgroup_account_snapshot()
1598 ret = commit_cowonly_roots(trans); in qgroup_account_snapshot()
1601 switch_commit_roots(trans); in qgroup_account_snapshot()
1602 ret = btrfs_write_and_wait_transaction(trans); in qgroup_account_snapshot()
1615 ret = record_root_in_trans(trans, parent, 1); in qgroup_account_snapshot()
1628 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, in create_pending_snapshot() argument
1632 struct btrfs_fs_info *fs_info = trans->fs_info; in create_pending_snapshot()
1680 btrfs_set_skip_qgroup(trans, objectid); in create_pending_snapshot()
1697 rsv = trans->block_rsv; in create_pending_snapshot()
1698 trans->block_rsv = &pending->block_rsv; in create_pending_snapshot()
1699 trans->bytes_reserved = trans->block_rsv->reserved; in create_pending_snapshot()
1701 trans->transid, in create_pending_snapshot()
1702 trans->bytes_reserved, 1); in create_pending_snapshot()
1704 ret = record_root_in_trans(trans, parent_root, 0); in create_pending_snapshot()
1714 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1727 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1732 ret = btrfs_create_qgroup(trans, objectid); in create_pending_snapshot()
1734 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1744 ret = btrfs_run_delayed_items(trans); in create_pending_snapshot()
1746 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1750 ret = record_root_in_trans(trans, root, 0); in create_pending_snapshot()
1752 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1755 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1767 trans->transid); in create_pending_snapshot()
1781 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1784 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old, in create_pending_snapshot()
1789 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1793 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); in create_pending_snapshot()
1798 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1807 key.offset = trans->transid; in create_pending_snapshot()
1808 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); in create_pending_snapshot()
1812 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1819 ret = btrfs_add_root_ref(trans, objectid, in create_pending_snapshot()
1824 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1833 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1837 ret = btrfs_reloc_post_snapshot(trans, pending); in create_pending_snapshot()
1839 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1850 ret = qgroup_account_snapshot(trans, root, parent_root, in create_pending_snapshot()
1853 ret = btrfs_qgroup_inherit(trans, btrfs_root_id(root), objectid, in create_pending_snapshot()
1858 ret = btrfs_insert_dir_item(trans, &fname.disk_name, in create_pending_snapshot()
1862 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1870 ret = btrfs_update_inode_fallback(trans, BTRFS_I(parent_inode)); in create_pending_snapshot()
1872 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1875 ret = btrfs_uuid_tree_add(trans, new_root_item->uuid, in create_pending_snapshot()
1879 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1883 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid, in create_pending_snapshot()
1887 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1895 trans->block_rsv = rsv; in create_pending_snapshot()
1896 trans->bytes_reserved = 0; in create_pending_snapshot()
1898 btrfs_clear_skip_qgroup(trans); in create_pending_snapshot()
1913 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans) in create_pending_snapshots() argument
1916 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1921 ret = create_pending_snapshot(trans, pending); in create_pending_snapshots()
1954 struct btrfs_transaction *trans; in btrfs_transaction_blocked() local
1958 trans = info->running_transaction; in btrfs_transaction_blocked()
1959 if (trans) in btrfs_transaction_blocked()
1960 ret = is_transaction_blocked(trans); in btrfs_transaction_blocked()
1965 void btrfs_commit_transaction_async(struct btrfs_trans_handle *trans) in btrfs_commit_transaction_async() argument
1967 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction_async()
1975 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1978 btrfs_end_transaction(trans); in btrfs_commit_transaction_async()
1998 struct btrfs_trans_handle *trans; in btrfs_commit_current_transaction() local
2000 trans = btrfs_attach_transaction_barrier(root); in btrfs_commit_current_transaction()
2001 if (IS_ERR(trans)) { in btrfs_commit_current_transaction()
2002 int ret = PTR_ERR(trans); in btrfs_commit_current_transaction()
2007 return btrfs_commit_transaction(trans); in btrfs_commit_current_transaction()
2010 static void cleanup_transaction(struct btrfs_trans_handle *trans, int err) in cleanup_transaction() argument
2012 struct btrfs_fs_info *fs_info = trans->fs_info; in cleanup_transaction()
2013 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
2015 WARN_ON(refcount_read(&trans->use_count) > 1); in cleanup_transaction()
2017 btrfs_abort_transaction(trans, err); in cleanup_transaction()
2055 btrfs_cleanup_one_transaction(trans->transaction, fs_info); in cleanup_transaction()
2062 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
2069 if (current->journal_info == trans) in cleanup_transaction()
2086 kmem_cache_free(btrfs_trans_handle_cachep, trans); in cleanup_transaction()
2093 static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans) in btrfs_cleanup_pending_block_groups() argument
2095 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_cleanup_pending_block_groups()
2098 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { in btrfs_cleanup_pending_block_groups()
2142 static void add_pending_snapshot(struct btrfs_trans_handle *trans) in add_pending_snapshot() argument
2144 struct btrfs_transaction *cur_trans = trans->transaction; in add_pending_snapshot()
2146 if (!trans->pending_snapshot) in add_pending_snapshot()
2149 lockdep_assert_held(&trans->fs_info->trans_lock); in add_pending_snapshot()
2152 list_add(&trans->pending_snapshot->list, &cur_trans->pending_snapshots); in add_pending_snapshot()
2164 int btrfs_commit_transaction(struct btrfs_trans_handle *trans) in btrfs_commit_transaction() argument
2166 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction()
2167 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
2173 ASSERT(refcount_read(&trans->use_count) == 1); in btrfs_commit_transaction()
2184 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2185 trans->block_rsv = NULL; in btrfs_commit_transaction()
2197 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
2202 btrfs_create_pending_block_groups(trans); in btrfs_commit_transaction()
2227 ret = btrfs_start_dirty_block_groups(trans); in btrfs_commit_transaction()
2237 add_pending_snapshot(trans); in btrfs_commit_transaction()
2242 if (trans->in_fsync) in btrfs_commit_transaction()
2247 ret = btrfs_end_transaction(trans); in btrfs_commit_transaction()
2265 if (trans->in_fsync) in btrfs_commit_transaction()
2307 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
2313 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2328 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2352 add_pending_snapshot(trans); in btrfs_commit_transaction()
2400 ret = create_pending_snapshots(trans); in btrfs_commit_transaction()
2414 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2418 ret = btrfs_run_delayed_refs(trans, U64_MAX); in btrfs_commit_transaction()
2428 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
2430 ret = commit_fs_roots(trans); in btrfs_commit_transaction()
2437 btrfs_free_log_root_tree(trans, fs_info); in btrfs_commit_transaction()
2443 ret = btrfs_qgroup_account_extents(trans); in btrfs_commit_transaction()
2447 ret = commit_cowonly_roots(trans); in btrfs_commit_transaction()
2479 switch_commit_roots(trans); in btrfs_commit_transaction()
2495 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2521 ret = btrfs_write_and_wait_transaction(trans); in btrfs_commit_transaction()
2546 btrfs_finish_extent_commit(trans); in btrfs_commit_transaction()
2567 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2576 if (current->journal_info == trans) in btrfs_commit_transaction()
2579 kmem_cache_free(btrfs_trans_handle_cachep, trans); in btrfs_commit_transaction()
2593 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2594 btrfs_cleanup_pending_block_groups(trans); in btrfs_commit_transaction()
2595 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2596 trans->block_rsv = NULL; in btrfs_commit_transaction()
2598 if (current->journal_info == trans) in btrfs_commit_transaction()
2600 cleanup_transaction(trans, ret); in btrfs_commit_transaction()
2611 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2667 void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans, in __btrfs_abort_transaction() argument
2671 struct btrfs_fs_info *fs_info = trans->fs_info; in __btrfs_abort_transaction()
2673 WRITE_ONCE(trans->aborted, error); in __btrfs_abort_transaction()
2674 WRITE_ONCE(trans->transaction->aborted, error); in __btrfs_abort_transaction()