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
158 static noinline void switch_commit_roots(struct btrfs_trans_handle *trans) in switch_commit_roots() argument
160 struct btrfs_transaction *cur_trans = trans->transaction; in switch_commit_roots()
161 struct btrfs_fs_info *fs_info = trans->fs_info; in switch_commit_roots()
182 btrfs_free_log(trans, root); in switch_commit_roots()
231 static inline void extwriter_counter_inc(struct btrfs_transaction *trans, in extwriter_counter_inc() argument
235 atomic_inc(&trans->num_extwriters); in extwriter_counter_inc()
238 static inline void extwriter_counter_dec(struct btrfs_transaction *trans, in extwriter_counter_dec() argument
242 atomic_dec(&trans->num_extwriters); in extwriter_counter_dec()
245 static inline void extwriter_counter_init(struct btrfs_transaction *trans, in extwriter_counter_init() argument
248 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0)); in extwriter_counter_init()
251 static inline int extwriter_counter_read(struct btrfs_transaction *trans) in extwriter_counter_read() argument
253 return atomic_read(&trans->num_extwriters); in extwriter_counter_read()
263 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_chunk_metadata() argument
265 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_chunk_metadata()
267 if (!trans->chunk_bytes_reserved) in btrfs_trans_release_chunk_metadata()
271 trans->chunk_bytes_reserved, NULL); in btrfs_trans_release_chunk_metadata()
272 trans->chunk_bytes_reserved = 0; in btrfs_trans_release_chunk_metadata()
349 * One for this trans handle, one so it will live on until we in join_transaction()
407 static int record_root_in_trans(struct btrfs_trans_handle *trans, in record_root_in_trans() argument
415 root->last_trans < trans->transid) || force) { in record_root_in_trans()
432 if (root->last_trans == trans->transid && !force) { in record_root_in_trans()
440 root->last_trans = trans->transid; in record_root_in_trans()
461 ret = btrfs_init_reloc_root(trans, root); in record_root_in_trans()
469 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans, in btrfs_add_dropped_root() argument
473 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_add_dropped_root()
488 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, in btrfs_record_root_in_trans() argument
502 if (root->last_trans == trans->transid && in btrfs_record_root_in_trans()
507 ret = record_root_in_trans(trans, root, 0); in btrfs_record_root_in_trans()
513 static inline int is_transaction_blocked(struct btrfs_transaction *trans) in is_transaction_blocked() argument
515 return (trans->state >= TRANS_STATE_COMMIT_START && in is_transaction_blocked()
516 trans->state < TRANS_STATE_UNBLOCKED && in is_transaction_blocked()
517 !TRANS_ABORTED(trans)); in is_transaction_blocked()
613 * worth of delayed refs updates in this trans handle, and in start_transaction()
835 struct btrfs_trans_handle *trans; in btrfs_attach_transaction_barrier() local
837 trans = start_transaction(root, 0, TRANS_ATTACH, in btrfs_attach_transaction_barrier()
839 if (trans == ERR_PTR(-ENOENT)) in btrfs_attach_transaction_barrier()
842 return trans; in btrfs_attach_transaction_barrier()
915 static bool should_end_transaction(struct btrfs_trans_handle *trans) in should_end_transaction() argument
917 struct btrfs_fs_info *fs_info = trans->fs_info; in should_end_transaction()
925 bool btrfs_should_end_transaction(struct btrfs_trans_handle *trans) in btrfs_should_end_transaction() argument
927 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
933 return should_end_transaction(trans); in btrfs_should_end_transaction()
936 static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_metadata() argument
939 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_metadata()
941 if (!trans->block_rsv) { in btrfs_trans_release_metadata()
942 ASSERT(!trans->bytes_reserved); in btrfs_trans_release_metadata()
946 if (!trans->bytes_reserved) in btrfs_trans_release_metadata()
949 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv); in btrfs_trans_release_metadata()
951 trans->transid, trans->bytes_reserved, 0); in btrfs_trans_release_metadata()
952 btrfs_block_rsv_release(fs_info, trans->block_rsv, in btrfs_trans_release_metadata()
953 trans->bytes_reserved, NULL); in btrfs_trans_release_metadata()
954 trans->bytes_reserved = 0; in btrfs_trans_release_metadata()
957 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, in __btrfs_end_transaction() argument
960 struct btrfs_fs_info *info = trans->fs_info; in __btrfs_end_transaction()
961 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
964 if (refcount_read(&trans->use_count) > 1) { in __btrfs_end_transaction()
965 refcount_dec(&trans->use_count); in __btrfs_end_transaction()
966 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
970 btrfs_trans_release_metadata(trans); in __btrfs_end_transaction()
971 trans->block_rsv = NULL; in __btrfs_end_transaction()
973 btrfs_create_pending_block_groups(trans); in __btrfs_end_transaction()
975 btrfs_trans_release_chunk_metadata(trans); in __btrfs_end_transaction()
977 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
983 extwriter_counter_dec(cur_trans, trans->type); in __btrfs_end_transaction()
988 if (current->journal_info == trans) in __btrfs_end_transaction()
994 if (TRANS_ABORTED(trans) || in __btrfs_end_transaction()
997 if (TRANS_ABORTED(trans)) in __btrfs_end_transaction()
998 err = trans->aborted; in __btrfs_end_transaction()
1003 kmem_cache_free(btrfs_trans_handle_cachep, trans); in __btrfs_end_transaction()
1007 int btrfs_end_transaction(struct btrfs_trans_handle *trans) in btrfs_end_transaction() argument
1009 return __btrfs_end_transaction(trans, 0); in btrfs_end_transaction()
1012 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans) in btrfs_end_transaction_throttle() argument
1014 return __btrfs_end_transaction(trans, 1); in btrfs_end_transaction_throttle()
1159 * @trans: transaction whose dirty pages we'd like to write
1161 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans) in btrfs_write_and_wait_transaction() argument
1165 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages; in btrfs_write_and_wait_transaction()
1166 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_write_and_wait_transaction()
1174 extent_io_tree_release(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1194 static int update_cowonly_root(struct btrfs_trans_handle *trans, in update_cowonly_root() argument
1212 ret = btrfs_update_root(trans, tree_root, in update_cowonly_root()
1231 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans) in commit_cowonly_roots() argument
1233 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_cowonly_roots()
1234 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1235 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1241 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1249 ret = btrfs_run_dev_stats(trans); in commit_cowonly_roots()
1252 ret = btrfs_run_dev_replace(trans); in commit_cowonly_roots()
1255 ret = btrfs_run_qgroups(trans); in commit_cowonly_roots()
1259 ret = btrfs_setup_space_cache(trans); in commit_cowonly_roots()
1273 &trans->transaction->switch_commits); in commit_cowonly_roots()
1274 ret = update_cowonly_root(trans, root); in commit_cowonly_roots()
1280 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1285 ret = btrfs_write_dirty_block_groups(trans); in commit_cowonly_roots()
1295 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1304 &trans->transaction->switch_commits); in commit_cowonly_roots()
1333 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans) in commit_fs_roots() argument
1335 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_fs_roots()
1357 btrfs_free_log(trans, root); in commit_fs_roots()
1358 ret2 = btrfs_update_reloc_root(trans, root); in commit_fs_roots()
1368 &trans->transaction->switch_commits); in commit_fs_roots()
1373 ret2 = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1393 struct btrfs_trans_handle *trans; in btrfs_defrag_root() local
1400 trans = btrfs_start_transaction(root, 0); in btrfs_defrag_root()
1401 if (IS_ERR(trans)) { in btrfs_defrag_root()
1402 ret = PTR_ERR(trans); in btrfs_defrag_root()
1406 ret = btrfs_defrag_leaves(trans, root); in btrfs_defrag_root()
1408 btrfs_end_transaction(trans); in btrfs_defrag_root()
1432 static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, in qgroup_account_snapshot() argument
1455 ret = record_root_in_trans(trans, src, 1); in qgroup_account_snapshot()
1470 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in qgroup_account_snapshot()
1472 btrfs_abort_transaction(trans, ret); in qgroup_account_snapshot()
1482 ret = commit_fs_roots(trans); in qgroup_account_snapshot()
1485 ret = btrfs_qgroup_account_extents(trans); in qgroup_account_snapshot()
1490 ret = btrfs_qgroup_inherit(trans, src->root_key.objectid, dst_objectid, in qgroup_account_snapshot()
1507 ret = commit_cowonly_roots(trans); in qgroup_account_snapshot()
1510 switch_commit_roots(trans); in qgroup_account_snapshot()
1511 ret = btrfs_write_and_wait_transaction(trans); in qgroup_account_snapshot()
1526 ret = record_root_in_trans(trans, parent, 1); in qgroup_account_snapshot()
1539 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, in create_pending_snapshot() argument
1543 struct btrfs_fs_info *fs_info = trans->fs_info; in create_pending_snapshot()
1577 btrfs_set_skip_qgroup(trans, objectid); in create_pending_snapshot()
1594 rsv = trans->block_rsv; in create_pending_snapshot()
1595 trans->block_rsv = &pending->block_rsv; in create_pending_snapshot()
1596 trans->bytes_reserved = trans->block_rsv->reserved; in create_pending_snapshot()
1598 trans->transid, in create_pending_snapshot()
1599 trans->bytes_reserved, 1); in create_pending_snapshot()
1603 ret = record_root_in_trans(trans, parent_root, 0); in create_pending_snapshot()
1624 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1635 ret = btrfs_run_delayed_items(trans); in create_pending_snapshot()
1637 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1641 ret = record_root_in_trans(trans, root, 0); in create_pending_snapshot()
1643 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1646 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1658 trans->transid); in create_pending_snapshot()
1672 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1675 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old, in create_pending_snapshot()
1680 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1684 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); in create_pending_snapshot()
1689 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1698 key.offset = trans->transid; in create_pending_snapshot()
1699 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); in create_pending_snapshot()
1703 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1710 ret = btrfs_add_root_ref(trans, objectid, in create_pending_snapshot()
1715 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1724 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1728 ret = btrfs_reloc_post_snapshot(trans, pending); in create_pending_snapshot()
1730 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1740 ret = qgroup_account_snapshot(trans, root, parent_root, in create_pending_snapshot()
1745 ret = btrfs_insert_dir_item(trans, dentry->d_name.name, in create_pending_snapshot()
1751 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1759 ret = btrfs_update_inode_fallback(trans, parent_root, BTRFS_I(parent_inode)); in create_pending_snapshot()
1761 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1764 ret = btrfs_uuid_tree_add(trans, new_root_item->uuid, in create_pending_snapshot()
1768 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1772 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid, in create_pending_snapshot()
1776 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1784 trans->block_rsv = rsv; in create_pending_snapshot()
1785 trans->bytes_reserved = 0; in create_pending_snapshot()
1787 btrfs_clear_skip_qgroup(trans); in create_pending_snapshot()
1800 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans) in create_pending_snapshots() argument
1803 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1808 ret = create_pending_snapshot(trans, pending); in create_pending_snapshots()
1841 struct btrfs_transaction *trans; in btrfs_transaction_in_commit() local
1845 trans = info->running_transaction; in btrfs_transaction_in_commit()
1846 if (trans) in btrfs_transaction_in_commit()
1847 ret = (trans->state >= TRANS_STATE_COMMIT_START); in btrfs_transaction_in_commit()
1854 struct btrfs_transaction *trans; in btrfs_transaction_blocked() local
1858 trans = info->running_transaction; in btrfs_transaction_blocked()
1859 if (trans) in btrfs_transaction_blocked()
1860 ret = is_transaction_blocked(trans); in btrfs_transaction_blocked()
1892 int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans) in btrfs_commit_transaction_async() argument
1894 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction_async()
1903 ac->newtrans = btrfs_join_transaction(trans->root); in btrfs_commit_transaction_async()
1911 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1914 btrfs_end_transaction(trans); in btrfs_commit_transaction_async()
1931 if (current->journal_info == trans) in btrfs_commit_transaction_async()
1939 static void cleanup_transaction(struct btrfs_trans_handle *trans, int err) in cleanup_transaction() argument
1941 struct btrfs_fs_info *fs_info = trans->fs_info; in cleanup_transaction()
1942 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
1944 WARN_ON(refcount_read(&trans->use_count) > 1); in cleanup_transaction()
1946 btrfs_abort_transaction(trans, err); in cleanup_transaction()
1978 btrfs_cleanup_one_transaction(trans->transaction, fs_info); in cleanup_transaction()
1985 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
1990 trace_btrfs_transaction_commit(trans->root); in cleanup_transaction()
1992 if (current->journal_info == trans) in cleanup_transaction()
1996 kmem_cache_free(btrfs_trans_handle_cachep, trans); in cleanup_transaction()
2003 static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans) in btrfs_cleanup_pending_block_groups() argument
2005 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_cleanup_pending_block_groups()
2008 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { in btrfs_cleanup_pending_block_groups()
2036 int btrfs_commit_transaction(struct btrfs_trans_handle *trans) in btrfs_commit_transaction() argument
2038 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction()
2039 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
2043 ASSERT(refcount_read(&trans->use_count) == 1); in btrfs_commit_transaction()
2048 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2052 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2053 trans->block_rsv = NULL; 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()
2072 btrfs_create_pending_block_groups(trans); in btrfs_commit_transaction()
2097 ret = btrfs_start_dirty_block_groups(trans); in btrfs_commit_transaction()
2099 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2112 if (trans->in_fsync) in btrfs_commit_transaction()
2114 ret = btrfs_end_transaction(trans); in btrfs_commit_transaction()
2131 if (trans->in_fsync) in btrfs_commit_transaction()
2164 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
2170 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2178 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2220 ret = create_pending_snapshots(trans); in btrfs_commit_transaction()
2234 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2238 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in btrfs_commit_transaction()
2248 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
2258 * writers, but a little lower down we drop the trans mutex in btrfs_commit_transaction()
2265 ret = commit_fs_roots(trans); in btrfs_commit_transaction()
2278 btrfs_free_log_root_tree(trans, fs_info); in btrfs_commit_transaction()
2284 ret = btrfs_qgroup_account_extents(trans); in btrfs_commit_transaction()
2288 ret = commit_cowonly_roots(trans); in btrfs_commit_transaction()
2313 switch_commit_roots(trans); in btrfs_commit_transaction()
2329 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2339 ret = btrfs_write_and_wait_transaction(trans); in btrfs_commit_transaction()
2374 btrfs_finish_extent_commit(trans); in btrfs_commit_transaction()
2394 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2397 trace_btrfs_transaction_commit(trans->root); in btrfs_commit_transaction()
2401 if (current->journal_info == trans) in btrfs_commit_transaction()
2404 kmem_cache_free(btrfs_trans_handle_cachep, trans); in btrfs_commit_transaction()
2415 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2416 btrfs_cleanup_pending_block_groups(trans); in btrfs_commit_transaction()
2417 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2418 trans->block_rsv = NULL; in btrfs_commit_transaction()
2420 if (current->journal_info == trans) in btrfs_commit_transaction()
2422 cleanup_transaction(trans, ret); in btrfs_commit_transaction()