btrfs-progs: use btrfs_tree_parent_check for btrfs_read_extent_buffer

In the kernel we have a control structure call btrfs_tree_parent_check
to pass around the various sanity checks we have for extent buffers.
Add this to btrfs_tree_parent_check and then update the callers.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Josef Bacik 2023-08-23 10:33:00 -04:00 committed by David Sterba
parent 909bde13f4
commit a38570f9d6
3 changed files with 21 additions and 7 deletions

View File

@ -332,8 +332,8 @@ int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, int mirr
return 0;
}
int btrfs_read_extent_buffer(struct extent_buffer *eb, u64 parent_transid,
int level, struct btrfs_key *first_key)
int btrfs_read_extent_buffer(struct extent_buffer *eb,
struct btrfs_tree_parent_check *check)
{
struct btrfs_fs_info *fs_info = eb->fs_info;
int ret;
@ -349,7 +349,7 @@ int btrfs_read_extent_buffer(struct extent_buffer *eb, u64 parent_transid,
ret = read_whole_eb(fs_info, eb, mirror_num);
if (ret == 0 && csum_tree_block(fs_info, eb, 1) == 0 &&
check_tree_block(fs_info, eb) == 0 &&
verify_parent_transid(eb, parent_transid, ignore) == 0) {
verify_parent_transid(eb, check->transid, ignore) == 0) {
if (eb->flags & EXTENT_BUFFER_BAD_TRANSID &&
list_empty(&eb->recow)) {
list_add_tail(&eb->recow,
@ -420,10 +420,20 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
u64 owner_root, u64 parent_transid,
int level, struct btrfs_key *first_key)
{
struct btrfs_tree_parent_check check = {
.owner_root = owner_root,
.transid = parent_transid,
.level = level,
};
int ret;
struct extent_buffer *eb;
u32 sectorsize = fs_info->sectorsize;
if (first_key) {
check.has_first_key = true;
memcpy(&check.first_key, first_key, sizeof(*first_key));
}
/*
* Don't even try to create tree block for unaligned tree block
* bytenr.
@ -443,7 +453,7 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
if (btrfs_buffer_uptodate(eb, parent_transid, 0))
return eb;
ret = btrfs_read_extent_buffer(eb, parent_transid, level, first_key);
ret = btrfs_read_extent_buffer(eb, &check);
if (ret) {
/*
* We failed to read this tree block, it be should deleted right

View File

@ -23,6 +23,8 @@
#include "kernel-shared/ctree.h"
#include "kernel-lib/sizes.h"
struct btrfs_tree_parent_check;
#define BTRFS_SUPER_MIRROR_MAX 3
#define BTRFS_SUPER_MIRROR_SHIFT 12
@ -243,8 +245,8 @@ int btrfs_global_root_insert(struct btrfs_fs_info *fs_info,
int btrfs_find_and_setup_root(struct btrfs_root *tree_root,
struct btrfs_fs_info *fs_info,
u64 objectid, struct btrfs_root *root);
int btrfs_read_extent_buffer(struct extent_buffer *eb, u64 parent_transid,
int level, struct btrfs_key *first_key);
int btrfs_read_extent_buffer(struct extent_buffer *eb,
struct btrfs_tree_parent_check *check);
static inline struct btrfs_root *btrfs_block_group_root(
struct btrfs_fs_info *fs_info)

View File

@ -24,6 +24,7 @@
#include "kernel-shared/file-item.h"
#include "kernel-shared/extent_io.h"
#include "kernel-shared/transaction.h"
#include "kernel-shared/tree-checker.h"
#include "common/messages.h"
#include "common/internal.h"
#include "common/utils.h"
@ -494,6 +495,7 @@ static int rewrite_tree_block_csum(struct btrfs_fs_info *fs_info, u64 logical,
u16 new_csum_type)
{
struct extent_buffer *eb;
struct btrfs_tree_parent_check check = { 0 };
u8 result_old[BTRFS_CSUM_SIZE];
u8 result_new[BTRFS_CSUM_SIZE];
int ret;
@ -502,7 +504,7 @@ static int rewrite_tree_block_csum(struct btrfs_fs_info *fs_info, u64 logical,
if (!eb)
return -ENOMEM;
ret = btrfs_read_extent_buffer(eb, 0, 0, NULL);
ret = btrfs_read_extent_buffer(eb, &check);
if (ret < 0) {
errno = -ret;
error("failed to read tree block at logical %llu: %m", logical);