Lines Matching +full:re +full:- +full:started

1 // SPDX-License-Identifier: GPL-2.0
17 #include "disk-io.h"
20 #include "tree-log.h"
22 #include "dev-replace.h"
24 #include "block-group.h"
25 #include "space-info.h"
28 #include "extent-tree.h"
29 #include "root-tree.h"
30 #include "dir-item.h"
31 #include "uuid-tree.h"
66 * | - Wait for all other trans handle holders to release.
68 * | - Wait for current transaction to be committed by others.
82 * | The heavy lifting transaction work is started.
141 WARN_ON(refcount_read(&transaction->use_count) == 0); in btrfs_put_transaction()
142 if (refcount_dec_and_test(&transaction->use_count)) { in btrfs_put_transaction()
143 BUG_ON(!list_empty(&transaction->list)); in btrfs_put_transaction()
144 WARN_ON(!xa_empty(&transaction->delayed_refs.head_refs)); in btrfs_put_transaction()
145 WARN_ON(!xa_empty(&transaction->delayed_refs.dirty_extents)); in btrfs_put_transaction()
146 if (transaction->delayed_refs.pending_csums) in btrfs_put_transaction()
147 btrfs_err(transaction->fs_info, in btrfs_put_transaction()
149 transaction->delayed_refs.pending_csums); in btrfs_put_transaction()
151 * If any block groups are found in ->deleted_bgs then it's in btrfs_put_transaction()
157 while (!list_empty(&transaction->deleted_bgs)) { in btrfs_put_transaction()
160 cache = list_first_entry(&transaction->deleted_bgs, in btrfs_put_transaction()
163 list_del_init(&cache->bg_list); in btrfs_put_transaction()
167 WARN_ON(!list_empty(&transaction->dev_update_list)); in btrfs_put_transaction()
174 struct btrfs_transaction *cur_trans = trans->transaction; in switch_commit_roots()
175 struct btrfs_fs_info *fs_info = trans->fs_info; in switch_commit_roots()
182 ASSERT(cur_trans->state == TRANS_STATE_COMMIT_DOING); in switch_commit_roots()
184 down_write(&fs_info->commit_root_sem); in switch_commit_roots()
186 if (test_bit(BTRFS_FS_RELOC_RUNNING, &fs_info->flags)) in switch_commit_roots()
187 fs_info->last_reloc_trans = trans->transid; in switch_commit_roots()
189 list_for_each_entry_safe(root, tmp, &cur_trans->switch_commits, in switch_commit_roots()
191 list_del_init(&root->dirty_list); in switch_commit_roots()
192 free_extent_buffer(root->commit_root); in switch_commit_roots()
193 root->commit_root = btrfs_root_node(root); in switch_commit_roots()
194 extent_io_tree_release(&root->dirty_log_pages); in switch_commit_roots()
199 spin_lock(&cur_trans->dropped_roots_lock); in switch_commit_roots()
200 while (!list_empty(&cur_trans->dropped_roots)) { in switch_commit_roots()
201 root = list_first_entry(&cur_trans->dropped_roots, in switch_commit_roots()
203 list_del_init(&root->root_list); in switch_commit_roots()
204 spin_unlock(&cur_trans->dropped_roots_lock); in switch_commit_roots()
207 spin_lock(&cur_trans->dropped_roots_lock); in switch_commit_roots()
209 spin_unlock(&cur_trans->dropped_roots_lock); in switch_commit_roots()
211 up_write(&fs_info->commit_root_sem); in switch_commit_roots()
218 atomic_inc(&trans->num_extwriters); in extwriter_counter_inc()
225 atomic_dec(&trans->num_extwriters); in extwriter_counter_dec()
231 atomic_set(&trans->num_extwriters, ((type & TRANS_EXTWRITERS) ? 1 : 0)); in extwriter_counter_init()
236 return atomic_read(&trans->num_extwriters); in extwriter_counter_read()
248 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_chunk_metadata()
250 if (!trans->chunk_bytes_reserved) in btrfs_trans_release_chunk_metadata()
253 btrfs_block_rsv_release(fs_info, &fs_info->chunk_block_rsv, in btrfs_trans_release_chunk_metadata()
254 trans->chunk_bytes_reserved, NULL); in btrfs_trans_release_chunk_metadata()
255 trans->chunk_bytes_reserved = 0; in btrfs_trans_release_chunk_metadata()
266 spin_lock(&fs_info->trans_lock); in join_transaction()
270 spin_unlock(&fs_info->trans_lock); in join_transaction()
271 return -EROFS; in join_transaction()
274 cur_trans = fs_info->running_transaction; in join_transaction()
277 spin_unlock(&fs_info->trans_lock); in join_transaction()
278 return cur_trans->aborted; in join_transaction()
280 if (btrfs_blocked_trans_types[cur_trans->state] & type) { in join_transaction()
281 spin_unlock(&fs_info->trans_lock); in join_transaction()
282 return -EBUSY; in join_transaction()
284 refcount_inc(&cur_trans->use_count); in join_transaction()
285 atomic_inc(&cur_trans->num_writers); in join_transaction()
287 spin_unlock(&fs_info->trans_lock); in join_transaction()
292 spin_unlock(&fs_info->trans_lock); in join_transaction()
300 return -ENOENT; in join_transaction()
304 * it is impossible that ->running_transaction is NULL in join_transaction()
310 return -ENOMEM; in join_transaction()
315 spin_lock(&fs_info->trans_lock); in join_transaction()
316 if (fs_info->running_transaction) { in join_transaction()
318 * someone started a transaction after we unlocked. Make sure in join_transaction()
326 spin_unlock(&fs_info->trans_lock); in join_transaction()
330 return -EROFS; in join_transaction()
333 cur_trans->fs_info = fs_info; in join_transaction()
334 atomic_set(&cur_trans->pending_ordered, 0); in join_transaction()
335 init_waitqueue_head(&cur_trans->pending_wait); in join_transaction()
336 atomic_set(&cur_trans->num_writers, 1); in join_transaction()
338 init_waitqueue_head(&cur_trans->writer_wait); in join_transaction()
339 init_waitqueue_head(&cur_trans->commit_wait); in join_transaction()
340 cur_trans->state = TRANS_STATE_RUNNING; in join_transaction()
345 refcount_set(&cur_trans->use_count, 2); in join_transaction()
346 cur_trans->flags = 0; in join_transaction()
347 cur_trans->start_time = ktime_get_seconds(); in join_transaction()
349 memset(&cur_trans->delayed_refs, 0, sizeof(cur_trans->delayed_refs)); in join_transaction()
351 xa_init(&cur_trans->delayed_refs.head_refs); in join_transaction()
352 xa_init(&cur_trans->delayed_refs.dirty_extents); in join_transaction()
359 if (!list_empty(&fs_info->tree_mod_seq_list)) in join_transaction()
361 if (!RB_EMPTY_ROOT(&fs_info->tree_mod_log)) in join_transaction()
363 atomic64_set(&fs_info->tree_mod_seq, 0); in join_transaction()
365 spin_lock_init(&cur_trans->delayed_refs.lock); in join_transaction()
367 INIT_LIST_HEAD(&cur_trans->pending_snapshots); in join_transaction()
368 INIT_LIST_HEAD(&cur_trans->dev_update_list); in join_transaction()
369 INIT_LIST_HEAD(&cur_trans->switch_commits); in join_transaction()
370 INIT_LIST_HEAD(&cur_trans->dirty_bgs); in join_transaction()
371 INIT_LIST_HEAD(&cur_trans->io_bgs); in join_transaction()
372 INIT_LIST_HEAD(&cur_trans->dropped_roots); in join_transaction()
373 mutex_init(&cur_trans->cache_write_mutex); in join_transaction()
374 spin_lock_init(&cur_trans->dirty_bgs_lock); in join_transaction()
375 INIT_LIST_HEAD(&cur_trans->deleted_bgs); in join_transaction()
376 spin_lock_init(&cur_trans->dropped_roots_lock); in join_transaction()
377 list_add_tail(&cur_trans->list, &fs_info->trans_list); in join_transaction()
378 extent_io_tree_init(fs_info, &cur_trans->dirty_pages, in join_transaction()
380 extent_io_tree_init(fs_info, &cur_trans->pinned_extents, in join_transaction()
382 btrfs_set_fs_generation(fs_info, fs_info->generation + 1); in join_transaction()
383 cur_trans->transid = fs_info->generation; in join_transaction()
384 fs_info->running_transaction = cur_trans; in join_transaction()
385 cur_trans->aborted = 0; in join_transaction()
386 spin_unlock(&fs_info->trans_lock); in join_transaction()
401 struct btrfs_fs_info *fs_info = root->fs_info; in record_root_in_trans()
404 if ((test_bit(BTRFS_ROOT_SHAREABLE, &root->state) && in record_root_in_trans()
405 btrfs_get_root_last_trans(root) < trans->transid) || force) { in record_root_in_trans()
406 WARN_ON(!force && root->commit_root != root->node); in record_root_in_trans()
413 set_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state); in record_root_in_trans()
416 * they find our root->last_trans update in record_root_in_trans()
420 spin_lock(&fs_info->fs_roots_radix_lock); in record_root_in_trans()
421 if (btrfs_get_root_last_trans(root) == trans->transid && !force) { in record_root_in_trans()
422 spin_unlock(&fs_info->fs_roots_radix_lock); in record_root_in_trans()
425 radix_tree_tag_set(&fs_info->fs_roots_radix, in record_root_in_trans()
428 spin_unlock(&fs_info->fs_roots_radix_lock); in record_root_in_trans()
429 btrfs_set_root_last_trans(root, trans->transid); in record_root_in_trans()
433 * unless we're really doing the first setup for this root in in record_root_in_trans()
436 * Normally we'd use root->last_trans as a flag to decide in record_root_in_trans()
439 * But, we have to set root->last_trans before we in record_root_in_trans()
442 * with root IN_TRANS_SETUP. When this is 1, we're still in record_root_in_trans()
445 * When this is zero, they can trust root->last_trans and fly in record_root_in_trans()
452 clear_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state); in record_root_in_trans()
461 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_add_dropped_root()
462 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_add_dropped_root()
465 spin_lock(&cur_trans->dropped_roots_lock); in btrfs_add_dropped_root()
466 list_add_tail(&root->root_list, &cur_trans->dropped_roots); in btrfs_add_dropped_root()
467 spin_unlock(&cur_trans->dropped_roots_lock); in btrfs_add_dropped_root()
470 spin_lock(&fs_info->fs_roots_radix_lock); in btrfs_add_dropped_root()
471 radix_tree_tag_clear(&fs_info->fs_roots_radix, in btrfs_add_dropped_root()
474 spin_unlock(&fs_info->fs_roots_radix_lock); in btrfs_add_dropped_root()
480 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_record_root_in_trans()
483 if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) in btrfs_record_root_in_trans()
491 if (btrfs_get_root_last_trans(root) == trans->transid && in btrfs_record_root_in_trans()
492 !test_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state)) in btrfs_record_root_in_trans()
495 mutex_lock(&fs_info->reloc_mutex); in btrfs_record_root_in_trans()
497 mutex_unlock(&fs_info->reloc_mutex); in btrfs_record_root_in_trans()
504 return (trans->state >= TRANS_STATE_COMMIT_START && in is_transaction_blocked()
505 trans->state < TRANS_STATE_UNBLOCKED && in is_transaction_blocked()
517 spin_lock(&fs_info->trans_lock); in wait_current_trans()
518 cur_trans = fs_info->running_transaction; in wait_current_trans()
520 refcount_inc(&cur_trans->use_count); in wait_current_trans()
521 spin_unlock(&fs_info->trans_lock); in wait_current_trans()
524 wait_event(fs_info->transaction_wait, in wait_current_trans()
525 cur_trans->state >= TRANS_STATE_UNBLOCKED || in wait_current_trans()
529 spin_unlock(&fs_info->trans_lock); in wait_current_trans()
535 if (test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) in may_wait_transaction()
546 struct btrfs_fs_info *fs_info = root->fs_info; in need_reserve_reloc_root()
548 if (!fs_info->reloc_ctl || in need_reserve_reloc_root()
549 !test_bit(BTRFS_ROOT_SHAREABLE, &root->state) || in need_reserve_reloc_root()
551 root->reloc_root) in need_reserve_reloc_root()
562 struct btrfs_space_info *si = fs_info->trans_block_rsv.space_info; in btrfs_reserve_trans_metadata()
578 bytes -= *delayed_refs_bytes; in btrfs_reserve_trans_metadata()
591 struct btrfs_fs_info *fs_info = root->fs_info; in start_transaction()
592 struct btrfs_block_rsv *delayed_refs_rsv = &fs_info->delayed_refs_rsv; in start_transaction()
593 struct btrfs_block_rsv *trans_rsv = &fs_info->trans_block_rsv; in start_transaction()
604 return ERR_PTR(-EROFS); in start_transaction()
606 if (current->journal_info) { in start_transaction()
608 h = current->journal_info; in start_transaction()
609 refcount_inc(&h->use_count); in start_transaction()
610 WARN_ON(refcount_read(&h->use_count) > 2); in start_transaction()
611 h->orig_rsv = h->block_rsv; in start_transaction()
612 h->block_rsv = NULL; in start_transaction()
620 if (num_items && root != fs_info->chunk_root) { in start_transaction()
621 qgroup_reserved = num_items * fs_info->nodesize; in start_transaction()
647 num_bytes += fs_info->nodesize; in start_transaction()
658 if (trans_rsv->space_info->force_alloc) in start_transaction()
676 ret = -ENOMEM; in start_transaction()
681 * If we are JOIN_NOLOCK we're already committing a transaction and in start_transaction()
683 * because we're already holding a ref. We need this because we could in start_transaction()
691 sb_start_intwrite(fs_info->sb); in start_transaction()
698 if (ret == -EBUSY) { in start_transaction()
702 ret = -ENOENT; in start_transaction()
704 } while (ret == -EBUSY); in start_transaction()
709 cur_trans = fs_info->running_transaction; in start_transaction()
711 h->transid = cur_trans->transid; in start_transaction()
712 h->transaction = cur_trans; in start_transaction()
713 refcount_set(&h->use_count, 1); in start_transaction()
714 h->fs_info = root->fs_info; in start_transaction()
716 h->type = type; in start_transaction()
717 INIT_LIST_HEAD(&h->new_bgs); in start_transaction()
718 btrfs_init_metadata_block_rsv(fs_info, &h->delayed_rsv, BTRFS_BLOCK_RSV_DELOPS); in start_transaction()
721 if (cur_trans->state >= TRANS_STATE_COMMIT_START && in start_transaction()
723 current->journal_info = h; in start_transaction()
730 h->transid, num_bytes, 1); in start_transaction()
731 h->block_rsv = trans_rsv; in start_transaction()
732 h->bytes_reserved = num_bytes; in start_transaction()
736 h->transid, in start_transaction()
738 h->delayed_refs_bytes_reserved = delayed_refs_bytes; in start_transaction()
739 btrfs_block_rsv_add_bytes(&h->delayed_rsv, delayed_refs_bytes, true); in start_transaction()
742 h->reloc_reserved = reloc_reserved; in start_transaction()
746 if (!current->journal_info) in start_transaction()
747 current->journal_info = h; in start_transaction()
756 u64 flags = h->block_rsv->space_info->flags; in start_transaction()
764 * call btrfs_join_transaction() while we're also starting a in start_transaction()
767 * Thus it need to be called after current->journal_info initialized, in start_transaction()
792 sb_end_intwrite(fs_info->sb); in start_transaction()
798 btrfs_space_info_free_bytes_may_use(trans_rsv->space_info, delayed_refs_bytes); in start_transaction()
835 * happen if the transaction commit already started but it's not yet in the
850 * Note: If this function return -ENOENT, it just means there is no
853 * inactive transaction in the fs when -ENOENT is returned, you should
877 if (trans == ERR_PTR(-ENOENT)) { in btrfs_attach_transaction_barrier()
880 ret = btrfs_wait_for_commit(root->fs_info, 0); in btrfs_attach_transaction_barrier()
892 struct btrfs_fs_info *fs_info = commit->fs_info; in wait_for_commit()
893 u64 transid = commit->transid; in wait_for_commit()
906 wait_event(commit->commit_wait, commit->state >= min_state); in wait_for_commit()
920 spin_lock(&fs_info->trans_lock); in wait_for_commit()
921 commit = list_first_entry_or_null(&fs_info->trans_list, in wait_for_commit()
924 if (!commit || commit->transid > transid) { in wait_for_commit()
925 spin_unlock(&fs_info->trans_lock); in wait_for_commit()
928 refcount_inc(&commit->use_count); in wait_for_commit()
930 spin_unlock(&fs_info->trans_lock); in wait_for_commit()
944 spin_lock(&fs_info->trans_lock); in btrfs_wait_for_commit()
945 list_for_each_entry(t, &fs_info->trans_list, list) { in btrfs_wait_for_commit()
946 if (t->transid == transid) { in btrfs_wait_for_commit()
948 refcount_inc(&cur_trans->use_count); in btrfs_wait_for_commit()
952 if (t->transid > transid) { in btrfs_wait_for_commit()
957 spin_unlock(&fs_info->trans_lock); in btrfs_wait_for_commit()
965 ret = -EINVAL; in btrfs_wait_for_commit()
970 spin_lock(&fs_info->trans_lock); in btrfs_wait_for_commit()
971 list_for_each_entry_reverse(t, &fs_info->trans_list, in btrfs_wait_for_commit()
973 if (t->state >= TRANS_STATE_COMMIT_START) { in btrfs_wait_for_commit()
974 if (t->state == TRANS_STATE_COMPLETED) in btrfs_wait_for_commit()
977 refcount_inc(&cur_trans->use_count); in btrfs_wait_for_commit()
981 spin_unlock(&fs_info->trans_lock); in btrfs_wait_for_commit()
987 ret = cur_trans->aborted; in btrfs_wait_for_commit()
1000 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_should_end_transaction()
1002 if (cur_trans->state >= TRANS_STATE_COMMIT_START || in btrfs_should_end_transaction()
1003 test_bit(BTRFS_DELAYED_REFS_FLUSHING, &cur_trans->delayed_refs.flags)) in btrfs_should_end_transaction()
1006 if (btrfs_check_space_for_delayed_refs(trans->fs_info)) in btrfs_should_end_transaction()
1009 return !!btrfs_block_rsv_check(&trans->fs_info->global_block_rsv, 50); in btrfs_should_end_transaction()
1015 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_trans_release_metadata()
1017 if (!trans->block_rsv) { in btrfs_trans_release_metadata()
1018 ASSERT(!trans->bytes_reserved); in btrfs_trans_release_metadata()
1019 ASSERT(!trans->delayed_refs_bytes_reserved); in btrfs_trans_release_metadata()
1023 if (!trans->bytes_reserved) { in btrfs_trans_release_metadata()
1024 ASSERT(!trans->delayed_refs_bytes_reserved); in btrfs_trans_release_metadata()
1028 ASSERT(trans->block_rsv == &fs_info->trans_block_rsv); in btrfs_trans_release_metadata()
1030 trans->transid, trans->bytes_reserved, 0); in btrfs_trans_release_metadata()
1031 btrfs_block_rsv_release(fs_info, trans->block_rsv, in btrfs_trans_release_metadata()
1032 trans->bytes_reserved, NULL); in btrfs_trans_release_metadata()
1033 trans->bytes_reserved = 0; in btrfs_trans_release_metadata()
1035 if (!trans->delayed_refs_bytes_reserved) in btrfs_trans_release_metadata()
1039 trans->transid, in btrfs_trans_release_metadata()
1040 trans->delayed_refs_bytes_reserved, 0); in btrfs_trans_release_metadata()
1041 btrfs_block_rsv_release(fs_info, &trans->delayed_rsv, in btrfs_trans_release_metadata()
1042 trans->delayed_refs_bytes_reserved, NULL); in btrfs_trans_release_metadata()
1043 trans->delayed_refs_bytes_reserved = 0; in btrfs_trans_release_metadata()
1049 struct btrfs_fs_info *info = trans->fs_info; in __btrfs_end_transaction()
1050 struct btrfs_transaction *cur_trans = trans->transaction; in __btrfs_end_transaction()
1053 if (refcount_read(&trans->use_count) > 1) { in __btrfs_end_transaction()
1054 refcount_dec(&trans->use_count); in __btrfs_end_transaction()
1055 trans->block_rsv = trans->orig_rsv; in __btrfs_end_transaction()
1060 trans->block_rsv = NULL; in __btrfs_end_transaction()
1066 if (trans->type & __TRANS_FREEZABLE) in __btrfs_end_transaction()
1067 sb_end_intwrite(info->sb); in __btrfs_end_transaction()
1069 WARN_ON(cur_trans != info->running_transaction); in __btrfs_end_transaction()
1070 WARN_ON(atomic_read(&cur_trans->num_writers) < 1); in __btrfs_end_transaction()
1071 atomic_dec(&cur_trans->num_writers); in __btrfs_end_transaction()
1072 extwriter_counter_dec(cur_trans, trans->type); in __btrfs_end_transaction()
1074 cond_wake_up(&cur_trans->writer_wait); in __btrfs_end_transaction()
1081 if (current->journal_info == trans) in __btrfs_end_transaction()
1082 current->journal_info = NULL; in __btrfs_end_transaction()
1088 wake_up_process(info->transaction_kthread); in __btrfs_end_transaction()
1090 ret = trans->aborted; in __btrfs_end_transaction()
1092 ret = -EROFS; in __btrfs_end_transaction()
1118 struct address_space *mapping = fs_info->btree_inode->i_mapping; in btrfs_write_marked_extents()
1131 * convert_extent_bit can return -ENOMEM, which is most of the in btrfs_write_marked_extents()
1133 * and wait for writeback of this range to finish - because we in btrfs_write_marked_extents()
1136 * writeback for this range started and therefore wouldn't in btrfs_write_marked_extents()
1137 * wait for it to finish - we don't want to commit a in btrfs_write_marked_extents()
1143 if (ret == -ENOMEM) { in btrfs_write_marked_extents()
1170 struct address_space *mapping = fs_info->btree_inode->i_mapping; in __btrfs_wait_marked_extents()
1179 * Ignore -ENOMEM errors returned by clear_extent_bit(). in __btrfs_wait_marked_extents()
1183 * concurrently - we do it only at transaction commit time when in __btrfs_wait_marked_extents()
1188 if (ret == -ENOMEM) in __btrfs_wait_marked_extents()
1209 if (test_and_clear_bit(BTRFS_FS_BTREE_ERR, &fs_info->flags)) in btrfs_wait_extents()
1213 err = -EIO; in btrfs_wait_extents()
1219 struct btrfs_fs_info *fs_info = log_root->fs_info; in btrfs_wait_tree_log_extents()
1220 struct extent_io_tree *dirty_pages = &log_root->dirty_log_pages; in btrfs_wait_tree_log_extents()
1228 test_and_clear_bit(BTRFS_FS_LOG1_ERR, &fs_info->flags)) in btrfs_wait_tree_log_extents()
1232 test_and_clear_bit(BTRFS_FS_LOG2_ERR, &fs_info->flags)) in btrfs_wait_tree_log_extents()
1236 err = -EIO; in btrfs_wait_tree_log_extents()
1251 struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages; in btrfs_write_and_wait_transaction()
1252 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_write_and_wait_transaction()
1260 extent_io_tree_release(&trans->transaction->dirty_pages); in btrfs_write_and_wait_transaction()
1286 struct btrfs_fs_info *fs_info = root->fs_info; in update_cowonly_root()
1287 struct btrfs_root *tree_root = fs_info->tree_root; in update_cowonly_root()
1289 old_root_used = btrfs_root_used(&root->root_item); in update_cowonly_root()
1292 old_root_bytenr = btrfs_root_bytenr(&root->root_item); in update_cowonly_root()
1293 if (old_root_bytenr == root->node->start && in update_cowonly_root()
1294 old_root_used == btrfs_root_used(&root->root_item)) in update_cowonly_root()
1297 btrfs_set_root_node(&root->root_item, root->node); in update_cowonly_root()
1299 &root->root_key, in update_cowonly_root()
1300 &root->root_item); in update_cowonly_root()
1304 old_root_used = btrfs_root_used(&root->root_item); in update_cowonly_root()
1319 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_cowonly_roots()
1320 struct list_head *dirty_bgs = &trans->transaction->dirty_bgs; in commit_cowonly_roots()
1321 struct list_head *io_bgs = &trans->transaction->io_bgs; in commit_cowonly_roots()
1330 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING); in commit_cowonly_roots()
1332 eb = btrfs_lock_root_node(fs_info->tree_root); in commit_cowonly_roots()
1333 ret = btrfs_cow_block(trans, fs_info->tree_root, eb, NULL, in commit_cowonly_roots()
1356 while (!list_empty(&fs_info->dirty_cowonly_roots)) { in commit_cowonly_roots()
1358 next = fs_info->dirty_cowonly_roots.next; in commit_cowonly_roots()
1361 clear_bit(BTRFS_ROOT_DIRTY, &root->state); in commit_cowonly_roots()
1363 list_add_tail(&root->dirty_list, in commit_cowonly_roots()
1364 &trans->transaction->switch_commits); in commit_cowonly_roots()
1381 * We're writing the dirty block groups, which could generate in commit_cowonly_roots()
1391 if (!list_empty(&fs_info->dirty_cowonly_roots)) in commit_cowonly_roots()
1394 /* Update dev-replace pointer once everything is committed */ in commit_cowonly_roots()
1395 fs_info->dev_replace.committed_cursor_left = in commit_cowonly_roots()
1396 fs_info->dev_replace.cursor_left_last_write_of_item; in commit_cowonly_roots()
1412 spin_lock(&fs_info->trans_lock); in btrfs_maybe_wake_unfinished_drop()
1413 if (!list_empty(&fs_info->dead_roots)) { in btrfs_maybe_wake_unfinished_drop()
1414 struct btrfs_root *root = list_first_entry(&fs_info->dead_roots, in btrfs_maybe_wake_unfinished_drop()
1417 if (test_bit(BTRFS_ROOT_UNFINISHED_DROP, &root->state)) { in btrfs_maybe_wake_unfinished_drop()
1418 spin_unlock(&fs_info->trans_lock); in btrfs_maybe_wake_unfinished_drop()
1422 spin_unlock(&fs_info->trans_lock); in btrfs_maybe_wake_unfinished_drop()
1434 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_add_dead_root()
1436 spin_lock(&fs_info->trans_lock); in btrfs_add_dead_root()
1437 if (list_empty(&root->root_list)) { in btrfs_add_dead_root()
1441 if (test_bit(BTRFS_ROOT_UNFINISHED_DROP, &root->state)) in btrfs_add_dead_root()
1442 list_add(&root->root_list, &fs_info->dead_roots); in btrfs_add_dead_root()
1444 list_add_tail(&root->root_list, &fs_info->dead_roots); in btrfs_add_dead_root()
1446 spin_unlock(&fs_info->trans_lock); in btrfs_add_dead_root()
1455 struct btrfs_fs_info *fs_info = trans->fs_info; in commit_fs_roots()
1464 ASSERT(trans->transaction->state == TRANS_STATE_COMMIT_DOING); in commit_fs_roots()
1466 spin_lock(&fs_info->fs_roots_radix_lock); in commit_fs_roots()
1468 ret = radix_tree_gang_lookup_tag(&fs_info->fs_roots_radix, in commit_fs_roots()
1482 ASSERT(atomic_read(&root->log_writers) == 0); in commit_fs_roots()
1483 ASSERT(atomic_read(&root->log_commit[0]) == 0); in commit_fs_roots()
1484 ASSERT(atomic_read(&root->log_commit[1]) == 0); in commit_fs_roots()
1486 radix_tree_tag_clear(&fs_info->fs_roots_radix, in commit_fs_roots()
1490 spin_unlock(&fs_info->fs_roots_radix_lock); in commit_fs_roots()
1498 clear_bit(BTRFS_ROOT_FORCE_COW, &root->state); in commit_fs_roots()
1501 if (root->commit_root != root->node) { in commit_fs_roots()
1502 list_add_tail(&root->dirty_list, in commit_fs_roots()
1503 &trans->transaction->switch_commits); in commit_fs_roots()
1504 btrfs_set_root_node(&root->root_item, in commit_fs_roots()
1505 root->node); in commit_fs_roots()
1508 ret2 = btrfs_update_root(trans, fs_info->tree_root, in commit_fs_roots()
1509 &root->root_key, in commit_fs_roots()
1510 &root->root_item); in commit_fs_roots()
1513 spin_lock(&fs_info->fs_roots_radix_lock); in commit_fs_roots()
1516 spin_unlock(&fs_info->fs_roots_radix_lock); in commit_fs_roots()
1533 struct btrfs_fs_info *fs_info = src->fs_info; in qgroup_account_snapshot()
1560 * we're doing the qgroup_inherit. But that's a problem for the future, in qgroup_account_snapshot()
1629 struct btrfs_fs_info *fs_info = trans->fs_info; in create_pending_snapshot()
1632 struct btrfs_root *tree_root = fs_info->tree_root; in create_pending_snapshot()
1633 struct btrfs_root *root = pending->root; in create_pending_snapshot()
1636 struct inode *parent_inode = &pending->dir->vfs_inode; in create_pending_snapshot()
1650 ASSERT(pending->path); in create_pending_snapshot()
1651 path = pending->path; in create_pending_snapshot()
1653 ASSERT(pending->root_item); in create_pending_snapshot()
1654 new_root_item = pending->root_item; in create_pending_snapshot()
1657 * We're inside a transaction and must make sure that any potential in create_pending_snapshot()
1662 pending->error = fscrypt_setup_filename(parent_inode, in create_pending_snapshot()
1663 &pending->dentry->d_name, 0, in create_pending_snapshot()
1666 if (pending->error) in create_pending_snapshot()
1669 pending->error = btrfs_get_free_objectid(tree_root, &objectid); in create_pending_snapshot()
1670 if (pending->error) in create_pending_snapshot()
1682 pending->error = btrfs_block_rsv_add(fs_info, in create_pending_snapshot()
1683 &pending->block_rsv, in create_pending_snapshot()
1686 if (pending->error) in create_pending_snapshot()
1691 key.offset = (u64)-1; in create_pending_snapshot()
1694 rsv = trans->block_rsv; in create_pending_snapshot()
1695 trans->block_rsv = &pending->block_rsv; in create_pending_snapshot()
1696 trans->bytes_reserved = trans->block_rsv->reserved; in create_pending_snapshot()
1698 trans->transid, in create_pending_snapshot()
1699 trans->bytes_reserved, 1); in create_pending_snapshot()
1700 parent_root = BTRFS_I(parent_inode)->root; in create_pending_snapshot()
1720 pending->error = -EEXIST; in create_pending_snapshot()
1730 if (ret && ret != -EEXIST) { in create_pending_snapshot()
1752 btrfs_set_root_last_snapshot(&root->root_item, trans->transid); in create_pending_snapshot()
1753 memcpy(new_root_item, &root->root_item, sizeof(*new_root_item)); in create_pending_snapshot()
1757 if (pending->readonly) in create_pending_snapshot()
1764 trans->transid); in create_pending_snapshot()
1765 generate_random_guid(new_root_item->uuid); in create_pending_snapshot()
1766 memcpy(new_root_item->parent_uuid, root->root_item.uuid, in create_pending_snapshot()
1769 memset(new_root_item->received_uuid, 0, in create_pending_snapshot()
1770 sizeof(new_root_item->received_uuid)); in create_pending_snapshot()
1771 memset(&new_root_item->stime, 0, sizeof(new_root_item->stime)); in create_pending_snapshot()
1772 memset(&new_root_item->rtime, 0, sizeof(new_root_item->rtime)); in create_pending_snapshot()
1776 btrfs_set_stack_timespec_sec(&new_root_item->otime, cur_time.tv_sec); in create_pending_snapshot()
1777 btrfs_set_stack_timespec_nsec(&new_root_item->otime, cur_time.tv_nsec); in create_pending_snapshot()
1778 btrfs_set_root_otransid(new_root_item, trans->transid); in create_pending_snapshot()
1799 set_bit(BTRFS_ROOT_FORCE_COW, &root->state); in create_pending_snapshot()
1804 key.offset = trans->transid; in create_pending_snapshot()
1825 key.offset = (u64)-1; in create_pending_snapshot()
1826 pending->snap = btrfs_get_new_fs_root(fs_info, objectid, &pending->anon_dev); in create_pending_snapshot()
1827 if (IS_ERR(pending->snap)) { in create_pending_snapshot()
1828 ret = PTR_ERR(pending->snap); in create_pending_snapshot()
1829 pending->snap = NULL; in create_pending_snapshot()
1843 * To co-operate with that hack, we do hack again. in create_pending_snapshot()
1848 pending->inherit, objectid); in create_pending_snapshot()
1851 btrfs_root_id(parent_root), pending->inherit); in create_pending_snapshot()
1863 btrfs_i_size_write(BTRFS_I(parent_inode), parent_inode->i_size + in create_pending_snapshot()
1872 ret = btrfs_uuid_tree_add(trans, new_root_item->uuid, in create_pending_snapshot()
1879 if (!btrfs_is_empty_uuid(new_root_item->received_uuid)) { in create_pending_snapshot()
1880 ret = btrfs_uuid_tree_add(trans, new_root_item->received_uuid, in create_pending_snapshot()
1883 if (ret && ret != -EEXIST) { in create_pending_snapshot()
1890 pending->error = ret; in create_pending_snapshot()
1892 trans->block_rsv = rsv; in create_pending_snapshot()
1893 trans->bytes_reserved = 0; in create_pending_snapshot()
1900 pending->root_item = NULL; in create_pending_snapshot()
1902 pending->path = NULL; in create_pending_snapshot()
1913 struct list_head *head = &trans->transaction->pending_snapshots; in create_pending_snapshots()
1917 list_del(&pending->list); in create_pending_snapshots()
1930 super = fs_info->super_copy; in update_super_roots()
1932 root_item = &fs_info->chunk_root->root_item; in update_super_roots()
1933 super->chunk_root = root_item->bytenr; in update_super_roots()
1934 super->chunk_root_generation = root_item->generation; in update_super_roots()
1935 super->chunk_root_level = root_item->level; in update_super_roots()
1937 root_item = &fs_info->tree_root->root_item; in update_super_roots()
1938 super->root = root_item->bytenr; in update_super_roots()
1939 super->generation = root_item->generation; in update_super_roots()
1940 super->root_level = root_item->level; in update_super_roots()
1942 super->cache_generation = root_item->generation; in update_super_roots()
1943 else if (test_bit(BTRFS_FS_CLEANUP_SPACE_CACHE_V1, &fs_info->flags)) in update_super_roots()
1944 super->cache_generation = 0; in update_super_roots()
1945 if (test_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags)) in update_super_roots()
1946 super->uuid_tree_generation = root_item->generation; in update_super_roots()
1954 spin_lock(&info->trans_lock); in btrfs_transaction_blocked()
1955 trans = info->running_transaction; in btrfs_transaction_blocked()
1958 spin_unlock(&info->trans_lock); in btrfs_transaction_blocked()
1964 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction_async()
1968 set_bit(BTRFS_FS_COMMIT_TRANS, &fs_info->flags); in btrfs_commit_transaction_async()
1969 wake_up_process(fs_info->transaction_kthread); in btrfs_commit_transaction_async()
1972 cur_trans = trans->transaction; in btrfs_commit_transaction_async()
1973 refcount_inc(&cur_trans->use_count); in btrfs_commit_transaction_async()
1982 wait_event(fs_info->transaction_blocked_wait, in btrfs_commit_transaction_async()
1983 cur_trans->state >= TRANS_STATE_COMMIT_START || in btrfs_commit_transaction_async()
2001 return (ret == -ENOENT) ? 0 : ret; in btrfs_commit_current_transaction()
2009 struct btrfs_fs_info *fs_info = trans->fs_info; in cleanup_transaction()
2010 struct btrfs_transaction *cur_trans = trans->transaction; in cleanup_transaction()
2012 WARN_ON(refcount_read(&trans->use_count) > 1); in cleanup_transaction()
2016 spin_lock(&fs_info->trans_lock); in cleanup_transaction()
2023 BUG_ON(list_empty(&cur_trans->list)); in cleanup_transaction()
2025 if (cur_trans == fs_info->running_transaction) { in cleanup_transaction()
2026 cur_trans->state = TRANS_STATE_COMMIT_DOING; in cleanup_transaction()
2027 spin_unlock(&fs_info->trans_lock); in cleanup_transaction()
2034 wait_event(cur_trans->writer_wait, in cleanup_transaction()
2035 atomic_read(&cur_trans->num_writers) == 1); in cleanup_transaction()
2037 spin_lock(&fs_info->trans_lock); in cleanup_transaction()
2044 * other task is still using it, which could result in a use-after-free in cleanup_transaction()
2048 list_del_init(&cur_trans->list); in cleanup_transaction()
2050 spin_unlock(&fs_info->trans_lock); in cleanup_transaction()
2052 btrfs_cleanup_one_transaction(trans->transaction); in cleanup_transaction()
2054 spin_lock(&fs_info->trans_lock); in cleanup_transaction()
2055 if (cur_trans == fs_info->running_transaction) in cleanup_transaction()
2056 fs_info->running_transaction = NULL; in cleanup_transaction()
2057 spin_unlock(&fs_info->trans_lock); in cleanup_transaction()
2059 if (trans->type & __TRANS_FREEZABLE) in cleanup_transaction()
2060 sb_end_intwrite(fs_info->sb); in cleanup_transaction()
2066 if (current->journal_info == trans) in cleanup_transaction()
2067 current->journal_info = NULL; in cleanup_transaction()
2080 if (!test_bit(BTRFS_FS_RELOC_RUNNING, &fs_info->flags)) in cleanup_transaction()
2092 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_cleanup_pending_block_groups()
2095 list_for_each_entry_safe(block_group, tmp, &trans->new_bgs, bg_list) { in btrfs_cleanup_pending_block_groups()
2097 list_del_init(&block_group->bg_list); in btrfs_cleanup_pending_block_groups()
2110 * have to re-take the fs freeze lock. in btrfs_start_delalloc_flush()
2113 * if it can read lock sb->s_umount. It will always be able to lock it, in btrfs_start_delalloc_flush()
2116 * writeback_inodes_sb() while holding a write lock on sb->s_umount. in btrfs_start_delalloc_flush()
2118 * will emit a warning if sb->s_umount is not locked. in btrfs_start_delalloc_flush()
2121 try_to_writeback_inodes_sb(fs_info->sb, WB_REASON_SYNC); in btrfs_start_delalloc_flush()
2133 * respective handle. This must be called after the transaction commit started
2134 * and while holding fs_info->trans_lock.
2141 struct btrfs_transaction *cur_trans = trans->transaction; in add_pending_snapshot()
2143 if (!trans->pending_snapshot) in add_pending_snapshot()
2146 lockdep_assert_held(&trans->fs_info->trans_lock); in add_pending_snapshot()
2147 ASSERT(cur_trans->state >= TRANS_STATE_COMMIT_PREP); in add_pending_snapshot()
2149 list_add(&trans->pending_snapshot->list, &cur_trans->pending_snapshots); in add_pending_snapshot()
2154 fs_info->commit_stats.commit_count++; in update_commit_stats()
2155 fs_info->commit_stats.last_commit_dur = interval; in update_commit_stats()
2156 fs_info->commit_stats.max_commit_dur = in update_commit_stats()
2157 max_t(u64, fs_info->commit_stats.max_commit_dur, interval); in update_commit_stats()
2158 fs_info->commit_stats.total_commit_dur += interval; in update_commit_stats()
2163 struct btrfs_fs_info *fs_info = trans->fs_info; in btrfs_commit_transaction()
2164 struct btrfs_transaction *cur_trans = trans->transaction; in btrfs_commit_transaction()
2170 ASSERT(refcount_read(&trans->use_count) == 1); in btrfs_commit_transaction()
2173 clear_bit(BTRFS_FS_NEED_TRANS_COMMIT, &fs_info->flags); in btrfs_commit_transaction()
2175 /* Stop the commit early if ->aborted is set */ in btrfs_commit_transaction()
2177 ret = cur_trans->aborted; in btrfs_commit_transaction()
2182 trans->block_rsv = NULL; in btrfs_commit_transaction()
2189 &cur_trans->delayed_refs.flags)) { in btrfs_commit_transaction()
2201 if (!test_bit(BTRFS_TRANS_DIRTY_BG_RUN, &cur_trans->flags)) { in btrfs_commit_transaction()
2217 mutex_lock(&fs_info->ro_block_group_mutex); in btrfs_commit_transaction()
2219 &cur_trans->flags)) in btrfs_commit_transaction()
2221 mutex_unlock(&fs_info->ro_block_group_mutex); in btrfs_commit_transaction()
2230 spin_lock(&fs_info->trans_lock); in btrfs_commit_transaction()
2231 if (cur_trans->state >= TRANS_STATE_COMMIT_PREP) { in btrfs_commit_transaction()
2236 spin_unlock(&fs_info->trans_lock); in btrfs_commit_transaction()
2237 refcount_inc(&cur_trans->use_count); in btrfs_commit_transaction()
2239 if (trans->in_fsync) in btrfs_commit_transaction()
2248 ret = cur_trans->aborted; in btrfs_commit_transaction()
2255 cur_trans->state = TRANS_STATE_COMMIT_PREP; in btrfs_commit_transaction()
2256 wake_up(&fs_info->transaction_blocked_wait); in btrfs_commit_transaction()
2259 if (cur_trans->list.prev != &fs_info->trans_list) { in btrfs_commit_transaction()
2262 if (trans->in_fsync) in btrfs_commit_transaction()
2265 prev_trans = list_entry(cur_trans->list.prev, in btrfs_commit_transaction()
2267 if (prev_trans->state < want_state) { in btrfs_commit_transaction()
2268 refcount_inc(&prev_trans->use_count); in btrfs_commit_transaction()
2269 spin_unlock(&fs_info->trans_lock); in btrfs_commit_transaction()
2273 ret = READ_ONCE(prev_trans->aborted); in btrfs_commit_transaction()
2278 spin_lock(&fs_info->trans_lock); in btrfs_commit_transaction()
2283 * from the list of transactions at fs_info->trans_list. So we in btrfs_commit_transaction()
2288 spin_unlock(&fs_info->trans_lock); in btrfs_commit_transaction()
2289 ret = -EROFS; in btrfs_commit_transaction()
2294 cur_trans->state = TRANS_STATE_COMMIT_START; in btrfs_commit_transaction()
2295 wake_up(&fs_info->transaction_blocked_wait); in btrfs_commit_transaction()
2296 spin_unlock(&fs_info->trans_lock); in btrfs_commit_transaction()
2304 extwriter_counter_dec(cur_trans, trans->type); in btrfs_commit_transaction()
2315 * The thread has started/joined the transaction thus it holds the in btrfs_commit_transaction()
2321 wait_event(cur_trans->writer_wait, in btrfs_commit_transaction()
2334 * Wait for all ordered extents started by a fast fsync that joined this in btrfs_commit_transaction()
2339 wait_event(cur_trans->pending_wait, in btrfs_commit_transaction()
2340 atomic_read(&cur_trans->pending_ordered) == 0); in btrfs_commit_transaction()
2345 * commit the transaction. We could have started a join before setting in btrfs_commit_transaction()
2348 spin_lock(&fs_info->trans_lock); in btrfs_commit_transaction()
2350 cur_trans->state = TRANS_STATE_COMMIT_DOING; in btrfs_commit_transaction()
2351 spin_unlock(&fs_info->trans_lock); in btrfs_commit_transaction()
2354 * The thread has started/joined the transaction thus it holds the in btrfs_commit_transaction()
2360 wait_event(cur_trans->writer_wait, in btrfs_commit_transaction()
2361 atomic_read(&cur_trans->num_writers) == 1); in btrfs_commit_transaction()
2374 * We've started the commit, clear the flag in case we were triggered to in btrfs_commit_transaction()
2375 * do an async commit but somebody else started before the transaction in btrfs_commit_transaction()
2378 clear_bit(BTRFS_FS_COMMIT_TRANS, &fs_info->flags); in btrfs_commit_transaction()
2381 ret = cur_trans->aborted; in btrfs_commit_transaction()
2390 mutex_lock(&fs_info->reloc_mutex); in btrfs_commit_transaction()
2425 WARN_ON(cur_trans != trans->transaction); in btrfs_commit_transaction()
2450 * update ->aborted, check it. in btrfs_commit_transaction()
2453 ret = cur_trans->aborted; in btrfs_commit_transaction()
2457 cur_trans = fs_info->running_transaction; in btrfs_commit_transaction()
2459 btrfs_set_root_node(&fs_info->tree_root->root_item, in btrfs_commit_transaction()
2460 fs_info->tree_root->node); in btrfs_commit_transaction()
2461 list_add_tail(&fs_info->tree_root->dirty_list, in btrfs_commit_transaction()
2462 &cur_trans->switch_commits); in btrfs_commit_transaction()
2464 btrfs_set_root_node(&fs_info->chunk_root->root_item, in btrfs_commit_transaction()
2465 fs_info->chunk_root->node); in btrfs_commit_transaction()
2466 list_add_tail(&fs_info->chunk_root->dirty_list, in btrfs_commit_transaction()
2467 &cur_trans->switch_commits); in btrfs_commit_transaction()
2470 btrfs_set_root_node(&fs_info->block_group_root->root_item, in btrfs_commit_transaction()
2471 fs_info->block_group_root->node); in btrfs_commit_transaction()
2472 list_add_tail(&fs_info->block_group_root->dirty_list, in btrfs_commit_transaction()
2473 &cur_trans->switch_commits); in btrfs_commit_transaction()
2478 ASSERT(list_empty(&cur_trans->dirty_bgs)); in btrfs_commit_transaction()
2479 ASSERT(list_empty(&cur_trans->io_bgs)); in btrfs_commit_transaction()
2482 btrfs_set_super_log_root(fs_info->super_copy, 0); in btrfs_commit_transaction()
2483 btrfs_set_super_log_root_level(fs_info->super_copy, 0); in btrfs_commit_transaction()
2484 memcpy(fs_info->super_for_commit, fs_info->super_copy, in btrfs_commit_transaction()
2485 sizeof(*fs_info->super_copy)); in btrfs_commit_transaction()
2489 clear_bit(BTRFS_FS_LOG1_ERR, &fs_info->flags); in btrfs_commit_transaction()
2490 clear_bit(BTRFS_FS_LOG2_ERR, &fs_info->flags); in btrfs_commit_transaction()
2496 * setting fs_info->running_transaction to NULL, lock tree_log_mutex to in btrfs_commit_transaction()
2502 mutex_lock(&fs_info->tree_log_mutex); in btrfs_commit_transaction()
2504 spin_lock(&fs_info->trans_lock); in btrfs_commit_transaction()
2505 cur_trans->state = TRANS_STATE_UNBLOCKED; in btrfs_commit_transaction()
2506 fs_info->running_transaction = NULL; in btrfs_commit_transaction()
2507 spin_unlock(&fs_info->trans_lock); in btrfs_commit_transaction()
2508 mutex_unlock(&fs_info->reloc_mutex); in btrfs_commit_transaction()
2510 wake_up(&fs_info->transaction_wait); in btrfs_commit_transaction()
2514 if (test_bit(BTRFS_FS_FEATURE_CHANGED, &fs_info->flags) && in btrfs_commit_transaction()
2515 fs_info->cleaner_kthread) in btrfs_commit_transaction()
2516 wake_up_process(fs_info->cleaner_kthread); in btrfs_commit_transaction()
2522 mutex_unlock(&fs_info->tree_log_mutex); in btrfs_commit_transaction()
2528 * the super is written, we can safely allow the tree-loggers in btrfs_commit_transaction()
2531 mutex_unlock(&fs_info->tree_log_mutex); in btrfs_commit_transaction()
2539 cur_trans->state = TRANS_STATE_SUPER_COMMITTED; in btrfs_commit_transaction()
2540 wake_up(&cur_trans->commit_wait); in btrfs_commit_transaction()
2545 if (test_bit(BTRFS_TRANS_HAVE_FREE_BGS, &cur_trans->flags)) in btrfs_commit_transaction()
2548 btrfs_set_last_trans_committed(fs_info, cur_trans->transid); in btrfs_commit_transaction()
2553 cur_trans->state = TRANS_STATE_COMPLETED; in btrfs_commit_transaction()
2554 wake_up(&cur_trans->commit_wait); in btrfs_commit_transaction()
2557 spin_lock(&fs_info->trans_lock); in btrfs_commit_transaction()
2558 list_del_init(&cur_trans->list); in btrfs_commit_transaction()
2559 spin_unlock(&fs_info->trans_lock); in btrfs_commit_transaction()
2564 if (trans->type & __TRANS_FREEZABLE) in btrfs_commit_transaction()
2565 sb_end_intwrite(fs_info->sb); in btrfs_commit_transaction()
2569 interval = ktime_get_ns() - start_time; in btrfs_commit_transaction()
2573 if (current->journal_info == trans) in btrfs_commit_transaction()
2574 current->journal_info = NULL; in btrfs_commit_transaction()
2583 mutex_unlock(&fs_info->reloc_mutex); in btrfs_commit_transaction()
2593 trans->block_rsv = NULL; in btrfs_commit_transaction()
2595 if (current->journal_info == trans) in btrfs_commit_transaction()
2596 current->journal_info = NULL; in btrfs_commit_transaction()
2627 spin_lock(&fs_info->trans_lock); in btrfs_clean_one_deleted_snapshot()
2628 if (list_empty(&fs_info->dead_roots)) { in btrfs_clean_one_deleted_snapshot()
2629 spin_unlock(&fs_info->trans_lock); in btrfs_clean_one_deleted_snapshot()
2632 root = list_first_entry(&fs_info->dead_roots, in btrfs_clean_one_deleted_snapshot()
2634 list_del_init(&root->root_list); in btrfs_clean_one_deleted_snapshot()
2635 spin_unlock(&fs_info->trans_lock); in btrfs_clean_one_deleted_snapshot()
2641 if (btrfs_header_backref_rev(root->node) < in btrfs_clean_one_deleted_snapshot()
2652 * We only mark the transaction aborted and then set the file system read-only.
2659 * in the call path but will return -EIO.
2668 struct btrfs_fs_info *fs_info = trans->fs_info; in __btrfs_abort_transaction()
2670 WRITE_ONCE(trans->aborted, error); in __btrfs_abort_transaction()
2671 WRITE_ONCE(trans->transaction->aborted, error); in __btrfs_abort_transaction()
2672 if (first_hit && error == -ENOSPC) in __btrfs_abort_transaction()
2675 wake_up(&fs_info->transaction_wait); in __btrfs_abort_transaction()
2676 wake_up(&fs_info->transaction_blocked_wait); in __btrfs_abort_transaction()
2684 return -ENOMEM; in btrfs_transaction_init()