Skip to content

Commit 90d0451

Browse files
fdmananakdave
authored andcommitted
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: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2d81eb1 commit 90d0451

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

fs/btrfs/tree-log.c

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ enum {
9494
};
9595

9696
static int btrfs_log_inode(struct btrfs_trans_handle *trans,
97-
struct btrfs_root *root, struct btrfs_inode *inode,
97+
struct btrfs_inode *inode,
9898
int inode_only,
9999
struct btrfs_log_ctx *ctx);
100100
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,
36383638
* to replay anything deleted before the fsync
36393639
*/
36403640
static noinline int log_dir_items(struct btrfs_trans_handle *trans,
3641-
struct btrfs_root *root, struct btrfs_inode *inode,
3641+
struct btrfs_inode *inode,
36423642
struct btrfs_path *path,
36433643
struct btrfs_path *dst_path, int key_type,
36443644
struct btrfs_log_ctx *ctx,
36453645
u64 min_offset, u64 *last_offset_ret)
36463646
{
36473647
struct btrfs_key min_key;
3648+
struct btrfs_root *root = inode->root;
36483649
struct btrfs_root *log = root->log_root;
36493650
struct extent_buffer *src;
36503651
int err = 0;
@@ -3845,7 +3846,7 @@ static noinline int log_dir_items(struct btrfs_trans_handle *trans,
38453846
* key logged by this transaction.
38463847
*/
38473848
static noinline int log_directory_changes(struct btrfs_trans_handle *trans,
3848-
struct btrfs_root *root, struct btrfs_inode *inode,
3849+
struct btrfs_inode *inode,
38493850
struct btrfs_path *path,
38503851
struct btrfs_path *dst_path,
38513852
struct btrfs_log_ctx *ctx)
@@ -3859,7 +3860,7 @@ static noinline int log_directory_changes(struct btrfs_trans_handle *trans,
38593860
min_key = 0;
38603861
max_key = 0;
38613862
while (1) {
3862-
ret = log_dir_items(trans, root, inode, path, dst_path, key_type,
3863+
ret = log_dir_items(trans, inode, path, dst_path, key_type,
38633864
ctx, min_key, &max_key);
38643865
if (ret)
38653866
return ret;
@@ -4356,13 +4357,13 @@ static int log_extent_csums(struct btrfs_trans_handle *trans,
43564357
}
43574358

43584359
static int log_one_extent(struct btrfs_trans_handle *trans,
4359-
struct btrfs_inode *inode, struct btrfs_root *root,
4360+
struct btrfs_inode *inode,
43604361
const struct extent_map *em,
43614362
struct btrfs_path *path,
43624363
struct btrfs_log_ctx *ctx)
43634364
{
43644365
struct btrfs_drop_extents_args drop_args = { 0 };
4365-
struct btrfs_root *log = root->log_root;
4366+
struct btrfs_root *log = inode->root->log_root;
43664367
struct btrfs_file_extent_item *fi;
43674368
struct extent_buffer *leaf;
43684369
struct btrfs_map_token token;
@@ -4580,7 +4581,6 @@ static int btrfs_log_prealloc_extents(struct btrfs_trans_handle *trans,
45804581
}
45814582

45824583
static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans,
4583-
struct btrfs_root *root,
45844584
struct btrfs_inode *inode,
45854585
struct btrfs_path *path,
45864586
struct btrfs_log_ctx *ctx)
@@ -4645,7 +4645,7 @@ static int btrfs_log_changed_extents(struct btrfs_trans_handle *trans,
46454645

46464646
write_unlock(&tree->lock);
46474647

4648-
ret = log_one_extent(trans, inode, root, em, path, ctx);
4648+
ret = log_one_extent(trans, inode, em, path, ctx);
46494649
write_lock(&tree->lock);
46504650
clear_em_logging(tree, em);
46514651
free_extent_map(em);
@@ -4734,11 +4734,11 @@ static int logged_inode_size(struct btrfs_root *log, struct btrfs_inode *inode,
47344734
* with a journal, ext3/4, xfs, f2fs, etc).
47354735
*/
47364736
static int btrfs_log_all_xattrs(struct btrfs_trans_handle *trans,
4737-
struct btrfs_root *root,
47384737
struct btrfs_inode *inode,
47394738
struct btrfs_path *path,
47404739
struct btrfs_path *dst_path)
47414740
{
4741+
struct btrfs_root *root = inode->root;
47424742
int ret;
47434743
struct btrfs_key key;
47444744
const u64 ino = btrfs_ino(inode);
@@ -4812,10 +4812,10 @@ static int btrfs_log_all_xattrs(struct btrfs_trans_handle *trans,
48124812
* truncate operation that changes the inode's size.
48134813
*/
48144814
static int btrfs_log_holes(struct btrfs_trans_handle *trans,
4815-
struct btrfs_root *root,
48164815
struct btrfs_inode *inode,
48174816
struct btrfs_path *path)
48184817
{
4818+
struct btrfs_root *root = inode->root;
48194819
struct btrfs_fs_info *fs_info = root->fs_info;
48204820
struct btrfs_key key;
48214821
const u64 ino = btrfs_ino(inode);
@@ -5092,7 +5092,7 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans,
50925092
if (IS_ERR(inode)) {
50935093
ret = PTR_ERR(inode);
50945094
} else {
5095-
ret = btrfs_log_inode(trans, root,
5095+
ret = btrfs_log_inode(trans,
50965096
BTRFS_I(inode),
50975097
LOG_OTHER_INODE_ALL,
50985098
ctx);
@@ -5152,8 +5152,7 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans,
51525152
* well because during a rename we pin the log and update the
51535153
* log with the new name before we unpin it.
51545154
*/
5155-
ret = btrfs_log_inode(trans, root, BTRFS_I(inode),
5156-
LOG_OTHER_INODE, ctx);
5155+
ret = btrfs_log_inode(trans, BTRFS_I(inode), LOG_OTHER_INODE, ctx);
51575156
if (ret) {
51585157
btrfs_add_delayed_iput(inode);
51595158
continue;
@@ -5364,15 +5363,15 @@ static int copy_inode_items_to_log(struct btrfs_trans_handle *trans,
53645363
* This handles both files and directories.
53655364
*/
53665365
static int btrfs_log_inode(struct btrfs_trans_handle *trans,
5367-
struct btrfs_root *root, struct btrfs_inode *inode,
5366+
struct btrfs_inode *inode,
53685367
int inode_only,
53695368
struct btrfs_log_ctx *ctx)
53705369
{
53715370
struct btrfs_path *path;
53725371
struct btrfs_path *dst_path;
53735372
struct btrfs_key min_key;
53745373
struct btrfs_key max_key;
5375-
struct btrfs_root *log = root->log_root;
5374+
struct btrfs_root *log = inode->root->log_root;
53765375
int err = 0;
53775376
int ret = 0;
53785377
bool fast_search = false;
@@ -5522,14 +5521,14 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
55225521

55235522
btrfs_release_path(path);
55245523
btrfs_release_path(dst_path);
5525-
err = btrfs_log_all_xattrs(trans, root, inode, path, dst_path);
5524+
err = btrfs_log_all_xattrs(trans, inode, path, dst_path);
55265525
if (err)
55275526
goto out_unlock;
55285527
xattrs_logged = true;
55295528
if (max_key.type >= BTRFS_EXTENT_DATA_KEY && !fast_search) {
55305529
btrfs_release_path(path);
55315530
btrfs_release_path(dst_path);
5532-
err = btrfs_log_holes(trans, root, inode, path);
5531+
err = btrfs_log_holes(trans, inode, path);
55335532
if (err)
55345533
goto out_unlock;
55355534
}
@@ -5549,16 +5548,14 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
55495548
* BTRFS_INODE_COPY_EVERYTHING set.
55505549
*/
55515550
if (!xattrs_logged && inode->logged_trans < trans->transid) {
5552-
err = btrfs_log_all_xattrs(trans, root, inode, path,
5553-
dst_path);
5551+
err = btrfs_log_all_xattrs(trans, inode, path, dst_path);
55545552
if (err)
55555553
goto out_unlock;
55565554
btrfs_release_path(path);
55575555
}
55585556
}
55595557
if (fast_search) {
5560-
ret = btrfs_log_changed_extents(trans, root, inode, dst_path,
5561-
ctx);
5558+
ret = btrfs_log_changed_extents(trans, inode, dst_path, ctx);
55625559
if (ret) {
55635560
err = ret;
55645561
goto out_unlock;
@@ -5573,8 +5570,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans,
55735570
}
55745571

55755572
if (inode_only == LOG_INODE_ALL && S_ISDIR(inode->vfs_inode.i_mode)) {
5576-
ret = log_directory_changes(trans, root, inode, path, dst_path,
5577-
ctx);
5573+
ret = log_directory_changes(trans, inode, path, dst_path, ctx);
55785574
if (ret) {
55795575
err = ret;
55805576
goto out_unlock;
@@ -5803,7 +5799,7 @@ static int log_new_dir_dentries(struct btrfs_trans_handle *trans,
58035799
ctx->log_new_dentries = false;
58045800
if (type == BTRFS_FT_DIR || type == BTRFS_FT_SYMLINK)
58055801
log_mode = LOG_INODE_ALL;
5806-
ret = btrfs_log_inode(trans, root, BTRFS_I(di_inode),
5802+
ret = btrfs_log_inode(trans, BTRFS_I(di_inode),
58075803
log_mode, ctx);
58085804
btrfs_add_delayed_iput(di_inode);
58095805
if (ret)
@@ -5948,7 +5944,7 @@ static int btrfs_log_all_parents(struct btrfs_trans_handle *trans,
59485944
}
59495945

59505946
ctx->log_new_dentries = false;
5951-
ret = btrfs_log_inode(trans, root, BTRFS_I(dir_inode),
5947+
ret = btrfs_log_inode(trans, BTRFS_I(dir_inode),
59525948
LOG_INODE_ALL, ctx);
59535949
if (!ret && ctx->log_new_dentries)
59545950
ret = log_new_dir_dentries(trans, root,
@@ -5996,7 +5992,7 @@ static int log_new_ancestors(struct btrfs_trans_handle *trans,
59965992

59975993
if (BTRFS_I(inode)->generation >= trans->transid &&
59985994
need_log_inode(trans, BTRFS_I(inode)))
5999-
ret = btrfs_log_inode(trans, root, BTRFS_I(inode),
5995+
ret = btrfs_log_inode(trans, BTRFS_I(inode),
60005996
LOG_INODE_EXISTS, ctx);
60015997
btrfs_add_delayed_iput(inode);
60025998
if (ret)
@@ -6051,7 +6047,7 @@ static int log_new_ancestors_fast(struct btrfs_trans_handle *trans,
60516047

60526048
if (inode->generation >= trans->transid &&
60536049
need_log_inode(trans, inode)) {
6054-
ret = btrfs_log_inode(trans, root, inode,
6050+
ret = btrfs_log_inode(trans, inode,
60556051
LOG_INODE_EXISTS, ctx);
60566052
if (ret)
60576053
break;
@@ -6194,7 +6190,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
61946190
if (ret)
61956191
goto end_no_trans;
61966192

6197-
ret = btrfs_log_inode(trans, root, inode, inode_only, ctx);
6193+
ret = btrfs_log_inode(trans, inode, inode_only, ctx);
61986194
if (ret)
61996195
goto end_trans;
62006196

0 commit comments

Comments
 (0)