Skip to content

Commit 2cac5af

Browse files
josefbacikkdave
authored andcommitted
btrfs: move btrfs_verify_level_key into tree-checker.c
This is more a buffer validation helper, move it into the tree-checker files where it makes more sense. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent c26fa93 commit 2cac5af

File tree

4 files changed

+60
-60
lines changed

4 files changed

+60
-60
lines changed

fs/btrfs/disk-io.c

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -180,64 +180,6 @@ int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
180180
return 0;
181181
}
182182

183-
int btrfs_verify_level_key(struct extent_buffer *eb, int level,
184-
struct btrfs_key *first_key, u64 parent_transid)
185-
{
186-
struct btrfs_fs_info *fs_info = eb->fs_info;
187-
int found_level;
188-
struct btrfs_key found_key;
189-
int ret;
190-
191-
found_level = btrfs_header_level(eb);
192-
if (found_level != level) {
193-
WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
194-
KERN_ERR "BTRFS: tree level check failed\n");
195-
btrfs_err(fs_info,
196-
"tree level mismatch detected, bytenr=%llu level expected=%u has=%u",
197-
eb->start, level, found_level);
198-
return -EIO;
199-
}
200-
201-
if (!first_key)
202-
return 0;
203-
204-
/*
205-
* For live tree block (new tree blocks in current transaction),
206-
* we need proper lock context to avoid race, which is impossible here.
207-
* So we only checks tree blocks which is read from disk, whose
208-
* generation <= fs_info->last_trans_committed.
209-
*/
210-
if (btrfs_header_generation(eb) > fs_info->last_trans_committed)
211-
return 0;
212-
213-
/* We have @first_key, so this @eb must have at least one item */
214-
if (btrfs_header_nritems(eb) == 0) {
215-
btrfs_err(fs_info,
216-
"invalid tree nritems, bytenr=%llu nritems=0 expect >0",
217-
eb->start);
218-
WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG));
219-
return -EUCLEAN;
220-
}
221-
222-
if (found_level)
223-
btrfs_node_key_to_cpu(eb, &found_key, 0);
224-
else
225-
btrfs_item_key_to_cpu(eb, &found_key, 0);
226-
ret = btrfs_comp_cpu_keys(first_key, &found_key);
227-
228-
if (ret) {
229-
WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
230-
KERN_ERR "BTRFS: tree first key check failed\n");
231-
btrfs_err(fs_info,
232-
"tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)",
233-
eb->start, parent_transid, first_key->objectid,
234-
first_key->type, first_key->offset,
235-
found_key.objectid, found_key.type,
236-
found_key.offset);
237-
}
238-
return ret;
239-
}
240-
241183
static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb,
242184
int mirror_num)
243185
{

fs/btrfs/disk-io.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ struct btrfs_tree_parent_check;
3131

3232
void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info);
3333
void btrfs_init_fs_info(struct btrfs_fs_info *fs_info);
34-
int btrfs_verify_level_key(struct extent_buffer *eb, int level,
35-
struct btrfs_key *first_key, u64 parent_transid);
3634
struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
3735
struct btrfs_tree_parent_check *check);
3836
struct extent_buffer *btrfs_find_create_tree_block(

fs/btrfs/tree-checker.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,3 +1963,61 @@ int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner)
19631963
}
19641964
return 0;
19651965
}
1966+
1967+
int btrfs_verify_level_key(struct extent_buffer *eb, int level,
1968+
struct btrfs_key *first_key, u64 parent_transid)
1969+
{
1970+
struct btrfs_fs_info *fs_info = eb->fs_info;
1971+
int found_level;
1972+
struct btrfs_key found_key;
1973+
int ret;
1974+
1975+
found_level = btrfs_header_level(eb);
1976+
if (found_level != level) {
1977+
WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
1978+
KERN_ERR "BTRFS: tree level check failed\n");
1979+
btrfs_err(fs_info,
1980+
"tree level mismatch detected, bytenr=%llu level expected=%u has=%u",
1981+
eb->start, level, found_level);
1982+
return -EIO;
1983+
}
1984+
1985+
if (!first_key)
1986+
return 0;
1987+
1988+
/*
1989+
* For live tree block (new tree blocks in current transaction),
1990+
* we need proper lock context to avoid race, which is impossible here.
1991+
* So we only checks tree blocks which is read from disk, whose
1992+
* generation <= fs_info->last_trans_committed.
1993+
*/
1994+
if (btrfs_header_generation(eb) > fs_info->last_trans_committed)
1995+
return 0;
1996+
1997+
/* We have @first_key, so this @eb must have at least one item */
1998+
if (btrfs_header_nritems(eb) == 0) {
1999+
btrfs_err(fs_info,
2000+
"invalid tree nritems, bytenr=%llu nritems=0 expect >0",
2001+
eb->start);
2002+
WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG));
2003+
return -EUCLEAN;
2004+
}
2005+
2006+
if (found_level)
2007+
btrfs_node_key_to_cpu(eb, &found_key, 0);
2008+
else
2009+
btrfs_item_key_to_cpu(eb, &found_key, 0);
2010+
ret = btrfs_comp_cpu_keys(first_key, &found_key);
2011+
2012+
if (ret) {
2013+
WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
2014+
KERN_ERR "BTRFS: tree first key check failed\n");
2015+
btrfs_err(fs_info,
2016+
"tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)",
2017+
eb->start, parent_transid, first_key->objectid,
2018+
first_key->type, first_key->offset,
2019+
found_key.objectid, found_key.type,
2020+
found_key.offset);
2021+
}
2022+
return ret;
2023+
}

fs/btrfs/tree-checker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,7 @@ int btrfs_check_node(struct extent_buffer *node);
6666
int btrfs_check_chunk_valid(struct extent_buffer *leaf,
6767
struct btrfs_chunk *chunk, u64 logical);
6868
int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner);
69+
int btrfs_verify_level_key(struct extent_buffer *eb, int level,
70+
struct btrfs_key *first_key, u64 parent_transid);
6971

7072
#endif

0 commit comments

Comments
 (0)