Lines Matching full:trans
38 * | New trans handles can be attached to transaction N by calling all
42 * | Call btrfs_commit_transaction() on any trans handle attached to
51 * | - Wait for all other trans handle holders to release.
62 * | Caller is chosen to commit transaction N, and all other trans handle
153 static noinline void switch_commit_roots(struct btrfs_trans_handle *trans) in switch_commit_roots() argument
155 struct btrfs_transaction *cur_trans = trans->transaction; in switch_commit_roots()
156 struct btrfs_fs_info *fs_info = trans->fs_info; in switch_commit_roots()
178 btrfs_free_log(trans, root); in switch_commit_roots()
186 static inline void extwriter_counter_inc(struct btrfs_transaction *trans, in extwriter_counter_inc() argument
190 atomic_inc(&trans->num_extwriters); in extwriter_counter_inc()
193 static inline void extwriter_counter_dec(struct btrfs_transaction *trans, in extwriter_counter_dec() argument
197 atomic_dec(&trans->num_extwriters); in extwriter_counter_dec()
200 static inline void extwriter_counter_init(struct btrfs_transaction *trans, in extwriter_counter_init() argument
203 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0)); in extwriter_counter_init()
206 static inline int extwriter_counter_read(struct btrfs_transaction *trans) in extwriter_counter_read() argument
208 return atomic_read(&trans->num_extwriters); in extwriter_counter_read()
215 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_chunk_metadata() argument
217 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_chunk_metadata()
219 if (!trans->chunk_bytes_reserved) in btrfs_trans_release_chunk_metadata()
222 WARN_ON_ONCE(!list_empty(&trans->new_bgs)); in btrfs_trans_release_chunk_metadata()
225 trans->chunk_bytes_reserved, NULL); in btrfs_trans_release_chunk_metadata()
226 trans->chunk_bytes_reserved = 0; in btrfs_trans_release_chunk_metadata()
303 * One for this trans handle, one so it will live on until we in join_transaction()
359 static int record_root_in_trans(struct btrfs_trans_handle *trans, in record_root_in_trans() argument
366 root->last_trans < trans->transid) || force) { in record_root_in_trans()
383 if (root->last_trans == trans->transid && !force) { in record_root_in_trans()
391 root->last_trans = trans->transid; in record_root_in_trans()
412 btrfs_init_reloc_root(trans, root); in record_root_in_trans()
420 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans, in btrfs_add_dropped_root() argument
424 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_add_dropped_root()
439 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, in btrfs_record_root_in_trans() argument
452 if (root->last_trans == trans->transid && in btrfs_record_root_in_trans()
457 record_root_in_trans(trans, root, 0); in btrfs_record_root_in_trans()
463 static inline int is_transaction_blocked(struct btrfs_transaction *trans) in is_transaction_blocked() argument
465 return (trans->state >= TRANS_STATE_COMMIT_START && in is_transaction_blocked()
466 trans->state < TRANS_STATE_UNBLOCKED && in is_transaction_blocked()
467 !TRANS_ABORTED(trans)); in is_transaction_blocked()
566 * worth of delayed refs updates in this trans handle, and in start_transaction()
780 struct btrfs_trans_handle *trans; in btrfs_attach_transaction_barrier() local
782 trans = start_transaction(root, 0, TRANS_ATTACH, in btrfs_attach_transaction_barrier()
784 if (trans == ERR_PTR(-ENOENT)) in btrfs_attach_transaction_barrier()
787 return trans; in btrfs_attach_transaction_barrier()
859 static int should_end_transaction(struct btrfs_trans_handle *trans) in should_end_transaction() argument
861 struct btrfs_fs_info *fs_info = trans->fs_info; in should_end_transaction()
869 int btrfs_should_end_transaction(struct btrfs_trans_handle *trans) in btrfs_should_end_transaction() argument
871 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
878 return should_end_transaction(trans); in btrfs_should_end_transaction()
881 static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_metadata() argument
884 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_metadata()
886 if (!trans->block_rsv) { in btrfs_trans_release_metadata()
887 ASSERT(!trans->bytes_reserved); in btrfs_trans_release_metadata()
891 if (!trans->bytes_reserved) in btrfs_trans_release_metadata()
894 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv); in btrfs_trans_release_metadata()
896 trans->transid, trans->bytes_reserved, 0); in btrfs_trans_release_metadata()
897 btrfs_block_rsv_release(fs_info, trans->block_rsv, in btrfs_trans_release_metadata()
898 trans->bytes_reserved, NULL); in btrfs_trans_release_metadata()
899 trans->bytes_reserved = 0; in btrfs_trans_release_metadata()
902 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, in __btrfs_end_transaction() argument
905 struct btrfs_fs_info *info = trans->fs_info; in __btrfs_end_transaction()
906 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
909 if (refcount_read(&trans->use_count) > 1) { in __btrfs_end_transaction()
910 refcount_dec(&trans->use_count); in __btrfs_end_transaction()
911 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
915 btrfs_trans_release_metadata(trans); in __btrfs_end_transaction()
916 trans->block_rsv = NULL; in __btrfs_end_transaction()
918 btrfs_create_pending_block_groups(trans); in __btrfs_end_transaction()
920 btrfs_trans_release_chunk_metadata(trans); in __btrfs_end_transaction()
922 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
928 extwriter_counter_dec(cur_trans, trans->type); in __btrfs_end_transaction()
933 if (current->journal_info == trans) in __btrfs_end_transaction()
939 if (TRANS_ABORTED(trans) || in __btrfs_end_transaction()
942 if (TRANS_ABORTED(trans)) in __btrfs_end_transaction()
943 err = trans->aborted; in __btrfs_end_transaction()
948 kmem_cache_free(btrfs_trans_handle_cachep, trans); in __btrfs_end_transaction()
952 int btrfs_end_transaction(struct btrfs_trans_handle *trans) in btrfs_end_transaction() argument
954 return __btrfs_end_transaction(trans, 0); in btrfs_end_transaction()
957 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans) in btrfs_end_transaction_throttle() argument
959 return __btrfs_end_transaction(trans, 1); in btrfs_end_transaction_throttle()
1104 * @trans: transaction whose dirty pages we'd like to write
1106 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans) in btrfs_write_and_wait_transaction() argument
1110 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages; in btrfs_write_and_wait_transaction()
1111 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_write_and_wait_transaction()
1119 extent_io_tree_release(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1139 static int update_cowonly_root(struct btrfs_trans_handle *trans, in update_cowonly_root() argument
1157 ret = btrfs_update_root(trans, tree_root, in update_cowonly_root()
1176 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans) in commit_cowonly_roots() argument
1178 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_cowonly_roots()
1179 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1180 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1186 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1194 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1198 ret = btrfs_run_dev_stats(trans); in commit_cowonly_roots()
1201 ret = btrfs_run_dev_replace(trans); in commit_cowonly_roots()
1204 ret = btrfs_run_qgroups(trans); in commit_cowonly_roots()
1208 ret = btrfs_setup_space_cache(trans); in commit_cowonly_roots()
1213 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1226 &trans->transaction->switch_commits); in commit_cowonly_roots()
1227 ret = update_cowonly_root(trans, root); in commit_cowonly_roots()
1230 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1236 ret = btrfs_write_dirty_block_groups(trans); in commit_cowonly_roots()
1239 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1248 &trans->transaction->switch_commits); in commit_cowonly_roots()
1277 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans) in commit_fs_roots() argument
1279 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_fs_roots()
1300 btrfs_free_log(trans, root); in commit_fs_roots()
1301 btrfs_update_reloc_root(trans, root); in commit_fs_roots()
1303 btrfs_save_ino_cache(root, trans); in commit_fs_roots()
1311 &trans->transaction->switch_commits); in commit_fs_roots()
1316 err = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1336 struct btrfs_trans_handle *trans; in btrfs_defrag_root() local
1343 trans = btrfs_start_transaction(root, 0); in btrfs_defrag_root()
1344 if (IS_ERR(trans)) in btrfs_defrag_root()
1345 return PTR_ERR(trans); in btrfs_defrag_root()
1347 ret = btrfs_defrag_leaves(trans, root); in btrfs_defrag_root()
1349 btrfs_end_transaction(trans); in btrfs_defrag_root()
1373 static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, in qgroup_account_snapshot() argument
1396 record_root_in_trans(trans, src, 1); in qgroup_account_snapshot()
1404 ret = commit_fs_roots(trans); in qgroup_account_snapshot()
1407 ret = btrfs_qgroup_account_extents(trans); in qgroup_account_snapshot()
1412 ret = btrfs_qgroup_inherit(trans, src->root_key.objectid, dst_objectid, in qgroup_account_snapshot()
1429 ret = commit_cowonly_roots(trans); in qgroup_account_snapshot()
1432 switch_commit_roots(trans); in qgroup_account_snapshot()
1433 ret = btrfs_write_and_wait_transaction(trans); in qgroup_account_snapshot()
1448 record_root_in_trans(trans, parent, 1); in qgroup_account_snapshot()
1461 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, in create_pending_snapshot() argument
1465 struct btrfs_fs_info *fs_info = trans->fs_info; in create_pending_snapshot()
1499 btrfs_set_skip_qgroup(trans, objectid); in create_pending_snapshot()
1516 rsv = trans->block_rsv; in create_pending_snapshot()
1517 trans->block_rsv = &pending->block_rsv; in create_pending_snapshot()
1518 trans->bytes_reserved = trans->block_rsv->reserved; in create_pending_snapshot()
1520 trans->transid, in create_pending_snapshot()
1521 trans->bytes_reserved, 1); in create_pending_snapshot()
1525 record_root_in_trans(trans, parent_root, 0); in create_pending_snapshot()
1545 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1556 ret = btrfs_run_delayed_items(trans); in create_pending_snapshot()
1558 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1562 record_root_in_trans(trans, root, 0); in create_pending_snapshot()
1563 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1575 trans->transid); in create_pending_snapshot()
1589 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1592 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old, in create_pending_snapshot()
1597 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1603 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); in create_pending_snapshot()
1608 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1617 key.offset = trans->transid; in create_pending_snapshot()
1618 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); in create_pending_snapshot()
1622 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1629 ret = btrfs_add_root_ref(trans, objectid, in create_pending_snapshot()
1634 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1643 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1647 ret = btrfs_reloc_post_snapshot(trans, pending); in create_pending_snapshot()
1649 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1653 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in create_pending_snapshot()
1655 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1665 ret = qgroup_account_snapshot(trans, root, parent_root, in create_pending_snapshot()
1670 ret = btrfs_insert_dir_item(trans, dentry->d_name.name, in create_pending_snapshot()
1676 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1684 ret = btrfs_update_inode_fallback(trans, parent_root, parent_inode); in create_pending_snapshot()
1686 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1689 ret = btrfs_uuid_tree_add(trans, new_root_item->uuid, in create_pending_snapshot()
1693 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1697 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid, in create_pending_snapshot()
1701 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1706 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in create_pending_snapshot()
1708 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1715 trans->block_rsv = rsv; in create_pending_snapshot()
1716 trans->bytes_reserved = 0; in create_pending_snapshot()
1718 btrfs_clear_skip_qgroup(trans); in create_pending_snapshot()
1731 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans) in create_pending_snapshots() argument
1734 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1739 ret = create_pending_snapshot(trans, pending); in create_pending_snapshots()
1770 struct btrfs_transaction *trans; in btrfs_transaction_in_commit() local
1774 trans = info->running_transaction; in btrfs_transaction_in_commit()
1775 if (trans) in btrfs_transaction_in_commit()
1776 ret = (trans->state >= TRANS_STATE_COMMIT_START); in btrfs_transaction_in_commit()
1783 struct btrfs_transaction *trans; in btrfs_transaction_blocked() local
1787 trans = info->running_transaction; in btrfs_transaction_blocked()
1788 if (trans) in btrfs_transaction_blocked()
1789 ret = is_transaction_blocked(trans); in btrfs_transaction_blocked()
1799 struct btrfs_transaction *trans) in wait_current_trans_commit_start() argument
1802 trans->state >= TRANS_STATE_COMMIT_START || in wait_current_trans_commit_start()
1803 TRANS_ABORTED(trans)); in wait_current_trans_commit_start()
1812 struct btrfs_transaction *trans) in wait_current_trans_commit_start_and_unblock() argument
1815 trans->state >= TRANS_STATE_UNBLOCKED || in wait_current_trans_commit_start_and_unblock()
1816 TRANS_ABORTED(trans)); in wait_current_trans_commit_start_and_unblock()
1846 int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, in btrfs_commit_transaction_async() argument
1849 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction_async()
1858 ac->newtrans = btrfs_join_transaction(trans->root); in btrfs_commit_transaction_async()
1866 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1869 btrfs_end_transaction(trans); in btrfs_commit_transaction_async()
1886 if (current->journal_info == trans) in btrfs_commit_transaction_async()
1894 static void cleanup_transaction(struct btrfs_trans_handle *trans, int err) in cleanup_transaction() argument
1896 struct btrfs_fs_info *fs_info = trans->fs_info; in cleanup_transaction()
1897 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
1899 WARN_ON(refcount_read(&trans->use_count) > 1); in cleanup_transaction()
1901 btrfs_abort_transaction(trans, err); in cleanup_transaction()
1923 btrfs_cleanup_one_transaction(trans->transaction, fs_info); in cleanup_transaction()
1930 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
1935 trace_btrfs_transaction_commit(trans->root); in cleanup_transaction()
1937 if (current->journal_info == trans) in cleanup_transaction()
1941 kmem_cache_free(btrfs_trans_handle_cachep, trans); in cleanup_transaction()
1948 static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans) in btrfs_cleanup_pending_block_groups() argument
1950 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_cleanup_pending_block_groups()
1953 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { in btrfs_cleanup_pending_block_groups()
1959 static inline int btrfs_start_delalloc_flush(struct btrfs_trans_handle *trans) in btrfs_start_delalloc_flush() argument
1961 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_start_delalloc_flush()
1976 struct list_head *head = &trans->transaction->pending_snapshots; in btrfs_start_delalloc_flush()
1996 static inline void btrfs_wait_delalloc_flush(struct btrfs_trans_handle *trans) in btrfs_wait_delalloc_flush() argument
1998 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_wait_delalloc_flush()
2004 struct list_head *head = &trans->transaction->pending_snapshots; in btrfs_wait_delalloc_flush()
2018 int btrfs_commit_transaction(struct btrfs_trans_handle *trans) in btrfs_commit_transaction() argument
2020 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction()
2021 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
2025 ASSERT(refcount_read(&trans->use_count) == 1); in btrfs_commit_transaction()
2030 * transaction as failed, so set trans->dirty to make the abort code do in btrfs_commit_transaction()
2033 trans->dirty = true; in btrfs_commit_transaction()
2038 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2042 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2043 trans->block_rsv = NULL; in btrfs_commit_transaction()
2048 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
2050 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2054 cur_trans = trans->transaction; in btrfs_commit_transaction()
2063 btrfs_create_pending_block_groups(trans); in btrfs_commit_transaction()
2065 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
2067 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2094 ret = btrfs_start_dirty_block_groups(trans); in btrfs_commit_transaction()
2096 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2106 ret = btrfs_end_transaction(trans); in btrfs_commit_transaction()
2151 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
2153 ret = btrfs_start_delalloc_flush(trans); in btrfs_commit_transaction()
2157 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2165 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2169 btrfs_wait_delalloc_flush(trans); in btrfs_commit_transaction()
2207 ret = create_pending_snapshots(trans); in btrfs_commit_transaction()
2221 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2225 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in btrfs_commit_transaction()
2235 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
2245 * writers, but a little lower down we drop the trans mutex in btrfs_commit_transaction()
2252 ret = commit_fs_roots(trans); in btrfs_commit_transaction()
2265 btrfs_free_log_root_tree(trans, fs_info); in btrfs_commit_transaction()
2271 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in btrfs_commit_transaction()
2279 ret = btrfs_qgroup_account_extents(trans); in btrfs_commit_transaction()
2283 ret = commit_cowonly_roots(trans); in btrfs_commit_transaction()
2310 switch_commit_roots(trans); in btrfs_commit_transaction()
2326 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2336 ret = btrfs_write_and_wait_transaction(trans); in btrfs_commit_transaction()
2357 btrfs_finish_extent_commit(trans); in btrfs_commit_transaction()
2377 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2380 trace_btrfs_transaction_commit(trans->root); in btrfs_commit_transaction()
2384 if (current->journal_info == trans) in btrfs_commit_transaction()
2387 kmem_cache_free(btrfs_trans_handle_cachep, trans); in btrfs_commit_transaction()
2398 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2399 btrfs_cleanup_pending_block_groups(trans); in btrfs_commit_transaction()
2400 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2401 trans->block_rsv = NULL; in btrfs_commit_transaction()
2403 if (current->journal_info == trans) in btrfs_commit_transaction()
2405 cleanup_transaction(trans, ret); in btrfs_commit_transaction()