Userland btrfs_alloc_chunk() and its kernel side counterpart __btrfs_alloc_chunk() is so diverged that it's difficult to use the kernel code as is. This commit introduces some RAID parameter variables and read them from btrfs_raid_array as the same as in kernel land. Signed-off-by: Naohiro Aota <naohiro.aota@xxxxxxx> --- volumes.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/volumes.c b/volumes.c index 143164f02ac0..8bfffa5586eb 100644 --- a/volumes.c +++ b/volumes.c @@ -1014,6 +1014,18 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, int max_stripes = 0; int min_stripes = 1; int sub_stripes = 1; + int dev_stripes __attribute__((unused)); + /* stripes per dev */ + int devs_max; /* max devs to use */ + int devs_min __attribute__((unused)); + /* min devs needed */ + int devs_increment __attribute__((unused)); + /* ndevs has to be a multiple of this */ + int ncopies __attribute__((unused)); + /* how many copies to data has */ + int nparity __attribute__((unused)); + /* number of stripes worth of bytes to + store parity information */ int looped = 0; int ret; int index; @@ -1025,6 +1037,18 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, return -ENOSPC; } + index = btrfs_bg_flags_to_raid_index(type); + + sub_stripes = btrfs_raid_array[index].sub_stripes; + dev_stripes = btrfs_raid_array[index].dev_stripes; + devs_max = btrfs_raid_array[index].devs_max; + if (!devs_max) + devs_max = BTRFS_MAX_DEVS(info); + devs_min = btrfs_raid_array[index].devs_min; + devs_increment = btrfs_raid_array[index].devs_increment; + ncopies = btrfs_raid_array[index].ncopies; + nparity = btrfs_raid_array[index].nparity; + if (type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { if (type & BTRFS_BLOCK_GROUP_SYSTEM) { calc_size = SZ_8M; @@ -1085,7 +1109,6 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, if (num_stripes < 4) return -ENOSPC; num_stripes &= ~(u32)1; - sub_stripes = 2; min_stripes = 4; } if (type & (BTRFS_BLOCK_GROUP_RAID5)) { -- 2.24.0