Skip to content

Commit 313ab75

Browse files
fdmananakdave
authored andcommitted
btrfs: add and use helper for unlinking inode during log replay
During log replay there is this pattern of running delayed items after every inode unlink. To avoid repeating this several times, move the logic into an helper function and use it instead of calling btrfs_unlink_inode() followed by btrfs_run_delayed_items(). Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 06bae87 commit 313ab75

1 file changed

Lines changed: 29 additions & 48 deletions

File tree

fs/btrfs/tree-log.c

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,26 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
899899
return ret;
900900
}
901901

902+
static int unlink_inode_for_log_replay(struct btrfs_trans_handle *trans,
903+
struct btrfs_inode *dir,
904+
struct btrfs_inode *inode,
905+
const char *name,
906+
int name_len)
907+
{
908+
int ret;
909+
910+
ret = btrfs_unlink_inode(trans, dir, inode, name, name_len);
911+
if (ret)
912+
return ret;
913+
/*
914+
* Whenever we need to check if a name exists or not, we check the
915+
* fs/subvolume tree. So after an unlink we must run delayed items, so
916+
* that future checks for a name during log replay see that the name
917+
* does not exists anymore.
918+
*/
919+
return btrfs_run_delayed_items(trans);
920+
}
921+
902922
/*
903923
* when cleaning up conflicts between the directory names in the
904924
* subvolume, directory names in the log and directory names in the
@@ -941,12 +961,8 @@ static noinline int drop_one_dir_item(struct btrfs_trans_handle *trans,
941961
if (ret)
942962
goto out;
943963

944-
ret = btrfs_unlink_inode(trans, dir, BTRFS_I(inode), name,
964+
ret = unlink_inode_for_log_replay(trans, dir, BTRFS_I(inode), name,
945965
name_len);
946-
if (ret)
947-
goto out;
948-
else
949-
ret = btrfs_run_delayed_items(trans);
950966
out:
951967
kfree(name);
952968
iput(inode);
@@ -1106,12 +1122,9 @@ static inline int __add_inode_ref(struct btrfs_trans_handle *trans,
11061122
inc_nlink(&inode->vfs_inode);
11071123
btrfs_release_path(path);
11081124

1109-
ret = btrfs_unlink_inode(trans, dir, inode,
1125+
ret = unlink_inode_for_log_replay(trans, dir, inode,
11101126
victim_name, victim_name_len);
11111127
kfree(victim_name);
1112-
if (ret)
1113-
return ret;
1114-
ret = btrfs_run_delayed_items(trans);
11151128
if (ret)
11161129
return ret;
11171130
*search_done = 1;
@@ -1178,14 +1191,11 @@ static inline int __add_inode_ref(struct btrfs_trans_handle *trans,
11781191
inc_nlink(&inode->vfs_inode);
11791192
btrfs_release_path(path);
11801193

1181-
ret = btrfs_unlink_inode(trans,
1194+
ret = unlink_inode_for_log_replay(trans,
11821195
BTRFS_I(victim_parent),
11831196
inode,
11841197
victim_name,
11851198
victim_name_len);
1186-
if (!ret)
1187-
ret = btrfs_run_delayed_items(
1188-
trans);
11891199
}
11901200
iput(victim_parent);
11911201
kfree(victim_name);
@@ -1340,19 +1350,10 @@ static int unlink_old_inode_refs(struct btrfs_trans_handle *trans,
13401350
kfree(name);
13411351
goto out;
13421352
}
1343-
ret = btrfs_unlink_inode(trans, BTRFS_I(dir),
1353+
ret = unlink_inode_for_log_replay(trans, BTRFS_I(dir),
13441354
inode, name, namelen);
13451355
kfree(name);
13461356
iput(dir);
1347-
/*
1348-
* Whenever we need to check if a name exists or not, we
1349-
* check the subvolume tree. So after an unlink we must
1350-
* run delayed items, so that future checks for a name
1351-
* during log replay see that the name does not exists
1352-
* anymore.
1353-
*/
1354-
if (!ret)
1355-
ret = btrfs_run_delayed_items(trans);
13561357
if (ret)
13571358
goto out;
13581359
goto again;
@@ -1448,8 +1449,8 @@ static int add_link(struct btrfs_trans_handle *trans,
14481449
ret = -ENOENT;
14491450
goto out;
14501451
}
1451-
ret = btrfs_unlink_inode(trans, BTRFS_I(dir), BTRFS_I(other_inode),
1452-
name, namelen);
1452+
ret = unlink_inode_for_log_replay(trans, BTRFS_I(dir), BTRFS_I(other_inode),
1453+
name, namelen);
14531454
if (ret)
14541455
goto out;
14551456
/*
@@ -1458,10 +1459,6 @@ static int add_link(struct btrfs_trans_handle *trans,
14581459
*/
14591460
if (other_inode->i_nlink == 0)
14601461
inc_nlink(other_inode);
1461-
1462-
ret = btrfs_run_delayed_items(trans);
1463-
if (ret)
1464-
goto out;
14651462
add_link:
14661463
ret = btrfs_add_link(trans, BTRFS_I(dir), BTRFS_I(inode),
14671464
name, namelen, 0, ref_index);
@@ -1594,7 +1591,7 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
15941591
ret = btrfs_inode_ref_exists(inode, dir, key->type,
15951592
name, namelen);
15961593
if (ret > 0) {
1597-
ret = btrfs_unlink_inode(trans,
1594+
ret = unlink_inode_for_log_replay(trans,
15981595
BTRFS_I(dir),
15991596
BTRFS_I(inode),
16001597
name, namelen);
@@ -1605,15 +1602,6 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
16051602
*/
16061603
if (!ret && inode->i_nlink == 0)
16071604
inc_nlink(inode);
1608-
/*
1609-
* Whenever we need to check if a name exists or
1610-
* not, we check the subvolume tree. So after an
1611-
* unlink we must run delayed items, so that future
1612-
* checks for a name during log replay see that the
1613-
* name does not exists anymore.
1614-
*/
1615-
if (!ret)
1616-
ret = btrfs_run_delayed_items(trans);
16171605
}
16181606
if (ret < 0)
16191607
goto out;
@@ -2350,15 +2338,8 @@ static noinline int check_item_in_log(struct btrfs_trans_handle *trans,
23502338
goto out;
23512339

23522340
inc_nlink(inode);
2353-
ret = btrfs_unlink_inode(trans, BTRFS_I(dir), BTRFS_I(inode), name,
2354-
name_len);
2355-
if (ret)
2356-
goto out;
2357-
2358-
ret = btrfs_run_delayed_items(trans);
2359-
if (ret)
2360-
goto out;
2361-
2341+
ret = unlink_inode_for_log_replay(trans, BTRFS_I(dir), BTRFS_I(inode),
2342+
name, name_len);
23622343
/*
23632344
* Unlike dir item keys, dir index keys can only have one name (entry) in
23642345
* them, as there are no key collisions since each key has a unique offset

0 commit comments

Comments
 (0)