@@ -165,9 +165,16 @@ static int check_free_space_tree(struct btrfs_root *root)
}
bg = btrfs_lookup_first_block_group(fs_info, key.objectid);
- if (!bg) {
+ if (!bg || key.objectid != bg->start ||
+ key.offset != bg->length) {
fprintf(stderr,
- "We have a space info key for a block group that doesn't exist\n");
+ "We have a space info key [%llu %u %llu] for a block group that "
+ "doesn't exist.\n",
+ key.objectid, key.type, key.offset);
+ fprintf(stderr,
+ "This is likely due to a minor bug in mkfs.btrfs that doesn't properly\n"
+ "cleanup free spaces and can be fixed using btrfs rescue "
+ "clear-space-cache v2\n");
ret = -EINVAL;
goto out;
}
Check that the block-group that is found matches the objectid and offset of the free-space-info. Without this the check only verifies that there is some block-group that exists with objectid >= free-space-info's objectid. I have softened the language of the warning and included instructions on how to fix the problem. This can be done in a couple of ways: - btrfs check --repair - btrfs rescue clear-space-cache v2 I chose to include btrfs rescue as it is more targeted. Signed-off-by: Leo Martins <loemra.dev@gmail.com> --- CHANGELOG: v3: - softened the warning and added instructions --- common/clear-cache.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)