Skip to content

Commit 85d8a82

Browse files
josefbacikkdave
authored andcommitted
btrfs: simplify btrfs_check_leaf_* helpers into a single helper
We have two helpers for checking leaves, because we have an extra check for debugging in btrfs_mark_buffer_dirty(), and at that stage we may have item data that isn't consistent yet. However we can handle this case internally in the helper, if BTRFS_HEADER_FLAG_WRITTEN is set we know the buffer should be internally consistent, otherwise we need to skip checking the item data. Simplify this helper down a single helper and handle the item data checking logic internally to the helper. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 4aec05f commit 85d8a82

File tree

3 files changed

+13
-32
lines changed

3 files changed

+13
-32
lines changed

fs/btrfs/disk-io.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static int csum_one_extent_buffer(struct extent_buffer *eb)
326326
if (btrfs_header_level(eb))
327327
ret = btrfs_check_node(eb);
328328
else
329-
ret = btrfs_check_leaf_full(eb);
329+
ret = btrfs_check_leaf(eb);
330330

331331
if (ret < 0)
332332
goto error;
@@ -583,7 +583,7 @@ static int validate_extent_buffer(struct extent_buffer *eb,
583583
* that we don't try and read the other copies of this block, just
584584
* return -EIO.
585585
*/
586-
if (found_level == 0 && btrfs_check_leaf_full(eb)) {
586+
if (found_level == 0 && btrfs_check_leaf(eb)) {
587587
set_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags);
588588
ret = -EIO;
589589
}
@@ -4701,12 +4701,10 @@ void btrfs_mark_buffer_dirty(struct extent_buffer *buf)
47014701
fs_info->dirty_metadata_batch);
47024702
#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
47034703
/*
4704-
* Since btrfs_mark_buffer_dirty() can be called with item pointer set
4705-
* but item data not updated.
4706-
* So here we should only check item pointers, not item data.
4704+
* btrfs_check_leaf() won't check item data if we don't have WRITTEN
4705+
* set, so this will only validate the basic structure of the items.
47074706
*/
4708-
if (btrfs_header_level(buf) == 0 &&
4709-
btrfs_check_leaf_relaxed(buf)) {
4707+
if (btrfs_header_level(buf) == 0 && btrfs_check_leaf(buf)) {
47104708
btrfs_print_leaf(buf);
47114709
ASSERT(0);
47124710
}

fs/btrfs/tree-checker.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ static int check_leaf_item(struct extent_buffer *leaf,
16741674
return ret;
16751675
}
16761676

1677-
static int check_leaf(struct extent_buffer *leaf, bool check_item_data)
1677+
int btrfs_check_leaf(struct extent_buffer *leaf)
16781678
{
16791679
struct btrfs_fs_info *fs_info = leaf->fs_info;
16801680
/* No valid key type is 0, so all key should be larger than this key */
@@ -1807,7 +1807,11 @@ static int check_leaf(struct extent_buffer *leaf, bool check_item_data)
18071807
return -EUCLEAN;
18081808
}
18091809

1810-
if (check_item_data) {
1810+
/*
1811+
* We only want to do this if WRITTEN is set, otherwise the leaf
1812+
* may be in some intermediate state and won't appear valid.
1813+
*/
1814+
if (btrfs_header_flag(leaf, BTRFS_HEADER_FLAG_WRITTEN)) {
18111815
/*
18121816
* Check if the item size and content meet other
18131817
* criteria
@@ -1824,17 +1828,7 @@ static int check_leaf(struct extent_buffer *leaf, bool check_item_data)
18241828

18251829
return 0;
18261830
}
1827-
1828-
int btrfs_check_leaf_full(struct extent_buffer *leaf)
1829-
{
1830-
return check_leaf(leaf, true);
1831-
}
1832-
ALLOW_ERROR_INJECTION(btrfs_check_leaf_full, ERRNO);
1833-
1834-
int btrfs_check_leaf_relaxed(struct extent_buffer *leaf)
1835-
{
1836-
return check_leaf(leaf, false);
1837-
}
1831+
ALLOW_ERROR_INJECTION(btrfs_check_leaf, ERRNO);
18381832

18391833
int btrfs_check_node(struct extent_buffer *node)
18401834
{

fs/btrfs/tree-checker.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,7 @@ struct btrfs_tree_parent_check {
4040
u8 level;
4141
};
4242

43-
/*
44-
* Comprehensive leaf checker.
45-
* Will check not only the item pointers, but also every possible member
46-
* in item data.
47-
*/
48-
int btrfs_check_leaf_full(struct extent_buffer *leaf);
49-
50-
/*
51-
* Less strict leaf checker.
52-
* Will only check item pointers, not reading item data.
53-
*/
54-
int btrfs_check_leaf_relaxed(struct extent_buffer *leaf);
43+
int btrfs_check_leaf(struct extent_buffer *leaf);
5544
int btrfs_check_node(struct extent_buffer *node);
5645

5746
int btrfs_check_chunk_valid(struct extent_buffer *leaf,

0 commit comments

Comments
 (0)