Lines Matching refs:trans

105 static noinline void switch_commit_roots(struct btrfs_transaction *trans,  in switch_commit_roots()  argument
111 list_for_each_entry_safe(root, tmp, &trans->switch_commits, in switch_commit_roots()
123 static inline void extwriter_counter_inc(struct btrfs_transaction *trans, in extwriter_counter_inc() argument
127 atomic_inc(&trans->num_extwriters); in extwriter_counter_inc()
130 static inline void extwriter_counter_dec(struct btrfs_transaction *trans, in extwriter_counter_dec() argument
134 atomic_dec(&trans->num_extwriters); in extwriter_counter_dec()
137 static inline void extwriter_counter_init(struct btrfs_transaction *trans, in extwriter_counter_init() argument
140 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0)); in extwriter_counter_init()
143 static inline int extwriter_counter_read(struct btrfs_transaction *trans) in extwriter_counter_read() argument
145 return atomic_read(&trans->num_extwriters); in extwriter_counter_read()
277 static int record_root_in_trans(struct btrfs_trans_handle *trans, in record_root_in_trans() argument
281 root->last_trans < trans->transid) { in record_root_in_trans()
298 if (root->last_trans == trans->transid) { in record_root_in_trans()
306 root->last_trans = trans->transid; in record_root_in_trans()
327 btrfs_init_reloc_root(trans, root); in record_root_in_trans()
335 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, in btrfs_record_root_in_trans() argument
346 if (root->last_trans == trans->transid && in btrfs_record_root_in_trans()
351 record_root_in_trans(trans, root); in btrfs_record_root_in_trans()
357 static inline int is_transaction_blocked(struct btrfs_transaction *trans) in is_transaction_blocked() argument
359 return (trans->state >= TRANS_STATE_BLOCKED && in is_transaction_blocked()
360 trans->state < TRANS_STATE_UNBLOCKED && in is_transaction_blocked()
361 !trans->aborted); in is_transaction_blocked()
624 struct btrfs_trans_handle *trans; in btrfs_attach_transaction_barrier() local
626 trans = start_transaction(root, 0, TRANS_ATTACH, 0); in btrfs_attach_transaction_barrier()
627 if (IS_ERR(trans) && PTR_ERR(trans) == -ENOENT) in btrfs_attach_transaction_barrier()
630 return trans; in btrfs_attach_transaction_barrier()
704 static int should_end_transaction(struct btrfs_trans_handle *trans, in should_end_transaction() argument
708 btrfs_check_space_for_delayed_refs(trans, root)) in should_end_transaction()
714 int btrfs_should_end_transaction(struct btrfs_trans_handle *trans, in btrfs_should_end_transaction() argument
717 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
726 updates = trans->delayed_ref_updates; in btrfs_should_end_transaction()
727 trans->delayed_ref_updates = 0; in btrfs_should_end_transaction()
729 err = btrfs_run_delayed_refs(trans, root, updates * 2); in btrfs_should_end_transaction()
734 return should_end_transaction(trans, root); in btrfs_should_end_transaction()
737 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, in __btrfs_end_transaction() argument
740 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
742 unsigned long cur = trans->delayed_ref_updates; in __btrfs_end_transaction()
743 int lock = (trans->type != TRANS_JOIN_NOLOCK); in __btrfs_end_transaction()
747 if (trans->use_count > 1) { in __btrfs_end_transaction()
748 trans->use_count--; in __btrfs_end_transaction()
749 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
753 btrfs_trans_release_metadata(trans, root); in __btrfs_end_transaction()
754 trans->block_rsv = NULL; in __btrfs_end_transaction()
756 if (!list_empty(&trans->new_bgs)) in __btrfs_end_transaction()
757 btrfs_create_pending_block_groups(trans, root); in __btrfs_end_transaction()
759 if (!list_empty(&trans->ordered)) { in __btrfs_end_transaction()
761 list_splice_init(&trans->ordered, &cur_trans->pending_ordered); in __btrfs_end_transaction()
765 trans->delayed_ref_updates = 0; in __btrfs_end_transaction()
766 if (!trans->sync) { in __btrfs_end_transaction()
768 btrfs_should_throttle_delayed_refs(trans, root); in __btrfs_end_transaction()
776 (trans->type & (__TRANS_JOIN_NOLOCK | __TRANS_ATTACH))) in __btrfs_end_transaction()
780 if (trans->qgroup_reserved) { in __btrfs_end_transaction()
785 btrfs_qgroup_free(trans->root, trans->qgroup_reserved); in __btrfs_end_transaction()
786 trans->qgroup_reserved = 0; in __btrfs_end_transaction()
789 btrfs_trans_release_metadata(trans, root); in __btrfs_end_transaction()
790 trans->block_rsv = NULL; in __btrfs_end_transaction()
792 if (!list_empty(&trans->new_bgs)) in __btrfs_end_transaction()
793 btrfs_create_pending_block_groups(trans, root); in __btrfs_end_transaction()
796 should_end_transaction(trans, root) && in __btrfs_end_transaction()
806 return btrfs_commit_transaction(trans, root); in __btrfs_end_transaction()
811 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
817 extwriter_counter_dec(cur_trans, trans->type); in __btrfs_end_transaction()
824 if (current->journal_info == trans) in __btrfs_end_transaction()
830 if (trans->aborted || in __btrfs_end_transaction()
835 assert_qgroups_uptodate(trans); in __btrfs_end_transaction()
837 kmem_cache_free(btrfs_trans_handle_cachep, trans); in __btrfs_end_transaction()
845 int btrfs_end_transaction(struct btrfs_trans_handle *trans, in btrfs_end_transaction() argument
848 return __btrfs_end_transaction(trans, root, 0); in btrfs_end_transaction()
851 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans, in btrfs_end_transaction_throttle() argument
854 return __btrfs_end_transaction(trans, root, 1); in btrfs_end_transaction_throttle()
1001 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, in btrfs_write_and_wait_transaction() argument
1007 &trans->transaction->dirty_pages, in btrfs_write_and_wait_transaction()
1009 clear_btree_io_tree(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1024 static int update_cowonly_root(struct btrfs_trans_handle *trans, in update_cowonly_root() argument
1041 ret = btrfs_update_root(trans, tree_root, in update_cowonly_root()
1060 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans, in commit_cowonly_roots() argument
1064 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1065 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1071 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1079 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in commit_cowonly_roots()
1083 ret = btrfs_run_dev_stats(trans, root->fs_info); in commit_cowonly_roots()
1086 ret = btrfs_run_dev_replace(trans, root->fs_info); in commit_cowonly_roots()
1089 ret = btrfs_run_qgroups(trans, root->fs_info); in commit_cowonly_roots()
1093 ret = btrfs_setup_space_cache(trans, root); in commit_cowonly_roots()
1098 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in commit_cowonly_roots()
1110 &trans->transaction->switch_commits); in commit_cowonly_roots()
1111 ret = update_cowonly_root(trans, root); in commit_cowonly_roots()
1114 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in commit_cowonly_roots()
1120 ret = btrfs_write_dirty_block_groups(trans, root); in commit_cowonly_roots()
1123 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in commit_cowonly_roots()
1132 &trans->transaction->switch_commits); in commit_cowonly_roots()
1154 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans, in commit_fs_roots() argument
1178 btrfs_free_log(trans, root); in commit_fs_roots()
1179 btrfs_update_reloc_root(trans, root); in commit_fs_roots()
1180 btrfs_orphan_commit_root(trans, root); in commit_fs_roots()
1182 btrfs_save_ino_cache(root, trans); in commit_fs_roots()
1190 &trans->transaction->switch_commits); in commit_fs_roots()
1195 err = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1214 struct btrfs_trans_handle *trans; in btrfs_defrag_root() local
1221 trans = btrfs_start_transaction(root, 0); in btrfs_defrag_root()
1222 if (IS_ERR(trans)) in btrfs_defrag_root()
1223 return PTR_ERR(trans); in btrfs_defrag_root()
1225 ret = btrfs_defrag_leaves(trans, root); in btrfs_defrag_root()
1227 btrfs_end_transaction(trans, root); in btrfs_defrag_root()
1253 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, in create_pending_snapshot() argument
1293 btrfs_reloc_pre_snapshot(trans, pending, &to_reserve); in create_pending_snapshot()
1308 rsv = trans->block_rsv; in create_pending_snapshot()
1309 trans->block_rsv = &pending->block_rsv; in create_pending_snapshot()
1310 trans->bytes_reserved = trans->block_rsv->reserved; in create_pending_snapshot()
1315 record_root_in_trans(trans, parent_root); in create_pending_snapshot()
1333 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1344 ret = btrfs_run_delayed_items(trans, root); in create_pending_snapshot()
1346 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1350 record_root_in_trans(trans, root); in create_pending_snapshot()
1351 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1363 trans->transid); in create_pending_snapshot()
1378 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1381 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old); in create_pending_snapshot()
1385 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1391 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); in create_pending_snapshot()
1396 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1404 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in create_pending_snapshot()
1406 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1410 ret = btrfs_qgroup_inherit(trans, fs_info, in create_pending_snapshot()
1414 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1424 key.offset = trans->transid; in create_pending_snapshot()
1425 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); in create_pending_snapshot()
1429 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1436 ret = btrfs_add_root_ref(trans, tree_root, objectid, in create_pending_snapshot()
1441 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1449 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1453 ret = btrfs_reloc_post_snapshot(trans, pending); in create_pending_snapshot()
1455 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1459 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in create_pending_snapshot()
1461 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1465 ret = btrfs_insert_dir_item(trans, parent_root, in create_pending_snapshot()
1472 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1479 ret = btrfs_update_inode_fallback(trans, parent_root, parent_inode); in create_pending_snapshot()
1481 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1484 ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root, new_uuid.b, in create_pending_snapshot()
1487 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1491 ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root, in create_pending_snapshot()
1496 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1503 trans->block_rsv = rsv; in create_pending_snapshot()
1504 trans->bytes_reserved = 0; in create_pending_snapshot()
1515 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans, in create_pending_snapshots() argument
1519 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1524 ret = create_pending_snapshot(trans, fs_info, pending); in create_pending_snapshots()
1555 struct btrfs_transaction *trans; in btrfs_transaction_in_commit() local
1559 trans = info->running_transaction; in btrfs_transaction_in_commit()
1560 if (trans) in btrfs_transaction_in_commit()
1561 ret = (trans->state >= TRANS_STATE_COMMIT_START); in btrfs_transaction_in_commit()
1568 struct btrfs_transaction *trans; in btrfs_transaction_blocked() local
1572 trans = info->running_transaction; in btrfs_transaction_blocked()
1573 if (trans) in btrfs_transaction_blocked()
1574 ret = is_transaction_blocked(trans); in btrfs_transaction_blocked()
1584 struct btrfs_transaction *trans) in wait_current_trans_commit_start() argument
1587 trans->state >= TRANS_STATE_COMMIT_START || in wait_current_trans_commit_start()
1588 trans->aborted); in wait_current_trans_commit_start()
1596 struct btrfs_transaction *trans) in wait_current_trans_commit_start_and_unblock() argument
1599 trans->state >= TRANS_STATE_UNBLOCKED || in wait_current_trans_commit_start_and_unblock()
1600 trans->aborted); in wait_current_trans_commit_start_and_unblock()
1633 int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, in btrfs_commit_transaction_async() argument
1654 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1657 btrfs_end_transaction(trans, root); in btrfs_commit_transaction_async()
1676 if (current->journal_info == trans) in btrfs_commit_transaction_async()
1684 static void cleanup_transaction(struct btrfs_trans_handle *trans, in cleanup_transaction() argument
1687 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
1690 WARN_ON(trans->use_count > 1); in cleanup_transaction()
1692 btrfs_abort_transaction(trans, root, err); in cleanup_transaction()
1714 btrfs_cleanup_one_transaction(trans->transaction, root); in cleanup_transaction()
1721 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
1728 if (current->journal_info == trans) in cleanup_transaction()
1732 kmem_cache_free(btrfs_trans_handle_cachep, trans); in cleanup_transaction()
1770 int btrfs_commit_transaction(struct btrfs_trans_handle *trans, in btrfs_commit_transaction() argument
1773 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
1781 btrfs_end_transaction(trans, root); in btrfs_commit_transaction()
1788 ret = btrfs_run_delayed_refs(trans, root, 0); in btrfs_commit_transaction()
1790 btrfs_end_transaction(trans, root); in btrfs_commit_transaction()
1794 btrfs_trans_release_metadata(trans, root); in btrfs_commit_transaction()
1795 trans->block_rsv = NULL; in btrfs_commit_transaction()
1796 if (trans->qgroup_reserved) { in btrfs_commit_transaction()
1797 btrfs_qgroup_free(root, trans->qgroup_reserved); in btrfs_commit_transaction()
1798 trans->qgroup_reserved = 0; in btrfs_commit_transaction()
1801 cur_trans = trans->transaction; in btrfs_commit_transaction()
1810 if (!list_empty(&trans->new_bgs)) in btrfs_commit_transaction()
1811 btrfs_create_pending_block_groups(trans, root); in btrfs_commit_transaction()
1813 ret = btrfs_run_delayed_refs(trans, root, 0); in btrfs_commit_transaction()
1815 btrfs_end_transaction(trans, root); in btrfs_commit_transaction()
1843 ret = btrfs_start_dirty_block_groups(trans, root); in btrfs_commit_transaction()
1846 btrfs_end_transaction(trans, root); in btrfs_commit_transaction()
1851 list_splice_init(&trans->ordered, &cur_trans->pending_ordered); in btrfs_commit_transaction()
1855 ret = btrfs_end_transaction(trans, root); in btrfs_commit_transaction()
1890 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
1896 ret = btrfs_run_delayed_items(trans, root); in btrfs_commit_transaction()
1904 ret = btrfs_run_delayed_items(trans, root); in btrfs_commit_transaction()
1941 ret = create_pending_snapshots(trans, root->fs_info); in btrfs_commit_transaction()
1957 ret = btrfs_run_delayed_items(trans, root); in btrfs_commit_transaction()
1963 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in btrfs_commit_transaction()
1975 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
1992 ret = commit_fs_roots(trans, root); in btrfs_commit_transaction()
2008 btrfs_free_log_root_tree(trans, root->fs_info); in btrfs_commit_transaction()
2010 ret = commit_cowonly_roots(trans, root); in btrfs_commit_transaction()
2028 btrfs_prepare_extent_commit(trans, root); in btrfs_commit_transaction()
2044 assert_qgroups_uptodate(trans); in btrfs_commit_transaction()
2068 ret = btrfs_write_and_wait_transaction(trans, root); in btrfs_commit_transaction()
2076 ret = write_ctree_super(trans, root, 0); in btrfs_commit_transaction()
2088 btrfs_finish_extent_commit(trans, root); in btrfs_commit_transaction()
2108 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2115 if (current->journal_info == trans) in btrfs_commit_transaction()
2118 kmem_cache_free(btrfs_trans_handle_cachep, trans); in btrfs_commit_transaction()
2128 btrfs_trans_release_metadata(trans, root); in btrfs_commit_transaction()
2129 trans->block_rsv = NULL; in btrfs_commit_transaction()
2130 if (trans->qgroup_reserved) { in btrfs_commit_transaction()
2131 btrfs_qgroup_free(root, trans->qgroup_reserved); in btrfs_commit_transaction()
2132 trans->qgroup_reserved = 0; in btrfs_commit_transaction()
2135 if (current->journal_info == trans) in btrfs_commit_transaction()
2137 cleanup_transaction(trans, root, ret); in btrfs_commit_transaction()