Skip to content

Commit afdb571

Browse files
jeffmahoneykdave
authored andcommitted
btrfs: simplify btrfs_wait_cache_io prototype
With the exception of the one case where btrfs_wait_cache_io is called without a block group, it's called with the same arguments. The root argument is only used in the special case, so let's factor out the core and simplify the call in the normal case to require a trans, block group, and path. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 71ff643 commit afdb571

3 files changed

Lines changed: 34 additions & 27 deletions

File tree

‎fs/btrfs/extent-tree.c‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3610,9 +3610,7 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans,
36103610
*/
36113611
if (!list_empty(&cache->io_list)) {
36123612
list_del_init(&cache->io_list);
3613-
btrfs_wait_cache_io(root, trans, cache,
3614-
&cache->io_ctl, path,
3615-
cache->key.objectid);
3613+
btrfs_wait_cache_io(trans, cache, path);
36163614
btrfs_put_block_group(cache);
36173615
}
36183616

@@ -3767,9 +3765,7 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
37673765
if (!list_empty(&cache->io_list)) {
37683766
spin_unlock(&cur_trans->dirty_bgs_lock);
37693767
list_del_init(&cache->io_list);
3770-
btrfs_wait_cache_io(root, trans, cache,
3771-
&cache->io_ctl, path,
3772-
cache->key.objectid);
3768+
btrfs_wait_cache_io(trans, cache, path);
37733769
btrfs_put_block_group(cache);
37743770
spin_lock(&cur_trans->dirty_bgs_lock);
37753771
}
@@ -3839,8 +3835,7 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
38393835
cache = list_first_entry(io, struct btrfs_block_group_cache,
38403836
io_list);
38413837
list_del_init(&cache->io_list);
3842-
btrfs_wait_cache_io(root, trans, cache,
3843-
&cache->io_ctl, path, cache->key.objectid);
3838+
btrfs_wait_cache_io(trans, cache, path);
38443839
btrfs_put_block_group(cache);
38453840
}
38463841

@@ -10383,9 +10378,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
1038310378
WARN_ON(!IS_ERR(inode) && inode != block_group->io_ctl.inode);
1038410379

1038510380
spin_unlock(&trans->transaction->dirty_bgs_lock);
10386-
btrfs_wait_cache_io(root, trans, block_group,
10387-
&block_group->io_ctl, path,
10388-
block_group->key.objectid);
10381+
btrfs_wait_cache_io(trans, block_group, path);
1038910382
btrfs_put_block_group(block_group);
1039010383
spin_lock(&trans->transaction->dirty_bgs_lock);
1039110384
}

‎fs/btrfs/free-space-cache.c‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ static int link_free_space(struct btrfs_free_space_ctl *ctl,
4242
struct btrfs_free_space *info);
4343
static void unlink_free_space(struct btrfs_free_space_ctl *ctl,
4444
struct btrfs_free_space *info);
45+
static int btrfs_wait_cache_io_root(struct btrfs_root *root,
46+
struct btrfs_trans_handle *trans,
47+
struct btrfs_io_ctl *io_ctl,
48+
struct btrfs_path *path);
4549

4650
static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
4751
struct btrfs_path *path,
@@ -244,9 +248,7 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root,
244248
if (!list_empty(&block_group->io_list)) {
245249
list_del_init(&block_group->io_list);
246250

247-
btrfs_wait_cache_io(root, trans, block_group,
248-
&block_group->io_ctl, path,
249-
block_group->key.objectid);
251+
btrfs_wait_cache_io(trans, block_group, path);
250252
btrfs_put_block_group(block_group);
251253
}
252254

@@ -1139,11 +1141,11 @@ cleanup_write_cache_enospc(struct inode *inode,
11391141
GFP_NOFS);
11401142
}
11411143

1142-
int btrfs_wait_cache_io(struct btrfs_root *root,
1143-
struct btrfs_trans_handle *trans,
1144-
struct btrfs_block_group_cache *block_group,
1145-
struct btrfs_io_ctl *io_ctl,
1146-
struct btrfs_path *path, u64 offset)
1144+
static int __btrfs_wait_cache_io(struct btrfs_root *root,
1145+
struct btrfs_trans_handle *trans,
1146+
struct btrfs_block_group_cache *block_group,
1147+
struct btrfs_io_ctl *io_ctl,
1148+
struct btrfs_path *path, u64 offset)
11471149
{
11481150
int ret;
11491151
struct inode *inode = io_ctl->inode;
@@ -1154,9 +1156,6 @@ int btrfs_wait_cache_io(struct btrfs_root *root,
11541156

11551157
fs_info = btrfs_sb(inode->i_sb);
11561158

1157-
if (block_group)
1158-
root = fs_info->tree_root;
1159-
11601159
/* Flush the dirty pages in the cache file. */
11611160
ret = flush_dirty_cache(inode);
11621161
if (ret)
@@ -1207,6 +1206,23 @@ int btrfs_wait_cache_io(struct btrfs_root *root,
12071206

12081207
}
12091208

1209+
static int btrfs_wait_cache_io_root(struct btrfs_root *root,
1210+
struct btrfs_trans_handle *trans,
1211+
struct btrfs_io_ctl *io_ctl,
1212+
struct btrfs_path *path)
1213+
{
1214+
return __btrfs_wait_cache_io(root, trans, NULL, io_ctl, path, 0);
1215+
}
1216+
1217+
int btrfs_wait_cache_io(struct btrfs_trans_handle *trans,
1218+
struct btrfs_block_group_cache *block_group,
1219+
struct btrfs_path *path)
1220+
{
1221+
return __btrfs_wait_cache_io(block_group->fs_info->tree_root, trans,
1222+
block_group, &block_group->io_ctl,
1223+
path, block_group->key.objectid);
1224+
}
1225+
12101226
/**
12111227
* __btrfs_write_out_cache - write out cached info to an inode
12121228
* @root - the root the inode belongs to
@@ -3541,7 +3557,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
35413557
* with or without an error.
35423558
*/
35433559
release_metadata = false;
3544-
ret = btrfs_wait_cache_io(root, trans, NULL, &io_ctl, path, 0);
3560+
ret = btrfs_wait_cache_io_root(root, trans, &io_ctl, path);
35453561
}
35463562

35473563
if (ret) {

‎fs/btrfs/free-space-cache.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root,
6767
struct inode *inode);
6868
int load_free_space_cache(struct btrfs_fs_info *fs_info,
6969
struct btrfs_block_group_cache *block_group);
70-
int btrfs_wait_cache_io(struct btrfs_root *root,
71-
struct btrfs_trans_handle *trans,
70+
int btrfs_wait_cache_io(struct btrfs_trans_handle *trans,
7271
struct btrfs_block_group_cache *block_group,
73-
struct btrfs_io_ctl *io_ctl,
74-
struct btrfs_path *path, u64 offset);
72+
struct btrfs_path *path);
7573
int btrfs_write_out_cache(struct btrfs_fs_info *fs_info,
7674
struct btrfs_trans_handle *trans,
7775
struct btrfs_block_group_cache *block_group,

0 commit comments

Comments
 (0)