diff options
Diffstat (limited to 'fs/btrfs/disk-io.c')
| -rw-r--r-- | fs/btrfs/disk-io.c | 90 |
1 files changed, 48 insertions, 42 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index df8c8f291831..e720d3e6ec20 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
| @@ -401,7 +401,8 @@ out: | |||
| 401 | * Return 0 if the superblock checksum type matches the checksum value of that | 401 | * Return 0 if the superblock checksum type matches the checksum value of that |
| 402 | * algorithm. Pass the raw disk superblock data. | 402 | * algorithm. Pass the raw disk superblock data. |
| 403 | */ | 403 | */ |
| 404 | static int btrfs_check_super_csum(char *raw_disk_sb) | 404 | static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, |
| 405 | char *raw_disk_sb) | ||
| 405 | { | 406 | { |
| 406 | struct btrfs_super_block *disk_sb = | 407 | struct btrfs_super_block *disk_sb = |
| 407 | (struct btrfs_super_block *)raw_disk_sb; | 408 | (struct btrfs_super_block *)raw_disk_sb; |
| @@ -427,7 +428,7 @@ static int btrfs_check_super_csum(char *raw_disk_sb) | |||
| 427 | } | 428 | } |
| 428 | 429 | ||
| 429 | if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) { | 430 | if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) { |
| 430 | pr_err("BTRFS: unsupported checksum algorithm %u\n", | 431 | btrfs_err(fs_info, "unsupported checksum algorithm %u", |
| 431 | csum_type); | 432 | csum_type); |
| 432 | ret = 1; | 433 | ret = 1; |
| 433 | } | 434 | } |
| @@ -2780,7 +2781,7 @@ int open_ctree(struct super_block *sb, | |||
| 2780 | * We want to check superblock checksum, the type is stored inside. | 2781 | * We want to check superblock checksum, the type is stored inside. |
| 2781 | * Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k). | 2782 | * Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k). |
| 2782 | */ | 2783 | */ |
| 2783 | if (btrfs_check_super_csum(bh->b_data)) { | 2784 | if (btrfs_check_super_csum(fs_info, bh->b_data)) { |
| 2784 | btrfs_err(fs_info, "superblock checksum mismatch"); | 2785 | btrfs_err(fs_info, "superblock checksum mismatch"); |
| 2785 | err = -EINVAL; | 2786 | err = -EINVAL; |
| 2786 | brelse(bh); | 2787 | brelse(bh); |
| @@ -3624,7 +3625,7 @@ int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags) | |||
| 3624 | } | 3625 | } |
| 3625 | 3626 | ||
| 3626 | if (min_tolerated == INT_MAX) { | 3627 | if (min_tolerated == INT_MAX) { |
| 3627 | pr_warn("BTRFS: unknown raid flag: %llu\n", flags); | 3628 | pr_warn("BTRFS: unknown raid flag: %llu", flags); |
| 3628 | min_tolerated = 0; | 3629 | min_tolerated = 0; |
| 3629 | } | 3630 | } |
| 3630 | 3631 | ||
| @@ -4114,24 +4115,24 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, | |||
| 4114 | int ret = 0; | 4115 | int ret = 0; |
| 4115 | 4116 | ||
| 4116 | if (btrfs_super_magic(sb) != BTRFS_MAGIC) { | 4117 | if (btrfs_super_magic(sb) != BTRFS_MAGIC) { |
| 4117 | pr_err("BTRFS: no valid FS found\n"); | 4118 | btrfs_err(fs_info, "no valid FS found"); |
| 4118 | ret = -EINVAL; | 4119 | ret = -EINVAL; |
| 4119 | } | 4120 | } |
| 4120 | if (btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP) | 4121 | if (btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP) |
| 4121 | pr_warn("BTRFS: unrecognized super flag: %llu\n", | 4122 | btrfs_warn(fs_info, "unrecognized super flag: %llu", |
| 4122 | btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP); | 4123 | btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP); |
| 4123 | if (btrfs_super_root_level(sb) >= BTRFS_MAX_LEVEL) { | 4124 | if (btrfs_super_root_level(sb) >= BTRFS_MAX_LEVEL) { |
| 4124 | pr_err("BTRFS: tree_root level too big: %d >= %d\n", | 4125 | btrfs_err(fs_info, "tree_root level too big: %d >= %d", |
| 4125 | btrfs_super_root_level(sb), BTRFS_MAX_LEVEL); | 4126 | btrfs_super_root_level(sb), BTRFS_MAX_LEVEL); |
| 4126 | ret = -EINVAL; | 4127 | ret = -EINVAL; |
| 4127 | } | 4128 | } |
| 4128 | if (btrfs_super_chunk_root_level(sb) >= BTRFS_MAX_LEVEL) { | 4129 | if (btrfs_super_chunk_root_level(sb) >= BTRFS_MAX_LEVEL) { |
| 4129 | pr_err("BTRFS: chunk_root level too big: %d >= %d\n", | 4130 | btrfs_err(fs_info, "chunk_root level too big: %d >= %d", |
| 4130 | btrfs_super_chunk_root_level(sb), BTRFS_MAX_LEVEL); | 4131 | btrfs_super_chunk_root_level(sb), BTRFS_MAX_LEVEL); |
| 4131 | ret = -EINVAL; | 4132 | ret = -EINVAL; |
| 4132 | } | 4133 | } |
| 4133 | if (btrfs_super_log_root_level(sb) >= BTRFS_MAX_LEVEL) { | 4134 | if (btrfs_super_log_root_level(sb) >= BTRFS_MAX_LEVEL) { |
| 4134 | pr_err("BTRFS: log_root level too big: %d >= %d\n", | 4135 | btrfs_err(fs_info, "log_root level too big: %d >= %d", |
| 4135 | btrfs_super_log_root_level(sb), BTRFS_MAX_LEVEL); | 4136 | btrfs_super_log_root_level(sb), BTRFS_MAX_LEVEL); |
| 4136 | ret = -EINVAL; | 4137 | ret = -EINVAL; |
| 4137 | } | 4138 | } |
| @@ -4142,47 +4143,48 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, | |||
| 4142 | */ | 4143 | */ |
| 4143 | if (!is_power_of_2(sectorsize) || sectorsize < 4096 || | 4144 | if (!is_power_of_2(sectorsize) || sectorsize < 4096 || |
| 4144 | sectorsize > BTRFS_MAX_METADATA_BLOCKSIZE) { | 4145 | sectorsize > BTRFS_MAX_METADATA_BLOCKSIZE) { |
| 4145 | pr_err("BTRFS: invalid sectorsize %llu\n", sectorsize); | 4146 | btrfs_err(fs_info, "invalid sectorsize %llu", sectorsize); |
| 4146 | ret = -EINVAL; | 4147 | ret = -EINVAL; |
| 4147 | } | 4148 | } |
| 4148 | /* Only PAGE SIZE is supported yet */ | 4149 | /* Only PAGE SIZE is supported yet */ |
| 4149 | if (sectorsize != PAGE_SIZE) { | 4150 | if (sectorsize != PAGE_SIZE) { |
| 4150 | pr_err("BTRFS: sectorsize %llu not supported yet, only support %lu\n", | 4151 | btrfs_err(fs_info, |
| 4151 | sectorsize, PAGE_SIZE); | 4152 | "sectorsize %llu not supported yet, only support %lu", |
| 4153 | sectorsize, PAGE_SIZE); | ||
| 4152 | ret = -EINVAL; | 4154 | ret = -EINVAL; |
| 4153 | } | 4155 | } |
| 4154 | if (!is_power_of_2(nodesize) || nodesize < sectorsize || | 4156 | if (!is_power_of_2(nodesize) || nodesize < sectorsize || |
| 4155 | nodesize > BTRFS_MAX_METADATA_BLOCKSIZE) { | 4157 | nodesize > BTRFS_MAX_METADATA_BLOCKSIZE) { |
| 4156 | pr_err("BTRFS: invalid nodesize %llu\n", nodesize); | 4158 | btrfs_err(fs_info, "invalid nodesize %llu", nodesize); |
| 4157 | ret = -EINVAL; | 4159 | ret = -EINVAL; |
| 4158 | } | 4160 | } |
| 4159 | if (nodesize != le32_to_cpu(sb->__unused_leafsize)) { | 4161 | if (nodesize != le32_to_cpu(sb->__unused_leafsize)) { |
| 4160 | pr_err("BTRFS: invalid leafsize %u, should be %llu\n", | 4162 | btrfs_err(fs_info, "invalid leafsize %u, should be %llu", |
| 4161 | le32_to_cpu(sb->__unused_leafsize), | 4163 | le32_to_cpu(sb->__unused_leafsize), nodesize); |
| 4162 | nodesize); | ||
| 4163 | ret = -EINVAL; | 4164 | ret = -EINVAL; |
| 4164 | } | 4165 | } |
| 4165 | 4166 | ||
| 4166 | /* Root alignment check */ | 4167 | /* Root alignment check */ |
| 4167 | if (!IS_ALIGNED(btrfs_super_root(sb), sectorsize)) { | 4168 | if (!IS_ALIGNED(btrfs_super_root(sb), sectorsize)) { |
| 4168 | pr_warn("BTRFS: tree_root block unaligned: %llu\n", | 4169 | btrfs_warn(fs_info, "tree_root block unaligned: %llu", |
| 4169 | btrfs_super_root(sb)); | 4170 | btrfs_super_root(sb)); |
| 4170 | ret = -EINVAL; | 4171 | ret = -EINVAL; |
| 4171 | } | 4172 | } |
| 4172 | if (!IS_ALIGNED(btrfs_super_chunk_root(sb), sectorsize)) { | 4173 | if (!IS_ALIGNED(btrfs_super_chunk_root(sb), sectorsize)) { |
| 4173 | pr_warn("BTRFS: chunk_root block unaligned: %llu\n", | 4174 | btrfs_warn(fs_info, "chunk_root block unaligned: %llu", |
| 4174 | btrfs_super_chunk_root(sb)); | 4175 | btrfs_super_chunk_root(sb)); |
| 4175 | ret = -EINVAL; | 4176 | ret = -EINVAL; |
| 4176 | } | 4177 | } |
| 4177 | if (!IS_ALIGNED(btrfs_super_log_root(sb), sectorsize)) { | 4178 | if (!IS_ALIGNED(btrfs_super_log_root(sb), sectorsize)) { |
| 4178 | pr_warn("BTRFS: log_root block unaligned: %llu\n", | 4179 | btrfs_warn(fs_info, "log_root block unaligned: %llu", |
| 4179 | btrfs_super_log_root(sb)); | 4180 | btrfs_super_log_root(sb)); |
| 4180 | ret = -EINVAL; | 4181 | ret = -EINVAL; |
| 4181 | } | 4182 | } |
| 4182 | 4183 | ||
| 4183 | if (memcmp(fs_info->fsid, sb->dev_item.fsid, BTRFS_UUID_SIZE) != 0) { | 4184 | if (memcmp(fs_info->fsid, sb->dev_item.fsid, BTRFS_UUID_SIZE) != 0) { |
| 4184 | pr_err("BTRFS: dev_item UUID does not match fsid: %pU != %pU\n", | 4185 | btrfs_err(fs_info, |
| 4185 | fs_info->fsid, sb->dev_item.fsid); | 4186 | "dev_item UUID does not match fsid: %pU != %pU", |
| 4187 | fs_info->fsid, sb->dev_item.fsid); | ||
| 4186 | ret = -EINVAL; | 4188 | ret = -EINVAL; |
| 4187 | } | 4189 | } |
| 4188 | 4190 | ||
| @@ -4192,25 +4194,25 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, | |||
| 4192 | */ | 4194 | */ |
| 4193 | if (btrfs_super_bytes_used(sb) < 6 * btrfs_super_nodesize(sb)) { | 4195 | if (btrfs_super_bytes_used(sb) < 6 * btrfs_super_nodesize(sb)) { |
| 4194 | btrfs_err(fs_info, "bytes_used is too small %llu", | 4196 | btrfs_err(fs_info, "bytes_used is too small %llu", |
| 4195 | btrfs_super_bytes_used(sb)); | 4197 | btrfs_super_bytes_used(sb)); |
| 4196 | ret = -EINVAL; | 4198 | ret = -EINVAL; |
| 4197 | } | 4199 | } |
| 4198 | if (!is_power_of_2(btrfs_super_stripesize(sb))) { | 4200 | if (!is_power_of_2(btrfs_super_stripesize(sb))) { |
| 4199 | btrfs_err(fs_info, "invalid stripesize %u", | 4201 | btrfs_err(fs_info, "invalid stripesize %u", |
| 4200 | btrfs_super_stripesize(sb)); | 4202 | btrfs_super_stripesize(sb)); |
| 4201 | ret = -EINVAL; | 4203 | ret = -EINVAL; |
| 4202 | } | 4204 | } |
| 4203 | if (btrfs_super_num_devices(sb) > (1UL << 31)) | 4205 | if (btrfs_super_num_devices(sb) > (1UL << 31)) |
| 4204 | pr_warn("BTRFS: suspicious number of devices: %llu\n", | 4206 | btrfs_warn(fs_info, "suspicious number of devices: %llu", |
| 4205 | btrfs_super_num_devices(sb)); | 4207 | btrfs_super_num_devices(sb)); |
| 4206 | if (btrfs_super_num_devices(sb) == 0) { | 4208 | if (btrfs_super_num_devices(sb) == 0) { |
| 4207 | pr_err("BTRFS: number of devices is 0\n"); | 4209 | btrfs_err(fs_info, "number of devices is 0"); |
| 4208 | ret = -EINVAL; | 4210 | ret = -EINVAL; |
| 4209 | } | 4211 | } |
| 4210 | 4212 | ||
| 4211 | if (btrfs_super_bytenr(sb) != BTRFS_SUPER_INFO_OFFSET) { | 4213 | if (btrfs_super_bytenr(sb) != BTRFS_SUPER_INFO_OFFSET) { |
| 4212 | pr_err("BTRFS: super offset mismatch %llu != %u\n", | 4214 | btrfs_err(fs_info, "super offset mismatch %llu != %u", |
| 4213 | btrfs_super_bytenr(sb), BTRFS_SUPER_INFO_OFFSET); | 4215 | btrfs_super_bytenr(sb), BTRFS_SUPER_INFO_OFFSET); |
| 4214 | ret = -EINVAL; | 4216 | ret = -EINVAL; |
| 4215 | } | 4217 | } |
| 4216 | 4218 | ||
| @@ -4219,17 +4221,17 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, | |||
| 4219 | * and one chunk | 4221 | * and one chunk |
| 4220 | */ | 4222 | */ |
| 4221 | if (btrfs_super_sys_array_size(sb) > BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) { | 4223 | if (btrfs_super_sys_array_size(sb) > BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) { |
| 4222 | pr_err("BTRFS: system chunk array too big %u > %u\n", | 4224 | btrfs_err(fs_info, "system chunk array too big %u > %u", |
| 4223 | btrfs_super_sys_array_size(sb), | 4225 | btrfs_super_sys_array_size(sb), |
| 4224 | BTRFS_SYSTEM_CHUNK_ARRAY_SIZE); | 4226 | BTRFS_SYSTEM_CHUNK_ARRAY_SIZE); |
| 4225 | ret = -EINVAL; | 4227 | ret = -EINVAL; |
| 4226 | } | 4228 | } |
| 4227 | if (btrfs_super_sys_array_size(sb) < sizeof(struct btrfs_disk_key) | 4229 | if (btrfs_super_sys_array_size(sb) < sizeof(struct btrfs_disk_key) |
| 4228 | + sizeof(struct btrfs_chunk)) { | 4230 | + sizeof(struct btrfs_chunk)) { |
| 4229 | pr_err("BTRFS: system chunk array too small %u < %zu\n", | 4231 | btrfs_err(fs_info, "system chunk array too small %u < %zu", |
| 4230 | btrfs_super_sys_array_size(sb), | 4232 | btrfs_super_sys_array_size(sb), |
| 4231 | sizeof(struct btrfs_disk_key) | 4233 | sizeof(struct btrfs_disk_key) |
| 4232 | + sizeof(struct btrfs_chunk)); | 4234 | + sizeof(struct btrfs_chunk)); |
| 4233 | ret = -EINVAL; | 4235 | ret = -EINVAL; |
| 4234 | } | 4236 | } |
| 4235 | 4237 | ||
| @@ -4238,12 +4240,16 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, | |||
| 4238 | * but it's still possible that it's the one that's wrong. | 4240 | * but it's still possible that it's the one that's wrong. |
| 4239 | */ | 4241 | */ |
| 4240 | if (btrfs_super_generation(sb) < btrfs_super_chunk_root_generation(sb)) | 4242 | if (btrfs_super_generation(sb) < btrfs_super_chunk_root_generation(sb)) |
| 4241 | pr_warn("BTRFS: suspicious: generation < chunk_root_generation: %llu < %llu\n", | 4243 | btrfs_warn(fs_info, |
| 4242 | btrfs_super_generation(sb), btrfs_super_chunk_root_generation(sb)); | 4244 | "suspicious: generation < chunk_root_generation: %llu < %llu", |
| 4245 | btrfs_super_generation(sb), | ||
| 4246 | btrfs_super_chunk_root_generation(sb)); | ||
| 4243 | if (btrfs_super_generation(sb) < btrfs_super_cache_generation(sb) | 4247 | if (btrfs_super_generation(sb) < btrfs_super_cache_generation(sb) |
| 4244 | && btrfs_super_cache_generation(sb) != (u64)-1) | 4248 | && btrfs_super_cache_generation(sb) != (u64)-1) |
| 4245 | pr_warn("BTRFS: suspicious: generation < cache_generation: %llu < %llu\n", | 4249 | btrfs_warn(fs_info, |
| 4246 | btrfs_super_generation(sb), btrfs_super_cache_generation(sb)); | 4250 | "suspicious: generation < cache_generation: %llu < %llu", |
| 4251 | btrfs_super_generation(sb), | ||
| 4252 | btrfs_super_cache_generation(sb)); | ||
| 4247 | 4253 | ||
| 4248 | return ret; | 4254 | return ret; |
| 4249 | } | 4255 | } |
