Commit 995946dd authored by Miao Xie's avatar Miao Xie Committed by Chris Mason

Btrfs: use helpers for last_trans_log_full_commit instead of opencode

Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
Signed-off-by: default avatarWang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent 1f21ef0a
...@@ -26,10 +26,9 @@ ...@@ -26,10 +26,9 @@
#include <linux/ratelimit.h> #include <linux/ratelimit.h>
#include <linux/percpu_counter.h> #include <linux/percpu_counter.h>
#include "hash.h" #include "hash.h"
#include "ctree.h" #include "tree-log.h"
#include "disk-io.h" #include "disk-io.h"
#include "print-tree.h" #include "print-tree.h"
#include "transaction.h"
#include "volumes.h" #include "volumes.h"
#include "raid56.h" #include "raid56.h"
#include "locking.h" #include "locking.h"
...@@ -8714,7 +8713,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, ...@@ -8714,7 +8713,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
extent_root = root->fs_info->extent_root; extent_root = root->fs_info->extent_root;
root->fs_info->last_trans_log_full_commit = trans->transid; btrfs_set_log_full_commit(root->fs_info, trans);
cache = btrfs_create_block_group_cache(root, chunk_offset, size); cache = btrfs_create_block_group_cache(root, chunk_offset, size);
if (!cache) if (!cache)
......
...@@ -8329,7 +8329,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -8329,7 +8329,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
BTRFS_I(old_inode)->dir_index = 0ULL; BTRFS_I(old_inode)->dir_index = 0ULL;
if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) { if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) {
/* force full log commit if subvolume involved. */ /* force full log commit if subvolume involved. */
root->fs_info->last_trans_log_full_commit = trans->transid; btrfs_set_log_full_commit(root->fs_info, trans);
} else { } else {
ret = btrfs_insert_inode_ref(trans, dest, ret = btrfs_insert_inode_ref(trans, dest,
new_dentry->d_name.name, new_dentry->d_name.name,
......
...@@ -20,13 +20,11 @@ ...@@ -20,13 +20,11 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/list_sort.h> #include <linux/list_sort.h>
#include "ctree.h" #include "tree-log.h"
#include "transaction.h"
#include "disk-io.h" #include "disk-io.h"
#include "locking.h" #include "locking.h"
#include "print-tree.h" #include "print-tree.h"
#include "backref.h" #include "backref.h"
#include "tree-log.h"
#include "hash.h" #include "hash.h"
/* magic values for the inode_only field in btrfs_log_inode: /* 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,12 +142,10 @@ static int start_log_trans(struct btrfs_trans_handle *trans,
mutex_lock(&root->log_mutex); mutex_lock(&root->log_mutex);
if (root->log_root) { if (root->log_root) {
if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) == if (btrfs_need_log_full_commit(root->fs_info, trans)) {
trans->transid) {
ret = -EAGAIN; ret = -EAGAIN;
goto out; goto out;
} }
if (!root->log_start_pid) { if (!root->log_start_pid) {
root->log_start_pid = current->pid; root->log_start_pid = current->pid;
clear_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state); clear_bit(BTRFS_ROOT_MULTI_LOG_TASKS, &root->state);
...@@ -2512,8 +2508,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, ...@@ -2512,8 +2508,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
} }
/* bail out if we need to do a full commit */ /* bail out if we need to do a full commit */
if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) == if (btrfs_need_log_full_commit(root->fs_info, trans)) {
trans->transid) {
ret = -EAGAIN; ret = -EAGAIN;
btrfs_free_logged_extents(log, log_transid); btrfs_free_logged_extents(log, log_transid);
mutex_unlock(&root->log_mutex); mutex_unlock(&root->log_mutex);
...@@ -2534,8 +2529,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, ...@@ -2534,8 +2529,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
blk_finish_plug(&plug); blk_finish_plug(&plug);
btrfs_abort_transaction(trans, root, ret); btrfs_abort_transaction(trans, root, ret);
btrfs_free_logged_extents(log, log_transid); btrfs_free_logged_extents(log, log_transid);
ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = btrfs_set_log_full_commit(root->fs_info, trans);
trans->transid;
mutex_unlock(&root->log_mutex); mutex_unlock(&root->log_mutex);
goto out; goto out;
} }
...@@ -2578,8 +2572,8 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, ...@@ -2578,8 +2572,8 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
list_del_init(&root_log_ctx.list); list_del_init(&root_log_ctx.list);
blk_finish_plug(&plug); blk_finish_plug(&plug);
ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = btrfs_set_log_full_commit(root->fs_info, trans);
trans->transid;
if (ret != -ENOSPC) { if (ret != -ENOSPC) {
btrfs_abort_transaction(trans, root, ret); btrfs_abort_transaction(trans, root, ret);
mutex_unlock(&log_root_tree->log_mutex); mutex_unlock(&log_root_tree->log_mutex);
...@@ -2623,8 +2617,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, ...@@ -2623,8 +2617,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
* now that we've moved on to the tree of log tree roots, * now that we've moved on to the tree of log tree roots,
* check the full commit flag again * check the full commit flag again
*/ */
if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) == if (btrfs_need_log_full_commit(root->fs_info, trans)) {
trans->transid) {
blk_finish_plug(&plug); blk_finish_plug(&plug);
btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark); btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
btrfs_free_logged_extents(log, log_transid); btrfs_free_logged_extents(log, log_transid);
...@@ -2638,8 +2631,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, ...@@ -2638,8 +2631,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
EXTENT_DIRTY | EXTENT_NEW); EXTENT_DIRTY | EXTENT_NEW);
blk_finish_plug(&plug); blk_finish_plug(&plug);
if (ret) { if (ret) {
ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = btrfs_set_log_full_commit(root->fs_info, trans);
trans->transid;
btrfs_abort_transaction(trans, root, ret); btrfs_abort_transaction(trans, root, ret);
btrfs_free_logged_extents(log, log_transid); btrfs_free_logged_extents(log, log_transid);
mutex_unlock(&log_root_tree->log_mutex); mutex_unlock(&log_root_tree->log_mutex);
...@@ -2668,8 +2660,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, ...@@ -2668,8 +2660,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
*/ */
ret = write_ctree_super(trans, root->fs_info->tree_root, 1); ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
if (ret) { if (ret) {
ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) = btrfs_set_log_full_commit(root->fs_info, trans);
trans->transid;
btrfs_abort_transaction(trans, root, ret); btrfs_abort_transaction(trans, root, ret);
goto out_wake_log_root; goto out_wake_log_root;
} }
...@@ -2887,7 +2878,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, ...@@ -2887,7 +2878,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
out_unlock: out_unlock:
mutex_unlock(&BTRFS_I(dir)->log_mutex); mutex_unlock(&BTRFS_I(dir)->log_mutex);
if (ret == -ENOSPC) { if (ret == -ENOSPC) {
root->fs_info->last_trans_log_full_commit = trans->transid; btrfs_set_log_full_commit(root->fs_info, trans);
ret = 0; ret = 0;
} else if (ret < 0) } else if (ret < 0)
btrfs_abort_transaction(trans, root, ret); btrfs_abort_transaction(trans, root, ret);
...@@ -2920,7 +2911,7 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans, ...@@ -2920,7 +2911,7 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
dirid, &index); dirid, &index);
mutex_unlock(&BTRFS_I(inode)->log_mutex); mutex_unlock(&BTRFS_I(inode)->log_mutex);
if (ret == -ENOSPC) { if (ret == -ENOSPC) {
root->fs_info->last_trans_log_full_commit = trans->transid; btrfs_set_log_full_commit(root->fs_info, trans);
ret = 0; ret = 0;
} else if (ret < 0 && ret != -ENOENT) } else if (ret < 0 && ret != -ENOENT)
btrfs_abort_transaction(trans, root, ret); btrfs_abort_transaction(trans, root, ret);
...@@ -4131,8 +4122,7 @@ static noinline int check_parent_dirs_for_sync(struct btrfs_trans_handle *trans, ...@@ -4131,8 +4122,7 @@ static noinline int check_parent_dirs_for_sync(struct btrfs_trans_handle *trans,
* make sure any commits to the log are forced * make sure any commits to the log are forced
* to be full commits * to be full commits
*/ */
root->fs_info->last_trans_log_full_commit = btrfs_set_log_full_commit(root->fs_info, trans);
trans->transid;
ret = 1; ret = 1;
break; break;
} }
...@@ -4178,6 +4168,10 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, ...@@ -4178,6 +4168,10 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
goto end_no_trans; goto end_no_trans;
} }
/*
* The prev transaction commit doesn't complete, we need do
* full commit by ourselves.
*/
if (root->fs_info->last_trans_log_full_commit > if (root->fs_info->last_trans_log_full_commit >
root->fs_info->last_trans_committed) { root->fs_info->last_trans_committed) {
ret = 1; ret = 1;
...@@ -4247,7 +4241,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, ...@@ -4247,7 +4241,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
end_trans: end_trans:
dput(old_parent); dput(old_parent);
if (ret < 0) { if (ret < 0) {
root->fs_info->last_trans_log_full_commit = trans->transid; btrfs_set_log_full_commit(root->fs_info, trans);
ret = 1; ret = 1;
} }
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
#ifndef __TREE_LOG_ #ifndef __TREE_LOG_
#define __TREE_LOG_ #define __TREE_LOG_
#include "ctree.h"
#include "transaction.h"
/* return value for btrfs_log_dentry_safe that means we don't need to log it at all */ /* return value for btrfs_log_dentry_safe that means we don't need to log it at all */
#define BTRFS_NO_LOG_SYNC 256 #define BTRFS_NO_LOG_SYNC 256
...@@ -35,6 +38,19 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx) ...@@ -35,6 +38,19 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
INIT_LIST_HEAD(&ctx->list); INIT_LIST_HEAD(&ctx->list);
} }
static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
struct btrfs_trans_handle *trans)
{
ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
}
static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
struct btrfs_trans_handle *trans)
{
return ACCESS_ONCE(fs_info->last_trans_log_full_commit) ==
trans->transid;
}
int btrfs_sync_log(struct btrfs_trans_handle *trans, int btrfs_sync_log(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_log_ctx *ctx); struct btrfs_root *root, struct btrfs_log_ctx *ctx);
int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root); int btrfs_free_log(struct btrfs_trans_handle *trans, struct btrfs_root *root);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment