mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-21 14:35:25 +00:00
btrfs-progs: check: make free space tree validation extent tree v2 aware
The free space tree needs to be validated against all referenced blocks in the file system, so use the btrfs_mark_used_blocks() helper to check the free space tree and free space cache against. This will do the right thing for both extent tree v1 and extent tree v2. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
b4d714a47a
commit
f9b65a54c0
88
check/main.c
88
check/main.c
@ -5637,72 +5637,38 @@ static int check_cache_range(struct btrfs_root *root,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int verify_space_cache(struct btrfs_root *root,
|
static int verify_space_cache(struct btrfs_root *root,
|
||||||
struct btrfs_block_group *cache)
|
struct btrfs_block_group *cache,
|
||||||
|
struct extent_io_tree *used)
|
||||||
{
|
{
|
||||||
struct btrfs_path path;
|
u64 start, end, last_end, bg_end;
|
||||||
struct extent_buffer *leaf;
|
|
||||||
struct btrfs_key key;
|
|
||||||
u64 last;
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
root = btrfs_extent_root(root->fs_info, cache->start);
|
start = cache->start;
|
||||||
|
bg_end = cache->start + cache->length;
|
||||||
|
last_end = start;
|
||||||
|
|
||||||
last = max_t(u64, cache->start, BTRFS_SUPER_INFO_OFFSET);
|
while (start < bg_end) {
|
||||||
|
ret = find_first_extent_bit(used, cache->start, &start, &end,
|
||||||
btrfs_init_path(&path);
|
EXTENT_DIRTY);
|
||||||
key.objectid = last;
|
if (ret || start >= bg_end) {
|
||||||
key.offset = 0;
|
|
||||||
key.type = BTRFS_EXTENT_ITEM_KEY;
|
|
||||||
ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
|
|
||||||
if (ret < 0)
|
|
||||||
goto out;
|
|
||||||
ret = 0;
|
|
||||||
while (1) {
|
|
||||||
if (path.slots[0] >= btrfs_header_nritems(path.nodes[0])) {
|
|
||||||
ret = btrfs_next_leaf(root, &path);
|
|
||||||
if (ret < 0)
|
|
||||||
goto out;
|
|
||||||
if (ret > 0) {
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
if (last_end < start) {
|
||||||
leaf = path.nodes[0];
|
ret = check_cache_range(root, cache, last_end,
|
||||||
btrfs_item_key_to_cpu(leaf, &key, path.slots[0]);
|
start - last_end);
|
||||||
if (key.objectid >= cache->start + cache->length)
|
|
||||||
break;
|
|
||||||
if (key.type != BTRFS_EXTENT_ITEM_KEY &&
|
|
||||||
key.type != BTRFS_METADATA_ITEM_KEY) {
|
|
||||||
path.slots[0]++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (last == key.objectid) {
|
|
||||||
if (key.type == BTRFS_EXTENT_ITEM_KEY)
|
|
||||||
last = key.objectid + key.offset;
|
|
||||||
else
|
|
||||||
last = key.objectid + gfs_info->nodesize;
|
|
||||||
path.slots[0]++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = check_cache_range(root, cache, last,
|
|
||||||
key.objectid - last);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
return ret;
|
||||||
if (key.type == BTRFS_EXTENT_ITEM_KEY)
|
}
|
||||||
last = key.objectid + key.offset;
|
end = min(end, bg_end - 1);
|
||||||
else
|
clear_extent_dirty(used, start, end);
|
||||||
last = key.objectid + gfs_info->nodesize;
|
start = end + 1;
|
||||||
path.slots[0]++;
|
last_end = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last < cache->start + cache->length)
|
if (last_end < bg_end)
|
||||||
ret = check_cache_range(root, cache, last,
|
ret = check_cache_range(root, cache, last_end,
|
||||||
cache->start + cache->length - last);
|
bg_end - last_end);
|
||||||
|
|
||||||
out:
|
|
||||||
btrfs_release_path(&path);
|
|
||||||
|
|
||||||
if (!ret &&
|
if (!ret &&
|
||||||
!RB_EMPTY_ROOT(&cache->free_space_ctl->free_space_offset)) {
|
!RB_EMPTY_ROOT(&cache->free_space_ctl->free_space_offset)) {
|
||||||
@ -5716,11 +5682,17 @@ out:
|
|||||||
|
|
||||||
static int check_space_cache(struct btrfs_root *root)
|
static int check_space_cache(struct btrfs_root *root)
|
||||||
{
|
{
|
||||||
|
struct extent_io_tree used;
|
||||||
struct btrfs_block_group *cache;
|
struct btrfs_block_group *cache;
|
||||||
u64 start = BTRFS_SUPER_INFO_OFFSET + BTRFS_SUPER_INFO_SIZE;
|
u64 start = BTRFS_SUPER_INFO_OFFSET + BTRFS_SUPER_INFO_SIZE;
|
||||||
int ret;
|
int ret;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
|
extent_io_tree_init(&used);
|
||||||
|
ret = btrfs_mark_used_blocks(gfs_info, &used);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
ctx.item_count++;
|
ctx.item_count++;
|
||||||
cache = btrfs_lookup_first_block_group(gfs_info, start);
|
cache = btrfs_lookup_first_block_group(gfs_info, start);
|
||||||
@ -5765,14 +5737,14 @@ static int check_space_cache(struct btrfs_root *root)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = verify_space_cache(root, cache);
|
ret = verify_space_cache(root, cache, &used);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
fprintf(stderr, "cache appears valid but isn't %llu\n",
|
fprintf(stderr, "cache appears valid but isn't %llu\n",
|
||||||
cache->start);
|
cache->start);
|
||||||
error++;
|
error++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
extent_io_tree_cleanup(&used);
|
||||||
return error ? -EINVAL : 0;
|
return error ? -EINVAL : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user