2018-04-03 17:16:55 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2017-10-09 01:51:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) Qu Wenruo 2017. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2018-04-03 17:16:55 +00:00
|
|
|
#ifndef BTRFS_TREE_CHECKER_H
|
|
|
|
#define BTRFS_TREE_CHECKER_H
|
2017-10-09 01:51:02 +00:00
|
|
|
|
|
|
|
#include "ctree.h"
|
|
|
|
#include "extent_io.h"
|
|
|
|
|
2017-11-08 00:54:24 +00:00
|
|
|
/*
|
|
|
|
* Comprehensive leaf checker.
|
|
|
|
* Will check not only the item pointers, but also every possible member
|
|
|
|
* in item data.
|
|
|
|
*/
|
2019-03-20 15:23:29 +00:00
|
|
|
int btrfs_check_leaf_full(struct extent_buffer *leaf);
|
2017-11-08 00:54:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Less strict leaf checker.
|
|
|
|
* Will only check item pointers, not reading item data.
|
|
|
|
*/
|
2019-03-20 15:24:18 +00:00
|
|
|
int btrfs_check_leaf_relaxed(struct extent_buffer *leaf);
|
2019-03-20 15:25:00 +00:00
|
|
|
int btrfs_check_node(struct extent_buffer *node);
|
2017-10-09 01:51:02 +00:00
|
|
|
|
2019-03-20 15:40:48 +00:00
|
|
|
int btrfs_check_chunk_valid(struct extent_buffer *leaf,
|
2019-03-20 05:16:42 +00:00
|
|
|
struct btrfs_chunk *chunk, u64 logical);
|
btrfs: tree-checker: check extent buffer owner against owner rootid
Btrfs doesn't check whether the tree block respects the root owner.
This means, if a tree block referred by a parent in extent tree, but has
owner of 5, btrfs can still continue reading the tree block, as long as
it doesn't trigger other sanity checks.
Normally this is fine, but combined with the empty tree check in
check_leaf(), if we hit an empty extent tree, but the root node has
csum tree owner, we can let such extent buffer to sneak in.
Shrink the hole by:
- Do extra eb owner check at tree read time
- Make sure the root owner extent buffer exactly matches the root id.
Unfortunately we can't yet completely patch the hole, there are several
call sites can't pass all info we need:
- For reloc/log trees
Their owner is key::offset, not key::objectid.
We need the full root key to do that accurate check.
For now, we just skip the ownership check for those trees.
- For add_data_references() of relocation
That call site doesn't have any parent/ownership info, as all the
bytenrs are all from btrfs_find_all_leafs().
- For direct backref items walk
Direct backref items records the parent bytenr directly, thus unlike
indirect backref item, we don't do a full tree search.
Thus in that case, we don't have full parent owner to check.
For the later two cases, they all pass 0 as @owner_root, thus we can
skip those cases if @owner_root is 0.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-03-16 00:05:58 +00:00
|
|
|
int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner);
|
2019-03-20 05:16:42 +00:00
|
|
|
|
2017-10-09 01:51:02 +00:00
|
|
|
#endif
|