Skip to content

Commit 23f8f9b

Browse files
Gui Hechengmasoncl
authored andcommitted
btrfs: add dev maxs limit for __btrfs_alloc_chunk in kernel space
For RAID0,5,6,10, For system chunk, there shouldn't be too many stripes to make a btrfs_chunk that exceeds BTRFS_SYSTEM_CHUNK_ARRAY_SIZE For data/meta chunk, there shouldn't be too many stripes to make a btrfs_chunk that exceeds a leaf. Signed-off-by: Gui Hecheng <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent 5f43f86 commit 23f8f9b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

fs/btrfs/volumes.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,6 +4027,16 @@ static void check_raid56_incompat_flag(struct btrfs_fs_info *info, u64 type)
40274027
btrfs_set_fs_incompat(info, RAID56);
40284028
}
40294029

4030+
#define BTRFS_MAX_DEVS(r) ((BTRFS_LEAF_DATA_SIZE(r) \
4031+
- sizeof(struct btrfs_item) \
4032+
- sizeof(struct btrfs_chunk)) \
4033+
/ sizeof(struct btrfs_stripe) + 1)
4034+
4035+
#define BTRFS_MAX_DEVS_SYS_CHUNK ((BTRFS_SYSTEM_CHUNK_ARRAY_SIZE \
4036+
- 2 * sizeof(struct btrfs_disk_key) \
4037+
- 2 * sizeof(struct btrfs_chunk)) \
4038+
/ sizeof(struct btrfs_stripe) + 1)
4039+
40304040
static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
40314041
struct btrfs_root *extent_root, u64 start,
40324042
u64 type)
@@ -4076,16 +4086,22 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
40764086
if (type & BTRFS_BLOCK_GROUP_DATA) {
40774087
max_stripe_size = 1024 * 1024 * 1024;
40784088
max_chunk_size = 10 * max_stripe_size;
4089+
if (!devs_max)
4090+
devs_max = BTRFS_MAX_DEVS(info->chunk_root);
40794091
} else if (type & BTRFS_BLOCK_GROUP_METADATA) {
40804092
/* for larger filesystems, use larger metadata chunks */
40814093
if (fs_devices->total_rw_bytes > 50ULL * 1024 * 1024 * 1024)
40824094
max_stripe_size = 1024 * 1024 * 1024;
40834095
else
40844096
max_stripe_size = 256 * 1024 * 1024;
40854097
max_chunk_size = max_stripe_size;
4098+
if (!devs_max)
4099+
devs_max = BTRFS_MAX_DEVS(info->chunk_root);
40864100
} else if (type & BTRFS_BLOCK_GROUP_SYSTEM) {
40874101
max_stripe_size = 32 * 1024 * 1024;
40884102
max_chunk_size = 2 * max_stripe_size;
4103+
if (!devs_max)
4104+
devs_max = BTRFS_MAX_DEVS_SYS_CHUNK;
40894105
} else {
40904106
btrfs_err(info, "invalid chunk type 0x%llx requested\n",
40914107
type);

0 commit comments

Comments
 (0)