Lines Matching refs:trans
153 static noinline void switch_commit_roots(struct btrfs_trans_handle *trans) in switch_commit_roots() argument
155 struct btrfs_transaction *cur_trans = trans->transaction; in switch_commit_roots()
156 struct btrfs_fs_info *fs_info = trans->fs_info; in switch_commit_roots()
179 btrfs_free_log(trans, root); in switch_commit_roots()
226 static inline void extwriter_counter_inc(struct btrfs_transaction *trans, in extwriter_counter_inc() argument
230 atomic_inc(&trans->num_extwriters); in extwriter_counter_inc()
233 static inline void extwriter_counter_dec(struct btrfs_transaction *trans, in extwriter_counter_dec() argument
237 atomic_dec(&trans->num_extwriters); in extwriter_counter_dec()
240 static inline void extwriter_counter_init(struct btrfs_transaction *trans, in extwriter_counter_init() argument
243 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0)); in extwriter_counter_init()
246 static inline int extwriter_counter_read(struct btrfs_transaction *trans) in extwriter_counter_read() argument
248 return atomic_read(&trans->num_extwriters); in extwriter_counter_read()
255 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_chunk_metadata() argument
257 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_chunk_metadata()
259 if (!trans->chunk_bytes_reserved) in btrfs_trans_release_chunk_metadata()
262 WARN_ON_ONCE(!list_empty(&trans->new_bgs)); in btrfs_trans_release_chunk_metadata()
265 trans->chunk_bytes_reserved, NULL); in btrfs_trans_release_chunk_metadata()
266 trans->chunk_bytes_reserved = 0; in btrfs_trans_release_chunk_metadata()
399 static int record_root_in_trans(struct btrfs_trans_handle *trans, in record_root_in_trans() argument
406 root->last_trans < trans->transid) || force) { in record_root_in_trans()
423 if (root->last_trans == trans->transid && !force) { in record_root_in_trans()
431 root->last_trans = trans->transid; in record_root_in_trans()
452 btrfs_init_reloc_root(trans, root); in record_root_in_trans()
460 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans, in btrfs_add_dropped_root() argument
464 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_add_dropped_root()
479 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, in btrfs_record_root_in_trans() argument
492 if (root->last_trans == trans->transid && in btrfs_record_root_in_trans()
497 record_root_in_trans(trans, root, 0); in btrfs_record_root_in_trans()
503 static inline int is_transaction_blocked(struct btrfs_transaction *trans) in is_transaction_blocked() argument
505 return (trans->state >= TRANS_STATE_COMMIT_START && in is_transaction_blocked()
506 trans->state < TRANS_STATE_UNBLOCKED && in is_transaction_blocked()
507 !TRANS_ABORTED(trans)); in is_transaction_blocked()
820 struct btrfs_trans_handle *trans; in btrfs_attach_transaction_barrier() local
822 trans = start_transaction(root, 0, TRANS_ATTACH, in btrfs_attach_transaction_barrier()
824 if (trans == ERR_PTR(-ENOENT)) in btrfs_attach_transaction_barrier()
827 return trans; in btrfs_attach_transaction_barrier()
899 static int should_end_transaction(struct btrfs_trans_handle *trans) in should_end_transaction() argument
901 struct btrfs_fs_info *fs_info = trans->fs_info; in should_end_transaction()
909 int btrfs_should_end_transaction(struct btrfs_trans_handle *trans) in btrfs_should_end_transaction() argument
911 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
918 return should_end_transaction(trans); in btrfs_should_end_transaction()
921 static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_metadata() argument
924 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_metadata()
926 if (!trans->block_rsv) { in btrfs_trans_release_metadata()
927 ASSERT(!trans->bytes_reserved); in btrfs_trans_release_metadata()
931 if (!trans->bytes_reserved) in btrfs_trans_release_metadata()
934 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv); in btrfs_trans_release_metadata()
936 trans->transid, trans->bytes_reserved, 0); in btrfs_trans_release_metadata()
937 btrfs_block_rsv_release(fs_info, trans->block_rsv, in btrfs_trans_release_metadata()
938 trans->bytes_reserved, NULL); in btrfs_trans_release_metadata()
939 trans->bytes_reserved = 0; in btrfs_trans_release_metadata()
942 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, in __btrfs_end_transaction() argument
945 struct btrfs_fs_info *info = trans->fs_info; in __btrfs_end_transaction()
946 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
949 if (refcount_read(&trans->use_count) > 1) { in __btrfs_end_transaction()
950 refcount_dec(&trans->use_count); in __btrfs_end_transaction()
951 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
955 btrfs_trans_release_metadata(trans); in __btrfs_end_transaction()
956 trans->block_rsv = NULL; in __btrfs_end_transaction()
958 btrfs_create_pending_block_groups(trans); in __btrfs_end_transaction()
960 btrfs_trans_release_chunk_metadata(trans); in __btrfs_end_transaction()
962 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
968 extwriter_counter_dec(cur_trans, trans->type); in __btrfs_end_transaction()
973 if (current->journal_info == trans) in __btrfs_end_transaction()
979 if (TRANS_ABORTED(trans) || in __btrfs_end_transaction()
982 if (TRANS_ABORTED(trans)) in __btrfs_end_transaction()
983 err = trans->aborted; in __btrfs_end_transaction()
988 kmem_cache_free(btrfs_trans_handle_cachep, trans); in __btrfs_end_transaction()
992 int btrfs_end_transaction(struct btrfs_trans_handle *trans) in btrfs_end_transaction() argument
994 return __btrfs_end_transaction(trans, 0); in btrfs_end_transaction()
997 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans) in btrfs_end_transaction_throttle() argument
999 return __btrfs_end_transaction(trans, 1); in btrfs_end_transaction_throttle()
1146 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans) in btrfs_write_and_wait_transaction() argument
1150 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages; in btrfs_write_and_wait_transaction()
1151 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_write_and_wait_transaction()
1159 extent_io_tree_release(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1179 static int update_cowonly_root(struct btrfs_trans_handle *trans, in update_cowonly_root() argument
1197 ret = btrfs_update_root(trans, tree_root, in update_cowonly_root()
1216 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans) in commit_cowonly_roots() argument
1218 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_cowonly_roots()
1219 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1220 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1226 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1234 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1238 ret = btrfs_run_dev_stats(trans); in commit_cowonly_roots()
1241 ret = btrfs_run_dev_replace(trans); in commit_cowonly_roots()
1244 ret = btrfs_run_qgroups(trans); in commit_cowonly_roots()
1248 ret = btrfs_setup_space_cache(trans); in commit_cowonly_roots()
1253 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1266 &trans->transaction->switch_commits); in commit_cowonly_roots()
1267 ret = update_cowonly_root(trans, root); in commit_cowonly_roots()
1270 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1276 ret = btrfs_write_dirty_block_groups(trans); in commit_cowonly_roots()
1279 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1288 &trans->transaction->switch_commits); in commit_cowonly_roots()
1317 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans) in commit_fs_roots() argument
1319 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_fs_roots()
1341 btrfs_free_log(trans, root); in commit_fs_roots()
1342 btrfs_update_reloc_root(trans, root); in commit_fs_roots()
1344 btrfs_save_ino_cache(root, trans); in commit_fs_roots()
1352 &trans->transaction->switch_commits); in commit_fs_roots()
1357 ret2 = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1377 struct btrfs_trans_handle *trans; in btrfs_defrag_root() local
1384 trans = btrfs_start_transaction(root, 0); in btrfs_defrag_root()
1385 if (IS_ERR(trans)) { in btrfs_defrag_root()
1386 ret = PTR_ERR(trans); in btrfs_defrag_root()
1390 ret = btrfs_defrag_leaves(trans, root); in btrfs_defrag_root()
1392 btrfs_end_transaction(trans); in btrfs_defrag_root()
1416 static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, in qgroup_account_snapshot() argument
1439 record_root_in_trans(trans, src, 1); in qgroup_account_snapshot()
1447 ret = commit_fs_roots(trans); in qgroup_account_snapshot()
1450 ret = btrfs_qgroup_account_extents(trans); in qgroup_account_snapshot()
1455 ret = btrfs_qgroup_inherit(trans, src->root_key.objectid, dst_objectid, in qgroup_account_snapshot()
1472 ret = commit_cowonly_roots(trans); in qgroup_account_snapshot()
1475 switch_commit_roots(trans); in qgroup_account_snapshot()
1476 ret = btrfs_write_and_wait_transaction(trans); in qgroup_account_snapshot()
1491 record_root_in_trans(trans, parent, 1); in qgroup_account_snapshot()
1504 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, in create_pending_snapshot() argument
1508 struct btrfs_fs_info *fs_info = trans->fs_info; in create_pending_snapshot()
1542 btrfs_set_skip_qgroup(trans, objectid); in create_pending_snapshot()
1559 rsv = trans->block_rsv; in create_pending_snapshot()
1560 trans->block_rsv = &pending->block_rsv; in create_pending_snapshot()
1561 trans->bytes_reserved = trans->block_rsv->reserved; in create_pending_snapshot()
1563 trans->transid, in create_pending_snapshot()
1564 trans->bytes_reserved, 1); in create_pending_snapshot()
1568 record_root_in_trans(trans, parent_root, 0); in create_pending_snapshot()
1588 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1599 ret = btrfs_run_delayed_items(trans); in create_pending_snapshot()
1601 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1605 record_root_in_trans(trans, root, 0); in create_pending_snapshot()
1606 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1618 trans->transid); in create_pending_snapshot()
1632 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1635 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old, in create_pending_snapshot()
1640 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1646 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); in create_pending_snapshot()
1651 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1660 key.offset = trans->transid; in create_pending_snapshot()
1661 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); in create_pending_snapshot()
1665 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1672 ret = btrfs_add_root_ref(trans, objectid, in create_pending_snapshot()
1677 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1686 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1690 ret = btrfs_reloc_post_snapshot(trans, pending); in create_pending_snapshot()
1692 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1696 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in create_pending_snapshot()
1698 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1708 ret = qgroup_account_snapshot(trans, root, parent_root, in create_pending_snapshot()
1713 ret = btrfs_insert_dir_item(trans, dentry->d_name.name, in create_pending_snapshot()
1719 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1727 ret = btrfs_update_inode_fallback(trans, parent_root, parent_inode); in create_pending_snapshot()
1729 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1732 ret = btrfs_uuid_tree_add(trans, new_root_item->uuid, in create_pending_snapshot()
1736 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1740 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid, in create_pending_snapshot()
1744 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1749 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in create_pending_snapshot()
1751 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1758 trans->block_rsv = rsv; in create_pending_snapshot()
1759 trans->bytes_reserved = 0; in create_pending_snapshot()
1761 btrfs_clear_skip_qgroup(trans); in create_pending_snapshot()
1774 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans) in create_pending_snapshots() argument
1777 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1782 ret = create_pending_snapshot(trans, pending); in create_pending_snapshots()
1813 struct btrfs_transaction *trans; in btrfs_transaction_in_commit() local
1817 trans = info->running_transaction; in btrfs_transaction_in_commit()
1818 if (trans) in btrfs_transaction_in_commit()
1819 ret = (trans->state >= TRANS_STATE_COMMIT_START); in btrfs_transaction_in_commit()
1826 struct btrfs_transaction *trans; in btrfs_transaction_blocked() local
1830 trans = info->running_transaction; in btrfs_transaction_blocked()
1831 if (trans) in btrfs_transaction_blocked()
1832 ret = is_transaction_blocked(trans); in btrfs_transaction_blocked()
1842 struct btrfs_transaction *trans) in wait_current_trans_commit_start() argument
1845 trans->state >= TRANS_STATE_COMMIT_START || in wait_current_trans_commit_start()
1846 TRANS_ABORTED(trans)); in wait_current_trans_commit_start()
1855 struct btrfs_transaction *trans) in wait_current_trans_commit_start_and_unblock() argument
1858 trans->state >= TRANS_STATE_UNBLOCKED || in wait_current_trans_commit_start_and_unblock()
1859 TRANS_ABORTED(trans)); in wait_current_trans_commit_start_and_unblock()
1889 int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, in btrfs_commit_transaction_async() argument
1892 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction_async()
1901 ac->newtrans = btrfs_join_transaction(trans->root); in btrfs_commit_transaction_async()
1909 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1912 btrfs_end_transaction(trans); in btrfs_commit_transaction_async()
1929 if (current->journal_info == trans) in btrfs_commit_transaction_async()
1937 static void cleanup_transaction(struct btrfs_trans_handle *trans, int err) in cleanup_transaction() argument
1939 struct btrfs_fs_info *fs_info = trans->fs_info; in cleanup_transaction()
1940 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
1942 WARN_ON(refcount_read(&trans->use_count) > 1); in cleanup_transaction()
1944 btrfs_abort_transaction(trans, err); in cleanup_transaction()
1976 btrfs_cleanup_one_transaction(trans->transaction, fs_info); in cleanup_transaction()
1983 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
1988 trace_btrfs_transaction_commit(trans->root); in cleanup_transaction()
1990 if (current->journal_info == trans) in cleanup_transaction()
1994 kmem_cache_free(btrfs_trans_handle_cachep, trans); in cleanup_transaction()
2001 static void btrfs_cleanup_pending_block_groups(struct btrfs_trans_handle *trans) in btrfs_cleanup_pending_block_groups() argument
2003 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_cleanup_pending_block_groups()
2006 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { in btrfs_cleanup_pending_block_groups()
2012 static inline int btrfs_start_delalloc_flush(struct btrfs_trans_handle *trans) in btrfs_start_delalloc_flush() argument
2014 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_start_delalloc_flush()
2029 struct list_head *head = &trans->transaction->pending_snapshots; in btrfs_start_delalloc_flush()
2049 static inline void btrfs_wait_delalloc_flush(struct btrfs_trans_handle *trans) in btrfs_wait_delalloc_flush() argument
2051 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_wait_delalloc_flush()
2057 struct list_head *head = &trans->transaction->pending_snapshots; in btrfs_wait_delalloc_flush()
2071 int btrfs_commit_transaction(struct btrfs_trans_handle *trans) in btrfs_commit_transaction() argument
2073 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction()
2074 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
2078 ASSERT(refcount_read(&trans->use_count) == 1); in btrfs_commit_transaction()
2086 trans->dirty = true; in btrfs_commit_transaction()
2091 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2095 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2096 trans->block_rsv = NULL; in btrfs_commit_transaction()
2101 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
2103 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2107 cur_trans = trans->transaction; in btrfs_commit_transaction()
2116 btrfs_create_pending_block_groups(trans); in btrfs_commit_transaction()
2118 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
2120 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2147 ret = btrfs_start_dirty_block_groups(trans); in btrfs_commit_transaction()
2149 btrfs_end_transaction(trans); in btrfs_commit_transaction()
2159 ret = btrfs_end_transaction(trans); in btrfs_commit_transaction()
2204 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
2206 ret = btrfs_start_delalloc_flush(trans); in btrfs_commit_transaction()
2210 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2218 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2222 btrfs_wait_delalloc_flush(trans); in btrfs_commit_transaction()
2260 ret = create_pending_snapshots(trans); in btrfs_commit_transaction()
2274 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2278 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in btrfs_commit_transaction()
2288 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
2305 ret = commit_fs_roots(trans); in btrfs_commit_transaction()
2318 btrfs_free_log_root_tree(trans, fs_info); in btrfs_commit_transaction()
2324 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in btrfs_commit_transaction()
2332 ret = btrfs_qgroup_account_extents(trans); in btrfs_commit_transaction()
2336 ret = commit_cowonly_roots(trans); in btrfs_commit_transaction()
2361 switch_commit_roots(trans); in btrfs_commit_transaction()
2377 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2387 ret = btrfs_write_and_wait_transaction(trans); in btrfs_commit_transaction()
2408 btrfs_finish_extent_commit(trans); in btrfs_commit_transaction()
2428 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2431 trace_btrfs_transaction_commit(trans->root); in btrfs_commit_transaction()
2435 if (current->journal_info == trans) in btrfs_commit_transaction()
2438 kmem_cache_free(btrfs_trans_handle_cachep, trans); in btrfs_commit_transaction()
2449 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2450 btrfs_cleanup_pending_block_groups(trans); in btrfs_commit_transaction()
2451 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2452 trans->block_rsv = NULL; in btrfs_commit_transaction()
2454 if (current->journal_info == trans) in btrfs_commit_transaction()
2456 cleanup_transaction(trans, ret); in btrfs_commit_transaction()