Skip to content

Commit 995946d

Browse files
Miao Xiemasoncl
authored andcommitted
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>
1 parent 1f21ef0 commit 995946d

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

fs/btrfs/extent-tree.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
#include <linux/ratelimit.h>
2727
#include <linux/percpu_counter.h>
2828
#include "hash.h"
29-
#include "ctree.h"
29+
#include "tree-log.h"
3030
#include "disk-io.h"
3131
#include "print-tree.h"
32-
#include "transaction.h"
3332
#include "volumes.h"
3433
#include "raid56.h"
3534
#include "locking.h"
@@ -8714,7 +8713,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
87148713

87158714
extent_root = root->fs_info->extent_root;
87168715

8717-
root->fs_info->last_trans_log_full_commit = trans->transid;
8716+
btrfs_set_log_full_commit(root->fs_info, trans);
87188717

87198718
cache = btrfs_create_block_group_cache(root, chunk_offset, size);
87208719
if (!cache)

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8329,7 +8329,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
83298329
BTRFS_I(old_inode)->dir_index = 0ULL;
83308330
if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) {
83318331
/* 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);
83338333
} else {
83348334
ret = btrfs_insert_inode_ref(trans, dest,
83358335
new_dentry->d_name.name,

fs/btrfs/tree-log.c

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
#include <linux/slab.h>
2121
#include <linux/blkdev.h>
2222
#include <linux/list_sort.h>
23-
#include "ctree.h"
24-
#include "transaction.h"
23+
#include "tree-log.h"
2524
#include "disk-io.h"
2625
#include "locking.h"
2726
#include "print-tree.h"
2827
#include "backref.h"
29-
#include "tree-log.h"
3028
#include "hash.h"
3129

3230
/* 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,
144142

145143
mutex_lock(&root->log_mutex);
146144
if (root->log_root) {
147-
if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
148-
trans->transid) {
145+
if (btrfs_need_log_full_commit(root->fs_info, trans)) {
149146
ret = -EAGAIN;
150147
goto out;
151148
}
152-
153149
if (!root->log_start_pid) {
154150
root->log_start_pid = current->pid;
155151
clear_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state);
@@ -2512,8 +2508,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
25122508
}
25132509

25142510
/* bail out if we need to do a full commit */
2515-
if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
2516-
trans->transid) {
2511+
if (btrfs_need_log_full_commit(root->fs_info, trans)) {
25172512
ret = -EAGAIN;
25182513
btrfs_free_logged_extents(log, log_transid);
25192514
mutex_unlock(&root->log_mutex);
@@ -2534,8 +2529,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
25342529
blk_finish_plug(&plug);
25352530
btrfs_abort_transaction(trans, root, ret);
25362531
btrfs_free_logged_extents(log, log_transid);
2537-
ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
2538-
trans->transid;
2532+
btrfs_set_log_full_commit(root->fs_info, trans);
25392533
mutex_unlock(&root->log_mutex);
25402534
goto out;
25412535
}
@@ -2578,8 +2572,8 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
25782572
list_del_init(&root_log_ctx.list);
25792573

25802574
blk_finish_plug(&plug);
2581-
ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
2582-
trans->transid;
2575+
btrfs_set_log_full_commit(root->fs_info, trans);
2576+
25832577
if (ret != -ENOSPC) {
25842578
btrfs_abort_transaction(trans, root, ret);
25852579
mutex_unlock(&log_root_tree->log_mutex);
@@ -2623,8 +2617,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
26232617
* now that we've moved on to the tree of log tree roots,
26242618
* check the full commit flag again
26252619
*/
2626-
if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
2627-
trans->transid) {
2620+
if (btrfs_need_log_full_commit(root->fs_info, trans)) {
26282621
blk_finish_plug(&plug);
26292622
btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
26302623
btrfs_free_logged_extents(log, log_transid);
@@ -2638,8 +2631,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
26382631
EXTENT_DIRTY | EXTENT_NEW);
26392632
blk_finish_plug(&plug);
26402633
if (ret) {
2641-
ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
2642-
trans->transid;
2634+
btrfs_set_log_full_commit(root->fs_info, trans);
26432635
btrfs_abort_transaction(trans, root, ret);
26442636
btrfs_free_logged_extents(log, log_transid);
26452637
mutex_unlock(&log_root_tree->log_mutex);
@@ -2668,8 +2660,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
26682660
*/
26692661
ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
26702662
if (ret) {
2671-
ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
2672-
trans->transid;
2663+
btrfs_set_log_full_commit(root->fs_info, trans);
26732664
btrfs_abort_transaction(trans, root, ret);
26742665
goto out_wake_log_root;
26752666
}
@@ -2887,7 +2878,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
28872878
out_unlock:
28882879
mutex_unlock(&BTRFS_I(dir)->log_mutex);
28892880
if (ret == -ENOSPC) {
2890-
root->fs_info->last_trans_log_full_commit = trans->transid;
2881+
btrfs_set_log_full_commit(root->fs_info, trans);
28912882
ret = 0;
28922883
} else if (ret < 0)
28932884
btrfs_abort_transaction(trans, root, ret);
@@ -2920,7 +2911,7 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
29202911
dirid, &index);
29212912
mutex_unlock(&BTRFS_I(inode)->log_mutex);
29222913
if (ret == -ENOSPC) {
2923-
root->fs_info->last_trans_log_full_commit = trans->transid;
2914+
btrfs_set_log_full_commit(root->fs_info, trans);
29242915
ret = 0;
29252916
} else if (ret < 0 && ret != -ENOENT)
29262917
btrfs_abort_transaction(trans, root, ret);
@@ -4131,8 +4122,7 @@ static noinline int check_parent_dirs_for_sync(struct btrfs_trans_handle *trans,
41314122
* make sure any commits to the log are forced
41324123
* to be full commits
41334124
*/
4134-
root->fs_info->last_trans_log_full_commit =
4135-
trans->transid;
4125+
btrfs_set_log_full_commit(root->fs_info, trans);
41364126
ret = 1;
41374127
break;
41384128
}
@@ -4178,6 +4168,10 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
41784168
goto end_no_trans;
41794169
}
41804170

4171+
/*
4172+
* The prev transaction commit doesn't complete, we need do
4173+
* full commit by ourselves.
4174+
*/
41814175
if (root->fs_info->last_trans_log_full_commit >
41824176
root->fs_info->last_trans_committed) {
41834177
ret = 1;
@@ -4247,7 +4241,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
42474241
end_trans:
42484242
dput(old_parent);
42494243
if (ret < 0) {
4250-
root->fs_info->last_trans_log_full_commit = trans->transid;
4244+
btrfs_set_log_full_commit(root->fs_info, trans);
42514245
ret = 1;
42524246
}
42534247

fs/btrfs/tree-log.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#ifndef __TREE_LOG_
2020
#define __TREE_LOG_
2121

22+
#include "ctree.h"
23+
#include "transaction.h"
24+
2225
/* return value for btrfs_log_dentry_safe that means we don't need to log it at all */
2326
#define BTRFS_NO_LOG_SYNC 256
2427

@@ -35,6 +38,19 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
3538
INIT_LIST_HEAD(&ctx->list);
3639
}
3740

41+
static 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+
47+
static 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+
3854
int btrfs_sync_log(struct btrfs_trans_handle *trans,
3955
struct btrfs_root *root, struct btrfs_log_ctx *ctx);
4056
int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root);

0 commit comments

Comments
 (0)