Btrfs-progs: add a free space cache checker to fsck
Subsystems (2)
PATCH 1/1 Btrfs-progs: add a free space cache checker to fsck
In trying to track down a weird tree log problem I wanted to make sure that the free space cache was actually valid, which we currently have no way of doing. So this patch adds a bunch of support for the free space cache code and then a checker to fsck. Basically we go through and if we can actually load the free space cache then we will walk the extent tree and verify that the free space cache exactly matches what is in the extent tree. Hopefully this will always be correct, the only time it wouldn't is if the extent tree is corrupt or we have some sort of awful bug in the free space cache. Thanks,
--- Makefile | 3 +- bitops.h | 220 +++++++++++++ cmds-check.c | 209 +++++++++++++ ctree.h | 14 + extent-tree.c | 12 +- extent_io.c | 51 +++ extent_io.h | 4 + free-space-cache.c | 871 ++++++++++++++++++++++++++++++++++++++++++++++++++++ free-space-cache.h | 53 ++++ 9 files changed, 1434 insertions(+), 3 deletions(-) create mode 100644 bitops.h create mode 100644 free-space-cache.c create mode 100644 free-space-cache.h
Makefile +2 -1
@@ -6,7 +6,8 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ root-tree.o dir-item.o file-item.o inode-item.o \ inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ volumes.o utils.o btrfs-list.o btrfslabel.o repair.o \ - send-stream.o send-utils.o qgroup.o raid6.o + send-stream.o send-utils.o qgroup.o raid6.o free-space-cache.o + cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \ cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
bitops.h new file +220 -0
220 lines not on this page · raw message
cmds-check.c +209 -0
227 lines not on this page · raw message
ctree.h +14 -0
@@ -28,6 +28,7 @@struct btrfs_root ;struct btrfs_trans_handle ; +struct btrfs_free_space_ctl ;#define BTRFS_MAGIC 0x4D5F53665248425F/* ascii _BHRfS_M, no null */ #define BTRFS_MAX_LEVEL 8
@@ -268,6 +269,15 @@ struct btrfs_chunk {/* additional stripes go here */ } __attribute__ ((__packed__)); +#define BTRFS_FREE_SPACE_EXTENT 1 +#define BTRFS_FREE_SPACE_BITMAP 2 + +struct btrfs_free_space_entry { +__le64 offset; +__le64 bytes; +u8 type; +} __attribute__ ((__packed__ )); +struct btrfs_free_space_header {struct btrfs_disk_key location;__le64 generation;
@@ -866,6 +876,7 @@ struct btrfs_block_group_cache {struct btrfs_key key;struct btrfs_block_group_item item;struct btrfs_space_info *space_info; +struct btrfs_free_space_ctl *free_space_ctl;u64 pinned;u64 flags;int cached;
@@ -2055,6 +2066,9 @@ int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);struct btrfs_block_group_cache *btrfs_lookup_block_group (struct btrfs_fs_info *info,u64 bytenr); +struct btrfs_block_group_cache *btrfs_lookup_first_block_group (struct +btrfs_fs_info *info, +u64 bytenr); struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root, struct btrfs_block_group_cache *hint, u64 search_start,
extent-tree.c +10 -2
@@ -26,6 +26,7 @@#include "transaction.h" #include "crc32c.h" #include "volumes.h" +#include "free-space-cache.h" #define BLOCK_GROUP_DATA EXTENT_WRITEBACK#define BLOCK_GROUP_METADATA EXTENT_UPTODATE
@@ -3176,6 +3177,7 @@ out:int btrfs_free_block_groups (struct btrfs_fs_info *info) {struct btrfs_space_info *sinfo; +struct btrfs_block_group_cache *cache;u64 start;u64 end;u64 ptr;
@@ -3187,8 +3189,14 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)if (ret)break ; ret =get_state_private (&info->block_group_cache, start, &ptr); -if (!ret) -kfree ((void *)(unsigned long )ptr); +if (!ret) { + cache = (struct btrfs_block_group_cache *)ptr; +if (cache->free_space_ctl) { +btrfs_remove_free_space_cache (cache); +kfree (cache->free_space_ctl); + } +kfree (cache); + }clear_extent_bits (&info->block_group_cache, start, end, (unsigned int )-1 ,GFP_NOFS ); }
extent_io.c +51 -0
63 lines not on this page · raw message
extent_io.h +4 -0
@@ -34,6 +34,8 @@#define EXTENT_CSUM (1 << 9)#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK) +struct btrfs_fs_info ; +struct extent_io_tree {struct cache_tree state;struct cache_tree cache;
@@ -115,4 +117,6 @@ void memset_extent_buffer(struct extent_buffer *eb, char c, unsigned long start, unsigned long len);int set_extent_buffer_dirty (struct extent_buffer *eb);int clear_extent_buffer_dirty (struct extent_buffer *eb); +int read_data_from_disk (struct btrfs_fs_info *info,void *buf,u64 offset, +u64 bytes,int mirror);#endif
free-space-cache.c new file +871 -0
871 lines not on this page · raw message
free-space-cache.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
1.7.7.6