Commit 77ab86bf authored by Jeff Mahoney's avatar Jeff Mahoney Committed by David Sterba

btrfs: free-space-cache, clean up unnecessary root arguments

The free space cache APIs accept a root but always use the tree root.

Also, btrfs_truncate_free_space_cache accepts a root AND an inode but
the inode always points to the root anyway, so let's just pass the inode.
Signed-off-by: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 5e00f193
...@@ -3374,7 +3374,7 @@ static int cache_save_setup(struct btrfs_block_group_cache *block_group, ...@@ -3374,7 +3374,7 @@ static int cache_save_setup(struct btrfs_block_group_cache *block_group,
if (trans->aborted) if (trans->aborted)
return 0; return 0;
again: again:
inode = lookup_free_space_inode(root, block_group, path); inode = lookup_free_space_inode(fs_info, block_group, path);
if (IS_ERR(inode) && PTR_ERR(inode) != -ENOENT) { if (IS_ERR(inode) && PTR_ERR(inode) != -ENOENT) {
ret = PTR_ERR(inode); ret = PTR_ERR(inode);
btrfs_release_path(path); btrfs_release_path(path);
...@@ -3388,7 +3388,8 @@ static int cache_save_setup(struct btrfs_block_group_cache *block_group, ...@@ -3388,7 +3388,8 @@ static int cache_save_setup(struct btrfs_block_group_cache *block_group,
if (block_group->ro) if (block_group->ro)
goto out_free; goto out_free;
ret = create_free_space_inode(root, trans, block_group, path); ret = create_free_space_inode(fs_info, trans, block_group,
path);
if (ret) if (ret)
goto out_free; goto out_free;
goto again; goto again;
...@@ -3430,7 +3431,7 @@ static int cache_save_setup(struct btrfs_block_group_cache *block_group, ...@@ -3430,7 +3431,7 @@ static int cache_save_setup(struct btrfs_block_group_cache *block_group,
if (ret) if (ret)
goto out_put; goto out_put;
ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode); ret = btrfs_truncate_free_space_cache(trans, NULL, inode);
if (ret) if (ret)
goto out_put; goto out_put;
} }
...@@ -10314,7 +10315,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, ...@@ -10314,7 +10315,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
* get the inode first so any iput calls done for the io_list * get the inode first so any iput calls done for the io_list
* aren't the final iput (no unlinks allowed now) * aren't the final iput (no unlinks allowed now)
*/ */
inode = lookup_free_space_inode(tree_root, block_group, path); inode = lookup_free_space_inode(fs_info, block_group, path);
mutex_lock(&trans->transaction->cache_write_mutex); mutex_lock(&trans->transaction->cache_write_mutex);
/* /*
......
...@@ -94,12 +94,11 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root, ...@@ -94,12 +94,11 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
return inode; return inode;
} }
struct inode *lookup_free_space_inode(struct btrfs_root *root, struct inode *lookup_free_space_inode(struct btrfs_fs_info *fs_info,
struct btrfs_block_group_cache struct btrfs_block_group_cache
*block_group, struct btrfs_path *path) *block_group, struct btrfs_path *path)
{ {
struct inode *inode = NULL; struct inode *inode = NULL;
struct btrfs_fs_info *fs_info = root->fs_info;
u32 flags = BTRFS_INODE_NODATASUM | BTRFS_INODE_NODATACOW; u32 flags = BTRFS_INODE_NODATASUM | BTRFS_INODE_NODATACOW;
spin_lock(&block_group->lock); spin_lock(&block_group->lock);
...@@ -109,7 +108,7 @@ struct inode *lookup_free_space_inode(struct btrfs_root *root, ...@@ -109,7 +108,7 @@ struct inode *lookup_free_space_inode(struct btrfs_root *root,
if (inode) if (inode)
return inode; return inode;
inode = __lookup_free_space_inode(root, path, inode = __lookup_free_space_inode(fs_info->tree_root, path,
block_group->key.objectid); block_group->key.objectid);
if (IS_ERR(inode)) if (IS_ERR(inode))
return inode; return inode;
...@@ -192,7 +191,7 @@ static int __create_free_space_inode(struct btrfs_root *root, ...@@ -192,7 +191,7 @@ static int __create_free_space_inode(struct btrfs_root *root,
return 0; return 0;
} }
int create_free_space_inode(struct btrfs_root *root, int create_free_space_inode(struct btrfs_fs_info *fs_info,
struct btrfs_trans_handle *trans, struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path) struct btrfs_path *path)
...@@ -200,11 +199,11 @@ int create_free_space_inode(struct btrfs_root *root, ...@@ -200,11 +199,11 @@ int create_free_space_inode(struct btrfs_root *root,
int ret; int ret;
u64 ino; u64 ino;
ret = btrfs_find_free_objectid(root, &ino); ret = btrfs_find_free_objectid(fs_info->tree_root, &ino);
if (ret < 0) if (ret < 0)
return ret; return ret;
return __create_free_space_inode(root, trans, path, ino, return __create_free_space_inode(fs_info->tree_root, trans, path, ino,
block_group->key.objectid); block_group->key.objectid);
} }
...@@ -227,11 +226,11 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, ...@@ -227,11 +226,11 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info,
return ret; return ret;
} }
int btrfs_truncate_free_space_cache(struct btrfs_root *root, int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct inode *inode) struct inode *inode)
{ {
struct btrfs_root *root = BTRFS_I(inode)->root;
int ret = 0; int ret = 0;
struct btrfs_path *path = btrfs_alloc_path(); struct btrfs_path *path = btrfs_alloc_path();
bool locked = false; bool locked = false;
...@@ -824,7 +823,6 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info, ...@@ -824,7 +823,6 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
struct btrfs_block_group_cache *block_group) struct btrfs_block_group_cache *block_group)
{ {
struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
struct btrfs_root *root = fs_info->tree_root;
struct inode *inode; struct inode *inode;
struct btrfs_path *path; struct btrfs_path *path;
int ret = 0; int ret = 0;
...@@ -848,7 +846,7 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info, ...@@ -848,7 +846,7 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
path->search_commit_root = 1; path->search_commit_root = 1;
path->skip_locking = 1; path->skip_locking = 1;
inode = lookup_free_space_inode(root, block_group, path); inode = lookup_free_space_inode(fs_info, block_group, path);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
btrfs_free_path(path); btrfs_free_path(path);
return 0; return 0;
...@@ -1370,7 +1368,6 @@ int btrfs_write_out_cache(struct btrfs_fs_info *fs_info, ...@@ -1370,7 +1368,6 @@ int btrfs_write_out_cache(struct btrfs_fs_info *fs_info,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path) struct btrfs_path *path)
{ {
struct btrfs_root *root = fs_info->tree_root;
struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
struct inode *inode; struct inode *inode;
int ret = 0; int ret = 0;
...@@ -1382,12 +1379,12 @@ int btrfs_write_out_cache(struct btrfs_fs_info *fs_info, ...@@ -1382,12 +1379,12 @@ int btrfs_write_out_cache(struct btrfs_fs_info *fs_info,
} }
spin_unlock(&block_group->lock); spin_unlock(&block_group->lock);
inode = lookup_free_space_inode(root, block_group, path); inode = lookup_free_space_inode(fs_info, block_group, path);
if (IS_ERR(inode)) if (IS_ERR(inode))
return 0; return 0;
ret = __btrfs_write_out_cache(root, inode, ctl, block_group, ret = __btrfs_write_out_cache(fs_info->tree_root, inode, ctl,
&block_group->io_ctl, trans); block_group, &block_group->io_ctl, trans);
if (ret) { if (ret) {
#ifdef DEBUG #ifdef DEBUG
btrfs_err(fs_info, btrfs_err(fs_info,
......
...@@ -51,18 +51,17 @@ struct btrfs_free_space_op { ...@@ -51,18 +51,17 @@ struct btrfs_free_space_op {
struct btrfs_io_ctl; struct btrfs_io_ctl;
struct inode *lookup_free_space_inode(struct btrfs_root *root, struct inode *lookup_free_space_inode(struct btrfs_fs_info *fs_info,
struct btrfs_block_group_cache struct btrfs_block_group_cache
*block_group, struct btrfs_path *path); *block_group, struct btrfs_path *path);
int create_free_space_inode(struct btrfs_root *root, int create_free_space_inode(struct btrfs_fs_info *fs_info,
struct btrfs_trans_handle *trans, struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path); struct btrfs_path *path);
int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *rsv); struct btrfs_block_rsv *rsv);
int btrfs_truncate_free_space_cache(struct btrfs_root *root, int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct inode *inode); struct inode *inode);
int load_free_space_cache(struct btrfs_fs_info *fs_info, int load_free_space_cache(struct btrfs_fs_info *fs_info,
......
...@@ -467,7 +467,7 @@ int btrfs_save_ino_cache(struct btrfs_root *root, ...@@ -467,7 +467,7 @@ int btrfs_save_ino_cache(struct btrfs_root *root,
} }
if (i_size_read(inode) > 0) { if (i_size_read(inode) > 0) {
ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode); ret = btrfs_truncate_free_space_cache(trans, NULL, inode);
if (ret) { if (ret) {
if (ret != -ENOSPC) if (ret != -ENOSPC)
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
......
...@@ -3543,7 +3543,7 @@ static int delete_block_group_cache(struct btrfs_fs_info *fs_info, ...@@ -3543,7 +3543,7 @@ static int delete_block_group_cache(struct btrfs_fs_info *fs_info,
goto out; goto out;
} }
ret = btrfs_truncate_free_space_cache(root, trans, block_group, inode); ret = btrfs_truncate_free_space_cache(trans, block_group, inode);
btrfs_end_transaction(trans); btrfs_end_transaction(trans);
btrfs_btree_balance_dirty(fs_info); btrfs_btree_balance_dirty(fs_info);
...@@ -4347,8 +4347,7 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start) ...@@ -4347,8 +4347,7 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start)
goto out; goto out;
} }
inode = lookup_free_space_inode(fs_info->tree_root, rc->block_group, inode = lookup_free_space_inode(fs_info, rc->block_group, path);
path);
btrfs_free_path(path); btrfs_free_path(path);
if (!IS_ERR(inode)) if (!IS_ERR(inode))
......
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