diff options
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r-- | fs/btrfs/transaction.c | 85 |
1 files changed, 26 insertions, 59 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index c6a872a..8c81bdc 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -57,7 +57,7 @@ static unsigned int btrfs_blocked_trans_types[TRANS_STATE_MAX] = { __TRANS_JOIN_NOLOCK), }; -void btrfs_put_transaction(struct btrfs_transaction *transaction) +static void put_transaction(struct btrfs_transaction *transaction) { WARN_ON(atomic_read(&transaction->use_count) == 0); if (atomic_dec_and_test(&transaction->use_count)) { @@ -332,7 +332,7 @@ static void wait_current_trans(struct btrfs_root *root) wait_event(root->fs_info->transaction_wait, cur_trans->state >= TRANS_STATE_UNBLOCKED || cur_trans->aborted); - btrfs_put_transaction(cur_trans); + put_transaction(cur_trans); } else { spin_unlock(&root->fs_info->trans_lock); } @@ -353,17 +353,6 @@ static int may_wait_transaction(struct btrfs_root *root, int type) return 0; } -static inline bool need_reserve_reloc_root(struct btrfs_root *root) -{ - if (!root->fs_info->reloc_ctl || - !root->ref_cows || - root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID || - root->reloc_root) - return false; - - return true; -} - static struct btrfs_trans_handle * start_transaction(struct btrfs_root *root, u64 num_items, unsigned int type, enum btrfs_reserve_flush_enum flush) @@ -371,9 +360,8 @@ start_transaction(struct btrfs_root *root, u64 num_items, unsigned int type, struct btrfs_trans_handle *h; struct btrfs_transaction *cur_trans; u64 num_bytes = 0; - u64 qgroup_reserved = 0; - bool reloc_reserved = false; int ret; + u64 qgroup_reserved = 0; if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) return ERR_PTR(-EROFS); @@ -402,14 +390,6 @@ start_transaction(struct btrfs_root *root, u64 num_items, unsigned int type, } num_bytes = btrfs_calc_trans_metadata_size(root, num_items); - /* - * Do the reservation for the relocation root creation - */ - if (unlikely(need_reserve_reloc_root(root))) { - num_bytes += root->nodesize; - reloc_reserved = true; - } - ret = btrfs_block_rsv_add(root, &root->fs_info->trans_block_rsv, num_bytes, flush); @@ -471,7 +451,6 @@ again: h->delayed_ref_elem.seq = 0; h->type = type; h->allocating_chunk = false; - h->reloc_reserved = false; INIT_LIST_HEAD(&h->qgroup_ref_list); INIT_LIST_HEAD(&h->new_bgs); @@ -487,7 +466,6 @@ again: h->transid, num_bytes, 1); h->block_rsv = &root->fs_info->trans_block_rsv; h->bytes_reserved = num_bytes; - h->reloc_reserved = reloc_reserved; } h->qgroup_reserved = qgroup_reserved; @@ -632,7 +610,7 @@ int btrfs_wait_for_commit(struct btrfs_root *root, u64 transid) } wait_for_commit(root, cur_trans); - btrfs_put_transaction(cur_trans); + put_transaction(cur_trans); out: return ret; } @@ -757,7 +735,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, smp_mb(); if (waitqueue_active(&cur_trans->writer_wait)) wake_up(&cur_trans->writer_wait); - btrfs_put_transaction(cur_trans); + put_transaction(cur_trans); if (current->journal_info == trans) current->journal_info = NULL; @@ -766,10 +744,8 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, btrfs_run_delayed_iputs(root); if (trans->aborted || - test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) { - wake_up_process(info->transaction_kthread); + test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) err = -EIO; - } assert_qgroups_uptodate(trans); kmem_cache_free(btrfs_trans_handle_cachep, trans); @@ -972,19 +948,16 @@ static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans, return ret; ret = btrfs_run_dev_stats(trans, root->fs_info); - if (ret) - return ret; + WARN_ON(ret); ret = btrfs_run_dev_replace(trans, root->fs_info); - if (ret) - return ret; + WARN_ON(ret); + ret = btrfs_run_qgroups(trans, root->fs_info); - if (ret) - return ret; + BUG_ON(ret); /* run_qgroups might have added some more refs */ ret = btrfs_run_delayed_refs(trans, root, (unsigned long)-1); - if (ret) - return ret; + BUG_ON(ret); while (!list_empty(&fs_info->dirty_cowonly_roots)) { next = fs_info->dirty_cowonly_roots.next; @@ -1480,7 +1453,7 @@ static void do_async_commit(struct work_struct *work) * We've got freeze protection passed with the transaction. * Tell lockdep about it. */ - if (ac->newtrans->type & __TRANS_FREEZABLE) + if (ac->newtrans->type < TRANS_JOIN_NOLOCK) rwsem_acquire_read( &ac->root->fs_info->sb->s_writers.lock_map[SB_FREEZE_FS-1], 0, 1, _THIS_IP_); @@ -1521,7 +1494,7 @@ int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, * Tell lockdep we've released the freeze rwsem, since the * async commit thread will be the one to unlock it. */ - if (ac->newtrans->type & __TRANS_FREEZABLE) + if (trans->type < TRANS_JOIN_NOLOCK) rwsem_release( &root->fs_info->sb->s_writers.lock_map[SB_FREEZE_FS-1], 1, _THIS_IP_); @@ -1537,7 +1510,7 @@ int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, if (current->journal_info == trans) current->journal_info = NULL; - btrfs_put_transaction(cur_trans); + put_transaction(cur_trans); return 0; } @@ -1579,10 +1552,8 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans, root->fs_info->running_transaction = NULL; spin_unlock(&root->fs_info->trans_lock); - if (trans->type & __TRANS_FREEZABLE) - sb_end_intwrite(root->fs_info->sb); - btrfs_put_transaction(cur_trans); - btrfs_put_transaction(cur_trans); + put_transaction(cur_trans); + put_transaction(cur_trans); trace_btrfs_transaction_commit(root); @@ -1600,19 +1571,15 @@ static int btrfs_flush_all_pending_stuffs(struct btrfs_trans_handle *trans, int ret; ret = btrfs_run_delayed_items(trans, root); + if (ret) + return ret; + /* * running the delayed items may have added new refs. account * them now so that they hinder processing of more delayed refs * as little as possible. */ - if (ret) { - btrfs_delayed_refs_qgroup_accounting(trans, root->fs_info); - return ret; - } - - ret = btrfs_delayed_refs_qgroup_accounting(trans, root->fs_info); - if (ret) - return ret; + btrfs_delayed_refs_qgroup_accounting(trans, root->fs_info); /* * rename don't use btrfs_join_transaction, so, once we @@ -1629,14 +1596,14 @@ static int btrfs_flush_all_pending_stuffs(struct btrfs_trans_handle *trans, static inline int btrfs_start_delalloc_flush(struct btrfs_fs_info *fs_info) { if (btrfs_test_opt(fs_info->tree_root, FLUSHONCOMMIT)) - return btrfs_start_delalloc_roots(fs_info, 1); + return btrfs_start_all_delalloc_inodes(fs_info, 1); return 0; } static inline void btrfs_wait_delalloc_flush(struct btrfs_fs_info *fs_info) { if (btrfs_test_opt(fs_info->tree_root, FLUSHONCOMMIT)) - btrfs_wait_ordered_roots(fs_info, -1); + btrfs_wait_all_ordered_extents(fs_info); } int btrfs_commit_transaction(struct btrfs_trans_handle *trans, @@ -1702,7 +1669,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, wait_for_commit(root, cur_trans); - btrfs_put_transaction(cur_trans); + put_transaction(cur_trans); return ret; } @@ -1719,7 +1686,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, wait_for_commit(root, prev_trans); - btrfs_put_transaction(prev_trans); + put_transaction(prev_trans); } else { spin_unlock(&root->fs_info->trans_lock); } @@ -1918,8 +1885,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, list_del_init(&cur_trans->list); spin_unlock(&root->fs_info->trans_lock); - btrfs_put_transaction(cur_trans); - btrfs_put_transaction(cur_trans); + put_transaction(cur_trans); + put_transaction(cur_trans); if (trans->type & __TRANS_FREEZABLE) sb_end_intwrite(root->fs_info->sb); |