Lines Matching defs: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)
155 struct btrfs_transaction *cur_trans = trans->transaction;
156 struct btrfs_fs_info *fs_info = trans->fs_info;
179 btrfs_free_log(trans, root);
226 static inline void extwriter_counter_inc(struct btrfs_transaction *trans,
230 atomic_inc(&trans->num_extwriters);
233 static inline void extwriter_counter_dec(struct btrfs_transaction *trans,
237 atomic_dec(&trans->num_extwriters);
240 static inline void extwriter_counter_init(struct btrfs_transaction *trans,
243 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0));
246 static inline int extwriter_counter_read(struct btrfs_transaction *trans)
248 return atomic_read(&trans->num_extwriters);
255 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans)
257 struct btrfs_fs_info *fs_info = trans->fs_info;
259 if (!trans->chunk_bytes_reserved)
262 WARN_ON_ONCE(!list_empty(&trans->new_bgs));
265 trans->chunk_bytes_reserved, NULL);
266 trans->chunk_bytes_reserved = 0;
344 * One for this trans handle, one so it will live on until we
400 static int record_root_in_trans(struct btrfs_trans_handle *trans,
407 root->last_trans < trans->transid) || force) {
424 if (root->last_trans == trans->transid && !force) {
432 root->last_trans = trans->transid;
453 btrfs_init_reloc_root(trans, root);
461 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans,
465 struct btrfs_transaction *cur_trans = trans->transaction;
480 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans,
493 if (root->last_trans == trans->transid &&
498 record_root_in_trans(trans, root, 0);
504 static inline int is_transaction_blocked(struct btrfs_transaction *trans)
506 return (trans->state >= TRANS_STATE_COMMIT_START &&
507 trans->state < TRANS_STATE_UNBLOCKED &&
508 !TRANS_ABORTED(trans));
607 * worth of delayed refs updates in this trans handle, and
821 struct btrfs_trans_handle *trans;
823 trans = start_transaction(root, 0, TRANS_ATTACH,
825 if (trans == ERR_PTR(-ENOENT)) {
833 return trans;
906 static int should_end_transaction(struct btrfs_trans_handle *trans)
908 struct btrfs_fs_info *fs_info = trans->fs_info;
916 int btrfs_should_end_transaction(struct btrfs_trans_handle *trans)
918 struct btrfs_transaction *cur_trans = trans->transaction;
925 return should_end_transaction(trans);
928 static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans)
931 struct btrfs_fs_info *fs_info = trans->fs_info;
933 if (!trans->block_rsv) {
934 ASSERT(!trans->bytes_reserved);
938 if (!trans->bytes_reserved)
941 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv);
943 trans->transid, trans->bytes_reserved, 0);
944 btrfs_block_rsv_release(fs_info, trans->block_rsv,
945 trans->bytes_reserved, NULL);
946 trans->bytes_reserved = 0;
949 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
952 struct btrfs_fs_info *info = trans->fs_info;
953 struct btrfs_transaction *cur_trans = trans->transaction;
956 if (refcount_read(&trans->use_count) > 1) {
957 refcount_dec(&trans->use_count);
958 trans->block_rsv = trans->orig_rsv;
962 btrfs_trans_release_metadata(trans);
963 trans->block_rsv = NULL;
965 btrfs_create_pending_block_groups(trans);
967 btrfs_trans_release_chunk_metadata(trans);
969 if (trans->type & __TRANS_FREEZABLE)
975 extwriter_counter_dec(cur_trans, trans->type);
980 if (current->journal_info == trans)
986 if (TRANS_ABORTED(trans) ||
989 if (TRANS_ABORTED(trans))
990 err = trans->aborted;
995 kmem_cache_free(btrfs_trans_handle_cachep, trans);
999 int btrfs_end_transaction(struct btrfs_trans_handle *trans)
1001 return __btrfs_end_transaction(trans, 0);
1004 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans)
1006 return __btrfs_end_transaction(trans, 1);
1151 * @trans: transaction whose dirty pages we'd like to write
1153 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans)
1157 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages;
1158 struct btrfs_fs_info *fs_info = trans->fs_info;
1166 extent_io_tree_release(&trans->transaction->dirty_pages);
1186 static int update_cowonly_root(struct btrfs_trans_handle *trans,
1204 ret = btrfs_update_root(trans, tree_root,
1223 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans)
1225 struct btrfs_fs_info *fs_info = trans->fs_info;
1226 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs;
1227 struct list_head *io_bgs = &trans->transaction->io_bgs;
1233 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL,
1241 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
1245 ret = btrfs_run_dev_stats(trans);
1248 ret = btrfs_run_dev_replace(trans);
1251 ret = btrfs_run_qgroups(trans);
1255 ret = btrfs_setup_space_cache(trans);
1260 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
1273 &trans->transaction->switch_commits);
1274 ret = update_cowonly_root(trans, root);
1277 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
1283 ret = btrfs_write_dirty_block_groups(trans);
1286 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
1295 &trans->transaction->switch_commits);
1324 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans)
1326 struct btrfs_fs_info *fs_info = trans->fs_info;
1348 btrfs_free_log(trans, root);
1349 btrfs_update_reloc_root(trans, root);
1351 btrfs_save_ino_cache(root, trans);
1359 &trans->transaction->switch_commits);
1364 ret2 = btrfs_update_root(trans, fs_info->tree_root,
1384 struct btrfs_trans_handle *trans;
1391 trans = btrfs_start_transaction(root, 0);
1392 if (IS_ERR(trans)) {
1393 ret = PTR_ERR(trans);
1397 ret = btrfs_defrag_leaves(trans, root);
1399 btrfs_end_transaction(trans);
1423 static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,
1446 record_root_in_trans(trans, src, 1);
1454 ret = commit_fs_roots(trans);
1457 ret = btrfs_qgroup_account_extents(trans);
1462 ret = btrfs_qgroup_inherit(trans, src->root_key.objectid, dst_objectid,
1479 ret = commit_cowonly_roots(trans);
1482 switch_commit_roots(trans);
1483 ret = btrfs_write_and_wait_transaction(trans);
1498 record_root_in_trans(trans, parent, 1);
1511 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
1515 struct btrfs_fs_info *fs_info = trans->fs_info;
1549 btrfs_set_skip_qgroup(trans, objectid);
1566 rsv = trans->block_rsv;
1567 trans->block_rsv = &pending->block_rsv;
1568 trans->bytes_reserved = trans->block_rsv->reserved;
1570 trans->transid,
1571 trans->bytes_reserved, 1);
1575 record_root_in_trans(trans, parent_root, 0);
1595 btrfs_abort_transaction(trans, ret);
1606 ret = btrfs_run_delayed_items(trans);
1608 btrfs_abort_transaction(trans, ret);
1612 record_root_in_trans(trans, root, 0);
1613 btrfs_set_root_last_snapshot(&root->root_item, trans->transid);
1625 trans->transid);
1639 btrfs_set_root_otransid(new_root_item, trans->transid);
1642 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old,
1647 btrfs_abort_transaction(trans, ret);
1653 ret = btrfs_copy_root(trans, root, old, &tmp, objectid);
1658 btrfs_abort_transaction(trans, ret);
1667 key.offset = trans->transid;
1668 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item);
1672 btrfs_abort_transaction(trans, ret);
1679 ret = btrfs_add_root_ref(trans, objectid,
1684 btrfs_abort_transaction(trans, ret);
1693 btrfs_abort_transaction(trans, ret);
1697 ret = btrfs_reloc_post_snapshot(trans, pending);
1699 btrfs_abort_transaction(trans, ret);
1703 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
1705 btrfs_abort_transaction(trans, ret);
1715 ret = qgroup_account_snapshot(trans, root, parent_root,
1720 ret = btrfs_insert_dir_item(trans, dentry->d_name.name,
1726 btrfs_abort_transaction(trans, ret);
1734 ret = btrfs_update_inode_fallback(trans, parent_root, parent_inode);
1736 btrfs_abort_transaction(trans, ret);
1739 ret = btrfs_uuid_tree_add(trans, new_root_item->uuid,
1743 btrfs_abort_transaction(trans, ret);
1747 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid,
1751 btrfs_abort_transaction(trans, ret);
1756 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
1758 btrfs_abort_transaction(trans, ret);
1765 trans->block_rsv = rsv;
1766 trans->bytes_reserved = 0;
1768 btrfs_clear_skip_qgroup(trans);
1781 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans)
1784 struct list_head *head = &trans->transaction->pending_snapshots;
1789 ret = create_pending_snapshot(trans, pending);
1820 struct btrfs_transaction *trans;
1824 trans = info->running_transaction;
1825 if (trans)
1826 ret = (trans->state >= TRANS_STATE_COMMIT_START);
1833 struct btrfs_transaction *trans;
1837 trans = info->running_transaction;
1838 if (trans)
1839 ret = is_transaction_blocked(trans);
1849 struct btrfs_transaction *trans)
1852 trans->state >= TRANS_STATE_COMMIT_START ||
1853 TRANS_ABORTED(trans));
1862 struct btrfs_transaction *trans)
1865 trans->state >= TRANS_STATE_UNBLOCKED ||
1866 TRANS_ABORTED(trans));
1896 int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
1899 struct btrfs_fs_info *fs_info = trans->fs_info;
1908 ac->newtrans = btrfs_join_transaction(trans->root);
1916 cur_trans = trans->transaction;
1919 btrfs_end_transaction(trans);
1936 if (current->journal_info == trans)
1944 static void cleanup_transaction(struct btrfs_trans_handle *trans, int err)
1946 struct btrfs_fs_info *fs_info = trans->fs_info;
1947 struct btrfs_transaction *cur_trans = trans->transaction;
1949 WARN_ON(refcount_read(&trans->use_count) > 1);
1951 btrfs_abort_transaction(trans, err);
1983 btrfs_cleanup_one_transaction(trans->transaction, fs_info);
1990 if (trans->type & __TRANS_FREEZABLE)
1995 trace_btrfs_transaction_commit(trans->root);
1997 if (current->journal_info == trans)
2001 kmem_cache_free(btrfs_trans_handle_cachep, trans);
2008 static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans)
2010 struct btrfs_fs_info *fs_info = trans->fs_info;
2013 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) {
2019 static inline int btrfs_start_delalloc_flush(struct btrfs_trans_handle *trans)
2021 struct btrfs_fs_info *fs_info = trans->fs_info;
2036 struct list_head *head = &trans->transaction->pending_snapshots;
2056 static inline void btrfs_wait_delalloc_flush(struct btrfs_trans_handle *trans)
2058 struct btrfs_fs_info *fs_info = trans->fs_info;
2064 struct list_head *head = &trans->transaction->pending_snapshots;
2078 int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
2080 struct btrfs_fs_info *fs_info = trans->fs_info;
2081 struct btrfs_transaction *cur_trans = trans->transaction;
2085 ASSERT(refcount_read(&trans->use_count) == 1);
2090 * transaction as failed, so set trans->dirty to make the abort code do
2093 trans->dirty = true;
2098 btrfs_end_transaction(trans);
2102 btrfs_trans_release_metadata(trans);
2103 trans->block_rsv = NULL;
2108 ret = btrfs_run_delayed_refs(trans, 0);
2110 btrfs_end_transaction(trans);
2114 cur_trans = trans->transaction;
2123 btrfs_create_pending_block_groups(trans);
2125 ret = btrfs_run_delayed_refs(trans, 0);
2127 btrfs_end_transaction(trans);
2154 ret = btrfs_start_dirty_block_groups(trans);
2156 btrfs_end_transaction(trans);
2166 ret = btrfs_end_transaction(trans);
2211 extwriter_counter_dec(cur_trans, trans->type);
2213 ret = btrfs_start_delalloc_flush(trans);
2217 ret = btrfs_run_delayed_items(trans);
2225 ret = btrfs_run_delayed_items(trans);
2229 btrfs_wait_delalloc_flush(trans);
2267 ret = create_pending_snapshots(trans);
2281 ret = btrfs_run_delayed_items(trans);
2285 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
2295 WARN_ON(cur_trans != trans->transaction);
2305 * writers, but a little lower down we drop the trans mutex
2312 ret = commit_fs_roots(trans);
2325 btrfs_free_log_root_tree(trans, fs_info);
2331 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1);
2339 ret = btrfs_qgroup_account_extents(trans);
2343 ret = commit_cowonly_roots(trans);
2368 switch_commit_roots(trans);
2384 btrfs_trans_release_chunk_metadata(trans);
2394 ret = btrfs_write_and_wait_transaction(trans);
2415 btrfs_finish_extent_commit(trans);
2435 if (trans->type & __TRANS_FREEZABLE)
2438 trace_btrfs_transaction_commit(trans->root);
2442 if (current->journal_info == trans)
2445 kmem_cache_free(btrfs_trans_handle_cachep, trans);
2456 btrfs_trans_release_metadata(trans);
2457 btrfs_cleanup_pending_block_groups(trans);
2458 btrfs_trans_release_chunk_metadata(trans);
2459 trans->block_rsv = NULL;
2461 if (current->journal_info == trans)
2463 cleanup_transaction(trans, ret);