Skip to contentSkip to conversation

Btrfs-progs: check for matchin free space in cache

PATCH Applied Josef Bacik 2 participants 2 messages Apr 17, 2015 – Apr 22, 2015 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Btrfs-progs: check for matchin 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,

---
V1->V2:
- only check matched if __load_free_space_cache is successful

 ctree.h            |  1 +
 extent-tree.c      | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 free-space-cache.c | 11 +++++++++++
 3 files changed, 63 insertions(+)
ctree.h +1 -0
index 2042771..10dc838 100644
@@ -936,6 +936,7 @@ struct btrfs_block_group_cache {
 	struct btrfs_block_group_item item;
 	struct btrfs_space_info *space_info;
 	struct btrfs_free_space_ctl *free_space_ctl;
+	u64 bytes_super;
 	u64 pinned;
 	u64 flags;
 	int cached;
extent-tree.c +51 -0

69 lines not on this page · raw message

free-space-cache.c +11 -0
index 99ad420..84a50e3 100644
@@ -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 abount of free space",
+		       block_group->key.objectid);
+		ret = -1;
+	}
+
 	if (ret < 0) {
 		ret = 0;
 
Signature · 1 line
1.8.3.1
Applied
#1 lore raw
Quoted 7 lines · Josef Bacik

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,

Applied, thanks.