Skip to content

Commit c26fa93

Browse files
josefbacikkdave
authored andcommitted
btrfs: add __btrfs_check_node helper
This helper returns a btrfs_tree_block_status for the various errors, and then btrfs_check_node() will return -EUCLEAN if it gets anything other than BTRFS_TREE_BLOCK_CLEAN which will be used by the kernel. In the future btrfs-progs will use this helper instead. Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 924452c commit c26fa93

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

fs/btrfs/tree-checker.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,29 +1845,28 @@ int btrfs_check_leaf(struct extent_buffer *leaf)
18451845
}
18461846
ALLOW_ERROR_INJECTION(btrfs_check_leaf, ERRNO);
18471847

1848-
int btrfs_check_node(struct extent_buffer *node)
1848+
enum btrfs_tree_block_status __btrfs_check_node(struct extent_buffer *node)
18491849
{
18501850
struct btrfs_fs_info *fs_info = node->fs_info;
18511851
unsigned long nr = btrfs_header_nritems(node);
18521852
struct btrfs_key key, next_key;
18531853
int slot;
18541854
int level = btrfs_header_level(node);
18551855
u64 bytenr;
1856-
int ret = 0;
18571856

18581857
if (unlikely(level <= 0 || level >= BTRFS_MAX_LEVEL)) {
18591858
generic_err(node, 0,
18601859
"invalid level for node, have %d expect [1, %d]",
18611860
level, BTRFS_MAX_LEVEL - 1);
1862-
return -EUCLEAN;
1861+
return BTRFS_TREE_BLOCK_INVALID_LEVEL;
18631862
}
18641863
if (unlikely(nr == 0 || nr > BTRFS_NODEPTRS_PER_BLOCK(fs_info))) {
18651864
btrfs_crit(fs_info,
18661865
"corrupt node: root=%llu block=%llu, nritems too %s, have %lu expect range [1,%u]",
18671866
btrfs_header_owner(node), node->start,
18681867
nr == 0 ? "small" : "large", nr,
18691868
BTRFS_NODEPTRS_PER_BLOCK(fs_info));
1870-
return -EUCLEAN;
1869+
return BTRFS_TREE_BLOCK_INVALID_NRITEMS;
18711870
}
18721871

18731872
for (slot = 0; slot < nr - 1; slot++) {
@@ -1878,15 +1877,13 @@ int btrfs_check_node(struct extent_buffer *node)
18781877
if (unlikely(!bytenr)) {
18791878
generic_err(node, slot,
18801879
"invalid NULL node pointer");
1881-
ret = -EUCLEAN;
1882-
goto out;
1880+
return BTRFS_TREE_BLOCK_INVALID_BLOCKPTR;
18831881
}
18841882
if (unlikely(!IS_ALIGNED(bytenr, fs_info->sectorsize))) {
18851883
generic_err(node, slot,
18861884
"unaligned pointer, have %llu should be aligned to %u",
18871885
bytenr, fs_info->sectorsize);
1888-
ret = -EUCLEAN;
1889-
goto out;
1886+
return BTRFS_TREE_BLOCK_INVALID_BLOCKPTR;
18901887
}
18911888

18921889
if (unlikely(btrfs_comp_cpu_keys(&key, &next_key) >= 0)) {
@@ -1895,12 +1892,20 @@ int btrfs_check_node(struct extent_buffer *node)
18951892
key.objectid, key.type, key.offset,
18961893
next_key.objectid, next_key.type,
18971894
next_key.offset);
1898-
ret = -EUCLEAN;
1899-
goto out;
1895+
return BTRFS_TREE_BLOCK_BAD_KEY_ORDER;
19001896
}
19011897
}
1902-
out:
1903-
return ret;
1898+
return BTRFS_TREE_BLOCK_CLEAN;
1899+
}
1900+
1901+
int btrfs_check_node(struct extent_buffer *node)
1902+
{
1903+
enum btrfs_tree_block_status ret;
1904+
1905+
ret = __btrfs_check_node(node);
1906+
if (unlikely(ret != BTRFS_TREE_BLOCK_CLEAN))
1907+
return -EUCLEAN;
1908+
return 0;
19041909
}
19051910
ALLOW_ERROR_INJECTION(btrfs_check_node, ERRNO);
19061911

fs/btrfs/tree-checker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ enum btrfs_tree_block_status {
5858
* btrfs_tree_block_status return codes.
5959
*/
6060
enum btrfs_tree_block_status __btrfs_check_leaf(struct extent_buffer *leaf);
61+
enum btrfs_tree_block_status __btrfs_check_node(struct extent_buffer *node);
6162

6263
int btrfs_check_leaf(struct extent_buffer *leaf);
6364
int btrfs_check_node(struct extent_buffer *node);

0 commit comments

Comments
 (0)