Lines Matching refs:root

114 	struct btrfs_root *root, *tmp;  in switch_commit_roots()  local
117 list_for_each_entry_safe(root, tmp, &trans->switch_commits, in switch_commit_roots()
119 list_del_init(&root->dirty_list); in switch_commit_roots()
120 free_extent_buffer(root->commit_root); in switch_commit_roots()
121 root->commit_root = btrfs_root_node(root); in switch_commit_roots()
122 if (is_fstree(root->objectid)) in switch_commit_roots()
123 btrfs_unpin_free_ino(root); in switch_commit_roots()
124 clear_btree_io_tree(&root->dirty_log_pages); in switch_commit_roots()
130 root = list_first_entry(&trans->dropped_roots, in switch_commit_roots()
132 list_del_init(&root->root_list); in switch_commit_roots()
134 btrfs_drop_and_free_fs_root(fs_info, root); in switch_commit_roots()
169 static noinline int join_transaction(struct btrfs_root *root, unsigned int type) in join_transaction() argument
172 struct btrfs_fs_info *fs_info = root->fs_info; in join_transaction()
297 struct btrfs_root *root) in record_root_in_trans() argument
299 if (test_bit(BTRFS_ROOT_REF_COWS, &root->state) && in record_root_in_trans()
300 root->last_trans < trans->transid) { in record_root_in_trans()
301 WARN_ON(root == root->fs_info->extent_root); in record_root_in_trans()
302 WARN_ON(root->commit_root != root->node); in record_root_in_trans()
309 set_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state); in record_root_in_trans()
316 spin_lock(&root->fs_info->fs_roots_radix_lock); in record_root_in_trans()
317 if (root->last_trans == trans->transid) { in record_root_in_trans()
318 spin_unlock(&root->fs_info->fs_roots_radix_lock); in record_root_in_trans()
321 radix_tree_tag_set(&root->fs_info->fs_roots_radix, in record_root_in_trans()
322 (unsigned long)root->root_key.objectid, in record_root_in_trans()
324 spin_unlock(&root->fs_info->fs_roots_radix_lock); 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()
348 clear_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state); in record_root_in_trans()
355 struct btrfs_root *root) in btrfs_add_dropped_root() argument
361 list_add_tail(&root->root_list, &cur_trans->dropped_roots); in btrfs_add_dropped_root()
365 spin_lock(&root->fs_info->fs_roots_radix_lock); in btrfs_add_dropped_root()
366 radix_tree_tag_clear(&root->fs_info->fs_roots_radix, in btrfs_add_dropped_root()
367 (unsigned long)root->root_key.objectid, in btrfs_add_dropped_root()
369 spin_unlock(&root->fs_info->fs_roots_radix_lock); in btrfs_add_dropped_root()
373 struct btrfs_root *root) in btrfs_record_root_in_trans() argument
375 if (!test_bit(BTRFS_ROOT_REF_COWS, &root->state)) in btrfs_record_root_in_trans()
383 if (root->last_trans == trans->transid && in btrfs_record_root_in_trans()
384 !test_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state)) in btrfs_record_root_in_trans()
387 mutex_lock(&root->fs_info->reloc_mutex); in btrfs_record_root_in_trans()
388 record_root_in_trans(trans, root); in btrfs_record_root_in_trans()
389 mutex_unlock(&root->fs_info->reloc_mutex); in btrfs_record_root_in_trans()
405 static void wait_current_trans(struct btrfs_root *root) in wait_current_trans() argument
409 spin_lock(&root->fs_info->trans_lock); in wait_current_trans()
410 cur_trans = root->fs_info->running_transaction; in wait_current_trans()
413 spin_unlock(&root->fs_info->trans_lock); in wait_current_trans()
415 wait_event(root->fs_info->transaction_wait, in wait_current_trans()
420 spin_unlock(&root->fs_info->trans_lock); in wait_current_trans()
424 static int may_wait_transaction(struct btrfs_root *root, int type) in may_wait_transaction() argument
426 if (root->fs_info->log_root_recovering) in may_wait_transaction()
433 !atomic_read(&root->fs_info->open_ioctl_trans)) in may_wait_transaction()
439 static inline bool need_reserve_reloc_root(struct btrfs_root *root) in need_reserve_reloc_root() argument
441 if (!root->fs_info->reloc_ctl || in need_reserve_reloc_root()
442 !test_bit(BTRFS_ROOT_REF_COWS, &root->state) || in need_reserve_reloc_root()
443 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID || in need_reserve_reloc_root()
444 root->reloc_root) in need_reserve_reloc_root()
451 start_transaction(struct btrfs_root *root, unsigned int num_items, in start_transaction() argument
464 if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) in start_transaction()
481 if (num_items > 0 && root != root->fs_info->chunk_root) { in start_transaction()
482 qgroup_reserved = num_items * root->nodesize; in start_transaction()
483 ret = btrfs_qgroup_reserve_meta(root, qgroup_reserved); in start_transaction()
487 num_bytes = btrfs_calc_trans_metadata_size(root, num_items); in start_transaction()
491 if (need_reserve_reloc_root(root)) { in start_transaction()
492 num_bytes += root->nodesize; in start_transaction()
496 ret = btrfs_block_rsv_add(root, in start_transaction()
497 &root->fs_info->trans_block_rsv, in start_transaction()
520 sb_start_intwrite(root->fs_info->sb); in start_transaction()
522 if (may_wait_transaction(root, type)) in start_transaction()
523 wait_current_trans(root); in start_transaction()
526 ret = join_transaction(root, type); in start_transaction()
528 wait_current_trans(root); in start_transaction()
540 cur_trans = root->fs_info->running_transaction; in start_transaction()
544 h->root = root; in start_transaction()
554 may_wait_transaction(root, type)) { in start_transaction()
556 btrfs_commit_transaction(h, root); in start_transaction()
561 trace_btrfs_space_reservation(root->fs_info, "transaction", in start_transaction()
563 h->block_rsv = &root->fs_info->trans_block_rsv; in start_transaction()
569 btrfs_record_root_in_trans(h, root); in start_transaction()
577 sb_end_intwrite(root->fs_info->sb); in start_transaction()
581 btrfs_block_rsv_release(root, &root->fs_info->trans_block_rsv, in start_transaction()
584 btrfs_qgroup_free_meta(root, qgroup_reserved); in start_transaction()
588 struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, in btrfs_start_transaction() argument
591 return start_transaction(root, num_items, TRANS_START, in btrfs_start_transaction()
595 struct btrfs_root *root, in btrfs_start_transaction_fallback_global_rsv() argument
603 trans = btrfs_start_transaction(root, num_items); in btrfs_start_transaction_fallback_global_rsv()
607 trans = btrfs_start_transaction(root, 0); in btrfs_start_transaction_fallback_global_rsv()
611 num_bytes = btrfs_calc_trans_metadata_size(root, num_items); in btrfs_start_transaction_fallback_global_rsv()
612 ret = btrfs_cond_migrate_bytes(root->fs_info, in btrfs_start_transaction_fallback_global_rsv()
613 &root->fs_info->trans_block_rsv, 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()
628 struct btrfs_root *root, in btrfs_start_transaction_lflush() argument
631 return start_transaction(root, num_items, TRANS_START, in btrfs_start_transaction_lflush()
635 struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root) in btrfs_join_transaction() argument
637 return start_transaction(root, 0, TRANS_JOIN, 0); in btrfs_join_transaction()
640 struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root) in btrfs_join_transaction_nolock() argument
642 return start_transaction(root, 0, TRANS_JOIN_NOLOCK, 0); in btrfs_join_transaction_nolock()
645 struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *root) in btrfs_start_ioctl_transaction() argument
647 return start_transaction(root, 0, TRANS_USERSPACE, 0); in btrfs_start_ioctl_transaction()
663 struct btrfs_trans_handle *btrfs_attach_transaction(struct btrfs_root *root) in btrfs_attach_transaction() argument
665 return start_transaction(root, 0, TRANS_ATTACH, 0); in btrfs_attach_transaction()
676 btrfs_attach_transaction_barrier(struct btrfs_root *root) in btrfs_attach_transaction_barrier() argument
680 trans = start_transaction(root, 0, TRANS_ATTACH, 0); in btrfs_attach_transaction_barrier()
682 btrfs_wait_for_commit(root, 0); in btrfs_attach_transaction_barrier()
688 static noinline void wait_for_commit(struct btrfs_root *root, in wait_for_commit() argument
694 int btrfs_wait_for_commit(struct btrfs_root *root, u64 transid) in btrfs_wait_for_commit() argument
700 if (transid <= root->fs_info->last_trans_committed) in btrfs_wait_for_commit()
704 spin_lock(&root->fs_info->trans_lock); in btrfs_wait_for_commit()
705 list_for_each_entry(t, &root->fs_info->trans_list, list) { in btrfs_wait_for_commit()
717 spin_unlock(&root->fs_info->trans_lock); in btrfs_wait_for_commit()
724 if (transid > root->fs_info->last_trans_committed) in btrfs_wait_for_commit()
730 spin_lock(&root->fs_info->trans_lock); in btrfs_wait_for_commit()
731 list_for_each_entry_reverse(t, &root->fs_info->trans_list, in btrfs_wait_for_commit()
741 spin_unlock(&root->fs_info->trans_lock); in btrfs_wait_for_commit()
746 wait_for_commit(root, cur_trans); in btrfs_wait_for_commit()
752 void btrfs_throttle(struct btrfs_root *root) in btrfs_throttle() argument
754 if (!atomic_read(&root->fs_info->open_ioctl_trans)) in btrfs_throttle()
755 wait_current_trans(root); in btrfs_throttle()
759 struct btrfs_root *root) in should_end_transaction() argument
761 if (root->fs_info->global_block_rsv.space_info->full && in should_end_transaction()
762 btrfs_check_space_for_delayed_refs(trans, root)) in should_end_transaction()
765 return !!btrfs_block_rsv_check(root, &root->fs_info->global_block_rsv, 5); in should_end_transaction()
769 struct btrfs_root *root) in btrfs_should_end_transaction() argument
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()
792 struct btrfs_root *root, int throttle) in __btrfs_end_transaction() argument
795 struct btrfs_fs_info *info = root->fs_info; in __btrfs_end_transaction()
807 btrfs_trans_release_metadata(trans, root); in __btrfs_end_transaction()
811 btrfs_create_pending_block_groups(trans, root); in __btrfs_end_transaction()
816 btrfs_should_throttle_delayed_refs(trans, root); in __btrfs_end_transaction()
828 btrfs_trans_release_metadata(trans, root); in __btrfs_end_transaction()
832 btrfs_create_pending_block_groups(trans, root); in __btrfs_end_transaction()
836 if (lock && !atomic_read(&root->fs_info->open_ioctl_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()
853 sb_end_intwrite(root->fs_info->sb); in __btrfs_end_transaction()
872 btrfs_run_delayed_iputs(root); in __btrfs_end_transaction()
875 test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) { in __btrfs_end_transaction()
883 btrfs_async_run_delayed_refs(root, cur, in __btrfs_end_transaction()
890 struct btrfs_root *root) in btrfs_end_transaction() argument
892 return __btrfs_end_transaction(trans, root, 0); in btrfs_end_transaction()
896 struct btrfs_root *root) in btrfs_end_transaction_throttle() argument
898 return __btrfs_end_transaction(trans, root, 1); in btrfs_end_transaction_throttle()
906 int btrfs_write_marked_extents(struct btrfs_root *root, in btrfs_write_marked_extents() argument
911 struct address_space *mapping = root->fs_info->btree_inode->i_mapping; in btrfs_write_marked_extents()
960 int btrfs_wait_marked_extents(struct btrfs_root *root, in btrfs_wait_marked_extents() argument
965 struct address_space *mapping = root->fs_info->btree_inode->i_mapping; in btrfs_wait_marked_extents()
969 struct btrfs_inode *btree_ino = BTRFS_I(root->fs_info->btree_inode); in btrfs_wait_marked_extents()
999 if (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID) { in btrfs_wait_marked_extents()
1026 static int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, in btrfs_write_and_wait_marked_extents() argument
1034 ret = btrfs_write_marked_extents(root, dirty_pages, mark); in btrfs_write_and_wait_marked_extents()
1036 ret2 = btrfs_wait_marked_extents(root, dirty_pages, mark); in btrfs_write_and_wait_marked_extents()
1046 struct btrfs_root *root) in btrfs_write_and_wait_transaction() argument
1050 ret = btrfs_write_and_wait_marked_extents(root, in btrfs_write_and_wait_transaction()
1069 struct btrfs_root *root) in update_cowonly_root() argument
1074 struct btrfs_root *tree_root = root->fs_info->tree_root; in update_cowonly_root()
1076 old_root_used = btrfs_root_used(&root->root_item); in update_cowonly_root()
1079 old_root_bytenr = btrfs_root_bytenr(&root->root_item); in update_cowonly_root()
1080 if (old_root_bytenr == root->node->start && in update_cowonly_root()
1081 old_root_used == btrfs_root_used(&root->root_item)) in update_cowonly_root()
1084 btrfs_set_root_node(&root->root_item, root->node); in update_cowonly_root()
1086 &root->root_key, in update_cowonly_root()
1087 &root->root_item); in update_cowonly_root()
1091 old_root_used = btrfs_root_used(&root->root_item); in update_cowonly_root()
1105 struct btrfs_root *root) in commit_cowonly_roots() argument
1107 struct btrfs_fs_info *fs_info = root->fs_info; 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()
1149 root = list_entry(next, struct btrfs_root, dirty_list); in commit_cowonly_roots()
1150 clear_bit(BTRFS_ROOT_DIRTY, &root->state); in commit_cowonly_roots()
1152 if (root != fs_info->extent_root) in commit_cowonly_roots()
1153 list_add_tail(&root->dirty_list, 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()
1187 void btrfs_add_dead_root(struct btrfs_root *root) in btrfs_add_dead_root() argument
1189 spin_lock(&root->fs_info->trans_lock); in btrfs_add_dead_root()
1190 if (list_empty(&root->root_list)) in btrfs_add_dead_root()
1191 list_add_tail(&root->root_list, &root->fs_info->dead_roots); in btrfs_add_dead_root()
1192 spin_unlock(&root->fs_info->trans_lock); in btrfs_add_dead_root()
1199 struct btrfs_root *root) in commit_fs_roots() argument
1202 struct btrfs_fs_info *fs_info = root->fs_info; in commit_fs_roots()
1216 root = gang[i]; in commit_fs_roots()
1218 (unsigned long)root->root_key.objectid, in commit_fs_roots()
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()
1229 clear_bit(BTRFS_ROOT_FORCE_COW, &root->state); in commit_fs_roots()
1232 if (root->commit_root != root->node) { in commit_fs_roots()
1233 list_add_tail(&root->dirty_list, in commit_fs_roots()
1235 btrfs_set_root_node(&root->root_item, in commit_fs_roots()
1236 root->node); in commit_fs_roots()
1240 &root->root_key, in commit_fs_roots()
1241 &root->root_item); in commit_fs_roots()
1245 btrfs_qgroup_free_meta_all(root); in commit_fs_roots()
1256 int btrfs_defrag_root(struct btrfs_root *root) in btrfs_defrag_root() argument
1258 struct btrfs_fs_info *info = root->fs_info; in btrfs_defrag_root()
1262 if (test_and_set_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state)) in btrfs_defrag_root()
1266 trans = btrfs_start_transaction(root, 0); 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()
1276 if (btrfs_fs_closing(root->fs_info) || ret != -EAGAIN) in btrfs_defrag_root()
1279 if (btrfs_defrag_cancelled(root->fs_info)) { in btrfs_defrag_root()
1285 clear_bit(BTRFS_ROOT_DEFRAG_RUNNING, &root->state); in btrfs_defrag_root()
1305 struct btrfs_root *root = pending->root; in create_pending_snapshot() local
1347 pending->error = btrfs_block_rsv_add(root, in create_pending_snapshot()
1365 parent_root = BTRFS_I(parent_inode)->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()
1403 memcpy(new_root_item, &root->root_item, sizeof(*new_root_item)); in create_pending_snapshot()
1417 memcpy(new_root_item->parent_uuid, root->root_item.uuid, in create_pending_snapshot()
1431 old = btrfs_lock_root_node(root); 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()
1451 set_bit(BTRFS_ROOT_FORCE_COW, &root->state); in create_pending_snapshot()
1461 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1473 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1478 pending->snap = btrfs_read_fs_root_no_name(root->fs_info, &key); in create_pending_snapshot()
1481 btrfs_abort_transaction(trans, root, ret); 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()
1504 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1513 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1519 btrfs_abort_transaction(trans, root, ret); 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()
1549 root->root_key.objectid, in create_pending_snapshot()
1552 btrfs_abort_transaction(trans, root, ret); in create_pending_snapshot()
1589 static void update_super_roots(struct btrfs_root *root) in update_super_roots() argument
1594 super = root->fs_info->super_copy; in update_super_roots()
1596 root_item = &root->fs_info->chunk_root->root_item; in update_super_roots()
1601 root_item = &root->fs_info->tree_root->root_item; in update_super_roots()
1602 super->root = root_item->bytenr; in update_super_roots()
1605 if (btrfs_test_opt(root, SPACE_CACHE)) in update_super_roots()
1607 if (root->fs_info->update_uuid_tree_gen) in update_super_roots()
1641 static void wait_current_trans_commit_start(struct btrfs_root *root, in wait_current_trans_commit_start() argument
1644 wait_event(root->fs_info->transaction_blocked_wait, in wait_current_trans_commit_start()
1653 static void wait_current_trans_commit_start_and_unblock(struct btrfs_root *root, in wait_current_trans_commit_start_and_unblock() argument
1656 wait_event(root->fs_info->transaction_wait, in wait_current_trans_commit_start_and_unblock()
1667 struct btrfs_root *root; member
1681 __sb_writers_acquired(ac->root->fs_info->sb, SB_FREEZE_FS); in do_async_commit()
1685 btrfs_commit_transaction(ac->newtrans, ac->root); in do_async_commit()
1690 struct btrfs_root *root, in btrfs_commit_transaction_async() argument
1701 ac->root = root; in btrfs_commit_transaction_async()
1702 ac->newtrans = btrfs_join_transaction(root); in btrfs_commit_transaction_async()
1713 btrfs_end_transaction(trans, root); in btrfs_commit_transaction_async()
1720 __sb_writers_release(root->fs_info->sb, SB_FREEZE_FS); in btrfs_commit_transaction_async()
1726 wait_current_trans_commit_start_and_unblock(root, cur_trans); in btrfs_commit_transaction_async()
1728 wait_current_trans_commit_start(root, cur_trans); in btrfs_commit_transaction_async()
1739 struct btrfs_root *root, int err) in cleanup_transaction() argument
1746 btrfs_abort_transaction(trans, root, err); in cleanup_transaction()
1748 spin_lock(&root->fs_info->trans_lock); in cleanup_transaction()
1758 if (cur_trans == root->fs_info->running_transaction) { in cleanup_transaction()
1760 spin_unlock(&root->fs_info->trans_lock); in cleanup_transaction()
1764 spin_lock(&root->fs_info->trans_lock); in cleanup_transaction()
1766 spin_unlock(&root->fs_info->trans_lock); in cleanup_transaction()
1768 btrfs_cleanup_one_transaction(trans->transaction, root); in cleanup_transaction()
1770 spin_lock(&root->fs_info->trans_lock); in cleanup_transaction()
1771 if (cur_trans == root->fs_info->running_transaction) in cleanup_transaction()
1772 root->fs_info->running_transaction = NULL; in cleanup_transaction()
1773 spin_unlock(&root->fs_info->trans_lock); in cleanup_transaction()
1776 sb_end_intwrite(root->fs_info->sb); in cleanup_transaction()
1780 trace_btrfs_transaction_commit(root); in cleanup_transaction()
1784 btrfs_scrub_cancel(root->fs_info); in cleanup_transaction()
1810 struct btrfs_root *root) in btrfs_commit_transaction() argument
1814 struct btrfs_inode *btree_ino = BTRFS_I(root->fs_info->btree_inode); 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()
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()
1870 mutex_lock(&root->fs_info->ro_block_group_mutex); in btrfs_commit_transaction()
1874 mutex_unlock(&root->fs_info->ro_block_group_mutex); 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()
1884 spin_lock(&root->fs_info->trans_lock); in btrfs_commit_transaction()
1886 spin_unlock(&root->fs_info->trans_lock); in btrfs_commit_transaction()
1888 ret = btrfs_end_transaction(trans, root); in btrfs_commit_transaction()
1890 wait_for_commit(root, cur_trans); in btrfs_commit_transaction()
1901 wake_up(&root->fs_info->transaction_blocked_wait); in btrfs_commit_transaction()
1903 if (cur_trans->list.prev != &root->fs_info->trans_list) { in btrfs_commit_transaction()
1908 spin_unlock(&root->fs_info->trans_lock); in btrfs_commit_transaction()
1910 wait_for_commit(root, prev_trans); in btrfs_commit_transaction()
1917 spin_unlock(&root->fs_info->trans_lock); in btrfs_commit_transaction()
1920 spin_unlock(&root->fs_info->trans_lock); in btrfs_commit_transaction()
1925 ret = btrfs_start_delalloc_flush(root->fs_info); 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()
1941 btrfs_wait_delalloc_flush(root->fs_info); in btrfs_commit_transaction()
1945 btrfs_scrub_pause(root); in btrfs_commit_transaction()
1951 spin_lock(&root->fs_info->trans_lock); in btrfs_commit_transaction()
1953 spin_unlock(&root->fs_info->trans_lock); in btrfs_commit_transaction()
1967 mutex_lock(&root->fs_info->reloc_mutex); in btrfs_commit_transaction()
1974 ret = create_pending_snapshots(trans, root->fs_info); in btrfs_commit_transaction()
1976 mutex_unlock(&root->fs_info->reloc_mutex); in btrfs_commit_transaction()
1990 ret = btrfs_run_delayed_items(trans, root); in btrfs_commit_transaction()
1992 mutex_unlock(&root->fs_info->reloc_mutex); in btrfs_commit_transaction()
1996 ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); in btrfs_commit_transaction()
1998 mutex_unlock(&root->fs_info->reloc_mutex); in btrfs_commit_transaction()
2003 ret = btrfs_qgroup_prepare_account_extents(trans, root->fs_info); in btrfs_commit_transaction()
2005 mutex_unlock(&root->fs_info->reloc_mutex); in btrfs_commit_transaction()
2013 btrfs_assert_delayed_root_empty(root); in btrfs_commit_transaction()
2030 mutex_lock(&root->fs_info->tree_log_mutex); in btrfs_commit_transaction()
2032 ret = commit_fs_roots(trans, root); in btrfs_commit_transaction()
2034 mutex_unlock(&root->fs_info->tree_log_mutex); in btrfs_commit_transaction()
2035 mutex_unlock(&root->fs_info->reloc_mutex); in btrfs_commit_transaction()
2043 btrfs_apply_pending_changes(root->fs_info); 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()
2056 mutex_unlock(&root->fs_info->tree_log_mutex); in btrfs_commit_transaction()
2057 mutex_unlock(&root->fs_info->reloc_mutex); in btrfs_commit_transaction()
2061 ret = commit_cowonly_roots(trans, root); in btrfs_commit_transaction()
2063 mutex_unlock(&root->fs_info->tree_log_mutex); in btrfs_commit_transaction()
2064 mutex_unlock(&root->fs_info->reloc_mutex); in btrfs_commit_transaction()
2074 mutex_unlock(&root->fs_info->tree_log_mutex); in btrfs_commit_transaction()
2075 mutex_unlock(&root->fs_info->reloc_mutex); in btrfs_commit_transaction()
2079 btrfs_prepare_extent_commit(trans, root); in btrfs_commit_transaction()
2081 cur_trans = root->fs_info->running_transaction; in btrfs_commit_transaction()
2083 btrfs_set_root_node(&root->fs_info->tree_root->root_item, in btrfs_commit_transaction()
2084 root->fs_info->tree_root->node); in btrfs_commit_transaction()
2085 list_add_tail(&root->fs_info->tree_root->dirty_list, in btrfs_commit_transaction()
2088 btrfs_set_root_node(&root->fs_info->chunk_root->root_item, in btrfs_commit_transaction()
2089 root->fs_info->chunk_root->node); in btrfs_commit_transaction()
2090 list_add_tail(&root->fs_info->chunk_root->dirty_list, in btrfs_commit_transaction()
2093 switch_commit_roots(cur_trans, root->fs_info); in btrfs_commit_transaction()
2098 update_super_roots(root); in btrfs_commit_transaction()
2100 btrfs_set_super_log_root(root->fs_info->super_copy, 0); in btrfs_commit_transaction()
2101 btrfs_set_super_log_root_level(root->fs_info->super_copy, 0); in btrfs_commit_transaction()
2102 memcpy(root->fs_info->super_for_commit, root->fs_info->super_copy, in btrfs_commit_transaction()
2103 sizeof(*root->fs_info->super_copy)); in btrfs_commit_transaction()
2105 btrfs_update_commit_device_size(root->fs_info); in btrfs_commit_transaction()
2106 btrfs_update_commit_device_bytes_used(root, cur_trans); in btrfs_commit_transaction()
2113 spin_lock(&root->fs_info->trans_lock); in btrfs_commit_transaction()
2115 root->fs_info->running_transaction = NULL; in btrfs_commit_transaction()
2116 spin_unlock(&root->fs_info->trans_lock); in btrfs_commit_transaction()
2117 mutex_unlock(&root->fs_info->reloc_mutex); in btrfs_commit_transaction()
2119 wake_up(&root->fs_info->transaction_wait); in btrfs_commit_transaction()
2121 ret = btrfs_write_and_wait_transaction(trans, root); in btrfs_commit_transaction()
2123 btrfs_std_error(root->fs_info, ret, in btrfs_commit_transaction()
2125 mutex_unlock(&root->fs_info->tree_log_mutex); in btrfs_commit_transaction()
2129 ret = write_ctree_super(trans, root, 0); in btrfs_commit_transaction()
2131 mutex_unlock(&root->fs_info->tree_log_mutex); in btrfs_commit_transaction()
2139 mutex_unlock(&root->fs_info->tree_log_mutex); in btrfs_commit_transaction()
2141 btrfs_finish_extent_commit(trans, root); in btrfs_commit_transaction()
2144 btrfs_clear_space_info_full(root->fs_info); in btrfs_commit_transaction()
2146 root->fs_info->last_trans_committed = cur_trans->transid; in btrfs_commit_transaction()
2154 spin_lock(&root->fs_info->trans_lock); in btrfs_commit_transaction()
2156 spin_unlock(&root->fs_info->trans_lock); in btrfs_commit_transaction()
2162 sb_end_intwrite(root->fs_info->sb); in btrfs_commit_transaction()
2164 trace_btrfs_transaction_commit(root); in btrfs_commit_transaction()
2166 btrfs_scrub_continue(root); in btrfs_commit_transaction()
2173 if (current != root->fs_info->transaction_kthread && in btrfs_commit_transaction()
2174 current != root->fs_info->cleaner_kthread) in btrfs_commit_transaction()
2175 btrfs_run_delayed_iputs(root); in btrfs_commit_transaction()
2180 btrfs_scrub_continue(root); in btrfs_commit_transaction()
2182 btrfs_trans_release_metadata(trans, root); in btrfs_commit_transaction()
2185 btrfs_warn(root->fs_info, "Skipping commit of aborted transaction."); in btrfs_commit_transaction()
2188 cleanup_transaction(trans, root, ret); in btrfs_commit_transaction()
2203 int btrfs_clean_one_deleted_snapshot(struct btrfs_root *root) in btrfs_clean_one_deleted_snapshot() argument
2206 struct btrfs_fs_info *fs_info = root->fs_info; in btrfs_clean_one_deleted_snapshot()
2213 root = list_first_entry(&fs_info->dead_roots, in btrfs_clean_one_deleted_snapshot()
2215 list_del_init(&root->root_list); in btrfs_clean_one_deleted_snapshot()
2218 pr_debug("BTRFS: cleaner removing %llu\n", root->objectid); in btrfs_clean_one_deleted_snapshot()
2220 btrfs_kill_all_delayed_nodes(root); in btrfs_clean_one_deleted_snapshot()
2222 if (btrfs_header_backref_rev(root->node) < in btrfs_clean_one_deleted_snapshot()
2224 ret = btrfs_drop_snapshot(root, NULL, 0, 0); in btrfs_clean_one_deleted_snapshot()
2226 ret = btrfs_drop_snapshot(root, NULL, 1, 0); in btrfs_clean_one_deleted_snapshot()