Skip to content

Commit 820c363

Browse files
naotakdave
authored andcommitted
btrfs: return allocated block group from do_chunk_alloc()
Return the allocated block group from do_chunk_alloc(). This is a preparation patch for the next patch. CC: stable@vger.kernel.org # 5.16+ Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Tested-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent a690e5f commit 820c363

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

fs/btrfs/block-group.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,7 +3451,7 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type)
34513451
return btrfs_chunk_alloc(trans, alloc_flags, CHUNK_ALLOC_FORCE);
34523452
}
34533453

3454-
static int do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags)
3454+
static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags)
34553455
{
34563456
struct btrfs_block_group *bg;
34573457
int ret;
@@ -3538,7 +3538,11 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags)
35383538
out:
35393539
btrfs_trans_release_chunk_metadata(trans);
35403540

3541-
return ret;
3541+
if (ret)
3542+
return ERR_PTR(ret);
3543+
3544+
btrfs_get_block_group(bg);
3545+
return bg;
35423546
}
35433547

35443548
/*
@@ -3653,6 +3657,7 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
36533657
{
36543658
struct btrfs_fs_info *fs_info = trans->fs_info;
36553659
struct btrfs_space_info *space_info;
3660+
struct btrfs_block_group *ret_bg;
36563661
bool wait_for_alloc = false;
36573662
bool should_alloc = false;
36583663
int ret = 0;
@@ -3746,9 +3751,14 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
37463751
force_metadata_allocation(fs_info);
37473752
}
37483753

3749-
ret = do_chunk_alloc(trans, flags);
3754+
ret_bg = do_chunk_alloc(trans, flags);
37503755
trans->allocating_chunk = false;
37513756

3757+
if (IS_ERR(ret_bg))
3758+
ret = PTR_ERR(ret_bg);
3759+
else
3760+
btrfs_put_block_group(ret_bg);
3761+
37523762
spin_lock(&space_info->lock);
37533763
if (ret < 0) {
37543764
if (ret == -ENOSPC)

0 commit comments

Comments
 (0)