diff options
author | Gui Hecheng <guihc.fnst@cn.fujitsu.com> | 2014-04-21 08:13:12 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-06-09 20:20:36 -0400 |
commit | 23f8f9b7caca83d3397b1288a519c6579b7fda88 (patch) | |
tree | 5853816c24f3d48cc969bf80581451a110262551 | |
parent | 5f43f86e3f62734dfeeb36c4d940425a2c6789dc (diff) |
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 <guihc.fnst@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r-- | fs/btrfs/volumes.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 5864f05243c2..8113f4567084 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -4027,6 +4027,16 @@ static void check_raid56_incompat_flag(struct btrfs_fs_info *info, u64 type) | |||
4027 | btrfs_set_fs_incompat(info, RAID56); | 4027 | btrfs_set_fs_incompat(info, RAID56); |
4028 | } | 4028 | } |
4029 | 4029 | ||
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 | |||
4030 | static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, | 4040 | static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, |
4031 | struct btrfs_root *extent_root, u64 start, | 4041 | struct btrfs_root *extent_root, u64 start, |
4032 | u64 type) | 4042 | u64 type) |
@@ -4076,6 +4086,8 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, | |||
4076 | if (type & BTRFS_BLOCK_GROUP_DATA) { | 4086 | if (type & BTRFS_BLOCK_GROUP_DATA) { |
4077 | max_stripe_size = 1024 * 1024 * 1024; | 4087 | max_stripe_size = 1024 * 1024 * 1024; |
4078 | max_chunk_size = 10 * max_stripe_size; | 4088 | max_chunk_size = 10 * max_stripe_size; |
4089 | if (!devs_max) | ||
4090 | devs_max = BTRFS_MAX_DEVS(info->chunk_root); | ||
4079 | } else if (type & BTRFS_BLOCK_GROUP_METADATA) { | 4091 | } else if (type & BTRFS_BLOCK_GROUP_METADATA) { |
4080 | /* for larger filesystems, use larger metadata chunks */ | 4092 | /* for larger filesystems, use larger metadata chunks */ |
4081 | if (fs_devices->total_rw_bytes > 50ULL * 1024 * 1024 * 1024) | 4093 | if (fs_devices->total_rw_bytes > 50ULL * 1024 * 1024 * 1024) |
@@ -4083,9 +4095,13 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, | |||
4083 | else | 4095 | else |
4084 | max_stripe_size = 256 * 1024 * 1024; | 4096 | max_stripe_size = 256 * 1024 * 1024; |
4085 | max_chunk_size = max_stripe_size; | 4097 | max_chunk_size = max_stripe_size; |
4098 | if (!devs_max) | ||
4099 | devs_max = BTRFS_MAX_DEVS(info->chunk_root); | ||
4086 | } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) { | 4100 | } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) { |
4087 | max_stripe_size = 32 * 1024 * 1024; | 4101 | max_stripe_size = 32 * 1024 * 1024; |
4088 | max_chunk_size = 2 * max_stripe_size; | 4102 | max_chunk_size = 2 * max_stripe_size; |
4103 | if (!devs_max) | ||
4104 | devs_max = BTRFS_MAX_DEVS_SYS_CHUNK; | ||
4089 | } else { | 4105 | } else { |
4090 | btrfs_err(info, "invalid chunk type 0x%llx requested\n", | 4106 | btrfs_err(info, "invalid chunk type 0x%llx requested\n", |
4091 | type); | 4107 | type); |