Lines Matching refs:trans

80 static noinline void switch_commit_roots(struct btrfs_transaction *trans)  in switch_commit_roots()  argument
82 struct btrfs_fs_info *fs_info = trans->fs_info; in switch_commit_roots()
86 list_for_each_entry_safe(root, tmp, &trans->switch_commits, in switch_commit_roots()
98 spin_lock(&trans->dropped_roots_lock); in switch_commit_roots()
99 while (!list_empty(&trans->dropped_roots)) { in switch_commit_roots()
100 root = list_first_entry(&trans->dropped_roots, in switch_commit_roots()
103 spin_unlock(&trans->dropped_roots_lock); in switch_commit_roots()
105 spin_lock(&trans->dropped_roots_lock); in switch_commit_roots()
107 spin_unlock(&trans->dropped_roots_lock); in switch_commit_roots()
111 static inline void extwriter_counter_inc(struct btrfs_transaction *trans, in extwriter_counter_inc() argument
115 atomic_inc(&trans->num_extwriters); in extwriter_counter_inc()
118 static inline void extwriter_counter_dec(struct btrfs_transaction *trans, in extwriter_counter_dec() argument
122 atomic_dec(&trans->num_extwriters); in extwriter_counter_dec()
125 static inline void extwriter_counter_init(struct btrfs_transaction *trans, in extwriter_counter_init() argument
128 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0)); in extwriter_counter_init()
131 static inline int extwriter_counter_read(struct btrfs_transaction *trans) in extwriter_counter_read() argument
133 return atomic_read(&trans->num_extwriters); in extwriter_counter_read()
140 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_chunk_metadata() argument
142 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_chunk_metadata()
144 if (!trans->chunk_bytes_reserved) in btrfs_trans_release_chunk_metadata()
147 WARN_ON_ONCE(!list_empty(&trans->new_bgs)); in btrfs_trans_release_chunk_metadata()
150 trans->chunk_bytes_reserved); in btrfs_trans_release_chunk_metadata()
151 trans->chunk_bytes_reserved = 0; in btrfs_trans_release_chunk_metadata()
280 static int record_root_in_trans(struct btrfs_trans_handle *trans, in record_root_in_trans() argument
287 root->last_trans < trans->transid) || force) { in record_root_in_trans()
304 if (root->last_trans == trans->transid && !force) { in record_root_in_trans()
312 root->last_trans = trans->transid; in record_root_in_trans()
333 btrfs_init_reloc_root(trans, root); in record_root_in_trans()
341 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans, in btrfs_add_dropped_root() argument
345 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_add_dropped_root()
360 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, in btrfs_record_root_in_trans() argument
373 if (root->last_trans == trans->transid && in btrfs_record_root_in_trans()
378 record_root_in_trans(trans, root, 0); in btrfs_record_root_in_trans()
384 static inline int is_transaction_blocked(struct btrfs_transaction *trans) in is_transaction_blocked() argument
386 return (trans->state >= TRANS_STATE_BLOCKED && in is_transaction_blocked()
387 trans->state < TRANS_STATE_UNBLOCKED && in is_transaction_blocked()
388 !trans->aborted); in is_transaction_blocked()
621 struct btrfs_trans_handle *trans; in btrfs_start_transaction_fallback_global_rsv() local
631 trans = start_transaction(root, num_items, TRANS_START, in btrfs_start_transaction_fallback_global_rsv()
633 if (!IS_ERR(trans) || PTR_ERR(trans) != -ENOSPC) in btrfs_start_transaction_fallback_global_rsv()
634 return trans; in btrfs_start_transaction_fallback_global_rsv()
636 trans = btrfs_start_transaction(root, 0); in btrfs_start_transaction_fallback_global_rsv()
637 if (IS_ERR(trans)) in btrfs_start_transaction_fallback_global_rsv()
638 return trans; in btrfs_start_transaction_fallback_global_rsv()
644 btrfs_end_transaction(trans); in btrfs_start_transaction_fallback_global_rsv()
648 trans->block_rsv = &fs_info->trans_block_rsv; in btrfs_start_transaction_fallback_global_rsv()
649 trans->bytes_reserved = num_bytes; in btrfs_start_transaction_fallback_global_rsv()
651 trans->transid, num_bytes, 1); in btrfs_start_transaction_fallback_global_rsv()
653 return trans; in btrfs_start_transaction_fallback_global_rsv()
707 struct btrfs_trans_handle *trans; in btrfs_attach_transaction_barrier() local
709 trans = start_transaction(root, 0, TRANS_ATTACH, in btrfs_attach_transaction_barrier()
711 if (trans == ERR_PTR(-ENOENT)) in btrfs_attach_transaction_barrier()
714 return trans; in btrfs_attach_transaction_barrier()
786 static int should_end_transaction(struct btrfs_trans_handle *trans) in should_end_transaction() argument
788 struct btrfs_fs_info *fs_info = trans->fs_info; in should_end_transaction()
796 int btrfs_should_end_transaction(struct btrfs_trans_handle *trans) in btrfs_should_end_transaction() argument
798 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
805 return should_end_transaction(trans); in btrfs_should_end_transaction()
808 static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_metadata() argument
811 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_metadata()
813 if (!trans->block_rsv) { in btrfs_trans_release_metadata()
814 ASSERT(!trans->bytes_reserved); in btrfs_trans_release_metadata()
818 if (!trans->bytes_reserved) in btrfs_trans_release_metadata()
821 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv); in btrfs_trans_release_metadata()
823 trans->transid, trans->bytes_reserved, 0); in btrfs_trans_release_metadata()
824 btrfs_block_rsv_release(fs_info, trans->block_rsv, in btrfs_trans_release_metadata()
825 trans->bytes_reserved); in btrfs_trans_release_metadata()
826 trans->bytes_reserved = 0; in btrfs_trans_release_metadata()
829 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, in __btrfs_end_transaction() argument
832 struct btrfs_fs_info *info = trans->fs_info; in __btrfs_end_transaction()
833 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
834 int lock = (trans->type != TRANS_JOIN_NOLOCK); in __btrfs_end_transaction()
837 if (refcount_read(&trans->use_count) > 1) { in __btrfs_end_transaction()
838 refcount_dec(&trans->use_count); in __btrfs_end_transaction()
839 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
843 btrfs_trans_release_metadata(trans); in __btrfs_end_transaction()
844 trans->block_rsv = NULL; in __btrfs_end_transaction()
846 btrfs_create_pending_block_groups(trans); in __btrfs_end_transaction()
848 btrfs_trans_release_chunk_metadata(trans); in __btrfs_end_transaction()
852 return btrfs_commit_transaction(trans); in __btrfs_end_transaction()
857 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
863 extwriter_counter_dec(cur_trans, trans->type); in __btrfs_end_transaction()
868 if (current->journal_info == trans) in __btrfs_end_transaction()
874 if (trans->aborted || in __btrfs_end_transaction()
880 kmem_cache_free(btrfs_trans_handle_cachep, trans); in __btrfs_end_transaction()
884 int btrfs_end_transaction(struct btrfs_trans_handle *trans) in btrfs_end_transaction() argument
886 return __btrfs_end_transaction(trans, 0); in btrfs_end_transaction()
889 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans) in btrfs_end_transaction_throttle() argument
891 return __btrfs_end_transaction(trans, 1); in btrfs_end_transaction_throttle()
1038 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans) in btrfs_write_and_wait_transaction() argument
1042 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages; in btrfs_write_and_wait_transaction()
1043 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_write_and_wait_transaction()
1051 extent_io_tree_release(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1071 static int update_cowonly_root(struct btrfs_trans_handle *trans, in update_cowonly_root() argument
1089 ret = btrfs_update_root(trans, tree_root, in update_cowonly_root()
1108 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans) in commit_cowonly_roots() argument
1110 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_cowonly_roots()
1111 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1112 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1118 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1126 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1130 ret = btrfs_run_dev_stats(trans); in commit_cowonly_roots()
1133 ret = btrfs_run_dev_replace(trans); in commit_cowonly_roots()
1136 ret = btrfs_run_qgroups(trans); in commit_cowonly_roots()
1140 ret = btrfs_setup_space_cache(trans); in commit_cowonly_roots()
1145 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1158 &trans->transaction->switch_commits); in commit_cowonly_roots()
1159 ret = update_cowonly_root(trans, root); in commit_cowonly_roots()
1162 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1168 ret = btrfs_write_dirty_block_groups(trans); in commit_cowonly_roots()
1171 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1180 &trans->transaction->switch_commits); in commit_cowonly_roots()
1207 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans) in commit_fs_roots() argument
1209 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_fs_roots()
1230 btrfs_free_log(trans, root); in commit_fs_roots()
1231 btrfs_update_reloc_root(trans, root); in commit_fs_roots()
1233 btrfs_save_ino_cache(root, trans); in commit_fs_roots()
1241 &trans->transaction->switch_commits); in commit_fs_roots()
1246 err = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1266 struct btrfs_trans_handle *trans; in btrfs_defrag_root() local
1273 trans = btrfs_start_transaction(root, 0); in btrfs_defrag_root()
1274 if (IS_ERR(trans)) in btrfs_defrag_root()
1275 return PTR_ERR(trans); in btrfs_defrag_root()
1277 ret = btrfs_defrag_leaves(trans, root); in btrfs_defrag_root()
1279 btrfs_end_transaction(trans); in btrfs_defrag_root()
1303 static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, in qgroup_account_snapshot() argument
1326 record_root_in_trans(trans, src, 1); in qgroup_account_snapshot()
1334 ret = commit_fs_roots(trans); in qgroup_account_snapshot()
1337 ret = btrfs_qgroup_account_extents(trans); in qgroup_account_snapshot()
1342 ret = btrfs_qgroup_inherit(trans, src->root_key.objectid, dst_objectid, in qgroup_account_snapshot()
1359 ret = commit_cowonly_roots(trans); in qgroup_account_snapshot()
1362 switch_commit_roots(trans->transaction); in qgroup_account_snapshot()
1363 ret = btrfs_write_and_wait_transaction(trans); in qgroup_account_snapshot()
1378 record_root_in_trans(trans, parent, 1); in qgroup_account_snapshot()
1391 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, in create_pending_snapshot() argument
1395 struct btrfs_fs_info *fs_info = trans->fs_info; in create_pending_snapshot()
1430 btrfs_set_skip_qgroup(trans, objectid); in create_pending_snapshot()
1447 rsv = trans->block_rsv; in create_pending_snapshot()
1448 trans->block_rsv = &pending->block_rsv; in create_pending_snapshot()
1449 trans->bytes_reserved = trans->block_rsv->reserved; in create_pending_snapshot()
1451 trans->transid, in create_pending_snapshot()
1452 trans->bytes_reserved, 1); in create_pending_snapshot()
1456 record_root_in_trans(trans, parent_root, 0); in create_pending_snapshot()
1476 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1487 ret = btrfs_run_delayed_items(trans); in create_pending_snapshot()
1489 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1493 record_root_in_trans(trans, root, 0); in create_pending_snapshot()
1494 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1506 trans->transid); in create_pending_snapshot()
1521 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1524 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old); in create_pending_snapshot()
1528 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1534 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); in create_pending_snapshot()
1539 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1548 key.offset = trans->transid; in create_pending_snapshot()
1549 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); in create_pending_snapshot()
1553 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1560 ret = btrfs_add_root_ref(trans, objectid, in create_pending_snapshot()
1565 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1573 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1577 ret = btrfs_reloc_post_snapshot(trans, pending); in create_pending_snapshot()
1579 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1583 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in create_pending_snapshot()
1585 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1595 ret = qgroup_account_snapshot(trans, root, parent_root, in create_pending_snapshot()
1600 ret = btrfs_insert_dir_item(trans, dentry->d_name.name, in create_pending_snapshot()
1606 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1614 ret = btrfs_update_inode_fallback(trans, parent_root, parent_inode); in create_pending_snapshot()
1616 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1619 ret = btrfs_uuid_tree_add(trans, new_uuid.b, BTRFS_UUID_KEY_SUBVOL, in create_pending_snapshot()
1622 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1626 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid, in create_pending_snapshot()
1630 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1635 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in create_pending_snapshot()
1637 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1644 trans->block_rsv = rsv; in create_pending_snapshot()
1645 trans->bytes_reserved = 0; in create_pending_snapshot()
1647 btrfs_clear_skip_qgroup(trans); in create_pending_snapshot()
1660 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans) in create_pending_snapshots() argument
1663 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1668 ret = create_pending_snapshot(trans, pending); in create_pending_snapshots()
1699 struct btrfs_transaction *trans; in btrfs_transaction_in_commit() local
1703 trans = info->running_transaction; in btrfs_transaction_in_commit()
1704 if (trans) in btrfs_transaction_in_commit()
1705 ret = (trans->state >= TRANS_STATE_COMMIT_START); in btrfs_transaction_in_commit()
1712 struct btrfs_transaction *trans; in btrfs_transaction_blocked() local
1716 trans = info->running_transaction; in btrfs_transaction_blocked()
1717 if (trans) in btrfs_transaction_blocked()
1718 ret = is_transaction_blocked(trans); in btrfs_transaction_blocked()
1728 struct btrfs_transaction *trans) in wait_current_trans_commit_start() argument
1731 trans->state >= TRANS_STATE_COMMIT_START || trans->aborted); in wait_current_trans_commit_start()
1740 struct btrfs_transaction *trans) in wait_current_trans_commit_start_and_unblock() argument
1743 trans->state >= TRANS_STATE_UNBLOCKED || trans->aborted); in wait_current_trans_commit_start_and_unblock()
1773 int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, in btrfs_commit_transaction_async() argument
1776 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction_async()
1785 ac->newtrans = btrfs_join_transaction(trans->root); in btrfs_commit_transaction_async()
1793 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1796 btrfs_end_transaction(trans); in btrfs_commit_transaction_async()
1813 if (current->journal_info == trans) in btrfs_commit_transaction_async()
1821 static void cleanup_transaction(struct btrfs_trans_handle *trans, int err) in cleanup_transaction() argument
1823 struct btrfs_fs_info *fs_info = trans->fs_info; in cleanup_transaction()
1824 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
1826 WARN_ON(refcount_read(&trans->use_count) > 1); in cleanup_transaction()
1828 btrfs_abort_transaction(trans, err); in cleanup_transaction()
1850 btrfs_cleanup_one_transaction(trans->transaction, fs_info); in cleanup_transaction()
1857 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
1862 trace_btrfs_transaction_commit(trans->root); in cleanup_transaction()
1864 if (current->journal_info == trans) in cleanup_transaction()
1868 kmem_cache_free(btrfs_trans_handle_cachep, trans); in cleanup_transaction()
1875 static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans) in btrfs_cleanup_pending_block_groups() argument
1877 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_cleanup_pending_block_groups()
1880 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { in btrfs_cleanup_pending_block_groups()
1886 static inline int btrfs_start_delalloc_flush(struct btrfs_trans_handle *trans) in btrfs_start_delalloc_flush() argument
1888 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_start_delalloc_flush()
1903 struct list_head *head = &trans->transaction->pending_snapshots; in btrfs_start_delalloc_flush()
1923 static inline void btrfs_wait_delalloc_flush(struct btrfs_trans_handle *trans) in btrfs_wait_delalloc_flush() argument
1925 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_wait_delalloc_flush()
1931 struct list_head *head = &trans->transaction->pending_snapshots; in btrfs_wait_delalloc_flush()
1945 int btrfs_commit_transaction(struct btrfs_trans_handle *trans) in btrfs_commit_transaction() argument
1947 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction()
1948 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
1955 btrfs_end_transaction(trans); in btrfs_commit_transaction()
1959 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
1960 trans->block_rsv = NULL; in btrfs_commit_transaction()
1965 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
1967 btrfs_end_transaction(trans); in btrfs_commit_transaction()
1971 cur_trans = trans->transaction; in btrfs_commit_transaction()
1980 btrfs_create_pending_block_groups(trans); in btrfs_commit_transaction()
1982 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
1984 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2011 ret = btrfs_start_dirty_block_groups(trans); in btrfs_commit_transaction()
2013 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2023 ret = btrfs_end_transaction(trans); in btrfs_commit_transaction()
2068 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
2070 ret = btrfs_start_delalloc_flush(trans); in btrfs_commit_transaction()
2074 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2082 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2086 btrfs_wait_delalloc_flush(trans); in btrfs_commit_transaction()
2117 ret = create_pending_snapshots(trans); in btrfs_commit_transaction()
2133 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2139 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in btrfs_commit_transaction()
2151 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
2168 ret = commit_fs_roots(trans); in btrfs_commit_transaction()
2184 btrfs_free_log_root_tree(trans, fs_info); in btrfs_commit_transaction()
2190 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in btrfs_commit_transaction()
2201 ret = btrfs_qgroup_account_extents(trans); in btrfs_commit_transaction()
2208 ret = commit_cowonly_roots(trans); in btrfs_commit_transaction()
2256 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2266 ret = btrfs_write_and_wait_transaction(trans); in btrfs_commit_transaction()
2283 btrfs_finish_extent_commit(trans); in btrfs_commit_transaction()
2304 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2307 trace_btrfs_transaction_commit(trans->root); in btrfs_commit_transaction()
2311 if (current->journal_info == trans) in btrfs_commit_transaction()
2314 kmem_cache_free(btrfs_trans_handle_cachep, trans); in btrfs_commit_transaction()
2321 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2322 btrfs_cleanup_pending_block_groups(trans); in btrfs_commit_transaction()
2323 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2324 trans->block_rsv = NULL; in btrfs_commit_transaction()
2326 if (current->journal_info == trans) in btrfs_commit_transaction()
2328 cleanup_transaction(trans, ret); in btrfs_commit_transaction()