aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/tree-log.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/tree-log.c')
-rw-r--r--fs/btrfs/tree-log.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index ffee15856130..9e1f2cd5e67a 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -20,13 +20,11 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/blkdev.h> 21#include <linux/blkdev.h>
22#include <linux/list_sort.h> 22#include <linux/list_sort.h>
23#include "ctree.h" 23#include "tree-log.h"
24#include "transaction.h"
25#include "disk-io.h" 24#include "disk-io.h"
26#include "locking.h" 25#include "locking.h"
27#include "print-tree.h" 26#include "print-tree.h"
28#include "backref.h" 27#include "backref.h"
29#include "tree-log.h"
30#include "hash.h" 28#include "hash.h"
31 29
32/* magic values for the inode_only field in btrfs_log_inode: 30/* magic values for the inode_only field in btrfs_log_inode:
@@ -144,12 +142,10 @@ static int start_log_trans(struct btrfs_trans_handle *trans,
144 142
145 mutex_lock(&root->log_mutex); 143 mutex_lock(&root->log_mutex);
146 if (root->log_root) { 144 if (root->log_root) {
147 if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) == 145 if (btrfs_need_log_full_commit(root->fs_info, trans)) {
148 trans->transid) {
149 ret = -EAGAIN; 146 ret = -EAGAIN;
150 goto out; 147 goto out;
151 } 148 }
152
153 if (!root->log_start_pid) { 149 if (!root->log_start_pid) {
154 root->log_start_pid = current->pid; 150 root->log_start_pid = current->pid;
155 clear_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); 151 clear_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state);
@@ -2512,8 +2508,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
2512 } 2508 }
2513 2509
2514 /* bail out if we need to do a full commit */ 2510 /* bail out if we need to do a full commit */
2515 if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) == 2511 if (btrfs_need_log_full_commit(root->fs_info, trans)) {
2516 trans->transid) {
2517 ret = -EAGAIN; 2512 ret = -EAGAIN;
2518 btrfs_free_logged_extents(log, log_transid); 2513 btrfs_free_logged_extents(log, log_transid);
2519 mutex_unlock(&root->log_mutex); 2514 mutex_unlock(&root->log_mutex);
@@ -2534,8 +2529,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
2534 blk_finish_plug(&plug); 2529 blk_finish_plug(&plug);
2535 btrfs_abort_transaction(trans, root, ret); 2530 btrfs_abort_transaction(trans, root, ret);
2536 btrfs_free_logged_extents(log, log_transid); 2531 btrfs_free_logged_extents(log, log_transid);
2537 ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = 2532 btrfs_set_log_full_commit(root->fs_info, trans);
2538 trans->transid;
2539 mutex_unlock(&root->log_mutex); 2533 mutex_unlock(&root->log_mutex);
2540 goto out; 2534 goto out;
2541 } 2535 }
@@ -2578,8 +2572,8 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
2578 list_del_init(&root_log_ctx.list); 2572 list_del_init(&root_log_ctx.list);
2579 2573
2580 blk_finish_plug(&plug); 2574 blk_finish_plug(&plug);
2581 ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = 2575 btrfs_set_log_full_commit(root->fs_info, trans);
2582 trans->transid; 2576
2583 if (ret != -ENOSPC) { 2577 if (ret != -ENOSPC) {
2584 btrfs_abort_transaction(trans, root, ret); 2578 btrfs_abort_transaction(trans, root, ret);
2585 mutex_unlock(&log_root_tree->log_mutex); 2579 mutex_unlock(&log_root_tree->log_mutex);
@@ -2623,8 +2617,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
2623 * now that we've moved on to the tree of log tree roots, 2617 * now that we've moved on to the tree of log tree roots,
2624 * check the full commit flag again 2618 * check the full commit flag again
2625 */ 2619 */
2626 if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) == 2620 if (btrfs_need_log_full_commit(root->fs_info, trans)) {
2627 trans->transid) {
2628 blk_finish_plug(&plug); 2621 blk_finish_plug(&plug);
2629 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark); 2622 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
2630 btrfs_free_logged_extents(log, log_transid); 2623 btrfs_free_logged_extents(log, log_transid);
@@ -2638,8 +2631,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
2638 EXTENT_DIRTY | EXTENT_NEW); 2631 EXTENT_DIRTY | EXTENT_NEW);
2639 blk_finish_plug(&plug); 2632 blk_finish_plug(&plug);
2640 if (ret) { 2633 if (ret) {
2641 ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = 2634 btrfs_set_log_full_commit(root->fs_info, trans);
2642 trans->transid;
2643 btrfs_abort_transaction(trans, root, ret); 2635 btrfs_abort_transaction(trans, root, ret);
2644 btrfs_free_logged_extents(log, log_transid); 2636 btrfs_free_logged_extents(log, log_transid);
2645 mutex_unlock(&log_root_tree->log_mutex); 2637 mutex_unlock(&log_root_tree->log_mutex);
@@ -2668,8 +2660,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
2668 */ 2660 */
2669 ret = write_ctree_super(trans, root->fs_info->tree_root, 1); 2661 ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
2670 if (ret) { 2662 if (ret) {
2671 ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = 2663 btrfs_set_log_full_commit(root->fs_info, trans);
2672 trans->transid;
2673 btrfs_abort_transaction(trans, root, ret); 2664 btrfs_abort_transaction(trans, root, ret);
2674 goto out_wake_log_root; 2665 goto out_wake_log_root;
2675 } 2666 }
@@ -2887,7 +2878,7 @@ fail:
2887out_unlock: 2878out_unlock:
2888 mutex_unlock(&BTRFS_I(dir)->log_mutex); 2879 mutex_unlock(&BTRFS_I(dir)->log_mutex);
2889 if (ret == -ENOSPC) { 2880 if (ret == -ENOSPC) {
2890 root->fs_info->last_trans_log_full_commit = trans->transid; 2881 btrfs_set_log_full_commit(root->fs_info, trans);
2891 ret = 0; 2882 ret = 0;
2892 } else if (ret < 0) 2883 } else if (ret < 0)
2893 btrfs_abort_transaction(trans, root, ret); 2884 btrfs_abort_transaction(trans, root, ret);
@@ -2920,7 +2911,7 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
2920 dirid, &index); 2911 dirid, &index);
2921 mutex_unlock(&BTRFS_I(inode)->log_mutex); 2912 mutex_unlock(&BTRFS_I(inode)->log_mutex);
2922 if (ret == -ENOSPC) { 2913 if (ret == -ENOSPC) {
2923 root->fs_info->last_trans_log_full_commit = trans->transid; 2914 btrfs_set_log_full_commit(root->fs_info, trans);
2924 ret = 0; 2915 ret = 0;
2925 } else if (ret < 0 && ret != -ENOENT) 2916 } else if (ret < 0 && ret != -ENOENT)
2926 btrfs_abort_transaction(trans, root, ret); 2917 btrfs_abort_transaction(trans, root, ret);
@@ -4131,8 +4122,7 @@ static noinline int check_parent_dirs_for_sync(struct btrfs_trans_handle *trans,
4131 * make sure any commits to the log are forced 4122 * make sure any commits to the log are forced
4132 * to be full commits 4123 * to be full commits
4133 */ 4124 */
4134 root->fs_info->last_trans_log_full_commit = 4125 btrfs_set_log_full_commit(root->fs_info, trans);
4135 trans->transid;
4136 ret = 1; 4126 ret = 1;
4137 break; 4127 break;
4138 } 4128 }
@@ -4178,6 +4168,10 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
4178 goto end_no_trans; 4168 goto end_no_trans;
4179 } 4169 }
4180 4170
4171 /*
4172 * The prev transaction commit doesn't complete, we need do
4173 * full commit by ourselves.
4174 */
4181 if (root->fs_info->last_trans_log_full_commit > 4175 if (root->fs_info->last_trans_log_full_commit >
4182 root->fs_info->last_trans_committed) { 4176 root->fs_info->last_trans_committed) {
4183 ret = 1; 4177 ret = 1;
@@ -4247,7 +4241,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
4247end_trans: 4241end_trans:
4248 dput(old_parent); 4242 dput(old_parent);
4249 if (ret < 0) { 4243 if (ret < 0) {
4250 root->fs_info->last_trans_log_full_commit = trans->transid; 4244 btrfs_set_log_full_commit(root->fs_info, trans);
4251 ret = 1; 4245 ret = 1;
4252 } 4246 }
4253 4247