Lines Matching refs:trans

111 static noinline void switch_commit_roots(struct btrfs_transaction *trans,  in switch_commit_roots()  argument
117 list_for_each_entry_safe(root, tmp, &trans->switch_commits, in switch_commit_roots()
128 spin_lock(&trans->dropped_roots_lock); in switch_commit_roots()
129 while (!list_empty(&trans->dropped_roots)) { in switch_commit_roots()
130 root = list_first_entry(&trans->dropped_roots, in switch_commit_roots()
133 spin_unlock(&trans->dropped_roots_lock); in switch_commit_roots()
135 spin_lock(&trans->dropped_roots_lock); in switch_commit_roots()
137 spin_unlock(&trans->dropped_roots_lock); in switch_commit_roots()
141 static inline void extwriter_counter_inc(struct btrfs_transaction *trans, in extwriter_counter_inc() argument
145 atomic_inc(&trans->num_extwriters); in extwriter_counter_inc()
148 static inline void extwriter_counter_dec(struct btrfs_transaction *trans, in extwriter_counter_dec() argument
152 atomic_dec(&trans->num_extwriters); in extwriter_counter_dec()
155 static inline void extwriter_counter_init(struct btrfs_transaction *trans, in extwriter_counter_init() argument
158 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0)); in extwriter_counter_init()
161 static inline int extwriter_counter_read(struct btrfs_transaction *trans) in extwriter_counter_read() argument
163 return atomic_read(&trans->num_extwriters); in extwriter_counter_read()
296 static int record_root_in_trans(struct btrfs_trans_handle *trans, in record_root_in_trans() argument
300 root->last_trans < trans->transid) { in record_root_in_trans()
317 if (root->last_trans == trans->transid) { in record_root_in_trans()
325 root->last_trans = trans->transid; in record_root_in_trans()
346 btrfs_init_reloc_root(trans, root); in record_root_in_trans()
354 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans, in btrfs_add_dropped_root() argument
357 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_add_dropped_root()
372 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, in btrfs_record_root_in_trans() argument
383 if (root->last_trans == trans->transid && in btrfs_record_root_in_trans()
388 record_root_in_trans(trans, root); in btrfs_record_root_in_trans()
394 static inline int is_transaction_blocked(struct btrfs_transaction *trans) in is_transaction_blocked() argument
396 return (trans->state >= TRANS_STATE_BLOCKED && in is_transaction_blocked()
397 trans->state < TRANS_STATE_UNBLOCKED && in is_transaction_blocked()
398 !trans->aborted); in is_transaction_blocked()
599 struct btrfs_trans_handle *trans; in btrfs_start_transaction_fallback_global_rsv() local
603 trans = btrfs_start_transaction(root, num_items); in btrfs_start_transaction_fallback_global_rsv()
604 if (!IS_ERR(trans) || PTR_ERR(trans) != -ENOSPC) in btrfs_start_transaction_fallback_global_rsv()
605 return trans; in btrfs_start_transaction_fallback_global_rsv()
607 trans = btrfs_start_transaction(root, 0); in btrfs_start_transaction_fallback_global_rsv()
608 if (IS_ERR(trans)) in btrfs_start_transaction_fallback_global_rsv()
609 return trans; in btrfs_start_transaction_fallback_global_rsv()
617 btrfs_end_transaction(trans, root); in btrfs_start_transaction_fallback_global_rsv()
621 trans->block_rsv = &root->fs_info->trans_block_rsv; in btrfs_start_transaction_fallback_global_rsv()
622 trans->bytes_reserved = num_bytes; in btrfs_start_transaction_fallback_global_rsv()
624 return trans; in btrfs_start_transaction_fallback_global_rsv()
678 struct btrfs_trans_handle *trans; in btrfs_attach_transaction_barrier() local
680 trans = start_transaction(root, 0, TRANS_ATTACH, 0); in btrfs_attach_transaction_barrier()
681 if (IS_ERR(trans) && PTR_ERR(trans) == -ENOENT) in btrfs_attach_transaction_barrier()
684 return trans; in btrfs_attach_transaction_barrier()
758 static int should_end_transaction(struct btrfs_trans_handle *trans, in should_end_transaction() argument
762 btrfs_check_space_for_delayed_refs(trans, root)) in should_end_transaction()
768 int btrfs_should_end_transaction(struct btrfs_trans_handle *trans, in btrfs_should_end_transaction() argument
771 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
780 updates = trans->delayed_ref_updates; in btrfs_should_end_transaction()
781 trans->delayed_ref_updates = 0; in btrfs_should_end_transaction()
783 err = btrfs_run_delayed_refs(trans, root, updates * 2); in btrfs_should_end_transaction()
788 return should_end_transaction(trans, root); in btrfs_should_end_transaction()
791 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, in __btrfs_end_transaction() argument
794 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
796 unsigned long cur = trans->delayed_ref_updates; in __btrfs_end_transaction()
797 int lock = (trans->type != TRANS_JOIN_NOLOCK); in __btrfs_end_transaction()
801 if (trans->use_count > 1) { in __btrfs_end_transaction()
802 trans->use_count--; in __btrfs_end_transaction()
803 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
807 btrfs_trans_release_metadata(trans, root); in __btrfs_end_transaction()
808 trans->block_rsv = NULL; in __btrfs_end_transaction()
810 if (!list_empty(&trans->new_bgs)) in __btrfs_end_transaction()
811 btrfs_create_pending_block_groups(trans, root); in __btrfs_end_transaction()
813 trans->delayed_ref_updates = 0; in __btrfs_end_transaction()
814 if (!trans->sync) { in __btrfs_end_transaction()
816 btrfs_should_throttle_delayed_refs(trans, root); in __btrfs_end_transaction()
824 (trans->type & (__TRANS_JOIN_NOLOCK | __TRANS_ATTACH))) in __btrfs_end_transaction()
828 btrfs_trans_release_metadata(trans, root); in __btrfs_end_transaction()
829 trans->block_rsv = NULL; in __btrfs_end_transaction()
831 if (!list_empty(&trans->new_bgs)) in __btrfs_end_transaction()
832 btrfs_create_pending_block_groups(trans, root); in __btrfs_end_transaction()
834 btrfs_trans_release_chunk_metadata(trans); in __btrfs_end_transaction()
837 should_end_transaction(trans, root) && in __btrfs_end_transaction()
847 return btrfs_commit_transaction(trans, root); in __btrfs_end_transaction()
852 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
858 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()
879 assert_qgroups_uptodate(trans); in __btrfs_end_transaction()
881 kmem_cache_free(btrfs_trans_handle_cachep, trans); in __btrfs_end_transaction()
889 int btrfs_end_transaction(struct btrfs_trans_handle *trans, in btrfs_end_transaction() argument
892 return __btrfs_end_transaction(trans, root, 0); in btrfs_end_transaction()
895 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans, in btrfs_end_transaction_throttle() argument
898 return __btrfs_end_transaction(trans, root, 1); in btrfs_end_transaction_throttle()
1045 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans, in btrfs_write_and_wait_transaction() argument
1051 &trans->transaction->dirty_pages, in btrfs_write_and_wait_transaction()
1053 clear_btree_io_tree(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1068 static int update_cowonly_root(struct btrfs_trans_handle *trans, in update_cowonly_root() argument
1085 ret = btrfs_update_root(trans, tree_root, in update_cowonly_root()
1104 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans, in commit_cowonly_roots() argument
1108 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1109 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1115 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1123 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in commit_cowonly_roots()
1127 ret = btrfs_run_dev_stats(trans, root->fs_info); in commit_cowonly_roots()
1130 ret = btrfs_run_dev_replace(trans, root->fs_info); in commit_cowonly_roots()
1133 ret = btrfs_run_qgroups(trans, root->fs_info); in commit_cowonly_roots()
1137 ret = btrfs_setup_space_cache(trans, root); in commit_cowonly_roots()
1142 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in commit_cowonly_roots()
1154 &trans->transaction->switch_commits); in commit_cowonly_roots()
1155 ret = update_cowonly_root(trans, root); in commit_cowonly_roots()
1158 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in commit_cowonly_roots()
1164 ret = btrfs_write_dirty_block_groups(trans, root); in commit_cowonly_roots()
1167 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in commit_cowonly_roots()
1176 &trans->transaction->switch_commits); in commit_cowonly_roots()
1198 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans, in commit_fs_roots() argument
1222 btrfs_free_log(trans, root); in commit_fs_roots()
1223 btrfs_update_reloc_root(trans, root); in commit_fs_roots()
1224 btrfs_orphan_commit_root(trans, root); in commit_fs_roots()
1226 btrfs_save_ino_cache(root, trans); in commit_fs_roots()
1234 &trans->transaction->switch_commits); in commit_fs_roots()
1239 err = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1259 struct btrfs_trans_handle *trans; in btrfs_defrag_root() local
1266 trans = btrfs_start_transaction(root, 0); in btrfs_defrag_root()
1267 if (IS_ERR(trans)) in btrfs_defrag_root()
1268 return PTR_ERR(trans); in btrfs_defrag_root()
1270 ret = btrfs_defrag_leaves(trans, root); in btrfs_defrag_root()
1272 btrfs_end_transaction(trans, root); in btrfs_defrag_root()
1298 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, in create_pending_snapshot() argument
1342 btrfs_set_skip_qgroup(trans, objectid); in create_pending_snapshot()
1359 rsv = trans->block_rsv; in create_pending_snapshot()
1360 trans->block_rsv = &pending->block_rsv; in create_pending_snapshot()
1361 trans->bytes_reserved = trans->block_rsv->reserved; in create_pending_snapshot()
1366 record_root_in_trans(trans, parent_root); in create_pending_snapshot()
1384 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1395 ret = btrfs_run_delayed_items(trans, root); in create_pending_snapshot()
1397 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1401 record_root_in_trans(trans, root); in create_pending_snapshot()
1402 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1414 trans->transid); in create_pending_snapshot()
1429 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1432 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old); in create_pending_snapshot()
1436 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1442 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); in create_pending_snapshot()
1447 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1456 key.offset = trans->transid; in create_pending_snapshot()
1457 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); in create_pending_snapshot()
1461 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1468 ret = btrfs_add_root_ref(trans, tree_root, objectid, in create_pending_snapshot()
1473 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1481 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1485 ret = btrfs_reloc_post_snapshot(trans, pending); in create_pending_snapshot()
1487 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1491 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in create_pending_snapshot()
1493 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1497 ret = btrfs_insert_dir_item(trans, parent_root, in create_pending_snapshot()
1504 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1511 ret = btrfs_update_inode_fallback(trans, parent_root, parent_inode); in create_pending_snapshot()
1513 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1516 ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root, new_uuid.b, in create_pending_snapshot()
1519 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1523 ret = btrfs_uuid_tree_add(trans, fs_info->uuid_root, in create_pending_snapshot()
1528 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1533 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in create_pending_snapshot()
1535 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1542 ret = btrfs_qgroup_prepare_account_extents(trans, fs_info); in create_pending_snapshot()
1545 ret = btrfs_qgroup_account_extents(trans, fs_info); in create_pending_snapshot()
1548 ret = btrfs_qgroup_inherit(trans, fs_info, in create_pending_snapshot()
1552 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1559 trans->block_rsv = rsv; in create_pending_snapshot()
1560 trans->bytes_reserved = 0; in create_pending_snapshot()
1562 btrfs_clear_skip_qgroup(trans); in create_pending_snapshot()
1573 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans, in create_pending_snapshots() argument
1577 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1582 ret = create_pending_snapshot(trans, fs_info, pending); in create_pending_snapshots()
1613 struct btrfs_transaction *trans; in btrfs_transaction_in_commit() local
1617 trans = info->running_transaction; in btrfs_transaction_in_commit()
1618 if (trans) in btrfs_transaction_in_commit()
1619 ret = (trans->state >= TRANS_STATE_COMMIT_START); in btrfs_transaction_in_commit()
1626 struct btrfs_transaction *trans; in btrfs_transaction_blocked() local
1630 trans = info->running_transaction; in btrfs_transaction_blocked()
1631 if (trans) in btrfs_transaction_blocked()
1632 ret = is_transaction_blocked(trans); in btrfs_transaction_blocked()
1642 struct btrfs_transaction *trans) in wait_current_trans_commit_start() argument
1645 trans->state >= TRANS_STATE_COMMIT_START || in wait_current_trans_commit_start()
1646 trans->aborted); in wait_current_trans_commit_start()
1654 struct btrfs_transaction *trans) in wait_current_trans_commit_start_and_unblock() argument
1657 trans->state >= TRANS_STATE_UNBLOCKED || in wait_current_trans_commit_start_and_unblock()
1658 trans->aborted); in wait_current_trans_commit_start_and_unblock()
1689 int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, in btrfs_commit_transaction_async() argument
1710 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1713 btrfs_end_transaction(trans, root); in btrfs_commit_transaction_async()
1730 if (current->journal_info == trans) in btrfs_commit_transaction_async()
1738 static void cleanup_transaction(struct btrfs_trans_handle *trans, in cleanup_transaction() argument
1741 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
1744 WARN_ON(trans->use_count > 1); in cleanup_transaction()
1746 btrfs_abort_transaction(trans, root, err); in cleanup_transaction()
1768 btrfs_cleanup_one_transaction(trans->transaction, root); in cleanup_transaction()
1775 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
1782 if (current->journal_info == trans) in cleanup_transaction()
1786 kmem_cache_free(btrfs_trans_handle_cachep, trans); in cleanup_transaction()
1809 int btrfs_commit_transaction(struct btrfs_trans_handle *trans, in btrfs_commit_transaction() argument
1812 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
1820 btrfs_end_transaction(trans, root); in btrfs_commit_transaction()
1827 ret = btrfs_run_delayed_refs(trans, root, 0); in btrfs_commit_transaction()
1829 btrfs_end_transaction(trans, root); in btrfs_commit_transaction()
1833 btrfs_trans_release_metadata(trans, root); in btrfs_commit_transaction()
1834 trans->block_rsv = NULL; in btrfs_commit_transaction()
1836 cur_trans = trans->transaction; in btrfs_commit_transaction()
1845 if (!list_empty(&trans->new_bgs)) in btrfs_commit_transaction()
1846 btrfs_create_pending_block_groups(trans, root); in btrfs_commit_transaction()
1848 ret = btrfs_run_delayed_refs(trans, root, 0); in btrfs_commit_transaction()
1850 btrfs_end_transaction(trans, root); in btrfs_commit_transaction()
1877 ret = btrfs_start_dirty_block_groups(trans, root); in btrfs_commit_transaction()
1880 btrfs_end_transaction(trans, root); in btrfs_commit_transaction()
1888 ret = btrfs_end_transaction(trans, root); in btrfs_commit_transaction()
1923 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
1929 ret = btrfs_run_delayed_items(trans, root); in btrfs_commit_transaction()
1937 ret = btrfs_run_delayed_items(trans, root); in btrfs_commit_transaction()
1974 ret = create_pending_snapshots(trans, root->fs_info); in btrfs_commit_transaction()
1990 ret = btrfs_run_delayed_items(trans, root); in btrfs_commit_transaction()
1996 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in btrfs_commit_transaction()
2003 ret = btrfs_qgroup_prepare_account_extents(trans, root->fs_info); in btrfs_commit_transaction()
2015 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
2032 ret = commit_fs_roots(trans, root); in btrfs_commit_transaction()
2048 btrfs_free_log_root_tree(trans, root->fs_info); in btrfs_commit_transaction()
2054 ret = btrfs_qgroup_account_extents(trans, root->fs_info); in btrfs_commit_transaction()
2061 ret = commit_cowonly_roots(trans, root); in btrfs_commit_transaction()
2079 btrfs_prepare_extent_commit(trans, root); in btrfs_commit_transaction()
2095 assert_qgroups_uptodate(trans); in btrfs_commit_transaction()
2111 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2121 ret = btrfs_write_and_wait_transaction(trans, root); in btrfs_commit_transaction()
2129 ret = write_ctree_super(trans, root, 0); in btrfs_commit_transaction()
2141 btrfs_finish_extent_commit(trans, root); in btrfs_commit_transaction()
2161 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2168 if (current->journal_info == trans) in btrfs_commit_transaction()
2171 kmem_cache_free(btrfs_trans_handle_cachep, trans); in btrfs_commit_transaction()
2182 btrfs_trans_release_metadata(trans, root); in btrfs_commit_transaction()
2183 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2184 trans->block_rsv = NULL; in btrfs_commit_transaction()
2186 if (current->journal_info == trans) in btrfs_commit_transaction()
2188 cleanup_transaction(trans, root, ret); in btrfs_commit_transaction()