Lines Matching full:trans
48 * | New trans handles can be attached to transaction N by calling all
52 * | Call btrfs_commit_transaction() on any trans handle attached to
66 * | - Wait for all other trans handle holders to release.
77 * | Caller is chosen to commit transaction N, and all other trans handle
178 static noinline void switch_commit_roots(struct btrfs_trans_handle *trans) in switch_commit_roots() argument
180 struct btrfs_transaction *cur_trans = trans->transaction; in switch_commit_roots()
181 struct btrfs_fs_info *fs_info = trans->fs_info; in switch_commit_roots()
193 fs_info->last_reloc_trans = trans->transid; in switch_commit_roots()
211 btrfs_free_log(trans, root); in switch_commit_roots()
220 static inline void extwriter_counter_inc(struct btrfs_transaction *trans, in extwriter_counter_inc() argument
224 atomic_inc(&trans->num_extwriters); in extwriter_counter_inc()
227 static inline void extwriter_counter_dec(struct btrfs_transaction *trans, in extwriter_counter_dec() argument
231 atomic_dec(&trans->num_extwriters); in extwriter_counter_dec()
234 static inline void extwriter_counter_init(struct btrfs_transaction *trans, in extwriter_counter_init() argument
237 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0)); in extwriter_counter_init()
240 static inline int extwriter_counter_read(struct btrfs_transaction *trans) in extwriter_counter_read() argument
242 return atomic_read(&trans->num_extwriters); in extwriter_counter_read()
252 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_chunk_metadata() argument
254 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_chunk_metadata()
256 if (!trans->chunk_bytes_reserved) in btrfs_trans_release_chunk_metadata()
260 trans->chunk_bytes_reserved, NULL); in btrfs_trans_release_chunk_metadata()
261 trans->chunk_bytes_reserved = 0; in btrfs_trans_release_chunk_metadata()
350 * One for this trans handle, one so it will live on until we in join_transaction()
405 static int record_root_in_trans(struct btrfs_trans_handle *trans, in record_root_in_trans() argument
413 btrfs_get_root_last_trans(root) < trans->transid) || force) { in record_root_in_trans()
429 if (btrfs_get_root_last_trans(root) == trans->transid && !force) { in record_root_in_trans()
437 btrfs_set_root_last_trans(root, trans->transid); in record_root_in_trans()
458 ret = btrfs_init_reloc_root(trans, root); in record_root_in_trans()
466 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans, in btrfs_add_dropped_root() argument
470 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_add_dropped_root()
485 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, in btrfs_record_root_in_trans() argument
499 if (btrfs_get_root_last_trans(root) == trans->transid && in btrfs_record_root_in_trans()
504 ret = record_root_in_trans(trans, root, 0); in btrfs_record_root_in_trans()
510 static inline int is_transaction_blocked(struct btrfs_transaction *trans) in is_transaction_blocked() argument
512 return (trans->state >= TRANS_STATE_COMMIT_START && in is_transaction_blocked()
513 trans->state < TRANS_STATE_UNBLOCKED && in is_transaction_blocked()
514 !TRANS_ABORTED(trans)); in is_transaction_blocked()
882 struct btrfs_trans_handle *trans; in btrfs_attach_transaction_barrier() local
884 trans = start_transaction(root, 0, TRANS_ATTACH, in btrfs_attach_transaction_barrier()
886 if (trans == ERR_PTR(-ENOENT)) { in btrfs_attach_transaction_barrier()
894 return trans; in btrfs_attach_transaction_barrier()
1007 bool btrfs_should_end_transaction(struct btrfs_trans_handle *trans) in btrfs_should_end_transaction() argument
1009 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
1015 if (btrfs_check_space_for_delayed_refs(trans->fs_info)) in btrfs_should_end_transaction()
1018 return !!btrfs_block_rsv_check(&trans->fs_info->global_block_rsv, 50); in btrfs_should_end_transaction()
1021 static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_metadata() argument
1024 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_metadata()
1026 if (!trans->block_rsv) { in btrfs_trans_release_metadata()
1027 ASSERT(!trans->bytes_reserved); in btrfs_trans_release_metadata()
1028 ASSERT(!trans->delayed_refs_bytes_reserved); in btrfs_trans_release_metadata()
1032 if (!trans->bytes_reserved) { in btrfs_trans_release_metadata()
1033 ASSERT(!trans->delayed_refs_bytes_reserved); in btrfs_trans_release_metadata()
1037 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv); in btrfs_trans_release_metadata()
1039 trans->transid, trans->bytes_reserved, 0); in btrfs_trans_release_metadata()
1040 btrfs_block_rsv_release(fs_info, trans->block_rsv, in btrfs_trans_release_metadata()
1041 trans->bytes_reserved, NULL); in btrfs_trans_release_metadata()
1042 trans->bytes_reserved = 0; in btrfs_trans_release_metadata()
1044 if (!trans->delayed_refs_bytes_reserved) in btrfs_trans_release_metadata()
1048 trans->transid, in btrfs_trans_release_metadata()
1049 trans->delayed_refs_bytes_reserved, 0); in btrfs_trans_release_metadata()
1050 btrfs_block_rsv_release(fs_info, &trans->delayed_rsv, in btrfs_trans_release_metadata()
1051 trans->delayed_refs_bytes_reserved, NULL); in btrfs_trans_release_metadata()
1052 trans->delayed_refs_bytes_reserved = 0; in btrfs_trans_release_metadata()
1055 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, in __btrfs_end_transaction() argument
1058 struct btrfs_fs_info *info = trans->fs_info; in __btrfs_end_transaction()
1059 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
1062 if (refcount_read(&trans->use_count) > 1) { in __btrfs_end_transaction()
1063 refcount_dec(&trans->use_count); in __btrfs_end_transaction()
1064 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
1068 btrfs_trans_release_metadata(trans); in __btrfs_end_transaction()
1069 trans->block_rsv = NULL; in __btrfs_end_transaction()
1071 btrfs_create_pending_block_groups(trans); in __btrfs_end_transaction()
1073 btrfs_trans_release_chunk_metadata(trans); in __btrfs_end_transaction()
1075 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
1081 extwriter_counter_dec(cur_trans, trans->type); in __btrfs_end_transaction()
1090 if (current->journal_info == trans) in __btrfs_end_transaction()
1096 if (TRANS_ABORTED(trans) || BTRFS_FS_ERROR(info)) { in __btrfs_end_transaction()
1098 if (TRANS_ABORTED(trans)) in __btrfs_end_transaction()
1099 ret = trans->aborted; in __btrfs_end_transaction()
1104 kmem_cache_free(btrfs_trans_handle_cachep, trans); in __btrfs_end_transaction()
1108 int btrfs_end_transaction(struct btrfs_trans_handle *trans) in btrfs_end_transaction() argument
1110 return __btrfs_end_transaction(trans, 0); in btrfs_end_transaction()
1113 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans) in btrfs_end_transaction_throttle() argument
1115 return __btrfs_end_transaction(trans, 1); in btrfs_end_transaction_throttle()
1253 * @trans: transaction whose dirty pages we'd like to write
1255 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans) in btrfs_write_and_wait_transaction() argument
1259 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages; in btrfs_write_and_wait_transaction()
1260 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_write_and_wait_transaction()
1268 btrfs_extent_io_tree_release(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1288 static int update_cowonly_root(struct btrfs_trans_handle *trans, in update_cowonly_root() argument
1306 ret = btrfs_update_root(trans, tree_root, in update_cowonly_root()
1325 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans) in commit_cowonly_roots() argument
1327 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_cowonly_roots()
1328 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1329 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1337 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING); in commit_cowonly_roots()
1340 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1348 ret = btrfs_run_dev_stats(trans); in commit_cowonly_roots()
1351 ret = btrfs_run_dev_replace(trans); in commit_cowonly_roots()
1354 ret = btrfs_run_qgroups(trans); in commit_cowonly_roots()
1358 ret = btrfs_setup_space_cache(trans); in commit_cowonly_roots()
1370 &trans->transaction->switch_commits); in commit_cowonly_roots()
1372 ret = update_cowonly_root(trans, root); in commit_cowonly_roots()
1378 ret = btrfs_run_delayed_refs(trans, U64_MAX); in commit_cowonly_roots()
1383 ret = btrfs_write_dirty_block_groups(trans); in commit_cowonly_roots()
1393 ret = btrfs_run_delayed_refs(trans, U64_MAX); in commit_cowonly_roots()
1460 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans) in commit_fs_roots() argument
1462 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_fs_roots()
1471 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING); in commit_fs_roots()
1499 btrfs_free_log(trans, root); in commit_fs_roots()
1500 ret2 = btrfs_update_reloc_root(trans, root); in commit_fs_roots()
1510 &trans->transaction->switch_commits); in commit_fs_roots()
1515 ret2 = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1534 static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, in qgroup_account_snapshot() argument
1556 ret = record_root_in_trans(trans, src, 1); in qgroup_account_snapshot()
1571 ret = btrfs_run_delayed_refs(trans, U64_MAX); in qgroup_account_snapshot()
1573 btrfs_abort_transaction(trans, ret); in qgroup_account_snapshot()
1577 ret = commit_fs_roots(trans); in qgroup_account_snapshot()
1580 ret = btrfs_qgroup_account_extents(trans); in qgroup_account_snapshot()
1585 ret = btrfs_qgroup_inherit(trans, btrfs_root_id(src), dst_objectid, in qgroup_account_snapshot()
1602 ret = commit_cowonly_roots(trans); in qgroup_account_snapshot()
1605 switch_commit_roots(trans); in qgroup_account_snapshot()
1606 ret = btrfs_write_and_wait_transaction(trans); in qgroup_account_snapshot()
1619 ret = record_root_in_trans(trans, parent, 1); in qgroup_account_snapshot()
1632 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, in create_pending_snapshot() argument
1636 struct btrfs_fs_info *fs_info = trans->fs_info; in create_pending_snapshot()
1684 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()
1735 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1746 ret = btrfs_run_delayed_items(trans); in create_pending_snapshot()
1748 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1752 ret = record_root_in_trans(trans, root, 0); in create_pending_snapshot()
1754 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1757 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1769 trans->transid); in create_pending_snapshot()
1783 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1786 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old, in create_pending_snapshot()
1791 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1795 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); in create_pending_snapshot()
1800 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1811 key.offset = trans->transid; in create_pending_snapshot()
1812 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); in create_pending_snapshot()
1816 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1823 ret = btrfs_add_root_ref(trans, objectid, in create_pending_snapshot()
1828 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1837 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1841 ret = btrfs_reloc_post_snapshot(trans, pending); in create_pending_snapshot()
1843 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1854 ret = qgroup_account_snapshot(trans, root, parent_root, in create_pending_snapshot()
1857 ret = btrfs_qgroup_inherit(trans, btrfs_root_id(root), objectid, in create_pending_snapshot()
1862 ret = btrfs_insert_dir_item(trans, &fname.disk_name, in create_pending_snapshot()
1866 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1874 ret = btrfs_update_inode_fallback(trans, parent_inode); in create_pending_snapshot()
1876 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1879 ret = btrfs_uuid_tree_add(trans, new_root_item->uuid, in create_pending_snapshot()
1883 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1887 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid, in create_pending_snapshot()
1891 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1899 trans->block_rsv = rsv; in create_pending_snapshot()
1900 trans->bytes_reserved = 0; in create_pending_snapshot()
1902 btrfs_clear_skip_qgroup(trans); in create_pending_snapshot()
1916 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans) in create_pending_snapshots() argument
1919 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1924 ret = create_pending_snapshot(trans, pending); in create_pending_snapshots()
1957 struct btrfs_transaction *trans; in btrfs_transaction_blocked() local
1961 trans = info->running_transaction; in btrfs_transaction_blocked()
1962 if (trans) in btrfs_transaction_blocked()
1963 ret = is_transaction_blocked(trans); in btrfs_transaction_blocked()
1968 void btrfs_commit_transaction_async(struct btrfs_trans_handle *trans) in btrfs_commit_transaction_async() argument
1970 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction_async()
1978 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1981 btrfs_end_transaction(trans); in btrfs_commit_transaction_async()
2001 struct btrfs_trans_handle *trans; in btrfs_commit_current_transaction() local
2003 trans = btrfs_attach_transaction_barrier(root); in btrfs_commit_current_transaction()
2004 if (IS_ERR(trans)) { in btrfs_commit_current_transaction()
2005 int ret = PTR_ERR(trans); in btrfs_commit_current_transaction()
2010 return btrfs_commit_transaction(trans); in btrfs_commit_current_transaction()
2013 static void cleanup_transaction(struct btrfs_trans_handle *trans, int err) in cleanup_transaction() argument
2015 struct btrfs_fs_info *fs_info = trans->fs_info; in cleanup_transaction()
2016 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
2018 WARN_ON(refcount_read(&trans->use_count) > 1); in cleanup_transaction()
2020 btrfs_abort_transaction(trans, err); in cleanup_transaction()
2058 btrfs_cleanup_one_transaction(trans->transaction); in cleanup_transaction()
2065 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
2072 if (current->journal_info == trans) in cleanup_transaction()
2089 kmem_cache_free(btrfs_trans_handle_cachep, trans); in cleanup_transaction()
2096 static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans) in btrfs_cleanup_pending_block_groups() argument
2098 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_cleanup_pending_block_groups()
2101 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { in btrfs_cleanup_pending_block_groups()
2152 static void add_pending_snapshot(struct btrfs_trans_handle *trans) in add_pending_snapshot() argument
2154 struct btrfs_transaction *cur_trans = trans->transaction; in add_pending_snapshot()
2156 if (!trans->pending_snapshot) in add_pending_snapshot()
2159 lockdep_assert_held(&trans->fs_info->trans_lock); in add_pending_snapshot()
2162 list_add(&trans->pending_snapshot->list, &cur_trans->pending_snapshots); in add_pending_snapshot()
2180 int btrfs_commit_transaction(struct btrfs_trans_handle *trans) in btrfs_commit_transaction() argument
2182 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction()
2183 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
2187 ASSERT(refcount_read(&trans->use_count) == 1); in btrfs_commit_transaction()
2198 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2199 trans->block_rsv = NULL; in btrfs_commit_transaction()
2211 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
2216 btrfs_create_pending_block_groups(trans); in btrfs_commit_transaction()
2241 ret = btrfs_start_dirty_block_groups(trans); in btrfs_commit_transaction()
2251 add_pending_snapshot(trans); in btrfs_commit_transaction()
2256 if (trans->in_fsync) in btrfs_commit_transaction()
2261 ret = btrfs_end_transaction(trans); in btrfs_commit_transaction()
2279 if (trans->in_fsync) in btrfs_commit_transaction()
2319 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
2325 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2340 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2364 add_pending_snapshot(trans); in btrfs_commit_transaction()
2412 ret = create_pending_snapshots(trans); in btrfs_commit_transaction()
2426 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2430 ret = btrfs_run_delayed_refs(trans, U64_MAX); in btrfs_commit_transaction()
2440 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
2442 ret = commit_fs_roots(trans); in btrfs_commit_transaction()
2449 btrfs_free_log_root_tree(trans, fs_info); in btrfs_commit_transaction()
2455 ret = btrfs_qgroup_account_extents(trans); in btrfs_commit_transaction()
2459 ret = commit_cowonly_roots(trans); in btrfs_commit_transaction()
2491 switch_commit_roots(trans); in btrfs_commit_transaction()
2507 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2533 ret = btrfs_write_and_wait_transaction(trans); in btrfs_commit_transaction()
2559 ret = btrfs_finish_extent_commit(trans); in btrfs_commit_transaction()
2582 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2589 if (current->journal_info == trans) in btrfs_commit_transaction()
2592 kmem_cache_free(btrfs_trans_handle_cachep, trans); in btrfs_commit_transaction()
2604 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2605 btrfs_cleanup_pending_block_groups(trans); in btrfs_commit_transaction()
2606 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2607 trans->block_rsv = NULL; in btrfs_commit_transaction()
2609 if (current->journal_info == trans) in btrfs_commit_transaction()
2611 cleanup_transaction(trans, ret); in btrfs_commit_transaction()
2622 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2678 void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans, in __btrfs_abort_transaction() argument
2682 struct btrfs_fs_info *fs_info = trans->fs_info; in __btrfs_abort_transaction()
2684 WRITE_ONCE(trans->aborted, error); in __btrfs_abort_transaction()
2685 WRITE_ONCE(trans->transaction->aborted, error); in __btrfs_abort_transaction()