Commit 9270501c authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: change root to fs_info for btrfs_reserve_metadata_bytes

We used to need the root for btrfs_reserve_metadata_bytes to check the
orphan cleanup state, but we no longer need that, we simply need the
fs_info.  Change btrfs_reserve_metadata_bytes() to use the fs_info, and
change both btrfs_block_rsv_refill() and btrfs_block_rsv_add() to do the
same as they simply call btrfs_reserve_metadata_bytes() and then
manipulate the block_rsv that is being used.
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 54230013
...@@ -3790,7 +3790,7 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans, ...@@ -3790,7 +3790,7 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,
} }
if (!ret) { if (!ret) {
ret = btrfs_block_rsv_add(fs_info->chunk_root, ret = btrfs_block_rsv_add(fs_info,
&fs_info->chunk_block_rsv, &fs_info->chunk_block_rsv,
bytes, BTRFS_RESERVE_NO_FLUSH); bytes, BTRFS_RESERVE_NO_FLUSH);
if (!ret) if (!ret)
......
...@@ -208,7 +208,7 @@ void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info, ...@@ -208,7 +208,7 @@ void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info,
kfree(rsv); kfree(rsv);
} }
int btrfs_block_rsv_add(struct btrfs_root *root, int btrfs_block_rsv_add(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *block_rsv, u64 num_bytes, struct btrfs_block_rsv *block_rsv, u64 num_bytes,
enum btrfs_reserve_flush_enum flush) enum btrfs_reserve_flush_enum flush)
{ {
...@@ -217,7 +217,7 @@ int btrfs_block_rsv_add(struct btrfs_root *root, ...@@ -217,7 +217,7 @@ int btrfs_block_rsv_add(struct btrfs_root *root,
if (num_bytes == 0) if (num_bytes == 0)
return 0; return 0;
ret = btrfs_reserve_metadata_bytes(root, block_rsv, num_bytes, flush); ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, num_bytes, flush);
if (!ret) if (!ret)
btrfs_block_rsv_add_bytes(block_rsv, num_bytes, true); btrfs_block_rsv_add_bytes(block_rsv, num_bytes, true);
...@@ -241,7 +241,7 @@ int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_factor) ...@@ -241,7 +241,7 @@ int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_factor)
return ret; return ret;
} }
int btrfs_block_rsv_refill(struct btrfs_root *root, int btrfs_block_rsv_refill(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *block_rsv, u64 min_reserved, struct btrfs_block_rsv *block_rsv, u64 min_reserved,
enum btrfs_reserve_flush_enum flush) enum btrfs_reserve_flush_enum flush)
{ {
...@@ -262,7 +262,7 @@ int btrfs_block_rsv_refill(struct btrfs_root *root, ...@@ -262,7 +262,7 @@ int btrfs_block_rsv_refill(struct btrfs_root *root,
if (!ret) if (!ret)
return 0; return 0;
ret = btrfs_reserve_metadata_bytes(root, block_rsv, num_bytes, flush); ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, num_bytes, flush);
if (!ret) { if (!ret) {
btrfs_block_rsv_add_bytes(block_rsv, num_bytes, false); btrfs_block_rsv_add_bytes(block_rsv, num_bytes, false);
return 0; return 0;
...@@ -523,7 +523,7 @@ struct btrfs_block_rsv *btrfs_use_block_rsv(struct btrfs_trans_handle *trans, ...@@ -523,7 +523,7 @@ struct btrfs_block_rsv *btrfs_use_block_rsv(struct btrfs_trans_handle *trans,
block_rsv->type, ret); block_rsv->type, ret);
} }
try_reserve: try_reserve:
ret = btrfs_reserve_metadata_bytes(root, block_rsv, blocksize, ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, blocksize,
BTRFS_RESERVE_NO_FLUSH); BTRFS_RESERVE_NO_FLUSH);
if (!ret) if (!ret)
return block_rsv; return block_rsv;
......
...@@ -57,11 +57,11 @@ void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info, ...@@ -57,11 +57,11 @@ void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info,
unsigned short type); unsigned short type);
void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info, void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *rsv); struct btrfs_block_rsv *rsv);
int btrfs_block_rsv_add(struct btrfs_root *root, int btrfs_block_rsv_add(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *block_rsv, u64 num_bytes, struct btrfs_block_rsv *block_rsv, u64 num_bytes,
enum btrfs_reserve_flush_enum flush); enum btrfs_reserve_flush_enum flush);
int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_factor); int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_factor);
int btrfs_block_rsv_refill(struct btrfs_root *root, int btrfs_block_rsv_refill(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *block_rsv, u64 min_reserved, struct btrfs_block_rsv *block_rsv, u64 min_reserved,
enum btrfs_reserve_flush_enum flush); enum btrfs_reserve_flush_enum flush);
int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv, int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv,
......
...@@ -334,7 +334,7 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes) ...@@ -334,7 +334,7 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes)
ret = btrfs_qgroup_reserve_meta_prealloc(root, qgroup_reserve, true); ret = btrfs_qgroup_reserve_meta_prealloc(root, qgroup_reserve, true);
if (ret) if (ret)
return ret; return ret;
ret = btrfs_reserve_metadata_bytes(root, block_rsv, meta_reserve, flush); ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, meta_reserve, flush);
if (ret) { if (ret) {
btrfs_qgroup_free_meta_prealloc(root, qgroup_reserve); btrfs_qgroup_free_meta_prealloc(root, qgroup_reserve);
return ret; return ret;
......
...@@ -629,7 +629,7 @@ static int btrfs_delayed_inode_reserve_metadata( ...@@ -629,7 +629,7 @@ static int btrfs_delayed_inode_reserve_metadata(
BTRFS_QGROUP_RSV_META_PREALLOC, true); BTRFS_QGROUP_RSV_META_PREALLOC, true);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = btrfs_block_rsv_add(root, dst_rsv, num_bytes, ret = btrfs_block_rsv_add(fs_info, dst_rsv, num_bytes,
BTRFS_RESERVE_NO_FLUSH); BTRFS_RESERVE_NO_FLUSH);
/* NO_FLUSH could only fail with -ENOSPC */ /* NO_FLUSH could only fail with -ENOSPC */
ASSERT(ret == 0 || ret == -ENOSPC); ASSERT(ret == 0 || ret == -ENOSPC);
......
...@@ -191,8 +191,7 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, ...@@ -191,8 +191,7 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info,
if (!num_bytes) if (!num_bytes)
return 0; return 0;
ret = btrfs_reserve_metadata_bytes(fs_info->extent_root, block_rsv, ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, num_bytes, flush);
num_bytes, flush);
if (ret) if (ret)
return ret; return ret;
btrfs_block_rsv_add_bytes(block_rsv, num_bytes, 0); btrfs_block_rsv_add_bytes(block_rsv, num_bytes, 0);
......
...@@ -5539,10 +5539,10 @@ static struct btrfs_trans_handle *evict_refill_and_join(struct btrfs_root *root, ...@@ -5539,10 +5539,10 @@ static struct btrfs_trans_handle *evict_refill_and_join(struct btrfs_root *root,
* if we fail to make this reservation we can re-try without the * if we fail to make this reservation we can re-try without the
* delayed_refs_extra so we can make some forward progress. * delayed_refs_extra so we can make some forward progress.
*/ */
ret = btrfs_block_rsv_refill(root, rsv, rsv->size + delayed_refs_extra, ret = btrfs_block_rsv_refill(fs_info, rsv, rsv->size + delayed_refs_extra,
BTRFS_RESERVE_FLUSH_EVICT); BTRFS_RESERVE_FLUSH_EVICT);
if (ret) { if (ret) {
ret = btrfs_block_rsv_refill(root, rsv, rsv->size, ret = btrfs_block_rsv_refill(fs_info, rsv, rsv->size,
BTRFS_RESERVE_FLUSH_EVICT); BTRFS_RESERVE_FLUSH_EVICT);
if (ret) { if (ret) {
btrfs_warn(fs_info, btrfs_warn(fs_info,
......
...@@ -377,8 +377,9 @@ static int inherit_props(struct btrfs_trans_handle *trans, ...@@ -377,8 +377,9 @@ static int inherit_props(struct btrfs_trans_handle *trans,
*/ */
if (need_reserve) { if (need_reserve) {
num_bytes = btrfs_calc_insert_metadata_size(fs_info, 1); num_bytes = btrfs_calc_insert_metadata_size(fs_info, 1);
ret = btrfs_block_rsv_add(root, trans->block_rsv, ret = btrfs_block_rsv_add(fs_info, trans->block_rsv,
num_bytes, BTRFS_RESERVE_NO_FLUSH); num_bytes,
BTRFS_RESERVE_NO_FLUSH);
if (ret) if (ret)
return ret; return ret;
} }
......
...@@ -1736,7 +1736,8 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc, ...@@ -1736,7 +1736,8 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
memset(&next_key, 0, sizeof(next_key)); memset(&next_key, 0, sizeof(next_key));
while (1) { while (1) {
ret = btrfs_block_rsv_refill(root, rc->block_rsv, min_reserved, ret = btrfs_block_rsv_refill(fs_info, rc->block_rsv,
min_reserved,
BTRFS_RESERVE_FLUSH_LIMIT); BTRFS_RESERVE_FLUSH_LIMIT);
if (ret) if (ret)
goto out; goto out;
...@@ -1855,7 +1856,7 @@ int prepare_to_merge(struct reloc_control *rc, int err) ...@@ -1855,7 +1856,7 @@ int prepare_to_merge(struct reloc_control *rc, int err)
again: again:
if (!err) { if (!err) {
num_bytes = rc->merging_rsv_size; num_bytes = rc->merging_rsv_size;
ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes, ret = btrfs_block_rsv_add(fs_info, rc->block_rsv, num_bytes,
BTRFS_RESERVE_FLUSH_ALL); BTRFS_RESERVE_FLUSH_ALL);
if (ret) if (ret)
err = ret; err = ret;
...@@ -2323,7 +2324,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, ...@@ -2323,7 +2324,7 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans,
* If we get an enospc just kick back -EAGAIN so we know to drop the * If we get an enospc just kick back -EAGAIN so we know to drop the
* transaction and try to refill when we can flush all the things. * transaction and try to refill when we can flush all the things.
*/ */
ret = btrfs_block_rsv_refill(root, rc->block_rsv, num_bytes, ret = btrfs_block_rsv_refill(fs_info, rc->block_rsv, num_bytes,
BTRFS_RESERVE_FLUSH_LIMIT); BTRFS_RESERVE_FLUSH_LIMIT);
if (ret) { if (ret) {
tmp = fs_info->nodesize * RELOCATION_RESERVED_NODES; tmp = fs_info->nodesize * RELOCATION_RESERVED_NODES;
...@@ -3550,7 +3551,7 @@ int prepare_to_relocate(struct reloc_control *rc) ...@@ -3550,7 +3551,7 @@ int prepare_to_relocate(struct reloc_control *rc)
rc->reserved_bytes = 0; rc->reserved_bytes = 0;
rc->block_rsv->size = rc->extent_root->fs_info->nodesize * rc->block_rsv->size = rc->extent_root->fs_info->nodesize *
RELOCATION_RESERVED_NODES; RELOCATION_RESERVED_NODES;
ret = btrfs_block_rsv_refill(rc->extent_root, ret = btrfs_block_rsv_refill(rc->extent_root->fs_info,
rc->block_rsv, rc->block_rsv->size, rc->block_rsv, rc->block_rsv->size,
BTRFS_RESERVE_FLUSH_ALL); BTRFS_RESERVE_FLUSH_ALL);
if (ret) if (ret)
...@@ -3598,8 +3599,8 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc) ...@@ -3598,8 +3599,8 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
while (1) { while (1) {
rc->reserved_bytes = 0; rc->reserved_bytes = 0;
ret = btrfs_block_rsv_refill(rc->extent_root, ret = btrfs_block_rsv_refill(fs_info, rc->block_rsv,
rc->block_rsv, rc->block_rsv->size, rc->block_rsv->size,
BTRFS_RESERVE_FLUSH_ALL); BTRFS_RESERVE_FLUSH_ALL);
if (ret) { if (ret) {
err = ret; err = ret;
......
...@@ -502,7 +502,7 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, ...@@ -502,7 +502,7 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
num_bytes = btrfs_calc_insert_metadata_size(fs_info, items); num_bytes = btrfs_calc_insert_metadata_size(fs_info, items);
rsv->space_info = btrfs_find_space_info(fs_info, rsv->space_info = btrfs_find_space_info(fs_info,
BTRFS_BLOCK_GROUP_METADATA); BTRFS_BLOCK_GROUP_METADATA);
ret = btrfs_block_rsv_add(root, rsv, num_bytes, ret = btrfs_block_rsv_add(fs_info, rsv, num_bytes,
BTRFS_RESERVE_FLUSH_ALL); BTRFS_RESERVE_FLUSH_ALL);
if (ret == -ENOSPC && use_global_rsv) if (ret == -ENOSPC && use_global_rsv)
......
...@@ -1600,12 +1600,11 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info, ...@@ -1600,12 +1600,11 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info,
* regain reservations will be made and this will fail if there is not enough * regain reservations will be made and this will fail if there is not enough
* space already. * space already.
*/ */
int btrfs_reserve_metadata_bytes(struct btrfs_root *root, int btrfs_reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *block_rsv, struct btrfs_block_rsv *block_rsv,
u64 orig_bytes, u64 orig_bytes,
enum btrfs_reserve_flush_enum flush) enum btrfs_reserve_flush_enum flush)
{ {
struct btrfs_fs_info *fs_info = root->fs_info;
int ret; int ret;
ret = __reserve_bytes(fs_info, block_rsv->space_info, orig_bytes, flush); ret = __reserve_bytes(fs_info, block_rsv->space_info, orig_bytes, flush);
......
...@@ -123,7 +123,7 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info); ...@@ -123,7 +123,7 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
void btrfs_dump_space_info(struct btrfs_fs_info *fs_info, void btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
struct btrfs_space_info *info, u64 bytes, struct btrfs_space_info *info, u64 bytes,
int dump_block_groups); int dump_block_groups);
int btrfs_reserve_metadata_bytes(struct btrfs_root *root, int btrfs_reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *block_rsv, struct btrfs_block_rsv *block_rsv,
u64 orig_bytes, u64 orig_bytes,
enum btrfs_reserve_flush_enum flush); enum btrfs_reserve_flush_enum flush);
......
...@@ -634,7 +634,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items, ...@@ -634,7 +634,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
reloc_reserved = true; reloc_reserved = true;
} }
ret = btrfs_block_rsv_add(root, rsv, num_bytes, flush); ret = btrfs_block_rsv_add(fs_info, rsv, num_bytes, flush);
if (ret) if (ret)
goto reserve_fail; goto reserve_fail;
if (delayed_refs_bytes) { if (delayed_refs_bytes) {
...@@ -1597,7 +1597,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, ...@@ -1597,7 +1597,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
btrfs_reloc_pre_snapshot(pending, &to_reserve); btrfs_reloc_pre_snapshot(pending, &to_reserve);
if (to_reserve > 0) { if (to_reserve > 0) {
pending->error = btrfs_block_rsv_add(root, pending->error = btrfs_block_rsv_add(fs_info,
&pending->block_rsv, &pending->block_rsv,
to_reserve, to_reserve,
BTRFS_RESERVE_NO_FLUSH); BTRFS_RESERVE_NO_FLUSH);
......
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