Commit 90d04510 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: remove root argument from btrfs_log_inode() and its callees

The root argument passed to btrfs_log_inode() is unncessary, as it is
always the root of the inode we are going to log. This root also gets
unnecessarily propagated to several functions called by btrfs_log_inode(),
and all of them take the inode as an argument as well. So just remove
the root argument from these functions and have them get the root from
the inode where needed.

This patch is part of a patchset comprised of the following 5 patches:

  btrfs: remove root argument from btrfs_log_inode() and its callees
  btrfs: remove redundant log root assignment from log_dir_items()
  btrfs: factor out the copying loop of dir items from log_dir_items()
  btrfs: insert items in batches when logging a directory when possible
  btrfs: keep track of the last logged keys when logging a directory

This is patch 1/5. The change log of the last patch (5/5) has performance
results.
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 2d81eb1c
...@@ -94,7 +94,7 @@ enum { ...@@ -94,7 +94,7 @@ enum {
}; };
static int btrfs_log_inode(struct btrfs_trans_handle *trans, static int btrfs_log_inode(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_inode *inode, struct btrfs_inode *inode,
int inode_only, int inode_only,
struct btrfs_log_ctx *ctx); struct btrfs_log_ctx *ctx);
static int link_to_fixup_dir(struct btrfs_trans_handle *trans, static int link_to_fixup_dir(struct btrfs_trans_handle *trans,
...@@ -3638,13 +3638,14 @@ static noinline int insert_dir_log_key(struct btrfs_trans_handle *trans, ...@@ -3638,13 +3638,14 @@ static noinline int insert_dir_log_key(struct btrfs_trans_handle *trans,
* to replay anything deleted before the fsync * to replay anything deleted before the fsync
*/ */
static noinline int log_dir_items(struct btrfs_trans_handle *trans, static noinline int log_dir_items(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_inode *inode, struct btrfs_inode *inode,
struct btrfs_path *path, struct btrfs_path *path,
struct btrfs_path *dst_path, int key_type, struct btrfs_path *dst_path, int key_type,
struct btrfs_log_ctx *ctx, struct btrfs_log_ctx *ctx,
u64 min_offset, u64 *last_offset_ret) u64 min_offset, u64 *last_offset_ret)
{ {
struct btrfs_key min_key; struct btrfs_key min_key;
struct btrfs_root *root = inode->root;
struct btrfs_root *log = root->log_root; struct btrfs_root *log = root->log_root;
struct extent_buffer *src; struct extent_buffer *src;
int err = 0; int err = 0;
...@@ -3845,7 +3846,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans, ...@@ -3845,7 +3846,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
* key logged by this transaction. * key logged by this transaction.
*/ */
static noinline int log_directory_changes(struct btrfs_trans_handle *trans, static noinline int log_directory_changes(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_inode *inode, struct btrfs_inode *inode,
struct btrfs_path *path, struct btrfs_path *path,
struct btrfs_path *dst_path, struct btrfs_path *dst_path,
struct btrfs_log_ctx *ctx) struct btrfs_log_ctx *ctx)
...@@ -3859,7 +3860,7 @@ static noinline int log_directory_changes(struct btrfs_trans_handle *trans, ...@@ -3859,7 +3860,7 @@ static noinline int log_directory_changes(struct btrfs_trans_handle *trans,
min_key = 0; min_key = 0;
max_key = 0; max_key = 0;
while (1) { while (1) {
ret = log_dir_items(trans, root, inode, path, dst_path, key_type, ret = log_dir_items(trans, inode, path, dst_path, key_type,
ctx, min_key, &max_key); ctx, min_key, &max_key);
if (ret) if (ret)
return ret; return ret;
...@@ -4356,13 +4357,13 @@ static int log_extent_csums(struct btrfs_trans_handle *trans, ...@@ -4356,13 +4357,13 @@ static int log_extent_csums(struct btrfs_trans_handle *trans,
} }
static int log_one_extent(struct btrfs_trans_handle *trans, static int log_one_extent(struct btrfs_trans_handle *trans,
struct btrfs_inode *inode, struct btrfs_root *root, struct btrfs_inode *inode,
const struct extent_map *em, const struct extent_map *em,
struct btrfs_path *path, struct btrfs_path *path,
struct btrfs_log_ctx *ctx) struct btrfs_log_ctx *ctx)
{ {
struct btrfs_drop_extents_args drop_args = { 0 }; struct btrfs_drop_extents_args drop_args = { 0 };
struct btrfs_root *log = root->log_root; struct btrfs_root *log = inode->root->log_root;
struct btrfs_file_extent_item *fi; struct btrfs_file_extent_item *fi;
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_map_token token; struct btrfs_map_token token;
...@@ -4580,7 +4581,6 @@ static int btrfs_log_prealloc_extents(struct btrfs_trans_handle *trans, ...@@ -4580,7 +4581,6 @@ static int btrfs_log_prealloc_extents(struct btrfs_trans_handle *trans,
} }
static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans, static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_inode *inode, struct btrfs_inode *inode,
struct btrfs_path *path, struct btrfs_path *path,
struct btrfs_log_ctx *ctx) struct btrfs_log_ctx *ctx)
...@@ -4645,7 +4645,7 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans, ...@@ -4645,7 +4645,7 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans,
write_unlock(&tree->lock); write_unlock(&tree->lock);
ret = log_one_extent(trans, inode, root, em, path, ctx); ret = log_one_extent(trans, inode, em, path, ctx);
write_lock(&tree->lock); write_lock(&tree->lock);
clear_em_logging(tree, em); clear_em_logging(tree, em);
free_extent_map(em); free_extent_map(em);
...@@ -4734,11 +4734,11 @@ static int logged_inode_size(struct btrfs_root *log, struct btrfs_inode *inode, ...@@ -4734,11 +4734,11 @@ static int logged_inode_size(struct btrfs_root *log, struct btrfs_inode *inode,
* with a journal, ext3/4, xfs, f2fs, etc). * with a journal, ext3/4, xfs, f2fs, etc).
*/ */
static int btrfs_log_all_xattrs(struct btrfs_trans_handle *trans, static int btrfs_log_all_xattrs(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_inode *inode, struct btrfs_inode *inode,
struct btrfs_path *path, struct btrfs_path *path,
struct btrfs_path *dst_path) struct btrfs_path *dst_path)
{ {
struct btrfs_root *root = inode->root;
int ret; int ret;
struct btrfs_key key; struct btrfs_key key;
const u64 ino = btrfs_ino(inode); const u64 ino = btrfs_ino(inode);
...@@ -4812,10 +4812,10 @@ static int btrfs_log_all_xattrs(struct btrfs_trans_handle *trans, ...@@ -4812,10 +4812,10 @@ static int btrfs_log_all_xattrs(struct btrfs_trans_handle *trans,
* truncate operation that changes the inode's size. * truncate operation that changes the inode's size.
*/ */
static int btrfs_log_holes(struct btrfs_trans_handle *trans, static int btrfs_log_holes(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_inode *inode, struct btrfs_inode *inode,
struct btrfs_path *path) struct btrfs_path *path)
{ {
struct btrfs_root *root = inode->root;
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_key key; struct btrfs_key key;
const u64 ino = btrfs_ino(inode); const u64 ino = btrfs_ino(inode);
...@@ -5092,7 +5092,7 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans, ...@@ -5092,7 +5092,7 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans,
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
ret = PTR_ERR(inode); ret = PTR_ERR(inode);
} else { } else {
ret = btrfs_log_inode(trans, root, ret = btrfs_log_inode(trans,
BTRFS_I(inode), BTRFS_I(inode),
LOG_OTHER_INODE_ALL, LOG_OTHER_INODE_ALL,
ctx); ctx);
...@@ -5152,8 +5152,7 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans, ...@@ -5152,8 +5152,7 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans,
* well because during a rename we pin the log and update the * well because during a rename we pin the log and update the
* log with the new name before we unpin it. * log with the new name before we unpin it.
*/ */
ret = btrfs_log_inode(trans, root, BTRFS_I(inode), ret = btrfs_log_inode(trans, BTRFS_I(inode), LOG_OTHER_INODE, ctx);
LOG_OTHER_INODE, ctx);
if (ret) { if (ret) {
btrfs_add_delayed_iput(inode); btrfs_add_delayed_iput(inode);
continue; continue;
...@@ -5364,7 +5363,7 @@ static int copy_inode_items_to_log(struct btrfs_trans_handle *trans, ...@@ -5364,7 +5363,7 @@ static int copy_inode_items_to_log(struct btrfs_trans_handle *trans,
* This handles both files and directories. * This handles both files and directories.
*/ */
static int btrfs_log_inode(struct btrfs_trans_handle *trans, static int btrfs_log_inode(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_inode *inode, struct btrfs_inode *inode,
int inode_only, int inode_only,
struct btrfs_log_ctx *ctx) struct btrfs_log_ctx *ctx)
{ {
...@@ -5372,7 +5371,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, ...@@ -5372,7 +5371,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
struct btrfs_path *dst_path; struct btrfs_path *dst_path;
struct btrfs_key min_key; struct btrfs_key min_key;
struct btrfs_key max_key; struct btrfs_key max_key;
struct btrfs_root *log = root->log_root; struct btrfs_root *log = inode->root->log_root;
int err = 0; int err = 0;
int ret = 0; int ret = 0;
bool fast_search = false; bool fast_search = false;
...@@ -5522,14 +5521,14 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, ...@@ -5522,14 +5521,14 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
btrfs_release_path(path); btrfs_release_path(path);
btrfs_release_path(dst_path); btrfs_release_path(dst_path);
err = btrfs_log_all_xattrs(trans, root, inode, path, dst_path); err = btrfs_log_all_xattrs(trans, inode, path, dst_path);
if (err) if (err)
goto out_unlock; goto out_unlock;
xattrs_logged = true; xattrs_logged = true;
if (max_key.type >= BTRFS_EXTENT_DATA_KEY && !fast_search) { if (max_key.type >= BTRFS_EXTENT_DATA_KEY && !fast_search) {
btrfs_release_path(path); btrfs_release_path(path);
btrfs_release_path(dst_path); btrfs_release_path(dst_path);
err = btrfs_log_holes(trans, root, inode, path); err = btrfs_log_holes(trans, inode, path);
if (err) if (err)
goto out_unlock; goto out_unlock;
} }
...@@ -5549,16 +5548,14 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, ...@@ -5549,16 +5548,14 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
* BTRFS_INODE_COPY_EVERYTHING set. * BTRFS_INODE_COPY_EVERYTHING set.
*/ */
if (!xattrs_logged && inode->logged_trans < trans->transid) { if (!xattrs_logged && inode->logged_trans < trans->transid) {
err = btrfs_log_all_xattrs(trans, root, inode, path, err = btrfs_log_all_xattrs(trans, inode, path, dst_path);
dst_path);
if (err) if (err)
goto out_unlock; goto out_unlock;
btrfs_release_path(path); btrfs_release_path(path);
} }
} }
if (fast_search) { if (fast_search) {
ret = btrfs_log_changed_extents(trans, root, inode, dst_path, ret = btrfs_log_changed_extents(trans, inode, dst_path, ctx);
ctx);
if (ret) { if (ret) {
err = ret; err = ret;
goto out_unlock; goto out_unlock;
...@@ -5573,8 +5570,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, ...@@ -5573,8 +5570,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
} }
if (inode_only == LOG_INODE_ALL && S_ISDIR(inode->vfs_inode.i_mode)) { if (inode_only == LOG_INODE_ALL && S_ISDIR(inode->vfs_inode.i_mode)) {
ret = log_directory_changes(trans, root, inode, path, dst_path, ret = log_directory_changes(trans, inode, path, dst_path, ctx);
ctx);
if (ret) { if (ret) {
err = ret; err = ret;
goto out_unlock; goto out_unlock;
...@@ -5803,7 +5799,7 @@ static int log_new_dir_dentries(struct btrfs_trans_handle *trans, ...@@ -5803,7 +5799,7 @@ static int log_new_dir_dentries(struct btrfs_trans_handle *trans,
ctx->log_new_dentries = false; ctx->log_new_dentries = false;
if (type == BTRFS_FT_DIR || type == BTRFS_FT_SYMLINK) if (type == BTRFS_FT_DIR || type == BTRFS_FT_SYMLINK)
log_mode = LOG_INODE_ALL; log_mode = LOG_INODE_ALL;
ret = btrfs_log_inode(trans, root, BTRFS_I(di_inode), ret = btrfs_log_inode(trans, BTRFS_I(di_inode),
log_mode, ctx); log_mode, ctx);
btrfs_add_delayed_iput(di_inode); btrfs_add_delayed_iput(di_inode);
if (ret) if (ret)
...@@ -5948,7 +5944,7 @@ static int btrfs_log_all_parents(struct btrfs_trans_handle *trans, ...@@ -5948,7 +5944,7 @@ static int btrfs_log_all_parents(struct btrfs_trans_handle *trans,
} }
ctx->log_new_dentries = false; ctx->log_new_dentries = false;
ret = btrfs_log_inode(trans, root, BTRFS_I(dir_inode), ret = btrfs_log_inode(trans, BTRFS_I(dir_inode),
LOG_INODE_ALL, ctx); LOG_INODE_ALL, ctx);
if (!ret && ctx->log_new_dentries) if (!ret && ctx->log_new_dentries)
ret = log_new_dir_dentries(trans, root, ret = log_new_dir_dentries(trans, root,
...@@ -5996,7 +5992,7 @@ static int log_new_ancestors(struct btrfs_trans_handle *trans, ...@@ -5996,7 +5992,7 @@ static int log_new_ancestors(struct btrfs_trans_handle *trans,
if (BTRFS_I(inode)->generation >= trans->transid && if (BTRFS_I(inode)->generation >= trans->transid &&
need_log_inode(trans, BTRFS_I(inode))) need_log_inode(trans, BTRFS_I(inode)))
ret = btrfs_log_inode(trans, root, BTRFS_I(inode), ret = btrfs_log_inode(trans, BTRFS_I(inode),
LOG_INODE_EXISTS, ctx); LOG_INODE_EXISTS, ctx);
btrfs_add_delayed_iput(inode); btrfs_add_delayed_iput(inode);
if (ret) if (ret)
...@@ -6051,7 +6047,7 @@ static int log_new_ancestors_fast(struct btrfs_trans_handle *trans, ...@@ -6051,7 +6047,7 @@ static int log_new_ancestors_fast(struct btrfs_trans_handle *trans,
if (inode->generation >= trans->transid && if (inode->generation >= trans->transid &&
need_log_inode(trans, inode)) { need_log_inode(trans, inode)) {
ret = btrfs_log_inode(trans, root, inode, ret = btrfs_log_inode(trans, inode,
LOG_INODE_EXISTS, ctx); LOG_INODE_EXISTS, ctx);
if (ret) if (ret)
break; break;
...@@ -6194,7 +6190,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, ...@@ -6194,7 +6190,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
if (ret) if (ret)
goto end_no_trans; goto end_no_trans;
ret = btrfs_log_inode(trans, root, inode, inode_only, ctx); ret = btrfs_log_inode(trans, inode, inode_only, ctx);
if (ret) if (ret)
goto end_trans; goto end_trans;
......
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