Lines Matching refs:trans

110 static noinline void switch_commit_roots(struct btrfs_transaction *trans)  in switch_commit_roots()  argument
112 struct btrfs_fs_info *fs_info = trans->fs_info; in switch_commit_roots()
116 list_for_each_entry_safe(root, tmp, &trans->switch_commits, in switch_commit_roots()
127 spin_lock(&trans->dropped_roots_lock); in switch_commit_roots()
128 while (!list_empty(&trans->dropped_roots)) { in switch_commit_roots()
129 root = list_first_entry(&trans->dropped_roots, in switch_commit_roots()
132 spin_unlock(&trans->dropped_roots_lock); in switch_commit_roots()
134 spin_lock(&trans->dropped_roots_lock); in switch_commit_roots()
136 spin_unlock(&trans->dropped_roots_lock); in switch_commit_roots()
140 static inline void extwriter_counter_inc(struct btrfs_transaction *trans, in extwriter_counter_inc() argument
144 atomic_inc(&trans->num_extwriters); in extwriter_counter_inc()
147 static inline void extwriter_counter_dec(struct btrfs_transaction *trans, in extwriter_counter_dec() argument
151 atomic_dec(&trans->num_extwriters); in extwriter_counter_dec()
154 static inline void extwriter_counter_init(struct btrfs_transaction *trans, in extwriter_counter_init() argument
157 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0)); in extwriter_counter_init()
160 static inline int extwriter_counter_read(struct btrfs_transaction *trans) in extwriter_counter_read() argument
162 return atomic_read(&trans->num_extwriters); in extwriter_counter_read()
294 static int record_root_in_trans(struct btrfs_trans_handle *trans, in record_root_in_trans() argument
301 root->last_trans < trans->transid) || force) { in record_root_in_trans()
318 if (root->last_trans == trans->transid && !force) { in record_root_in_trans()
326 root->last_trans = trans->transid; in record_root_in_trans()
347 btrfs_init_reloc_root(trans, root); in record_root_in_trans()
355 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans, in btrfs_add_dropped_root() argument
359 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_add_dropped_root()
374 int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, in btrfs_record_root_in_trans() argument
387 if (root->last_trans == trans->transid && in btrfs_record_root_in_trans()
392 record_root_in_trans(trans, root, 0); in btrfs_record_root_in_trans()
398 static inline int is_transaction_blocked(struct btrfs_transaction *trans) in is_transaction_blocked() argument
400 return (trans->state >= TRANS_STATE_BLOCKED && in is_transaction_blocked()
401 trans->state < TRANS_STATE_UNBLOCKED && in is_transaction_blocked()
402 !trans->aborted); in is_transaction_blocked()
603 struct btrfs_trans_handle *trans; in btrfs_start_transaction_fallback_global_rsv() local
613 trans = start_transaction(root, num_items, TRANS_START, in btrfs_start_transaction_fallback_global_rsv()
615 if (!IS_ERR(trans) || PTR_ERR(trans) != -ENOSPC) in btrfs_start_transaction_fallback_global_rsv()
616 return trans; in btrfs_start_transaction_fallback_global_rsv()
618 trans = btrfs_start_transaction(root, 0); in btrfs_start_transaction_fallback_global_rsv()
619 if (IS_ERR(trans)) in btrfs_start_transaction_fallback_global_rsv()
620 return trans; in btrfs_start_transaction_fallback_global_rsv()
626 btrfs_end_transaction(trans); in btrfs_start_transaction_fallback_global_rsv()
630 trans->block_rsv = &fs_info->trans_block_rsv; in btrfs_start_transaction_fallback_global_rsv()
631 trans->bytes_reserved = num_bytes; in btrfs_start_transaction_fallback_global_rsv()
633 trans->transid, num_bytes, 1); in btrfs_start_transaction_fallback_global_rsv()
635 return trans; in btrfs_start_transaction_fallback_global_rsv()
679 struct btrfs_trans_handle *trans; in btrfs_attach_transaction_barrier() local
681 trans = start_transaction(root, 0, TRANS_ATTACH, in btrfs_attach_transaction_barrier()
683 if (trans == ERR_PTR(-ENOENT)) in btrfs_attach_transaction_barrier()
686 return trans; in btrfs_attach_transaction_barrier()
758 static int should_end_transaction(struct btrfs_trans_handle *trans) in should_end_transaction() argument
760 struct btrfs_fs_info *fs_info = trans->fs_info; in should_end_transaction()
762 if (btrfs_check_space_for_delayed_refs(trans, fs_info)) in should_end_transaction()
768 int btrfs_should_end_transaction(struct btrfs_trans_handle *trans) in btrfs_should_end_transaction() argument
770 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
779 updates = trans->delayed_ref_updates; in btrfs_should_end_transaction()
780 trans->delayed_ref_updates = 0; in btrfs_should_end_transaction()
782 err = btrfs_run_delayed_refs(trans, updates * 2); in btrfs_should_end_transaction()
787 return should_end_transaction(trans); in btrfs_should_end_transaction()
790 static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans) in btrfs_trans_release_metadata() argument
793 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_metadata()
795 if (!trans->block_rsv) { in btrfs_trans_release_metadata()
796 ASSERT(!trans->bytes_reserved); in btrfs_trans_release_metadata()
800 if (!trans->bytes_reserved) in btrfs_trans_release_metadata()
803 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv); in btrfs_trans_release_metadata()
805 trans->transid, trans->bytes_reserved, 0); in btrfs_trans_release_metadata()
806 btrfs_block_rsv_release(fs_info, trans->block_rsv, in btrfs_trans_release_metadata()
807 trans->bytes_reserved); in btrfs_trans_release_metadata()
808 trans->bytes_reserved = 0; in btrfs_trans_release_metadata()
811 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, in __btrfs_end_transaction() argument
814 struct btrfs_fs_info *info = trans->fs_info; in __btrfs_end_transaction()
815 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
816 u64 transid = trans->transid; in __btrfs_end_transaction()
817 unsigned long cur = trans->delayed_ref_updates; in __btrfs_end_transaction()
818 int lock = (trans->type != TRANS_JOIN_NOLOCK); in __btrfs_end_transaction()
822 if (refcount_read(&trans->use_count) > 1) { in __btrfs_end_transaction()
823 refcount_dec(&trans->use_count); in __btrfs_end_transaction()
824 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
828 btrfs_trans_release_metadata(trans); 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); in __btrfs_end_transaction()
834 trans->delayed_ref_updates = 0; in __btrfs_end_transaction()
835 if (!trans->sync) { in __btrfs_end_transaction()
837 btrfs_should_throttle_delayed_refs(trans, info); in __btrfs_end_transaction()
845 (trans->type & (__TRANS_JOIN_NOLOCK | __TRANS_ATTACH))) in __btrfs_end_transaction()
849 btrfs_trans_release_metadata(trans); in __btrfs_end_transaction()
850 trans->block_rsv = NULL; in __btrfs_end_transaction()
852 if (!list_empty(&trans->new_bgs)) in __btrfs_end_transaction()
853 btrfs_create_pending_block_groups(trans); in __btrfs_end_transaction()
855 btrfs_trans_release_chunk_metadata(trans); in __btrfs_end_transaction()
857 if (lock && should_end_transaction(trans) && in __btrfs_end_transaction()
867 return btrfs_commit_transaction(trans); in __btrfs_end_transaction()
872 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
878 extwriter_counter_dec(cur_trans, trans->type); in __btrfs_end_transaction()
883 if (current->journal_info == trans) in __btrfs_end_transaction()
889 if (trans->aborted || in __btrfs_end_transaction()
895 kmem_cache_free(btrfs_trans_handle_cachep, trans); in __btrfs_end_transaction()
903 int btrfs_end_transaction(struct btrfs_trans_handle *trans) in btrfs_end_transaction() argument
905 return __btrfs_end_transaction(trans, 0); in btrfs_end_transaction()
908 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans) in btrfs_end_transaction_throttle() argument
910 return __btrfs_end_transaction(trans, 1); in btrfs_end_transaction_throttle()
1057 static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans) in btrfs_write_and_wait_transaction() argument
1061 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages; in btrfs_write_and_wait_transaction()
1062 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_write_and_wait_transaction()
1070 clear_btree_io_tree(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1090 static int update_cowonly_root(struct btrfs_trans_handle *trans, in update_cowonly_root() argument
1108 ret = btrfs_update_root(trans, tree_root, in update_cowonly_root()
1127 static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans) in commit_cowonly_roots() argument
1129 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_cowonly_roots()
1130 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1131 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1137 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1145 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1149 ret = btrfs_run_dev_stats(trans, fs_info); in commit_cowonly_roots()
1152 ret = btrfs_run_dev_replace(trans, fs_info); in commit_cowonly_roots()
1155 ret = btrfs_run_qgroups(trans); in commit_cowonly_roots()
1159 ret = btrfs_setup_space_cache(trans, fs_info); in commit_cowonly_roots()
1164 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1177 &trans->transaction->switch_commits); in commit_cowonly_roots()
1178 ret = update_cowonly_root(trans, root); in commit_cowonly_roots()
1181 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1187 ret = btrfs_write_dirty_block_groups(trans, fs_info); in commit_cowonly_roots()
1190 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in commit_cowonly_roots()
1199 &trans->transaction->switch_commits); in commit_cowonly_roots()
1223 static noinline int commit_fs_roots(struct btrfs_trans_handle *trans) in commit_fs_roots() argument
1225 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_fs_roots()
1246 btrfs_free_log(trans, root); in commit_fs_roots()
1247 btrfs_update_reloc_root(trans, root); in commit_fs_roots()
1249 btrfs_save_ino_cache(root, trans); in commit_fs_roots()
1257 &trans->transaction->switch_commits); in commit_fs_roots()
1262 err = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1282 struct btrfs_trans_handle *trans; in btrfs_defrag_root() local
1289 trans = btrfs_start_transaction(root, 0); in btrfs_defrag_root()
1290 if (IS_ERR(trans)) in btrfs_defrag_root()
1291 return PTR_ERR(trans); in btrfs_defrag_root()
1293 ret = btrfs_defrag_leaves(trans, root); in btrfs_defrag_root()
1295 btrfs_end_transaction(trans); in btrfs_defrag_root()
1319 static int qgroup_account_snapshot(struct btrfs_trans_handle *trans, in qgroup_account_snapshot() argument
1342 record_root_in_trans(trans, src, 1); in qgroup_account_snapshot()
1350 ret = commit_fs_roots(trans); in qgroup_account_snapshot()
1353 ret = btrfs_qgroup_account_extents(trans); in qgroup_account_snapshot()
1358 ret = btrfs_qgroup_inherit(trans, src->root_key.objectid, dst_objectid, in qgroup_account_snapshot()
1375 ret = commit_cowonly_roots(trans); in qgroup_account_snapshot()
1378 switch_commit_roots(trans->transaction); in qgroup_account_snapshot()
1379 ret = btrfs_write_and_wait_transaction(trans); in qgroup_account_snapshot()
1394 record_root_in_trans(trans, parent, 1); in qgroup_account_snapshot()
1407 static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, in create_pending_snapshot() argument
1411 struct btrfs_fs_info *fs_info = trans->fs_info; in create_pending_snapshot()
1446 btrfs_set_skip_qgroup(trans, objectid); in create_pending_snapshot()
1463 rsv = trans->block_rsv; in create_pending_snapshot()
1464 trans->block_rsv = &pending->block_rsv; in create_pending_snapshot()
1465 trans->bytes_reserved = trans->block_rsv->reserved; in create_pending_snapshot()
1467 trans->transid, in create_pending_snapshot()
1468 trans->bytes_reserved, 1); in create_pending_snapshot()
1472 record_root_in_trans(trans, parent_root, 0); in create_pending_snapshot()
1492 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1503 ret = btrfs_run_delayed_items(trans); in create_pending_snapshot()
1505 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1509 record_root_in_trans(trans, root, 0); in create_pending_snapshot()
1510 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1522 trans->transid); in create_pending_snapshot()
1537 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1540 ret = btrfs_cow_block(trans, root, old, NULL, 0, &old); in create_pending_snapshot()
1544 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1550 ret = btrfs_copy_root(trans, root, old, &tmp, objectid); in create_pending_snapshot()
1555 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1564 key.offset = trans->transid; in create_pending_snapshot()
1565 ret = btrfs_insert_root(trans, tree_root, &key, new_root_item); in create_pending_snapshot()
1569 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1576 ret = btrfs_add_root_ref(trans, objectid, in create_pending_snapshot()
1581 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1589 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1593 ret = btrfs_reloc_post_snapshot(trans, pending); in create_pending_snapshot()
1595 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1599 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in create_pending_snapshot()
1601 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1611 ret = qgroup_account_snapshot(trans, root, parent_root, in create_pending_snapshot()
1616 ret = btrfs_insert_dir_item(trans, parent_root, in create_pending_snapshot()
1623 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1631 ret = btrfs_update_inode_fallback(trans, parent_root, parent_inode); in create_pending_snapshot()
1633 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1636 ret = btrfs_uuid_tree_add(trans, new_uuid.b, BTRFS_UUID_KEY_SUBVOL, in create_pending_snapshot()
1639 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1643 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid, in create_pending_snapshot()
1647 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1652 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in create_pending_snapshot()
1654 btrfs_abort_transaction(trans, ret); in create_pending_snapshot()
1661 trans->block_rsv = rsv; in create_pending_snapshot()
1662 trans->bytes_reserved = 0; in create_pending_snapshot()
1664 btrfs_clear_skip_qgroup(trans); in create_pending_snapshot()
1677 static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans) in create_pending_snapshots() argument
1680 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1685 ret = create_pending_snapshot(trans, pending); in create_pending_snapshots()
1716 struct btrfs_transaction *trans; in btrfs_transaction_in_commit() local
1720 trans = info->running_transaction; in btrfs_transaction_in_commit()
1721 if (trans) in btrfs_transaction_in_commit()
1722 ret = (trans->state >= TRANS_STATE_COMMIT_START); in btrfs_transaction_in_commit()
1729 struct btrfs_transaction *trans; in btrfs_transaction_blocked() local
1733 trans = info->running_transaction; in btrfs_transaction_blocked()
1734 if (trans) in btrfs_transaction_blocked()
1735 ret = is_transaction_blocked(trans); in btrfs_transaction_blocked()
1745 struct btrfs_transaction *trans) in wait_current_trans_commit_start() argument
1748 trans->state >= TRANS_STATE_COMMIT_START || trans->aborted); in wait_current_trans_commit_start()
1757 struct btrfs_transaction *trans) in wait_current_trans_commit_start_and_unblock() argument
1760 trans->state >= TRANS_STATE_UNBLOCKED || trans->aborted); in wait_current_trans_commit_start_and_unblock()
1790 int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, in btrfs_commit_transaction_async() argument
1793 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction_async()
1802 ac->newtrans = btrfs_join_transaction(trans->root); in btrfs_commit_transaction_async()
1810 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1813 btrfs_end_transaction(trans); in btrfs_commit_transaction_async()
1830 if (current->journal_info == trans) in btrfs_commit_transaction_async()
1838 static void cleanup_transaction(struct btrfs_trans_handle *trans, int err) in cleanup_transaction() argument
1840 struct btrfs_fs_info *fs_info = trans->fs_info; in cleanup_transaction()
1841 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
1844 WARN_ON(refcount_read(&trans->use_count) > 1); in cleanup_transaction()
1846 btrfs_abort_transaction(trans, err); in cleanup_transaction()
1868 btrfs_cleanup_one_transaction(trans->transaction, fs_info); in cleanup_transaction()
1875 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
1880 trace_btrfs_transaction_commit(trans->root); in cleanup_transaction()
1882 if (current->journal_info == trans) in cleanup_transaction()
1886 kmem_cache_free(btrfs_trans_handle_cachep, trans); in cleanup_transaction()
1918 int btrfs_commit_transaction(struct btrfs_trans_handle *trans) in btrfs_commit_transaction() argument
1920 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction()
1921 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
1928 btrfs_end_transaction(trans); in btrfs_commit_transaction()
1935 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
1937 btrfs_end_transaction(trans); in btrfs_commit_transaction()
1941 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
1942 trans->block_rsv = NULL; in btrfs_commit_transaction()
1944 cur_trans = trans->transaction; in btrfs_commit_transaction()
1953 if (!list_empty(&trans->new_bgs)) in btrfs_commit_transaction()
1954 btrfs_create_pending_block_groups(trans); in btrfs_commit_transaction()
1956 ret = btrfs_run_delayed_refs(trans, 0); in btrfs_commit_transaction()
1958 btrfs_end_transaction(trans); in btrfs_commit_transaction()
1985 ret = btrfs_start_dirty_block_groups(trans); in btrfs_commit_transaction()
1987 btrfs_end_transaction(trans); in btrfs_commit_transaction()
1997 ret = btrfs_end_transaction(trans); in btrfs_commit_transaction()
2032 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
2038 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2046 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2083 ret = create_pending_snapshots(trans); in btrfs_commit_transaction()
2099 ret = btrfs_run_delayed_items(trans); in btrfs_commit_transaction()
2105 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in btrfs_commit_transaction()
2117 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
2134 ret = commit_fs_roots(trans); in btrfs_commit_transaction()
2150 btrfs_free_log_root_tree(trans, fs_info); in btrfs_commit_transaction()
2156 ret = btrfs_run_delayed_refs(trans, (unsigned long)-1); in btrfs_commit_transaction()
2167 ret = btrfs_qgroup_account_extents(trans); in btrfs_commit_transaction()
2174 ret = commit_cowonly_roots(trans); in btrfs_commit_transaction()
2223 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2233 ret = btrfs_write_and_wait_transaction(trans); in btrfs_commit_transaction()
2250 btrfs_finish_extent_commit(trans); in btrfs_commit_transaction()
2271 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2274 trace_btrfs_transaction_commit(trans->root); in btrfs_commit_transaction()
2278 if (current->journal_info == trans) in btrfs_commit_transaction()
2281 kmem_cache_free(btrfs_trans_handle_cachep, trans); in btrfs_commit_transaction()
2297 btrfs_trans_release_metadata(trans); in btrfs_commit_transaction()
2298 btrfs_trans_release_chunk_metadata(trans); in btrfs_commit_transaction()
2299 trans->block_rsv = NULL; in btrfs_commit_transaction()
2301 if (current->journal_info == trans) in btrfs_commit_transaction()
2303 cleanup_transaction(trans, ret); in btrfs_commit_transaction()