aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2014-04-02 07:51:06 -0400
committerChris Mason <clm@fb.com>2014-06-09 20:20:45 -0400
commit995946dd2961776bb45e653810ae96643fbf4ce8 (patch)
tree98b3e1b9fd72ccdca5a6fe540cf421a58692deba /fs/btrfs
parent1f21ef0a34c37de0daf66fce7141b23b88630f29 (diff)
Btrfs: use helpers for last_trans_log_full_commit instead of opencode
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/extent-tree.c5
-rw-r--r--fs/btrfs/inode.c2
-rw-r--r--fs/btrfs/tree-log.c40
-rw-r--r--fs/btrfs/tree-log.h16
4 files changed, 36 insertions, 27 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 7c18566fd2b4..203d9a5a4030 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -26,10 +26,9 @@
26#include <linux/ratelimit.h> 26#include <linux/ratelimit.h>
27#include <linux/percpu_counter.h> 27#include <linux/percpu_counter.h>
28#include "hash.h" 28#include "hash.h"
29#include "ctree.h" 29#include "tree-log.h"
30#include "disk-io.h" 30#include "disk-io.h"
31#include "print-tree.h" 31#include "print-tree.h"
32#include "transaction.h"
33#include "volumes.h" 32#include "volumes.h"
34#include "raid56.h" 33#include "raid56.h"
35#include "locking.h" 34#include "locking.h"
@@ -8714,7 +8713,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
8714 8713
8715 extent_root = root->fs_info->extent_root; 8714 extent_root = root->fs_info->extent_root;
8716 8715
8717 root->fs_info->last_trans_log_full_commit = trans->transid; 8716 btrfs_set_log_full_commit(root->fs_info, trans);
8718 8717
8719 cache = btrfs_create_block_group_cache(root, chunk_offset, size); 8718 cache = btrfs_create_block_group_cache(root, chunk_offset, size);
8720 if (!cache) 8719 if (!cache)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index ef3bd3deca12..95ac6b4f2390 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8329,7 +8329,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
8329 BTRFS_I(old_inode)->dir_index = 0ULL; 8329 BTRFS_I(old_inode)->dir_index = 0ULL;
8330 if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) { 8330 if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) {
8331 /* force full log commit if subvolume involved. */ 8331 /* force full log commit if subvolume involved. */
8332 root->fs_info->last_trans_log_full_commit = trans->transid; 8332 btrfs_set_log_full_commit(root->fs_info, trans);
8333 } else { 8333 } else {
8334 ret = btrfs_insert_inode_ref(trans, dest, 8334 ret = btrfs_insert_inode_ref(trans, dest,
8335 new_dentry->d_name.name, 8335 new_dentry->d_name.name,
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
diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
index 91b145fce333..7f5b41bd5373 100644
--- a/fs/btrfs/tree-log.h
+++ b/fs/btrfs/tree-log.h
@@ -19,6 +19,9 @@
19#ifndef __TREE_LOG_ 19#ifndef __TREE_LOG_
20#define __TREE_LOG_ 20#define __TREE_LOG_
21 21
22#include "ctree.h"
23#include "transaction.h"
24
22/* return value for btrfs_log_dentry_safe that means we don't need to log it at all */ 25/* return value for btrfs_log_dentry_safe that means we don't need to log it at all */
23#define BTRFS_NO_LOG_SYNC 256 26#define BTRFS_NO_LOG_SYNC 256
24 27
@@ -35,6 +38,19 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
35 INIT_LIST_HEAD(&ctx->list); 38 INIT_LIST_HEAD(&ctx->list);
36} 39}
37 40
41static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
42 struct btrfs_trans_handle *trans)
43{
44 ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
45}
46
47static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
48 struct btrfs_trans_handle *trans)
49{
50 return ACCESS_ONCE(fs_info->last_trans_log_full_commit) ==
51 trans->transid;
52}
53
38int btrfs_sync_log(struct btrfs_trans_handle *trans, 54int btrfs_sync_log(struct btrfs_trans_handle *trans,
39 struct btrfs_root *root, struct btrfs_log_ctx *ctx); 55 struct btrfs_root *root, struct btrfs_log_ctx *ctx);
40int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root); 56int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root);