btrfs-progs: check: do not infinite loop on corrupt keys with lowmem mode

By enabling the lowmem checks properly I uncovered the case where test
fsck/007 will infinite loop at the detection stage.  This is because
when checking the inode item we will just btrfs_next_item(), and because
we ignore check tree block failures at read time we don't get an -EIO
from btrfs_next_leaf.  Generally what check usually does is validate the
leaves/nodes as we hit them, but in this case we're not doing that.  Fix
this by checking the leaf if we move to the next one and if it fails
bail.  This allows us to pass the fsck/007 test with lowmem.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Josef Bacik 2021-08-18 17:33:14 -04:00 committed by David Sterba
parent 4a1863d638
commit 04520da77b
1 changed files with 9 additions and 0 deletions

View File

@ -2676,6 +2676,15 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path)
while (1) {
btrfs_item_key_to_cpu(path->nodes[0], &last_key, path->slots[0]);
ret = btrfs_next_item(root, path);
/*
* New leaf, we need to check it and see if it's valid, if not
* we need to bail otherwise we could end up stuck.
*/
if (path->slots[0] == 0 &&
btrfs_check_leaf(gfs_info, NULL, path->nodes[0]))
ret = -EIO;
if (ret < 0) {
/* out will fill 'err' rusing current statistics */
goto out;