Lines Matching refs:trans

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()
404 static int record_root_in_trans(struct btrfs_trans_handle *trans, in record_root_in_trans() argument
412 root->last_trans < trans->transid) || force) { in record_root_in_trans()
428 if (root->last_trans == trans->transid && !force) { in record_root_in_trans()
436 root->last_trans = trans->transid; in record_root_in_trans()
457 ret = btrfs_init_reloc_root(trans, root); in record_root_in_trans()
465 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans, in btrfs_add_dropped_root() argument
469 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_add_dropped_root()
484 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, in btrfs_record_root_in_trans() argument
498 if (root->last_trans == trans->transid && in btrfs_record_root_in_trans()
503 ret = record_root_in_trans(trans, root, 0); in btrfs_record_root_in_trans()
509 static inline int is_transaction_blocked(struct btrfs_transaction *trans) in is_transaction_blocked() argument
511 return (trans->state >= TRANS_STATE_COMMIT_START && in is_transaction_blocked()
512 trans->state < TRANS_STATE_UNBLOCKED && in is_transaction_blocked()
513 !TRANS_ABORTED(trans)); in is_transaction_blocked()
848 struct btrfs_trans_handle *trans; in btrfs_attach_transaction_barrier() local
850 trans = start_transaction(root, 0, TRANS_ATTACH, in btrfs_attach_transaction_barrier()
852 if (trans == ERR_PTR(-ENOENT)) { in btrfs_attach_transaction_barrier()
860 return trans; in btrfs_attach_transaction_barrier()
973 bool btrfs_should_end_transaction(struct btrfs_trans_handle *trans) in btrfs_should_end_transaction() argument
975 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
981 if (btrfs_check_space_for_delayed_refs(trans->fs_info)) in btrfs_should_end_transaction()
984 return !!btrfs_block_rsv_check(&trans->fs_info->global_block_rsv, 50); in btrfs_should_end_transaction()
987 static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_metadata() argument
990 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_metadata()
992 if (!trans->block_rsv) { in btrfs_trans_release_metadata()
993 ASSERT(!trans->bytes_reserved); in btrfs_trans_release_metadata()
997 if (!trans->bytes_reserved) in btrfs_trans_release_metadata()
1000 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv); in btrfs_trans_release_metadata()
1002 trans->transid, trans->bytes_reserved, 0); in btrfs_trans_release_metadata()
1003 btrfs_block_rsv_release(fs_info, trans->block_rsv, in btrfs_trans_release_metadata()
1004 trans->bytes_reserved, NULL); in btrfs_trans_release_metadata()
1005 trans->bytes_reserved = 0; in btrfs_trans_release_metadata()
1008 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, in __btrfs_end_transaction() argument
1011 struct btrfs_fs_info *info = trans->fs_info; in __btrfs_end_transaction()
1012 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
1015 if (refcount_read(&trans->use_count) > 1) { in __btrfs_end_transaction()
1016 refcount_dec(&trans->use_count); in __btrfs_end_transaction()
1017 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
1021 btrfs_trans_release_metadata(trans); in __btrfs_end_transaction()
1022 trans->block_rsv = NULL; in __btrfs_end_transaction()
1024 btrfs_create_pending_block_groups(trans); in __btrfs_end_transaction()
1026 btrfs_trans_release_chunk_metadata(trans); in __btrfs_end_transaction()
1028 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
1034 extwriter_counter_dec(cur_trans, trans->type); in __btrfs_end_transaction()
1043 if (current->journal_info == trans) in __btrfs_end_transaction()
1049 if (TRANS_ABORTED(trans) || BTRFS_FS_ERROR(info)) { in __btrfs_end_transaction()
1051 if (TRANS_ABORTED(trans)) in __btrfs_end_transaction()
1052 err = trans->aborted; in __btrfs_end_transaction()
1057 kmem_cache_free(btrfs_trans_handle_cachep, trans); in __btrfs_end_transaction()
1061 int btrfs_end_transaction(struct btrfs_trans_handle *trans) in btrfs_end_transaction() argument
1063 return __btrfs_end_transaction(trans, 0); in btrfs_end_transaction()
1066 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans) in btrfs_end_transaction_throttle() argument
1068 return __btrfs_end_transaction(trans, 1); in btrfs_end_transaction_throttle()
1213 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans) in btrfs_write_and_wait_transaction() argument
1217 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages; in btrfs_write_and_wait_transaction()
1218 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_write_and_wait_transaction()
1226 extent_io_tree_release(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1246 static int update_cowonly_root(struct btrfs_trans_handle *trans, in update_cowonly_root() argument
1264 ret = btrfs_update_root(trans, tree_root, in update_cowonly_root()
1283 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans) in commit_cowonly_roots() argument
1285 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_cowonly_roots()
1286 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1287 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1296 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING); in commit_cowonly_roots()
1299 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1307 ret = btrfs_run_dev_stats(trans); in commit_cowonly_roots()
1310 ret = btrfs_run_dev_replace(trans); in commit_cowonly_roots()
1313 ret = btrfs_run_qgroups(trans); in commit_cowonly_roots()
1317 ret = btrfs_setup_space_cache(trans); in commit_cowonly_roots()
1330 &trans->transaction->switch_commits); in commit_cowonly_roots()
1331 ret = update_cowonly_root(trans, root); in commit_cowonly_roots()
1337 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1342 ret = btrfs_write_dirty_block_groups(trans); in commit_cowonly_roots()
1352 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1419 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans) in commit_fs_roots() argument
1421 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_fs_roots()
1430 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING); in commit_fs_roots()
1457 btrfs_free_log(trans, root); in commit_fs_roots()
1458 ret2 = btrfs_update_reloc_root(trans, root); in commit_fs_roots()
1468 &trans->transaction->switch_commits); in commit_fs_roots()
1473 ret2 = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1493 struct btrfs_trans_handle *trans; in btrfs_defrag_root() local
1500 trans = btrfs_start_transaction(root, 0); in btrfs_defrag_root()
1501 if (IS_ERR(trans)) { in btrfs_defrag_root()
1502 ret = PTR_ERR(trans); in btrfs_defrag_root()
1506 ret = btrfs_defrag_leaves(trans, root); in btrfs_defrag_root()
1508 btrfs_end_transaction(trans); in btrfs_defrag_root()
1532 static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, in qgroup_account_snapshot() argument
1555 ret = record_root_in_trans(trans, src, 1); in qgroup_account_snapshot()
1570 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in qgroup_account_snapshot()
1572 btrfs_abort_transaction(trans, ret); in qgroup_account_snapshot()
1576 ret = commit_fs_roots(trans); in qgroup_account_snapshot()
1579 ret = btrfs_qgroup_account_extents(trans); in qgroup_account_snapshot()
1584 ret = btrfs_qgroup_inherit(trans, src->root_key.objectid, dst_objectid, in qgroup_account_snapshot()
1601 ret = commit_cowonly_roots(trans); in qgroup_account_snapshot()
1604 switch_commit_roots(trans); in qgroup_account_snapshot()
1605 ret = btrfs_write_and_wait_transaction(trans); in qgroup_account_snapshot()
1618 ret = record_root_in_trans(trans, parent, 1); in qgroup_account_snapshot()
1631 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, in create_pending_snapshot() argument
1635 struct btrfs_fs_info *fs_info = trans->fs_info; in create_pending_snapshot()
1683 btrfs_set_skip_qgroup(trans, objectid); in create_pending_snapshot()
1700 rsv = trans->block_rsv; in create_pending_snapshot()
1701 trans->block_rsv = &pending->block_rsv; in create_pending_snapshot()
1702 trans->bytes_reserved = trans->block_rsv->reserved; in create_pending_snapshot()
1704 trans->transid, in create_pending_snapshot()
1705 trans->bytes_reserved, 1); in create_pending_snapshot()
1707 ret = record_root_in_trans(trans, parent_root, 0); in create_pending_snapshot()
1717 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1730 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1741 ret = btrfs_run_delayed_items(trans); in create_pending_snapshot()
1743 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1747 ret = record_root_in_trans(trans, root, 0); in create_pending_snapshot()
1749 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1752 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1764 trans->transid); in create_pending_snapshot()
1778 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1781 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old, in create_pending_snapshot()
1786 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1790 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); in create_pending_snapshot()
1795 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1804 key.offset = trans->transid; in create_pending_snapshot()
1805 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); in create_pending_snapshot()
1809 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1816 ret = btrfs_add_root_ref(trans, objectid, in create_pending_snapshot()
1821 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1830 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1834 ret = btrfs_reloc_post_snapshot(trans, pending); in create_pending_snapshot()
1836 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1846 ret = qgroup_account_snapshot(trans, root, parent_root, in create_pending_snapshot()
1851 ret = btrfs_insert_dir_item(trans, &fname.disk_name, in create_pending_snapshot()
1857 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1864 ret = btrfs_update_inode_fallback(trans, parent_root, BTRFS_I(parent_inode)); in create_pending_snapshot()
1866 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1869 ret = btrfs_uuid_tree_add(trans, new_root_item->uuid, in create_pending_snapshot()
1873 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1877 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid, in create_pending_snapshot()
1881 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1889 trans->block_rsv = rsv; in create_pending_snapshot()
1890 trans->bytes_reserved = 0; in create_pending_snapshot()
1892 btrfs_clear_skip_qgroup(trans); in create_pending_snapshot()
1907 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans) in create_pending_snapshots() argument
1910 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1915 ret = create_pending_snapshot(trans, pending); in create_pending_snapshots()
1948 struct btrfs_transaction *trans; in btrfs_transaction_in_commit() local
1952 trans = info->running_transaction; in btrfs_transaction_in_commit()
1953 if (trans) in btrfs_transaction_in_commit()
1954 ret = (trans->state >= TRANS_STATE_COMMIT_START); in btrfs_transaction_in_commit()
1961 struct btrfs_transaction *trans; in btrfs_transaction_blocked() local
1965 trans = info->running_transaction; in btrfs_transaction_blocked()
1966 if (trans) in btrfs_transaction_blocked()
1967 ret = is_transaction_blocked(trans); in btrfs_transaction_blocked()
1972 void btrfs_commit_transaction_async(struct btrfs_trans_handle *trans) in btrfs_commit_transaction_async() argument
1974 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction_async()
1982 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1985 btrfs_end_transaction(trans); in btrfs_commit_transaction_async()
1998 static void cleanup_transaction(struct btrfs_trans_handle *trans, int err) in cleanup_transaction() argument
2000 struct btrfs_fs_info *fs_info = trans->fs_info; in cleanup_transaction()
2001 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
2003 WARN_ON(refcount_read(&trans->use_count) > 1); in cleanup_transaction()
2005 btrfs_abort_transaction(trans, err); in cleanup_transaction()
2043 btrfs_cleanup_one_transaction(trans->transaction, fs_info); in cleanup_transaction()
2050 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
2057 if (current->journal_info == trans) in cleanup_transaction()
2074 kmem_cache_free(btrfs_trans_handle_cachep, trans); in cleanup_transaction()
2081 static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans) in btrfs_cleanup_pending_block_groups() argument
2083 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_cleanup_pending_block_groups()
2086 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { in btrfs_cleanup_pending_block_groups()
2130 static void add_pending_snapshot(struct btrfs_trans_handle *trans) in add_pending_snapshot() argument
2132 struct btrfs_transaction *cur_trans = trans->transaction; in add_pending_snapshot()
2134 if (!trans->pending_snapshot) in add_pending_snapshot()
2137 lockdep_assert_held(&trans->fs_info->trans_lock); in add_pending_snapshot()
2140 list_add(&trans->pending_snapshot->list, &cur_trans->pending_snapshots); in add_pending_snapshot()
2152 int btrfs_commit_transaction(struct btrfs_trans_handle *trans) in btrfs_commit_transaction() argument
2154 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction()
2155 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
2161 ASSERT(refcount_read(&trans->use_count) == 1); in btrfs_commit_transaction()
2172 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2173 trans->block_rsv = NULL; in btrfs_commit_transaction()
2185 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
2190 btrfs_create_pending_block_groups(trans); in btrfs_commit_transaction()
2215 ret = btrfs_start_dirty_block_groups(trans); in btrfs_commit_transaction()
2225 add_pending_snapshot(trans); in btrfs_commit_transaction()
2230 if (trans->in_fsync) in btrfs_commit_transaction()
2235 ret = btrfs_end_transaction(trans); in btrfs_commit_transaction()
2253 if (trans->in_fsync) in btrfs_commit_transaction()
2295 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
2301 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2316 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2340 add_pending_snapshot(trans); in btrfs_commit_transaction()
2388 ret = create_pending_snapshots(trans); in btrfs_commit_transaction()
2402 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2406 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in btrfs_commit_transaction()
2416 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
2418 ret = commit_fs_roots(trans); in btrfs_commit_transaction()
2425 btrfs_free_log_root_tree(trans, fs_info); in btrfs_commit_transaction()
2431 ret = btrfs_qgroup_account_extents(trans); in btrfs_commit_transaction()
2435 ret = commit_cowonly_roots(trans); in btrfs_commit_transaction()
2467 switch_commit_roots(trans); in btrfs_commit_transaction()
2483 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2509 ret = btrfs_write_and_wait_transaction(trans); in btrfs_commit_transaction()
2534 btrfs_finish_extent_commit(trans); in btrfs_commit_transaction()
2555 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2564 if (current->journal_info == trans) in btrfs_commit_transaction()
2567 kmem_cache_free(btrfs_trans_handle_cachep, trans); in btrfs_commit_transaction()
2581 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2582 btrfs_cleanup_pending_block_groups(trans); in btrfs_commit_transaction()
2583 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2584 trans->block_rsv = NULL; in btrfs_commit_transaction()
2586 if (current->journal_info == trans) in btrfs_commit_transaction()
2588 cleanup_transaction(trans, ret); in btrfs_commit_transaction()
2599 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2655 void __cold __btrfs_abort_transaction(struct btrfs_trans_handle *trans, in __btrfs_abort_transaction() argument
2659 struct btrfs_fs_info *fs_info = trans->fs_info; in __btrfs_abort_transaction()
2661 WRITE_ONCE(trans->aborted, errno); in __btrfs_abort_transaction()
2662 WRITE_ONCE(trans->transaction->aborted, errno); in __btrfs_abort_transaction()