Skip to content

Commit ad5c224

Browse files
josefbacikkdave
authored andcommitted
btrfs-progs: change btrfs_check_chunk_valid to match the kernel version
In btrfs-progs we check the actual leaf pointers as well as the chunk itself in btrfs_check_chunk_valid. However in the kernel the leaf stuff is handled separately as part of the read, and then we have the chunk checker itself. Change the btrfs-progs version to match the in-kernel version temporarily so it makes syncing the in-kernel code easier. Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent cf94ae8 commit ad5c224

File tree

4 files changed

+9
-52
lines changed

4 files changed

+9
-52
lines changed

check/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5329,8 +5329,7 @@ static int process_chunk_item(struct cache_tree *chunk_cache,
53295329
* wrong onwer(3) out of chunk tree, to pass both chunk tree check
53305330
* and owner<->key_type check.
53315331
*/
5332-
ret = btrfs_check_chunk_valid(gfs_info, eb, chunk, slot,
5333-
key->offset);
5332+
ret = btrfs_check_chunk_valid(eb, chunk, key->offset);
53345333
if (ret < 0) {
53355334
error("chunk(%llu, %llu) is not valid, ignore it",
53365335
key->offset, btrfs_chunk_length(eb, chunk));

check/mode-lowmem.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4470,8 +4470,7 @@ static int check_dev_extent_item(struct extent_buffer *eb, int slot)
44704470

44714471
l = path.nodes[0];
44724472
chunk = btrfs_item_ptr(l, path.slots[0], struct btrfs_chunk);
4473-
ret = btrfs_check_chunk_valid(gfs_info, l, chunk, path.slots[0],
4474-
chunk_key.offset);
4473+
ret = btrfs_check_chunk_valid(l, chunk, chunk_key.offset);
44754474
if (ret < 0)
44764475
goto out;
44774476

@@ -4702,8 +4701,7 @@ static int check_chunk_item(struct extent_buffer *eb, int slot)
47024701
chunk = btrfs_item_ptr(eb, slot, struct btrfs_chunk);
47034702
length = btrfs_chunk_length(eb, chunk);
47044703
chunk_end = chunk_key.offset + length;
4705-
ret = btrfs_check_chunk_valid(gfs_info, eb, chunk, slot,
4706-
chunk_key.offset);
4704+
ret = btrfs_check_chunk_valid(eb, chunk, chunk_key.offset);
47074705
if (ret < 0) {
47084706
error("chunk[%llu %llu) is invalid", chunk_key.offset,
47094707
chunk_end);

kernel-shared/volumes.c

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,33 +2090,19 @@ static struct btrfs_device *fill_missing_device(u64 devid)
20902090
* slot == -1: SYSTEM chunk
20912091
* return -EIO on error, otherwise return 0
20922092
*/
2093-
int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
2094-
struct extent_buffer *leaf,
2095-
struct btrfs_chunk *chunk,
2096-
int slot, u64 logical)
2093+
int btrfs_check_chunk_valid(struct extent_buffer *leaf,
2094+
struct btrfs_chunk *chunk, u64 logical)
20972095
{
2096+
struct btrfs_fs_info *fs_info = leaf->fs_info;
20982097
u64 length;
20992098
u64 stripe_len;
21002099
u16 num_stripes;
21012100
u16 sub_stripes;
21022101
u64 type;
2103-
u32 chunk_ondisk_size;
21042102
u32 sectorsize = fs_info->sectorsize;
21052103
int min_devs;
21062104
int table_sub_stripes;
21072105

2108-
/*
2109-
* Basic chunk item size check. Note that btrfs_chunk already contains
2110-
* one stripe, so no "==" check.
2111-
*/
2112-
if (slot >= 0 &&
2113-
btrfs_item_size(leaf, slot) < sizeof(struct btrfs_chunk)) {
2114-
error("invalid chunk item size, have %u expect [%zu, %u)",
2115-
btrfs_item_size(leaf, slot),
2116-
sizeof(struct btrfs_chunk),
2117-
BTRFS_LEAF_DATA_SIZE(fs_info));
2118-
return -EUCLEAN;
2119-
}
21202106
length = btrfs_chunk_length(leaf, chunk);
21212107
stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
21222108
num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
@@ -2128,13 +2114,6 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
21282114
num_stripes);
21292115
return -EUCLEAN;
21302116
}
2131-
if (slot >= 0 && btrfs_chunk_item_size(num_stripes) !=
2132-
btrfs_item_size(leaf, slot)) {
2133-
error("invalid chunk item size, have %u expect %lu",
2134-
btrfs_item_size(leaf, slot),
2135-
btrfs_chunk_item_size(num_stripes));
2136-
return -EUCLEAN;
2137-
}
21382117

21392118
/*
21402119
* These valid checks may be insufficient to cover every corner cases.
@@ -2156,11 +2135,6 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
21562135
error("invalid chunk stripe length: %llu", stripe_len);
21572136
return -EIO;
21582137
}
2159-
/* Check on chunk item type */
2160-
if (slot == -1 && (type & BTRFS_BLOCK_GROUP_SYSTEM) == 0) {
2161-
error("invalid chunk type %llu", type);
2162-
return -EIO;
2163-
}
21642138
if (type & ~(BTRFS_BLOCK_GROUP_TYPE_MASK |
21652139
BTRFS_BLOCK_GROUP_PROFILE_MASK)) {
21662140
error("unrecognized chunk type: %llu",
@@ -2183,18 +2157,6 @@ int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
21832157
return -EIO;
21842158
}
21852159

2186-
chunk_ondisk_size = btrfs_chunk_item_size(num_stripes);
2187-
/*
2188-
* Btrfs_chunk contains at least one stripe, and for sys_chunk
2189-
* it can't exceed the system chunk array size
2190-
* For normal chunk, it should match its chunk item size.
2191-
*/
2192-
if (num_stripes < 1 ||
2193-
(slot == -1 && chunk_ondisk_size > BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) ||
2194-
(slot >= 0 && chunk_ondisk_size > btrfs_item_size(leaf, slot))) {
2195-
error("invalid num_stripes: %u", num_stripes);
2196-
return -EIO;
2197-
}
21982160
/*
21992161
* Device number check against profile
22002162
*/
@@ -2243,7 +2205,7 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
22432205
length = btrfs_chunk_length(leaf, chunk);
22442206
num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
22452207
/* Validation check */
2246-
ret = btrfs_check_chunk_valid(fs_info, leaf, chunk, slot, logical);
2208+
ret = btrfs_check_chunk_valid(leaf, chunk, logical);
22472209
if (ret) {
22482210
error("%s checksums match, but it has an invalid chunk, %s",
22492211
(slot == -1) ? "Superblock" : "Metadata",

kernel-shared/volumes.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,8 @@ int write_raid56_with_parity(struct btrfs_fs_info *info,
294294
struct extent_buffer *eb,
295295
struct btrfs_multi_bio *multi,
296296
u64 stripe_len, u64 *raid_map);
297-
int btrfs_check_chunk_valid(struct btrfs_fs_info *fs_info,
298-
struct extent_buffer *leaf,
299-
struct btrfs_chunk *chunk,
300-
int slot, u64 logical);
297+
int btrfs_check_chunk_valid(struct extent_buffer *leaf,
298+
struct btrfs_chunk *chunk, u64 logical);
301299
u64 btrfs_stripe_length(struct btrfs_fs_info *fs_info,
302300
struct extent_buffer *leaf,
303301
struct btrfs_chunk *chunk);

0 commit comments

Comments
 (0)