mirror of
https://github.com/torvalds/linux.git
synced 2026-05-30 10:04:04 +02:00
btrfs: add space_info argument to btrfs_chunk_alloc()
Take a btrfs_space_info argument in btrfs_chunk_alloc(). New block group will belong to that space_info. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
1cfdbe0d53
commit
098a442d5b
|
|
@ -2966,6 +2966,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
|
|||
bool do_chunk_alloc)
|
||||
{
|
||||
struct btrfs_fs_info *fs_info = cache->fs_info;
|
||||
struct btrfs_space_info *space_info = cache->space_info;
|
||||
struct btrfs_trans_handle *trans;
|
||||
struct btrfs_root *root = btrfs_block_group_root(fs_info);
|
||||
u64 alloc_flags;
|
||||
|
|
@ -3018,7 +3019,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
|
|||
*/
|
||||
alloc_flags = btrfs_get_alloc_profile(fs_info, cache->flags);
|
||||
if (alloc_flags != cache->flags) {
|
||||
ret = btrfs_chunk_alloc(trans, alloc_flags,
|
||||
ret = btrfs_chunk_alloc(trans, space_info, alloc_flags,
|
||||
CHUNK_ALLOC_FORCE);
|
||||
/*
|
||||
* ENOSPC is allowed here, we may have enough space
|
||||
|
|
@ -3046,15 +3047,15 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
|
|||
(cache->flags & BTRFS_BLOCK_GROUP_SYSTEM))
|
||||
goto unlock_out;
|
||||
|
||||
alloc_flags = btrfs_get_alloc_profile(fs_info, cache->space_info->flags);
|
||||
ret = btrfs_chunk_alloc(trans, alloc_flags, CHUNK_ALLOC_FORCE);
|
||||
alloc_flags = btrfs_get_alloc_profile(fs_info, space_info->flags);
|
||||
ret = btrfs_chunk_alloc(trans, space_info, alloc_flags, CHUNK_ALLOC_FORCE);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
/*
|
||||
* We have allocated a new chunk. We also need to activate that chunk to
|
||||
* grant metadata tickets for zoned filesystem.
|
||||
*/
|
||||
ret = btrfs_zoned_activate_one_bg(fs_info, cache->space_info, true);
|
||||
ret = btrfs_zoned_activate_one_bg(fs_info, space_info, true);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
|
|
@ -3898,8 +3899,15 @@ static bool should_alloc_chunk(const struct btrfs_fs_info *fs_info,
|
|||
int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type)
|
||||
{
|
||||
u64 alloc_flags = btrfs_get_alloc_profile(trans->fs_info, type);
|
||||
struct btrfs_space_info *space_info;
|
||||
|
||||
return btrfs_chunk_alloc(trans, alloc_flags, CHUNK_ALLOC_FORCE);
|
||||
space_info = btrfs_find_space_info(trans->fs_info, type);
|
||||
if (!space_info) {
|
||||
DEBUG_WARN();
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return btrfs_chunk_alloc(trans, space_info, alloc_flags, CHUNK_ALLOC_FORCE);
|
||||
}
|
||||
|
||||
static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags)
|
||||
|
|
@ -4095,6 +4103,8 @@ static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans
|
|||
*
|
||||
* This function, btrfs_chunk_alloc(), belongs to phase 1.
|
||||
*
|
||||
* @space_info: specify which space_info the new chunk should belong to.
|
||||
*
|
||||
* If @force is CHUNK_ALLOC_FORCE:
|
||||
* - return 1 if it successfully allocates a chunk,
|
||||
* - return errors including -ENOSPC otherwise.
|
||||
|
|
@ -4103,11 +4113,11 @@ static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans
|
|||
* - return 1 if it successfully allocates a chunk,
|
||||
* - return errors including -ENOSPC otherwise.
|
||||
*/
|
||||
int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
|
||||
int btrfs_chunk_alloc(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_space_info *space_info, u64 flags,
|
||||
enum btrfs_chunk_alloc_enum force)
|
||||
{
|
||||
struct btrfs_fs_info *fs_info = trans->fs_info;
|
||||
struct btrfs_space_info *space_info;
|
||||
struct btrfs_block_group *ret_bg;
|
||||
bool wait_for_alloc = false;
|
||||
bool should_alloc = false;
|
||||
|
|
@ -4146,9 +4156,6 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
|
|||
if (flags & BTRFS_BLOCK_GROUP_SYSTEM)
|
||||
return -ENOSPC;
|
||||
|
||||
space_info = btrfs_find_space_info(fs_info, flags);
|
||||
ASSERT(space_info);
|
||||
|
||||
do {
|
||||
spin_lock(&space_info->lock);
|
||||
if (force < space_info->force_alloc)
|
||||
|
|
|
|||
|
|
@ -342,7 +342,8 @@ int btrfs_add_reserved_bytes(struct btrfs_block_group *cache,
|
|||
bool force_wrong_size_class);
|
||||
void btrfs_free_reserved_bytes(struct btrfs_block_group *cache,
|
||||
u64 num_bytes, int delalloc);
|
||||
int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
|
||||
int btrfs_chunk_alloc(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_space_info *space_info, u64 flags,
|
||||
enum btrfs_chunk_alloc_enum force);
|
||||
int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type);
|
||||
void check_system_chunk(struct btrfs_trans_handle *trans, const u64 type);
|
||||
|
|
|
|||
|
|
@ -4130,6 +4130,7 @@ static int can_allocate_chunk(struct btrfs_fs_info *fs_info,
|
|||
static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_key *ins,
|
||||
struct find_free_extent_ctl *ffe_ctl,
|
||||
struct btrfs_space_info *space_info,
|
||||
bool full_search)
|
||||
{
|
||||
struct btrfs_root *root = fs_info->chunk_root;
|
||||
|
|
@ -4184,7 +4185,7 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info,
|
|||
return ret;
|
||||
}
|
||||
|
||||
ret = btrfs_chunk_alloc(trans, ffe_ctl->flags,
|
||||
ret = btrfs_chunk_alloc(trans, space_info, ffe_ctl->flags,
|
||||
CHUNK_ALLOC_FORCE_FOR_EXTENT);
|
||||
|
||||
/* Do not bail out on ENOSPC since we can do more. */
|
||||
|
|
@ -4597,7 +4598,8 @@ static noinline int find_free_extent(struct btrfs_root *root,
|
|||
}
|
||||
up_read(&space_info->groups_sem);
|
||||
|
||||
ret = find_free_extent_update_loop(fs_info, ins, ffe_ctl, full_search);
|
||||
ret = find_free_extent_update_loop(fs_info, ins, ffe_ctl, space_info,
|
||||
full_search);
|
||||
if (ret > 0)
|
||||
goto search;
|
||||
|
||||
|
|
|
|||
|
|
@ -817,7 +817,7 @@ static void flush_space(struct btrfs_fs_info *fs_info,
|
|||
ret = PTR_ERR(trans);
|
||||
break;
|
||||
}
|
||||
ret = btrfs_chunk_alloc(trans,
|
||||
ret = btrfs_chunk_alloc(trans, space_info,
|
||||
btrfs_get_alloc_profile(fs_info, space_info->flags),
|
||||
(state == ALLOC_CHUNK) ? CHUNK_ALLOC_NO_FORCE :
|
||||
CHUNK_ALLOC_FORCE);
|
||||
|
|
|
|||
|
|
@ -761,9 +761,10 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
|
|||
* value here.
|
||||
*/
|
||||
if (do_chunk_alloc && num_bytes) {
|
||||
u64 flags = h->block_rsv->space_info->flags;
|
||||
struct btrfs_space_info *space_info = h->block_rsv->space_info;
|
||||
u64 flags = space_info->flags;
|
||||
|
||||
btrfs_chunk_alloc(h, btrfs_get_alloc_profile(fs_info, flags),
|
||||
btrfs_chunk_alloc(h, space_info, btrfs_get_alloc_profile(fs_info, flags),
|
||||
CHUNK_ALLOC_NO_FORCE);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user