Lines Matching defs:trans

50  * | New trans handles can be attached to transaction N by calling all
54 * | Call btrfs_commit_transaction() on any trans handle attached to
68 * | - Wait for all other trans handle holders to release.
79 * | Caller is chosen to commit transaction N, and all other trans handle
176 static noinline void switch_commit_roots(struct btrfs_trans_handle *trans)
178 struct btrfs_transaction *cur_trans = trans->transaction;
179 struct btrfs_fs_info *fs_info = trans->fs_info;
191 fs_info->last_reloc_trans = trans->transid;
209 btrfs_free_log(trans, root);
218 static inline void extwriter_counter_inc(struct btrfs_transaction *trans,
222 atomic_inc(&trans->num_extwriters);
225 static inline void extwriter_counter_dec(struct btrfs_transaction *trans,
229 atomic_dec(&trans->num_extwriters);
232 static inline void extwriter_counter_init(struct btrfs_transaction *trans,
235 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0));
238 static inline int extwriter_counter_read(struct btrfs_transaction *trans)
240 return atomic_read(&trans->num_extwriters);
250 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans)
252 struct btrfs_fs_info *fs_info = trans->fs_info;
254 if (!trans->chunk_bytes_reserved)
258 trans->chunk_bytes_reserved, NULL);
259 trans->chunk_bytes_reserved = 0;
346 * One for this trans handle, one so it will live on until we
402 static int record_root_in_trans(struct btrfs_trans_handle *trans,
410 root->last_trans < trans->transid) || force) {
426 if (root->last_trans == trans->transid && !force) {
434 root->last_trans = trans->transid;
455 ret = btrfs_init_reloc_root(trans, root);
463 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans,
467 struct btrfs_transaction *cur_trans = trans->transaction;
482 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans,
496 if (root->last_trans == trans->transid &&
501 ret = record_root_in_trans(trans, root, 0);
507 static inline int is_transaction_blocked(struct btrfs_transaction *trans)
509 return (trans->state >= TRANS_STATE_COMMIT_START &&
510 trans->state < TRANS_STATE_UNBLOCKED &&
511 !TRANS_ABORTED(trans));
613 * of delayed refs updates in this trans handle, and refill that
846 struct btrfs_trans_handle *trans;
848 trans = start_transaction(root, 0, TRANS_ATTACH,
850 if (trans == ERR_PTR(-ENOENT)) {
858 return trans;
971 bool btrfs_should_end_transaction(struct btrfs_trans_handle *trans)
973 struct btrfs_transaction *cur_trans = trans->transaction;
979 if (btrfs_check_space_for_delayed_refs(trans->fs_info))
982 return !!btrfs_block_rsv_check(&trans->fs_info->global_block_rsv, 50);
985 static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans)
988 struct btrfs_fs_info *fs_info = trans->fs_info;
990 if (!trans->block_rsv) {
991 ASSERT(!trans->bytes_reserved);
995 if (!trans->bytes_reserved)
998 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv);
1000 trans->transid, trans->bytes_reserved, 0);
1001 btrfs_block_rsv_release(fs_info, trans->block_rsv,
1002 trans->bytes_reserved, NULL);
1003 trans->bytes_reserved = 0;
1006 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
1009 struct btrfs_fs_info *info = trans->fs_info;
1010 struct btrfs_transaction *cur_trans = trans->transaction;
1013 if (refcount_read(&trans->use_count) > 1) {
1014 refcount_dec(&trans->use_count);
1015 trans->block_rsv = trans->orig_rsv;
1019 btrfs_trans_release_metadata(trans);
1020 trans->block_rsv = NULL;
1022 btrfs_create_pending_block_groups(trans);
1024 btrfs_trans_release_chunk_metadata(trans);
1026 if (trans->type & __TRANS_FREEZABLE)
1032 extwriter_counter_dec(cur_trans, trans->type);
1041 if (current->journal_info == trans)
1047 if (TRANS_ABORTED(trans) || BTRFS_FS_ERROR(info)) {
1049 if (TRANS_ABORTED(trans))
1050 err = trans->aborted;
1055 kmem_cache_free(btrfs_trans_handle_cachep, trans);
1059 int btrfs_end_transaction(struct btrfs_trans_handle *trans)
1061 return __btrfs_end_transaction(trans, 0);
1064 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans)
1066 return __btrfs_end_transaction(trans, 1);
1209 * @trans: transaction whose dirty pages we'd like to write
1211 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans)
1215 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages;
1216 struct btrfs_fs_info *fs_info = trans->fs_info;
1224 extent_io_tree_release(&trans->transaction->dirty_pages);
1244 static int update_cowonly_root(struct btrfs_trans_handle *trans,
1262 ret = btrfs_update_root(trans, tree_root,
1281 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans)
1283 struct btrfs_fs_info *fs_info = trans->fs_info;
1284 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs;
1285 struct list_head *io_bgs = &trans->transaction->io_bgs;
1294 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING);
1297 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL,
1305 ret = btrfs_run_dev_stats(trans);
1308 ret = btrfs_run_dev_replace(trans);
1311 ret = btrfs_run_qgroups(trans);
1315 ret = btrfs_setup_space_cache(trans);
1328 &trans->transaction->switch_commits);
1329 ret = update_cowonly_root(trans, root);
1335 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
1340 ret = btrfs_write_dirty_block_groups(trans);
1350 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
1417 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans)
1419 struct btrfs_fs_info *fs_info = trans->fs_info;
1428 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING);
1455 btrfs_free_log(trans, root);
1456 ret2 = btrfs_update_reloc_root(trans, root);
1466 &trans->transaction->switch_commits);
1471 ret2 = btrfs_update_root(trans, fs_info->tree_root,
1491 struct btrfs_trans_handle *trans;
1498 trans = btrfs_start_transaction(root, 0);
1499 if (IS_ERR(trans)) {
1500 ret = PTR_ERR(trans);
1504 ret = btrfs_defrag_leaves(trans, root);
1506 btrfs_end_transaction(trans);
1530 static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,
1553 ret = record_root_in_trans(trans, src, 1);
1568 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
1570 btrfs_abort_transaction(trans, ret);
1574 ret = commit_fs_roots(trans);
1577 ret = btrfs_qgroup_account_extents(trans);
1582 ret = btrfs_qgroup_inherit(trans, src->root_key.objectid, dst_objectid,
1599 ret = commit_cowonly_roots(trans);
1602 switch_commit_roots(trans);
1603 ret = btrfs_write_and_wait_transaction(trans);
1616 ret = record_root_in_trans(trans, parent, 1);
1629 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
1633 struct btrfs_fs_info *fs_info = trans->fs_info;
1681 btrfs_set_skip_qgroup(trans, objectid);
1698 rsv = trans->block_rsv;
1699 trans->block_rsv = &pending->block_rsv;
1700 trans->bytes_reserved = trans->block_rsv->reserved;
1702 trans->transid,
1703 trans->bytes_reserved, 1);
1705 ret = record_root_in_trans(trans, parent_root, 0);
1715 btrfs_abort_transaction(trans, ret);
1728 btrfs_abort_transaction(trans, ret);
1739 ret = btrfs_run_delayed_items(trans);
1741 btrfs_abort_transaction(trans, ret);
1745 ret = record_root_in_trans(trans, root, 0);
1747 btrfs_abort_transaction(trans, ret);
1750 btrfs_set_root_last_snapshot(&root->root_item, trans->transid);
1762 trans->transid);
1776 btrfs_set_root_otransid(new_root_item, trans->transid);
1779 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old,
1784 btrfs_abort_transaction(trans, ret);
1788 ret = btrfs_copy_root(trans, root, old, &tmp, objectid);
1793 btrfs_abort_transaction(trans, ret);
1802 key.offset = trans->transid;
1803 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item);
1807 btrfs_abort_transaction(trans, ret);
1814 ret = btrfs_add_root_ref(trans, objectid,
1819 btrfs_abort_transaction(trans, ret);
1828 btrfs_abort_transaction(trans, ret);
1832 ret = btrfs_reloc_post_snapshot(trans, pending);
1834 btrfs_abort_transaction(trans, ret);
1844 ret = qgroup_account_snapshot(trans, root, parent_root,
1849 ret = btrfs_insert_dir_item(trans, &fname.disk_name,
1855 btrfs_abort_transaction(trans, ret);
1862 ret = btrfs_update_inode_fallback(trans, parent_root, BTRFS_I(parent_inode));
1864 btrfs_abort_transaction(trans, ret);
1867 ret = btrfs_uuid_tree_add(trans, new_root_item->uuid,
1871 btrfs_abort_transaction(trans, ret);
1875 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid,
1879 btrfs_abort_transaction(trans, ret);
1887 trans->block_rsv = rsv;
1888 trans->bytes_reserved = 0;
1890 btrfs_clear_skip_qgroup(trans);
1905 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans)
1908 struct list_head *head = &trans->transaction->pending_snapshots;
1913 ret = create_pending_snapshot(trans, pending);
1946 struct btrfs_transaction *trans;
1950 trans = info->running_transaction;
1951 if (trans)
1952 ret = (trans->state >= TRANS_STATE_COMMIT_START);
1959 struct btrfs_transaction *trans;
1963 trans = info->running_transaction;
1964 if (trans)
1965 ret = is_transaction_blocked(trans);
1970 void btrfs_commit_transaction_async(struct btrfs_trans_handle *trans)
1972 struct btrfs_fs_info *fs_info = trans->fs_info;
1980 cur_trans = trans->transaction;
1983 btrfs_end_transaction(trans);
1996 static void cleanup_transaction(struct btrfs_trans_handle *trans, int err)
1998 struct btrfs_fs_info *fs_info = trans->fs_info;
1999 struct btrfs_transaction *cur_trans = trans->transaction;
2001 WARN_ON(refcount_read(&trans->use_count) > 1);
2003 btrfs_abort_transaction(trans, err);
2041 btrfs_cleanup_one_transaction(trans->transaction, fs_info);
2048 if (trans->type & __TRANS_FREEZABLE)
2055 if (current->journal_info == trans)
2072 kmem_cache_free(btrfs_trans_handle_cachep, trans);
2079 static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans)
2081 struct btrfs_fs_info *fs_info = trans->fs_info;
2084 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) {
2128 static void add_pending_snapshot(struct btrfs_trans_handle *trans)
2130 struct btrfs_transaction *cur_trans = trans->transaction;
2132 if (!trans->pending_snapshot)
2135 lockdep_assert_held(&trans->fs_info->trans_lock);
2138 list_add(&trans->pending_snapshot->list, &cur_trans->pending_snapshots);
2150 int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
2152 struct btrfs_fs_info *fs_info = trans->fs_info;
2153 struct btrfs_transaction *cur_trans = trans->transaction;
2159 ASSERT(refcount_read(&trans->use_count) == 1);
2170 btrfs_trans_release_metadata(trans);
2171 trans->block_rsv = NULL;
2183 ret = btrfs_run_delayed_refs(trans, 0);
2188 btrfs_create_pending_block_groups(trans);
2213 ret = btrfs_start_dirty_block_groups(trans);
2223 add_pending_snapshot(trans);
2228 if (trans->in_fsync)
2233 ret = btrfs_end_transaction(trans);
2251 if (trans->in_fsync)
2293 extwriter_counter_dec(cur_trans, trans->type);
2299 ret = btrfs_run_delayed_items(trans);
2314 ret = btrfs_run_delayed_items(trans);
2338 add_pending_snapshot(trans);
2386 ret = create_pending_snapshots(trans);
2400 ret = btrfs_run_delayed_items(trans);
2404 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
2414 WARN_ON(cur_trans != trans->transaction);
2416 ret = commit_fs_roots(trans);
2423 btrfs_free_log_root_tree(trans, fs_info);
2429 ret = btrfs_qgroup_account_extents(trans);
2433 ret = commit_cowonly_roots(trans);
2465 switch_commit_roots(trans);
2481 btrfs_trans_release_chunk_metadata(trans);
2507 ret = btrfs_write_and_wait_transaction(trans);
2532 btrfs_finish_extent_commit(trans);
2553 if (trans->type & __TRANS_FREEZABLE)
2562 if (current->journal_info == trans)
2565 kmem_cache_free(btrfs_trans_handle_cachep, trans);
2579 btrfs_trans_release_metadata(trans);
2580 btrfs_cleanup_pending_block_groups(trans);
2581 btrfs_trans_release_chunk_metadata(trans);
2582 trans->block_rsv = NULL;
2584 if (current->journal_info == trans)
2586 cleanup_transaction(trans, ret);
2597 btrfs_end_transaction(trans);
2653 void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
2657 struct btrfs_fs_info *fs_info = trans->fs_info;
2659 WRITE_ONCE(trans->aborted, errno);
2660 WRITE_ONCE(trans->transaction->aborted, errno);