mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 02:24:24 +02:00
btrfs: add space_info parameter for block group creation
Add struct btrfs_space_info parameter to btrfs_make_block_group(), its related functions and related struct. Passed space_info will have a new block group. 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
098a442d5b
commit
4d5a047e07
|
|
@ -2866,8 +2866,8 @@ static u64 calculate_global_root_id(const struct btrfs_fs_info *fs_info, u64 off
|
|||
}
|
||||
|
||||
struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *trans,
|
||||
u64 type,
|
||||
u64 chunk_offset, u64 size)
|
||||
struct btrfs_space_info *space_info,
|
||||
u64 type, u64 chunk_offset, u64 size)
|
||||
{
|
||||
struct btrfs_fs_info *fs_info = trans->fs_info;
|
||||
struct btrfs_block_group *cache;
|
||||
|
|
@ -2921,7 +2921,7 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
|
|||
* assigned to our block group. We want our bg to be added to the rbtree
|
||||
* with its ->space_info set.
|
||||
*/
|
||||
cache->space_info = btrfs_find_space_info(fs_info, cache->flags);
|
||||
cache->space_info = space_info;
|
||||
ASSERT(cache->space_info);
|
||||
|
||||
ret = btrfs_add_block_group_cache(cache);
|
||||
|
|
@ -3910,7 +3910,9 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type)
|
|||
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)
|
||||
static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_space_info *space_info,
|
||||
u64 flags)
|
||||
{
|
||||
struct btrfs_block_group *bg;
|
||||
int ret;
|
||||
|
|
@ -3923,7 +3925,7 @@ static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans
|
|||
*/
|
||||
check_system_chunk(trans, flags);
|
||||
|
||||
bg = btrfs_create_chunk(trans, flags);
|
||||
bg = btrfs_create_chunk(trans, space_info, flags);
|
||||
if (IS_ERR(bg)) {
|
||||
ret = PTR_ERR(bg);
|
||||
goto out;
|
||||
|
|
@ -3971,8 +3973,16 @@ static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans
|
|||
if (ret == -ENOSPC) {
|
||||
const u64 sys_flags = btrfs_system_alloc_profile(trans->fs_info);
|
||||
struct btrfs_block_group *sys_bg;
|
||||
struct btrfs_space_info *sys_space_info;
|
||||
|
||||
sys_bg = btrfs_create_chunk(trans, sys_flags);
|
||||
sys_space_info = btrfs_find_space_info(trans->fs_info, sys_flags);
|
||||
if (!sys_space_info) {
|
||||
ret = -EINVAL;
|
||||
btrfs_abort_transaction(trans, ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
sys_bg = btrfs_create_chunk(trans, sys_space_info, sys_flags);
|
||||
if (IS_ERR(sys_bg)) {
|
||||
ret = PTR_ERR(sys_bg);
|
||||
btrfs_abort_transaction(trans, ret);
|
||||
|
|
@ -4216,7 +4226,7 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans,
|
|||
force_metadata_allocation(fs_info);
|
||||
}
|
||||
|
||||
ret_bg = do_chunk_alloc(trans, flags);
|
||||
ret_bg = do_chunk_alloc(trans, space_info, flags);
|
||||
trans->allocating_chunk = false;
|
||||
|
||||
if (IS_ERR(ret_bg)) {
|
||||
|
|
@ -4292,6 +4302,10 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,
|
|||
if (left < bytes) {
|
||||
u64 flags = btrfs_system_alloc_profile(fs_info);
|
||||
struct btrfs_block_group *bg;
|
||||
struct btrfs_space_info *space_info;
|
||||
|
||||
space_info = btrfs_find_space_info(fs_info, flags);
|
||||
ASSERT(space_info);
|
||||
|
||||
/*
|
||||
* Ignore failure to create system chunk. We might end up not
|
||||
|
|
@ -4299,7 +4313,7 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,
|
|||
* the paths we visit in the chunk tree (they were already COWed
|
||||
* or created in the current transaction for example).
|
||||
*/
|
||||
bg = btrfs_create_chunk(trans, flags);
|
||||
bg = btrfs_create_chunk(trans, space_info, flags);
|
||||
if (IS_ERR(bg)) {
|
||||
ret = PTR_ERR(bg);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -326,8 +326,8 @@ void btrfs_reclaim_bgs(struct btrfs_fs_info *fs_info);
|
|||
void btrfs_mark_bg_to_reclaim(struct btrfs_block_group *bg);
|
||||
int btrfs_read_block_groups(struct btrfs_fs_info *info);
|
||||
struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *trans,
|
||||
u64 type,
|
||||
u64 chunk_offset, u64 size);
|
||||
struct btrfs_space_info *space_info,
|
||||
u64 type, u64 chunk_offset, u64 size);
|
||||
void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans);
|
||||
int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
|
||||
bool do_chunk_alloc);
|
||||
|
|
|
|||
|
|
@ -3331,8 +3331,16 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset)
|
|||
if (ret == -ENOSPC) {
|
||||
const u64 sys_flags = btrfs_system_alloc_profile(fs_info);
|
||||
struct btrfs_block_group *sys_bg;
|
||||
struct btrfs_space_info *space_info;
|
||||
|
||||
sys_bg = btrfs_create_chunk(trans, sys_flags);
|
||||
space_info = btrfs_find_space_info(fs_info, sys_flags);
|
||||
if (!space_info) {
|
||||
ret = -EINVAL;
|
||||
btrfs_abort_transaction(trans, ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
sys_bg = btrfs_create_chunk(trans, space_info, sys_flags);
|
||||
if (IS_ERR(sys_bg)) {
|
||||
ret = PTR_ERR(sys_bg);
|
||||
btrfs_abort_transaction(trans, ret);
|
||||
|
|
@ -5123,6 +5131,8 @@ struct alloc_chunk_ctl {
|
|||
u64 stripe_size;
|
||||
u64 chunk_size;
|
||||
int ndevs;
|
||||
/* Space_info the block group is going to belong. */
|
||||
struct btrfs_space_info *space_info;
|
||||
};
|
||||
|
||||
static void init_alloc_chunk_ctl_policy_regular(
|
||||
|
|
@ -5530,7 +5540,8 @@ static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans,
|
|||
return ERR_PTR(ret);
|
||||
}
|
||||
|
||||
block_group = btrfs_make_block_group(trans, type, start, ctl->chunk_size);
|
||||
block_group = btrfs_make_block_group(trans, ctl->space_info, type, start,
|
||||
ctl->chunk_size);
|
||||
if (IS_ERR(block_group)) {
|
||||
btrfs_remove_chunk_map(info, map);
|
||||
return block_group;
|
||||
|
|
@ -5556,7 +5567,8 @@ static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans,
|
|||
}
|
||||
|
||||
struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,
|
||||
u64 type)
|
||||
struct btrfs_space_info *space_info,
|
||||
u64 type)
|
||||
{
|
||||
struct btrfs_fs_info *info = trans->fs_info;
|
||||
struct btrfs_fs_devices *fs_devices = info->fs_devices;
|
||||
|
|
@ -5586,6 +5598,7 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,
|
|||
|
||||
ctl.start = find_next_chunk(info);
|
||||
ctl.type = type;
|
||||
ctl.space_info = space_info;
|
||||
init_alloc_chunk_ctl(fs_devices, &ctl);
|
||||
|
||||
devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info),
|
||||
|
|
@ -5729,7 +5742,9 @@ static noinline int init_first_rw_device(struct btrfs_trans_handle *trans)
|
|||
struct btrfs_fs_info *fs_info = trans->fs_info;
|
||||
u64 alloc_profile;
|
||||
struct btrfs_block_group *meta_bg;
|
||||
struct btrfs_space_info *meta_space_info;
|
||||
struct btrfs_block_group *sys_bg;
|
||||
struct btrfs_space_info *sys_space_info;
|
||||
|
||||
/*
|
||||
* When adding a new device for sprouting, the seed device is read-only
|
||||
|
|
@ -5753,12 +5768,22 @@ static noinline int init_first_rw_device(struct btrfs_trans_handle *trans)
|
|||
*/
|
||||
|
||||
alloc_profile = btrfs_metadata_alloc_profile(fs_info);
|
||||
meta_bg = btrfs_create_chunk(trans, alloc_profile);
|
||||
meta_space_info = btrfs_find_space_info(fs_info, alloc_profile);
|
||||
if (!meta_space_info) {
|
||||
DEBUG_WARN();
|
||||
return -EINVAL;
|
||||
}
|
||||
meta_bg = btrfs_create_chunk(trans, meta_space_info, alloc_profile);
|
||||
if (IS_ERR(meta_bg))
|
||||
return PTR_ERR(meta_bg);
|
||||
|
||||
alloc_profile = btrfs_system_alloc_profile(fs_info);
|
||||
sys_bg = btrfs_create_chunk(trans, alloc_profile);
|
||||
sys_space_info = btrfs_find_space_info(fs_info, alloc_profile);
|
||||
if (!sys_space_info) {
|
||||
DEBUG_WARN();
|
||||
return -EINVAL;
|
||||
}
|
||||
sys_bg = btrfs_create_chunk(trans, sys_space_info, alloc_profile);
|
||||
if (IS_ERR(sys_bg))
|
||||
return PTR_ERR(sys_bg);
|
||||
|
||||
|
|
|
|||
|
|
@ -714,7 +714,8 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info,
|
|||
int btrfs_read_sys_array(struct btrfs_fs_info *fs_info);
|
||||
int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info);
|
||||
struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,
|
||||
u64 type);
|
||||
struct btrfs_space_info *space_info,
|
||||
u64 type);
|
||||
void btrfs_mapping_tree_free(struct btrfs_fs_info *fs_info);
|
||||
int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
|
||||
blk_mode_t flags, void *holder);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user