From 2681e00f00fe3dc0eb5d78dfeb344d18fccaeb6c Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Fri, 17 Apr 2015 14:02:15 -0400 Subject: btrfs-progs: check for matching free space in cache We have this check in the kernel but not in userspace, which makes fsck fail when we wouldn't have a problem in the kernel. This was meant to catch this case because it really isn't good, unfortunately it will require a design change to fix in the kernel so in the meantime add this check so we can be sure our tests only catch real problems. Thanks, Signed-off-by: Josef Bacik Signed-off-by: David Sterba --- free-space-cache.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'free-space-cache.c') diff --git a/free-space-cache.c b/free-space-cache.c index 99ad4200..67f00fd2 100644 --- a/free-space-cache.c +++ b/free-space-cache.c @@ -428,7 +428,9 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info, { struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; struct btrfs_path *path; + u64 used = btrfs_block_group_used(&block_group->item); int ret = 0; + int matched; path = btrfs_alloc_path(); if (!path) @@ -438,6 +440,15 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info, block_group->key.objectid); btrfs_free_path(path); + matched = (ctl->free_space == (block_group->key.offset - used - + block_group->bytes_super)); + if (ret == 1 && !matched) { + __btrfs_remove_free_space_cache(ctl); + printf("block group %llu has wrong amount of free space", + block_group->key.objectid); + ret = -1; + } + if (ret < 0) { ret = 0; -- cgit v1.2.3