summaryrefslogtreecommitdiff
path: root/free-space-cache.c
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fb.com>2015-04-17 14:02:15 -0400
committerDavid Sterba <dsterba@suse.cz>2015-04-24 15:42:04 +0200
commit2681e00f00fe3dc0eb5d78dfeb344d18fccaeb6c (patch)
treec69c413ce7f4b3d4372441635b5d0d29890cec68 /free-space-cache.c
parentfb399a13013889c9dc91ba75d4d6ce549500d2f2 (diff)
downloadbtrfs-progs-2681e00f00fe3dc0eb5d78dfeb344d18fccaeb6c.tar.gz
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 <jbacik@fb.com> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'free-space-cache.c')
-rw-r--r--free-space-cache.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/free-space-cache.c b/free-space-cache.c
index 99ad420..67f00fd 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;