mirror of
https://github.com/kdave/btrfs-progs
synced 2025-04-22 06:55:22 +00:00
btrfs-progs: check/original: Check and repair root item geneartion
Add such ability to original mode to fix root generation mismatch, which can be rejected by kernel. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
ebf29e39c3
commit
1baf729743
21
check/main.c
21
check/main.c
@ -3437,8 +3437,10 @@ static int check_fs_root(struct btrfs_root *root,
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
bool generation_err = false;
|
||||||
int wret;
|
int wret;
|
||||||
int level;
|
int level;
|
||||||
|
u64 super_generation;
|
||||||
struct btrfs_path path;
|
struct btrfs_path path;
|
||||||
struct shared_node root_node;
|
struct shared_node root_node;
|
||||||
struct root_record *rec;
|
struct root_record *rec;
|
||||||
@ -3449,6 +3451,23 @@ static int check_fs_root(struct btrfs_root *root,
|
|||||||
struct unaligned_extent_rec_t *urec;
|
struct unaligned_extent_rec_t *urec;
|
||||||
struct unaligned_extent_rec_t *tmp;
|
struct unaligned_extent_rec_t *tmp;
|
||||||
|
|
||||||
|
super_generation = btrfs_super_generation(root->fs_info->super_copy);
|
||||||
|
if (btrfs_root_generation(root_item) > super_generation + 1) {
|
||||||
|
error(
|
||||||
|
"invalid generation for root %llu, have %llu expect (0, %llu]",
|
||||||
|
root->root_key.objectid, btrfs_root_generation(root_item),
|
||||||
|
super_generation + 1);
|
||||||
|
generation_err = true;
|
||||||
|
if (repair) {
|
||||||
|
root->node->flags |= EXTENT_BAD_TRANSID;
|
||||||
|
ret = recow_extent_buffer(root, root->node);
|
||||||
|
if (!ret) {
|
||||||
|
printf("Reset generation for root %llu\n",
|
||||||
|
root->root_key.objectid);
|
||||||
|
generation_err = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Reuse the corrupt_block cache tree to record corrupted tree block
|
* Reuse the corrupt_block cache tree to record corrupted tree block
|
||||||
*
|
*
|
||||||
@ -3597,6 +3616,8 @@ skip_walking:
|
|||||||
|
|
||||||
free_corrupt_blocks_tree(&corrupt_blocks);
|
free_corrupt_blocks_tree(&corrupt_blocks);
|
||||||
root->fs_info->corrupt_blocks = NULL;
|
root->fs_info->corrupt_blocks = NULL;
|
||||||
|
if (!ret && generation_err)
|
||||||
|
ret = -1;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user