Commit 03551d65 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: pass a space_info argument to btrfs_reserve_metadata_bytes()

We are passing a block reserve argument to btrfs_reserve_metadata_bytes()
which is not really used, all we need is to pass the space_info associated
to the block reserve, we don't change the block reserve at all.

Not only it's pointless to pass the block reserve, it's also confusing as
one might think that the reserved bytes will end up being added to the
passed block reserve, when that's not the case. The pattern for reserving
space and adding it to a block reserve is to first reserve space with
btrfs_reserve_metadata_bytes() and if that succeeds, then add the space to
a block reserve by calling btrfs_block_rsv_add_bytes().

Also the reverse of btrfs_reserve_metadata_bytes(), which is
btrfs_space_info_free_bytes_may_use(), takes a space_info argument and
not a block reserve, so one more reason to pass a space_info and not a
block reserve to btrfs_reserve_metadata_bytes().

So change btrfs_reserve_metadata_bytes() and its callers to pass a
space_info argument instead of a block reserve argument.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 9fb2acc2
...@@ -221,7 +221,8 @@ int btrfs_block_rsv_add(struct btrfs_fs_info *fs_info, ...@@ -221,7 +221,8 @@ int btrfs_block_rsv_add(struct btrfs_fs_info *fs_info,
if (num_bytes == 0) if (num_bytes == 0)
return 0; return 0;
ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, num_bytes, flush); ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv->space_info,
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);
...@@ -261,7 +262,8 @@ int btrfs_block_rsv_refill(struct btrfs_fs_info *fs_info, ...@@ -261,7 +262,8 @@ int btrfs_block_rsv_refill(struct btrfs_fs_info *fs_info,
if (!ret) if (!ret)
return 0; return 0;
ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, num_bytes, flush); ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv->space_info,
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;
...@@ -517,8 +519,8 @@ struct btrfs_block_rsv *btrfs_use_block_rsv(struct btrfs_trans_handle *trans, ...@@ -517,8 +519,8 @@ 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(fs_info, block_rsv, blocksize, ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv->space_info,
BTRFS_RESERVE_NO_FLUSH); blocksize, BTRFS_RESERVE_NO_FLUSH);
if (!ret) if (!ret)
return block_rsv; return block_rsv;
/* /*
...@@ -539,7 +541,7 @@ struct btrfs_block_rsv *btrfs_use_block_rsv(struct btrfs_trans_handle *trans, ...@@ -539,7 +541,7 @@ struct btrfs_block_rsv *btrfs_use_block_rsv(struct btrfs_trans_handle *trans,
* one last time to force a reservation if there's enough actual space * one last time to force a reservation if there's enough actual space
* on disk to make the reservation. * on disk to make the reservation.
*/ */
ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, blocksize, ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv->space_info, blocksize,
BTRFS_RESERVE_FLUSH_EMERGENCY); BTRFS_RESERVE_FLUSH_EMERGENCY);
if (!ret) if (!ret)
return block_rsv; return block_rsv;
......
...@@ -346,7 +346,8 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes, ...@@ -346,7 +346,8 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes,
noflush); noflush);
if (ret) if (ret)
return ret; return ret;
ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, meta_reserve, flush); ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv->space_info,
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;
......
...@@ -154,6 +154,7 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, ...@@ -154,6 +154,7 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info,
enum btrfs_reserve_flush_enum flush) enum btrfs_reserve_flush_enum flush)
{ {
struct btrfs_block_rsv *block_rsv = &fs_info->delayed_refs_rsv; struct btrfs_block_rsv *block_rsv = &fs_info->delayed_refs_rsv;
struct btrfs_space_info *space_info = block_rsv->space_info;
u64 limit = btrfs_calc_delayed_ref_bytes(fs_info, 1); u64 limit = btrfs_calc_delayed_ref_bytes(fs_info, 1);
u64 num_bytes = 0; u64 num_bytes = 0;
u64 refilled_bytes; u64 refilled_bytes;
...@@ -170,7 +171,7 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, ...@@ -170,7 +171,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, block_rsv, num_bytes, flush); ret = btrfs_reserve_metadata_bytes(fs_info, space_info, num_bytes, flush);
if (ret) if (ret)
return ret; return ret;
...@@ -199,8 +200,7 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, ...@@ -199,8 +200,7 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info,
spin_unlock(&block_rsv->lock); spin_unlock(&block_rsv->lock);
if (to_free > 0) if (to_free > 0)
btrfs_space_info_free_bytes_may_use(fs_info, block_rsv->space_info, btrfs_space_info_free_bytes_may_use(fs_info, space_info, to_free);
to_free);
if (refilled_bytes > 0) if (refilled_bytes > 0)
trace_btrfs_space_reservation(fs_info, "delayed_refs_rsv", 0, trace_btrfs_space_reservation(fs_info, "delayed_refs_rsv", 0,
......
...@@ -1743,7 +1743,7 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info, ...@@ -1743,7 +1743,7 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info,
* Try to reserve metadata bytes from the block_rsv's space. * Try to reserve metadata bytes from the block_rsv's space.
* *
* @fs_info: the filesystem * @fs_info: the filesystem
* @block_rsv: block_rsv we're allocating for * @space_info: the space_info we're allocating for
* @orig_bytes: number of bytes we want * @orig_bytes: number of bytes we want
* @flush: whether or not we can flush to make our reservation * @flush: whether or not we can flush to make our reservation
* *
...@@ -1755,21 +1755,19 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info, ...@@ -1755,21 +1755,19 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info,
* space already. * space already.
*/ */
int btrfs_reserve_metadata_bytes(struct btrfs_fs_info *fs_info, int btrfs_reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *block_rsv, struct btrfs_space_info *space_info,
u64 orig_bytes, u64 orig_bytes,
enum btrfs_reserve_flush_enum flush) enum btrfs_reserve_flush_enum flush)
{ {
int ret; int ret;
ret = __reserve_bytes(fs_info, block_rsv->space_info, orig_bytes, flush); ret = __reserve_bytes(fs_info, space_info, orig_bytes, flush);
if (ret == -ENOSPC) { if (ret == -ENOSPC) {
trace_btrfs_space_reservation(fs_info, "space_info:enospc", trace_btrfs_space_reservation(fs_info, "space_info:enospc",
block_rsv->space_info->flags, space_info->flags, orig_bytes, 1);
orig_bytes, 1);
if (btrfs_test_opt(fs_info, ENOSPC_DEBUG)) if (btrfs_test_opt(fs_info, ENOSPC_DEBUG))
btrfs_dump_space_info(fs_info, block_rsv->space_info, btrfs_dump_space_info(fs_info, space_info, orig_bytes, 0);
orig_bytes, 0);
} }
return ret; return ret;
} }
......
...@@ -213,7 +213,7 @@ void btrfs_dump_space_info(struct btrfs_fs_info *fs_info, ...@@ -213,7 +213,7 @@ 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_fs_info *fs_info, int btrfs_reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *block_rsv, struct btrfs_space_info *space_info,
u64 orig_bytes, u64 orig_bytes,
enum btrfs_reserve_flush_enum flush); enum btrfs_reserve_flush_enum flush);
void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info, void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info,
......
...@@ -631,7 +631,8 @@ start_transaction(struct btrfs_root *root, unsigned int num_items, ...@@ -631,7 +631,8 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
reloc_reserved = true; reloc_reserved = true;
} }
ret = btrfs_reserve_metadata_bytes(fs_info, rsv, num_bytes, flush); ret = btrfs_reserve_metadata_bytes(fs_info, rsv->space_info,
num_bytes, flush);
if (ret) if (ret)
goto reserve_fail; goto reserve_fail;
if (delayed_refs_bytes) { if (delayed_refs_bytes) {
......
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