mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2024-11-24 12:44:17 +08:00
btrfs-progs: check: drop unused fs_info
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
fd73539253
commit
2335cd02b3
140
check/main.c
140
check/main.c
@ -1640,8 +1640,7 @@ static int process_file_extent(struct btrfs_root *root,
|
||||
else
|
||||
disk_bytenr += extent_offset;
|
||||
|
||||
ret = count_csum_range(gfs_info, disk_bytenr, num_bytes,
|
||||
&found);
|
||||
ret = count_csum_range(disk_bytenr, num_bytes, &found);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (extent_type == BTRFS_FILE_EXTENT_REG) {
|
||||
@ -1653,8 +1652,7 @@ static int process_file_extent(struct btrfs_root *root,
|
||||
rec->errors |= I_ERR_SOME_CSUM_MISSING;
|
||||
} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
|
||||
if (found > 0) {
|
||||
ret = check_prealloc_extent_written(gfs_info,
|
||||
disk_bytenr,
|
||||
ret = check_prealloc_extent_written(disk_bytenr,
|
||||
num_bytes);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@ -3696,8 +3694,7 @@ skip_walking:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int check_fs_roots(struct btrfs_fs_info *fs_info,
|
||||
struct cache_tree *root_cache)
|
||||
static int check_fs_roots(struct cache_tree *root_cache)
|
||||
{
|
||||
struct btrfs_path path;
|
||||
struct btrfs_key key;
|
||||
@ -3714,7 +3711,7 @@ static int check_fs_roots(struct btrfs_fs_info *fs_info,
|
||||
* reflected into the free space cache yet.
|
||||
*/
|
||||
if (repair)
|
||||
reset_cached_block_groups(gfs_info);
|
||||
reset_cached_block_groups();
|
||||
memset(&wc, 0, sizeof(wc));
|
||||
cache_tree_init(&wc.shared);
|
||||
btrfs_init_path(&path);
|
||||
@ -3790,7 +3787,7 @@ again:
|
||||
root_cache);
|
||||
} else if (key.type == BTRFS_INODE_ITEM_KEY &&
|
||||
is_fstree(key.objectid)) {
|
||||
ret = check_repair_free_space_inode(gfs_info, &path);
|
||||
ret = check_repair_free_space_inode(&path);
|
||||
if (ret < 0 && !path.nodes[0]) {
|
||||
err = 1;
|
||||
goto out;
|
||||
@ -3873,15 +3870,14 @@ static struct data_backref *find_data_backref(struct extent_record *rec,
|
||||
return back;
|
||||
}
|
||||
|
||||
static int do_check_fs_roots(struct btrfs_fs_info *fs_info,
|
||||
struct cache_tree *root_cache)
|
||||
static int do_check_fs_roots(struct cache_tree *root_cache)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (check_mode == CHECK_MODE_LOWMEM)
|
||||
ret = check_fs_roots_lowmem(gfs_info);
|
||||
ret = check_fs_roots_lowmem();
|
||||
else
|
||||
ret = check_fs_roots(gfs_info, root_cache);
|
||||
ret = check_fs_roots(root_cache);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -4126,8 +4122,7 @@ static int is_extent_tree_record(struct extent_record *rec)
|
||||
}
|
||||
|
||||
|
||||
static int record_bad_block_io(struct btrfs_fs_info *info,
|
||||
struct cache_tree *extent_cache,
|
||||
static int record_bad_block_io(struct cache_tree *extent_cache,
|
||||
u64 start, u64 len)
|
||||
{
|
||||
struct extent_record *rec;
|
||||
@ -6228,7 +6223,7 @@ static int run_next_block(struct btrfs_root *root,
|
||||
/* fixme, get the real parent transid */
|
||||
buf = read_tree_block(gfs_info, bytenr, gen);
|
||||
if (!extent_buffer_uptodate(buf)) {
|
||||
record_bad_block_io(gfs_info, extent_cache, bytenr, size);
|
||||
record_bad_block_io(extent_cache, bytenr, size);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -6575,8 +6570,7 @@ static int add_root_to_pending(struct extent_buffer *buf,
|
||||
* we're tracking for repair. This hook makes sure we
|
||||
* remove any backrefs for blocks as we are fixing them.
|
||||
*/
|
||||
static int free_extent_hook(struct btrfs_fs_info *fs_info,
|
||||
u64 bytenr, u64 num_bytes, u64 parent,
|
||||
static int free_extent_hook(u64 bytenr, u64 num_bytes, u64 parent,
|
||||
u64 root_objectid, u64 owner, u64 offset,
|
||||
int refs_to_drop)
|
||||
{
|
||||
@ -6728,7 +6722,6 @@ static int delete_extent_records(struct btrfs_trans_handle *trans,
|
||||
* and add the backref to it.
|
||||
*/
|
||||
static int record_extent(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *info,
|
||||
struct btrfs_path *path,
|
||||
struct extent_record *rec,
|
||||
struct extent_backref *back,
|
||||
@ -6916,8 +6909,8 @@ static struct extent_entry *find_most_right_entry(struct list_head *entries)
|
||||
return best;
|
||||
}
|
||||
|
||||
static int repair_ref(struct btrfs_fs_info *info, struct btrfs_path *path,
|
||||
struct data_backref *dback, struct extent_entry *entry)
|
||||
static int repair_ref(struct btrfs_path *path, struct data_backref *dback,
|
||||
struct extent_entry *entry)
|
||||
{
|
||||
struct btrfs_trans_handle *trans;
|
||||
struct btrfs_root *root;
|
||||
@ -7066,8 +7059,7 @@ out:
|
||||
return ret ? ret : err;
|
||||
}
|
||||
|
||||
static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
|
||||
struct extent_record *rec)
|
||||
static int verify_backrefs(struct btrfs_path *path, struct extent_record *rec)
|
||||
{
|
||||
struct extent_backref *back, *tmp;
|
||||
struct data_backref *dback;
|
||||
@ -7227,7 +7219,7 @@ static int verify_backrefs(struct btrfs_fs_info *info, struct btrfs_path *path,
|
||||
dback->disk_bytenr == best->bytenr)
|
||||
continue;
|
||||
|
||||
ret = repair_ref(gfs_info, path, dback, best);
|
||||
ret = repair_ref(path, dback, best);
|
||||
if (ret)
|
||||
goto out;
|
||||
}
|
||||
@ -7509,8 +7501,7 @@ static int __find_possible_backrefs(struct btrfs_root *root,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int find_possible_backrefs(struct btrfs_fs_info *info,
|
||||
struct btrfs_path *path,
|
||||
static int find_possible_backrefs(struct btrfs_path *path,
|
||||
struct cache_tree *extent_cache,
|
||||
struct extent_record *rec)
|
||||
{
|
||||
@ -7594,8 +7585,7 @@ static int find_possible_backrefs(struct btrfs_fs_info *info,
|
||||
* all of the existing entries for it and recreate them
|
||||
* based on what the tree scan found.
|
||||
*/
|
||||
static int fixup_extent_refs(struct btrfs_fs_info *info,
|
||||
struct cache_tree *extent_cache,
|
||||
static int fixup_extent_refs(struct cache_tree *extent_cache,
|
||||
struct extent_record *rec)
|
||||
{
|
||||
struct btrfs_trans_handle *trans = NULL;
|
||||
@ -7618,13 +7608,13 @@ static int fixup_extent_refs(struct btrfs_fs_info *info,
|
||||
* them into the list if we find the backref so that
|
||||
* verify_backrefs can figure out what to do.
|
||||
*/
|
||||
ret = find_possible_backrefs(gfs_info, &path, extent_cache, rec);
|
||||
ret = find_possible_backrefs(&path, extent_cache, rec);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* step one, make sure all of the backrefs agree */
|
||||
ret = verify_backrefs(gfs_info, &path, rec);
|
||||
ret = verify_backrefs(&path, rec);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
@ -7659,8 +7649,7 @@ static int fixup_extent_refs(struct btrfs_fs_info *info,
|
||||
continue;
|
||||
|
||||
rec->bad_full_backref = 0;
|
||||
ret = record_extent(trans, gfs_info, &path, rec, back, allocated,
|
||||
flags);
|
||||
ret = record_extent(trans, &path, rec, back, allocated, flags);
|
||||
allocated = 1;
|
||||
|
||||
if (ret)
|
||||
@ -7682,8 +7671,7 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int fixup_extent_flags(struct btrfs_fs_info *fs_info,
|
||||
struct extent_record *rec)
|
||||
static int fixup_extent_flags(struct extent_record *rec)
|
||||
{
|
||||
struct btrfs_trans_handle *trans;
|
||||
struct btrfs_root *root = gfs_info->extent_root;
|
||||
@ -7753,7 +7741,6 @@ retry:
|
||||
|
||||
/* right now we only prune from the extent allocation tree */
|
||||
static int prune_one_block(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *info,
|
||||
struct btrfs_corrupt_block *corrupt)
|
||||
{
|
||||
int ret;
|
||||
@ -7820,7 +7807,7 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int prune_corrupt_blocks(struct btrfs_fs_info *info)
|
||||
static int prune_corrupt_blocks(void)
|
||||
{
|
||||
struct btrfs_trans_handle *trans = NULL;
|
||||
struct cache_extent *cache;
|
||||
@ -7836,7 +7823,7 @@ static int prune_corrupt_blocks(struct btrfs_fs_info *info)
|
||||
return PTR_ERR(trans);
|
||||
}
|
||||
corrupt = container_of(cache, struct btrfs_corrupt_block, cache);
|
||||
prune_one_block(trans, gfs_info, corrupt);
|
||||
prune_one_block(trans, corrupt);
|
||||
remove_cache_extent(gfs_info->corrupt_blocks, cache);
|
||||
}
|
||||
if (trans)
|
||||
@ -7844,8 +7831,7 @@ static int prune_corrupt_blocks(struct btrfs_fs_info *info)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int record_unaligned_extent_rec(struct btrfs_fs_info *fs_info,
|
||||
struct extent_record *rec)
|
||||
static int record_unaligned_extent_rec(struct extent_record *rec)
|
||||
{
|
||||
|
||||
struct extent_backref *back, *tmp;
|
||||
@ -7938,11 +7924,11 @@ static int check_extent_refs(struct btrfs_root *root,
|
||||
cache->start + cache->size - 1);
|
||||
cache = next_cache_extent(cache);
|
||||
}
|
||||
prune_corrupt_blocks(gfs_info);
|
||||
reset_cached_block_groups(gfs_info);
|
||||
prune_corrupt_blocks();
|
||||
reset_cached_block_groups();
|
||||
}
|
||||
|
||||
reset_cached_block_groups(gfs_info);
|
||||
reset_cached_block_groups();
|
||||
|
||||
/*
|
||||
* We need to delete any duplicate entries we find first otherwise we
|
||||
@ -8015,7 +8001,7 @@ static int check_extent_refs(struct btrfs_root *root,
|
||||
fprintf(stderr, "unaligned extent rec on [%llu %llu]\n",
|
||||
(unsigned long long)rec->start,
|
||||
(unsigned long long)rec->nr);
|
||||
ret = record_unaligned_extent_rec(gfs_info, rec);
|
||||
ret = record_unaligned_extent_rec(rec);
|
||||
if (ret)
|
||||
goto repair_abort;
|
||||
|
||||
@ -8039,7 +8025,7 @@ static int check_extent_refs(struct btrfs_root *root,
|
||||
}
|
||||
|
||||
if (repair && fix) {
|
||||
ret = fixup_extent_refs(gfs_info, extent_cache, rec);
|
||||
ret = fixup_extent_refs(extent_cache, rec);
|
||||
if (ret)
|
||||
goto repair_abort;
|
||||
}
|
||||
@ -8049,7 +8035,7 @@ static int check_extent_refs(struct btrfs_root *root,
|
||||
fprintf(stderr, "bad full backref, on [%llu]\n",
|
||||
(unsigned long long)rec->start);
|
||||
if (repair) {
|
||||
ret = fixup_extent_flags(gfs_info, rec);
|
||||
ret = fixup_extent_flags(rec);
|
||||
if (ret)
|
||||
goto repair_abort;
|
||||
fix = 1;
|
||||
@ -8331,7 +8317,7 @@ static int check_device_used(struct device_record *dev_rec,
|
||||
*
|
||||
* So this function will return the error for a fatal super total_bytes problem.
|
||||
*/
|
||||
static bool is_super_size_valid(struct btrfs_fs_info *fs_info)
|
||||
static bool is_super_size_valid(void)
|
||||
{
|
||||
struct btrfs_device *dev;
|
||||
struct list_head *dev_list = &gfs_info->fs_devices->devices;
|
||||
@ -8508,8 +8494,6 @@ static int deal_root_from_list(struct list_head *list,
|
||||
* parse_tree_roots - Go over all roots in the tree root and add each one to
|
||||
* a list.
|
||||
*
|
||||
* @fs_info - pointer to fs_info struct of the file system.
|
||||
*
|
||||
* @normal_trees - list to contains all roots which don't have a drop
|
||||
* operation in progress
|
||||
*
|
||||
@ -8518,9 +8502,8 @@ static int deal_root_from_list(struct list_head *list,
|
||||
*
|
||||
* Returns 0 on success or a negative value indicating an error.
|
||||
*/
|
||||
static int parse_tree_roots(struct btrfs_fs_info *fs_info,
|
||||
struct list_head *normal_trees,
|
||||
struct list_head *dropping_trees)
|
||||
static int parse_tree_roots(struct list_head *normal_trees,
|
||||
struct list_head *dropping_trees)
|
||||
{
|
||||
struct btrfs_path path;
|
||||
struct btrfs_key key;
|
||||
@ -8593,7 +8576,7 @@ out:
|
||||
*
|
||||
* Dev extents <-> chunk cross checking is already done in check_chunks().
|
||||
*/
|
||||
static int check_dev_extents(struct btrfs_fs_info *fs_info)
|
||||
static int check_dev_extents(void)
|
||||
{
|
||||
struct btrfs_path path;
|
||||
struct btrfs_key key;
|
||||
@ -8683,7 +8666,7 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int check_chunks_and_extents(struct btrfs_fs_info *fs_info)
|
||||
static int check_chunks_and_extents(void)
|
||||
{
|
||||
struct rb_root dev_cache;
|
||||
struct cache_tree chunk_cache;
|
||||
@ -8749,7 +8732,7 @@ again:
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
ret = parse_tree_roots(gfs_info, &normal_trees, &dropping_trees);
|
||||
ret = parse_tree_roots(&normal_trees, &dropping_trees);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
@ -8777,7 +8760,7 @@ again:
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = check_dev_extents(gfs_info);
|
||||
ret = check_dev_extents();
|
||||
if (ret < 0) {
|
||||
err = ret;
|
||||
goto out;
|
||||
@ -8840,14 +8823,14 @@ loop:
|
||||
goto again;
|
||||
}
|
||||
|
||||
static int do_check_chunks_and_extents(struct btrfs_fs_info *fs_info)
|
||||
static int do_check_chunks_and_extents(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (check_mode == CHECK_MODE_LOWMEM)
|
||||
ret = check_chunks_and_extents_lowmem(gfs_info);
|
||||
ret = check_chunks_and_extents_lowmem();
|
||||
else
|
||||
ret = check_chunks_and_extents(gfs_info);
|
||||
ret = check_chunks_and_extents();
|
||||
|
||||
/* Also repair device size related problems */
|
||||
if (repair && !ret) {
|
||||
@ -8914,7 +8897,7 @@ static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int reset_block_groups(struct btrfs_fs_info *fs_info)
|
||||
static int reset_block_groups(void)
|
||||
{
|
||||
struct btrfs_block_group *cache;
|
||||
struct btrfs_path path;
|
||||
@ -8984,8 +8967,7 @@ static int reset_block_groups(struct btrfs_fs_info *fs_info)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int reset_balance(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *fs_info)
|
||||
static int reset_balance(struct btrfs_trans_handle *trans)
|
||||
{
|
||||
struct btrfs_root *root = gfs_info->tree_root;
|
||||
struct btrfs_path path;
|
||||
@ -9087,8 +9069,7 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int reinit_extent_tree(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *fs_info, bool pin)
|
||||
static int reinit_extent_tree(struct btrfs_trans_handle *trans, bool pin)
|
||||
{
|
||||
u64 start = 0;
|
||||
int ret;
|
||||
@ -9117,13 +9098,13 @@ static int reinit_extent_tree(struct btrfs_trans_handle *trans,
|
||||
*/
|
||||
again:
|
||||
if (pin) {
|
||||
ret = pin_metadata_blocks(gfs_info);
|
||||
ret = pin_metadata_blocks();
|
||||
if (ret) {
|
||||
fprintf(stderr, "error pinning down used bytes\n");
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
ret = exclude_metadata_blocks(gfs_info);
|
||||
ret = exclude_metadata_blocks();
|
||||
if (ret) {
|
||||
fprintf(stderr, "error excluding used bytes\n");
|
||||
printf("try to pin down used bytes\n");
|
||||
@ -9137,7 +9118,7 @@ again:
|
||||
* of them again.
|
||||
*/
|
||||
btrfs_free_block_groups(gfs_info);
|
||||
ret = reset_block_groups(gfs_info);
|
||||
ret = reset_block_groups();
|
||||
if (ret) {
|
||||
fprintf(stderr, "error resetting the block groups\n");
|
||||
return ret;
|
||||
@ -9185,7 +9166,7 @@ again:
|
||||
btrfs_run_delayed_refs(trans, -1);
|
||||
}
|
||||
|
||||
ret = reset_balance(trans, gfs_info);
|
||||
ret = reset_balance(trans);
|
||||
if (ret)
|
||||
fprintf(stderr, "error resetting the pending balance\n");
|
||||
|
||||
@ -9496,7 +9477,7 @@ static void free_roots_info_cache(void)
|
||||
roots_info_cache = NULL;
|
||||
}
|
||||
|
||||
static int build_roots_info_cache(struct btrfs_fs_info *info)
|
||||
static int build_roots_info_cache(void)
|
||||
{
|
||||
int ret = 0;
|
||||
struct btrfs_key key;
|
||||
@ -9715,7 +9696,7 @@ static int maybe_repair_root_item(struct btrfs_path *path,
|
||||
* repair code delete or modify backrefs in the extent tree for example, which
|
||||
* will result in an inconsistent fs after repairing the root items.
|
||||
*/
|
||||
static int repair_root_items(struct btrfs_fs_info *info)
|
||||
static int repair_root_items(void)
|
||||
{
|
||||
struct btrfs_path path;
|
||||
struct btrfs_key key;
|
||||
@ -9727,7 +9708,7 @@ static int repair_root_items(struct btrfs_fs_info *info)
|
||||
|
||||
btrfs_init_path(&path);
|
||||
|
||||
ret = build_roots_info_cache(gfs_info);
|
||||
ret = build_roots_info_cache();
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
@ -9809,7 +9790,7 @@ out:
|
||||
return bad_roots;
|
||||
}
|
||||
|
||||
static int clear_free_space_cache(struct btrfs_fs_info *fs_info)
|
||||
static int clear_free_space_cache(void)
|
||||
{
|
||||
struct btrfs_trans_handle *trans;
|
||||
struct btrfs_block_group *bg_cache;
|
||||
@ -9839,8 +9820,7 @@ static int clear_free_space_cache(struct btrfs_fs_info *fs_info)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int do_clear_free_space_cache(struct btrfs_fs_info *fs_info,
|
||||
int clear_version)
|
||||
static int do_clear_free_space_cache(int clear_version)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -9851,7 +9831,7 @@ static int do_clear_free_space_cache(struct btrfs_fs_info *fs_info,
|
||||
ret = 1;
|
||||
goto close_out;
|
||||
}
|
||||
ret = clear_free_space_cache(gfs_info);
|
||||
ret = clear_free_space_cache();
|
||||
if (ret) {
|
||||
error("failed to clear free space cache");
|
||||
ret = 1;
|
||||
@ -9892,7 +9872,7 @@ static int validate_free_space_cache(struct btrfs_root *root)
|
||||
ret = check_space_cache(root);
|
||||
if (ret && btrfs_fs_compat_ro(gfs_info, FREE_SPACE_TREE) &&
|
||||
repair) {
|
||||
ret = do_clear_free_space_cache(gfs_info, 2);
|
||||
ret = do_clear_free_space_cache(2);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
@ -10187,7 +10167,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
|
||||
}
|
||||
|
||||
if (clear_space_cache) {
|
||||
ret = do_clear_free_space_cache(gfs_info, clear_space_cache);
|
||||
ret = do_clear_free_space_cache(clear_space_cache);
|
||||
err |= !!ret;
|
||||
goto close_out;
|
||||
}
|
||||
@ -10242,7 +10222,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
|
||||
trans->reinit_extent_tree = true;
|
||||
if (init_extent_tree) {
|
||||
printf("Creating a new extent tree\n");
|
||||
ret = reinit_extent_tree(trans, gfs_info,
|
||||
ret = reinit_extent_tree(trans,
|
||||
check_mode == CHECK_MODE_ORIGINAL);
|
||||
err |= !!ret;
|
||||
if (ret)
|
||||
@ -10297,7 +10277,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
|
||||
ctx.tp = TASK_ROOT_ITEMS;
|
||||
task_start(ctx.info, &ctx.start_time, &ctx.item_count);
|
||||
}
|
||||
ret = repair_root_items(gfs_info);
|
||||
ret = repair_root_items();
|
||||
task_stop(ctx.info);
|
||||
if (ret < 0) {
|
||||
err = !!ret;
|
||||
@ -10335,7 +10315,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
|
||||
ctx.tp = TASK_EXTENTS;
|
||||
task_start(ctx.info, &ctx.start_time, &ctx.item_count);
|
||||
}
|
||||
ret = do_check_chunks_and_extents(gfs_info);
|
||||
ret = do_check_chunks_and_extents();
|
||||
task_stop(ctx.info);
|
||||
err |= !!ret;
|
||||
if (ret)
|
||||
@ -10343,7 +10323,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
|
||||
"errors found in extent allocation tree or chunk allocation");
|
||||
|
||||
/* Only re-check super size after we checked and repaired the fs */
|
||||
err |= !is_super_size_valid(gfs_info);
|
||||
err |= !is_super_size_valid();
|
||||
|
||||
is_free_space_tree = btrfs_fs_compat_ro(gfs_info, FREE_SPACE_TREE);
|
||||
|
||||
@ -10375,7 +10355,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv)
|
||||
task_start(ctx.info, &ctx.start_time, &ctx.item_count);
|
||||
}
|
||||
|
||||
ret = do_check_fs_roots(gfs_info, &root_cache);
|
||||
ret = do_check_fs_roots(&root_cache);
|
||||
task_stop(ctx.info);
|
||||
err |= !!ret;
|
||||
if (ret) {
|
||||
|
@ -30,8 +30,7 @@
|
||||
*
|
||||
* Returns 1 if true, 0 if false and < 0 on error.
|
||||
*/
|
||||
static int check_prealloc_data_ref(struct btrfs_fs_info *fs_info,
|
||||
u64 disk_bytenr,
|
||||
static int check_prealloc_data_ref(u64 disk_bytenr,
|
||||
struct btrfs_extent_data_ref *dref,
|
||||
struct extent_buffer *eb)
|
||||
{
|
||||
@ -113,8 +112,7 @@ next:
|
||||
*
|
||||
* Returns 1 if true, 0 if false and < 0 on error.
|
||||
*/
|
||||
static int check_prealloc_shared_data_ref(struct btrfs_fs_info *fs_info,
|
||||
u64 parent, u64 disk_bytenr)
|
||||
static int check_prealloc_shared_data_ref(u64 parent, u64 disk_bytenr)
|
||||
{
|
||||
struct extent_buffer *eb;
|
||||
u32 nr;
|
||||
@ -175,8 +173,7 @@ static int check_prealloc_shared_data_ref(struct btrfs_fs_info *fs_info,
|
||||
* Returns 0 if the prealloc extent was not written yet by any inode, 1 if
|
||||
* at least one other inode has written to it, and < 0 on error.
|
||||
*/
|
||||
int check_prealloc_extent_written(struct btrfs_fs_info *fs_info,
|
||||
u64 disk_bytenr, u64 num_bytes)
|
||||
int check_prealloc_extent_written(u64 disk_bytenr, u64 num_bytes)
|
||||
{
|
||||
struct btrfs_path path;
|
||||
struct btrfs_key key;
|
||||
@ -220,7 +217,7 @@ int check_prealloc_extent_written(struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_extent_data_ref *dref;
|
||||
|
||||
dref = (struct btrfs_extent_data_ref *)(&iref->offset);
|
||||
ret = check_prealloc_data_ref(gfs_info, disk_bytenr,
|
||||
ret = check_prealloc_data_ref(disk_bytenr,
|
||||
dref, path.nodes[0]);
|
||||
if (ret != 0)
|
||||
goto out;
|
||||
@ -229,8 +226,7 @@ int check_prealloc_extent_written(struct btrfs_fs_info *fs_info,
|
||||
|
||||
parent = btrfs_extent_inline_ref_offset(path.nodes[0],
|
||||
iref);
|
||||
ret = check_prealloc_shared_data_ref(gfs_info,
|
||||
parent,
|
||||
ret = check_prealloc_shared_data_ref(parent,
|
||||
disk_bytenr);
|
||||
if (ret != 0)
|
||||
goto out;
|
||||
@ -261,13 +257,12 @@ int check_prealloc_extent_written(struct btrfs_fs_info *fs_info,
|
||||
|
||||
dref = btrfs_item_ptr(path.nodes[0], path.slots[0],
|
||||
struct btrfs_extent_data_ref);
|
||||
ret = check_prealloc_data_ref(gfs_info, disk_bytenr,
|
||||
ret = check_prealloc_data_ref(disk_bytenr,
|
||||
dref, path.nodes[0]);
|
||||
if (ret != 0)
|
||||
goto out;
|
||||
} else if (key.type == BTRFS_SHARED_DATA_REF_KEY) {
|
||||
ret = check_prealloc_shared_data_ref(gfs_info,
|
||||
key.offset,
|
||||
ret = check_prealloc_shared_data_ref(key.offset,
|
||||
disk_bytenr);
|
||||
if (ret != 0)
|
||||
goto out;
|
||||
@ -289,8 +284,7 @@ out:
|
||||
* @found: return value of found csum bytes
|
||||
* unit is BYTE.
|
||||
*/
|
||||
int count_csum_range(struct btrfs_fs_info *fs_info, u64 start,
|
||||
u64 len, u64 *found)
|
||||
int count_csum_range(u64 start, u64 len, u64 *found)
|
||||
{
|
||||
struct btrfs_key key;
|
||||
struct btrfs_path path;
|
||||
@ -579,7 +573,7 @@ int check_child_node(struct extent_buffer *parent, int slot,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void reset_cached_block_groups(struct btrfs_fs_info *fs_info)
|
||||
void reset_cached_block_groups()
|
||||
{
|
||||
struct btrfs_block_group *cache;
|
||||
u64 start, end;
|
||||
@ -604,9 +598,7 @@ void reset_cached_block_groups(struct btrfs_fs_info *fs_info)
|
||||
}
|
||||
}
|
||||
|
||||
static int traverse_tree_blocks(struct btrfs_fs_info *fs_info,
|
||||
struct extent_buffer *eb, int tree_root,
|
||||
int pin)
|
||||
static int traverse_tree_blocks(struct extent_buffer *eb, int tree_root, int pin)
|
||||
{
|
||||
struct extent_buffer *tmp;
|
||||
struct btrfs_root_item *ri;
|
||||
@ -666,7 +658,7 @@ static int traverse_tree_blocks(struct btrfs_fs_info *fs_info,
|
||||
fprintf(stderr, "Error reading root block\n");
|
||||
return -EIO;
|
||||
}
|
||||
ret = traverse_tree_blocks(gfs_info, tmp, 0, pin);
|
||||
ret = traverse_tree_blocks(tmp, 0, pin);
|
||||
free_extent_buffer(tmp);
|
||||
if (ret)
|
||||
return ret;
|
||||
@ -685,8 +677,7 @@ static int traverse_tree_blocks(struct btrfs_fs_info *fs_info,
|
||||
fprintf(stderr, "Error reading tree block\n");
|
||||
return -EIO;
|
||||
}
|
||||
ret = traverse_tree_blocks(gfs_info, tmp, tree_root,
|
||||
pin);
|
||||
ret = traverse_tree_blocks(tmp, tree_root, pin);
|
||||
free_extent_buffer(tmp);
|
||||
if (ret)
|
||||
return ret;
|
||||
@ -696,30 +687,28 @@ static int traverse_tree_blocks(struct btrfs_fs_info *fs_info,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pin_down_tree_blocks(struct btrfs_fs_info *fs_info,
|
||||
struct extent_buffer *eb, int tree_root)
|
||||
static int pin_down_tree_blocks(struct extent_buffer *eb, int tree_root)
|
||||
{
|
||||
return traverse_tree_blocks(gfs_info, eb, tree_root, 1);
|
||||
return traverse_tree_blocks(eb, tree_root, 1);
|
||||
}
|
||||
|
||||
int pin_metadata_blocks(struct btrfs_fs_info *fs_info)
|
||||
int pin_metadata_blocks(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = pin_down_tree_blocks(gfs_info, gfs_info->chunk_root->node, 0);
|
||||
ret = pin_down_tree_blocks(gfs_info->chunk_root->node, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return pin_down_tree_blocks(gfs_info, gfs_info->tree_root->node, 1);
|
||||
return pin_down_tree_blocks(gfs_info->tree_root->node, 1);
|
||||
}
|
||||
|
||||
static int exclude_tree_blocks(struct btrfs_fs_info *fs_info,
|
||||
struct extent_buffer *eb, int tree_root)
|
||||
static int exclude_tree_blocks(struct extent_buffer *eb, int tree_root)
|
||||
{
|
||||
return traverse_tree_blocks(gfs_info, eb, tree_root, 0);
|
||||
return traverse_tree_blocks(eb, tree_root, 0);
|
||||
}
|
||||
|
||||
int exclude_metadata_blocks(struct btrfs_fs_info *fs_info)
|
||||
int exclude_metadata_blocks(void)
|
||||
{
|
||||
int ret;
|
||||
struct extent_io_tree *excluded_extents;
|
||||
@ -730,13 +719,13 @@ int exclude_metadata_blocks(struct btrfs_fs_info *fs_info)
|
||||
extent_io_tree_init(excluded_extents);
|
||||
gfs_info->excluded_extents = excluded_extents;
|
||||
|
||||
ret = exclude_tree_blocks(gfs_info, gfs_info->chunk_root->node, 0);
|
||||
ret = exclude_tree_blocks(gfs_info->chunk_root->node, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
return exclude_tree_blocks(gfs_info, gfs_info->tree_root->node, 1);
|
||||
return exclude_tree_blocks(gfs_info->tree_root->node, 1);
|
||||
}
|
||||
|
||||
void cleanup_excluded_extents(struct btrfs_fs_info *fs_info)
|
||||
void cleanup_excluded_extents(void)
|
||||
{
|
||||
if (gfs_info->excluded_extents) {
|
||||
extent_io_tree_cleanup(gfs_info->excluded_extents);
|
||||
@ -1130,8 +1119,7 @@ abort:
|
||||
* cache inode doesn't have INODE_REF.
|
||||
* We just check its inode mode.
|
||||
*/
|
||||
int check_repair_free_space_inode(struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_path *path)
|
||||
int check_repair_free_space_inode(struct btrfs_path *path)
|
||||
{
|
||||
struct btrfs_inode_item *iitem;
|
||||
struct btrfs_key key;
|
||||
|
@ -101,10 +101,8 @@ static inline int fs_root_objectid(u64 objectid)
|
||||
return is_fstree(objectid);
|
||||
}
|
||||
|
||||
int check_prealloc_extent_written(struct btrfs_fs_info *fs_info,
|
||||
u64 disk_bytenr, u64 num_bytes);
|
||||
int count_csum_range(struct btrfs_fs_info *fs_info, u64 start,
|
||||
u64 len, u64 *found);
|
||||
int check_prealloc_extent_written(u64 disk_bytenr, u64 num_bytes);
|
||||
int count_csum_range(u64 start, u64 len, u64 *found);
|
||||
int insert_inode_item(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root, u64 ino, u64 size,
|
||||
u64 nbytes, u64 nlink, u32 mode);
|
||||
@ -118,10 +116,10 @@ void reada_walk_down(struct btrfs_root *root, struct extent_buffer *node,
|
||||
int slot);
|
||||
int check_child_node(struct extent_buffer *parent, int slot,
|
||||
struct extent_buffer *child);
|
||||
void reset_cached_block_groups(struct btrfs_fs_info *fs_info);
|
||||
int pin_metadata_blocks(struct btrfs_fs_info *fs_info);
|
||||
int exclude_metadata_blocks(struct btrfs_fs_info *fs_info);
|
||||
void cleanup_excluded_extents(struct btrfs_fs_info *fs_info);
|
||||
void reset_cached_block_groups(void);
|
||||
int pin_metadata_blocks(void);
|
||||
int exclude_metadata_blocks(void);
|
||||
void cleanup_excluded_extents(void);
|
||||
int delete_corrupted_dir_item(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root,
|
||||
struct btrfs_key *di_key, char *namebuf,
|
||||
@ -131,8 +129,8 @@ int detect_imode(struct btrfs_root *root, struct btrfs_path *path,
|
||||
int reset_imode(struct btrfs_trans_handle *trans, struct btrfs_root *root,
|
||||
struct btrfs_path *path, u64 ino, u32 mode);
|
||||
int repair_imode_common(struct btrfs_root *root, struct btrfs_path *path);
|
||||
int check_repair_free_space_inode(struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_path *path);
|
||||
int check_repair_free_space_inode(struct btrfs_path *path);
|
||||
|
||||
/*
|
||||
* Check if the inode mode @imode is valid
|
||||
*
|
||||
|
@ -238,8 +238,7 @@ static int update_nodes_refs(struct btrfs_root *root, u64 bytenr,
|
||||
* Mark all extents unfree in the block group. And set @block_group->cached
|
||||
* according to @cache.
|
||||
*/
|
||||
static int modify_block_group_cache(struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_block_group *block_group, int cache)
|
||||
static int modify_block_group_cache(struct btrfs_block_group *block_group, int cache)
|
||||
{
|
||||
struct extent_io_tree *free_space_cache = &gfs_info->free_space_cache;
|
||||
u64 start = block_group->start;
|
||||
@ -263,8 +262,7 @@ static int modify_block_group_cache(struct btrfs_fs_info *fs_info,
|
||||
* @cache: if 0, clear block groups cache state;
|
||||
* not 0, mark blocks groups cached.
|
||||
*/
|
||||
static int modify_block_groups_cache(struct btrfs_fs_info *fs_info, u64 flags,
|
||||
int cache)
|
||||
static int modify_block_groups_cache(u64 flags, int cache)
|
||||
{
|
||||
struct btrfs_root *root = gfs_info->extent_root;
|
||||
struct btrfs_key key;
|
||||
@ -302,7 +300,7 @@ static int modify_block_groups_cache(struct btrfs_fs_info *fs_info, u64 flags,
|
||||
read_extent_buffer(eb, &bg_item, (unsigned long)bi,
|
||||
sizeof(bg_item));
|
||||
if (btrfs_stack_block_group_flags(&bg_item) & flags)
|
||||
modify_block_group_cache(gfs_info, bg_cache, cache);
|
||||
modify_block_group_cache(bg_cache, cache);
|
||||
|
||||
ret = btrfs_next_item(root, &path);
|
||||
if (ret > 0) {
|
||||
@ -318,18 +316,17 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mark_block_groups_full(struct btrfs_fs_info *fs_info, u64 flags)
|
||||
static int mark_block_groups_full(u64 flags)
|
||||
{
|
||||
return modify_block_groups_cache(gfs_info, flags, 1);
|
||||
return modify_block_groups_cache(flags, 1);
|
||||
}
|
||||
|
||||
static int clear_block_groups_full(struct btrfs_fs_info *fs_info, u64 flags)
|
||||
static int clear_block_groups_full(u64 flags)
|
||||
{
|
||||
return modify_block_groups_cache(gfs_info, flags, 0);
|
||||
return modify_block_groups_cache(flags, 0);
|
||||
}
|
||||
|
||||
static int create_chunk_and_block_group(struct btrfs_fs_info *fs_info,
|
||||
u64 flags, u64 *start, u64 *nbytes)
|
||||
static int create_chunk_and_block_group(u64 flags, u64 *start, u64 *nbytes)
|
||||
{
|
||||
struct btrfs_trans_handle *trans;
|
||||
struct btrfs_root *root = gfs_info->extent_root;
|
||||
@ -364,8 +361,7 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int force_cow_in_new_chunk(struct btrfs_fs_info *fs_info,
|
||||
u64 *start_ret)
|
||||
static int force_cow_in_new_chunk(u64 *start_ret)
|
||||
{
|
||||
struct btrfs_block_group *bg;
|
||||
u64 start;
|
||||
@ -380,14 +376,14 @@ static int force_cow_in_new_chunk(struct btrfs_fs_info *fs_info,
|
||||
if (btrfs_fs_incompat(gfs_info, MIXED_GROUPS))
|
||||
flags |= BTRFS_BLOCK_GROUP_DATA;
|
||||
|
||||
ret = create_chunk_and_block_group(gfs_info, flags, &start, &nbytes);
|
||||
ret = create_chunk_and_block_group(flags, &start, &nbytes);
|
||||
if (ret)
|
||||
goto err;
|
||||
printf("Created new chunk [%llu %llu]\n", start, nbytes);
|
||||
|
||||
flags = BTRFS_BLOCK_GROUP_METADATA;
|
||||
/* Mark all metadata block groups cached and full in free space*/
|
||||
ret = mark_block_groups_full(gfs_info, flags);
|
||||
ret = mark_block_groups_full(flags);
|
||||
if (ret)
|
||||
goto clear_bgs_full;
|
||||
|
||||
@ -399,7 +395,7 @@ static int force_cow_in_new_chunk(struct btrfs_fs_info *fs_info,
|
||||
}
|
||||
|
||||
/* Clear block group cache just allocated */
|
||||
ret = modify_block_group_cache(gfs_info, bg, 0);
|
||||
ret = modify_block_group_cache(bg, 0);
|
||||
if (ret)
|
||||
goto clear_bgs_full;
|
||||
if (start_ret)
|
||||
@ -407,7 +403,7 @@ static int force_cow_in_new_chunk(struct btrfs_fs_info *fs_info,
|
||||
return 0;
|
||||
|
||||
clear_bgs_full:
|
||||
clear_block_groups_full(gfs_info, flags);
|
||||
clear_block_groups_full(flags);
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
@ -417,7 +413,7 @@ err:
|
||||
* Returns >0 means almost full.
|
||||
* Returns <0 means fatal error.
|
||||
*/
|
||||
static int is_chunk_almost_full(struct btrfs_fs_info *fs_info, u64 start)
|
||||
static int is_chunk_almost_full(u64 start)
|
||||
{
|
||||
struct btrfs_path path;
|
||||
struct btrfs_key key;
|
||||
@ -482,21 +478,20 @@ out:
|
||||
* Returns <0 for error.
|
||||
* Returns 0 for success.
|
||||
*/
|
||||
static int try_to_force_cow_in_new_chunk(struct btrfs_fs_info *fs_info,
|
||||
u64 old_start, u64 *new_start)
|
||||
static int try_to_force_cow_in_new_chunk(u64 old_start, u64 *new_start)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (old_start) {
|
||||
ret = is_chunk_almost_full(gfs_info, old_start);
|
||||
ret = is_chunk_almost_full(old_start);
|
||||
if (ret <= 0)
|
||||
return ret;
|
||||
}
|
||||
ret = force_cow_in_new_chunk(gfs_info, new_start);
|
||||
ret = force_cow_in_new_chunk(new_start);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int avoid_extents_overwrite(struct btrfs_fs_info *fs_info)
|
||||
static int avoid_extents_overwrite(void)
|
||||
{
|
||||
int ret;
|
||||
int mixed = btrfs_fs_incompat(gfs_info, MIXED_GROUPS);
|
||||
@ -505,8 +500,8 @@ static int avoid_extents_overwrite(struct btrfs_fs_info *fs_info)
|
||||
return 0;
|
||||
|
||||
if (last_allocated_chunk != (u64)-1) {
|
||||
ret = try_to_force_cow_in_new_chunk(gfs_info,
|
||||
last_allocated_chunk, &last_allocated_chunk);
|
||||
ret = try_to_force_cow_in_new_chunk(last_allocated_chunk,
|
||||
&last_allocated_chunk);
|
||||
if (!ret)
|
||||
goto out;
|
||||
/*
|
||||
@ -522,7 +517,7 @@ static int avoid_extents_overwrite(struct btrfs_fs_info *fs_info)
|
||||
|
||||
printf(
|
||||
"Try to exclude all metadata blocks and extents, it may be slow\n");
|
||||
ret = exclude_metadata_blocks(gfs_info);
|
||||
ret = exclude_metadata_blocks();
|
||||
out:
|
||||
if (ret) {
|
||||
errno = -ret;
|
||||
@ -531,14 +526,13 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int end_avoid_extents_overwrite(struct btrfs_fs_info *fs_info)
|
||||
static int end_avoid_extents_overwrite(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
cleanup_excluded_extents(gfs_info);
|
||||
cleanup_excluded_extents();
|
||||
if (last_allocated_chunk)
|
||||
ret = clear_block_groups_full(gfs_info,
|
||||
BTRFS_BLOCK_GROUP_METADATA);
|
||||
ret = clear_block_groups_full(BTRFS_BLOCK_GROUP_METADATA);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -554,7 +548,7 @@ static int delete_item(struct btrfs_root *root, struct btrfs_path *path)
|
||||
struct btrfs_trans_handle *trans;
|
||||
int ret = 0;
|
||||
|
||||
ret = avoid_extents_overwrite(gfs_info);
|
||||
ret = avoid_extents_overwrite();
|
||||
if (ret)
|
||||
return ret;
|
||||
trans = btrfs_start_transaction(root, 1);
|
||||
@ -596,7 +590,7 @@ out:
|
||||
* Returns 0 on success.
|
||||
* Returns != 0 on error.
|
||||
*/
|
||||
static int repair_block_accounting(struct btrfs_fs_info *fs_info)
|
||||
static int repair_block_accounting(void)
|
||||
{
|
||||
struct btrfs_trans_handle *trans = NULL;
|
||||
struct btrfs_root *root = gfs_info->extent_root;
|
||||
@ -675,7 +669,7 @@ static int repair_tree_block_ref(struct btrfs_root *root,
|
||||
if (nrefs->full_backref[level] != 0)
|
||||
flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF;
|
||||
|
||||
ret = avoid_extents_overwrite(gfs_info);
|
||||
ret = avoid_extents_overwrite();
|
||||
if (ret)
|
||||
goto out;
|
||||
trans = btrfs_start_transaction(extent_root, 1);
|
||||
@ -2104,8 +2098,7 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
|
||||
search_start = disk_bytenr;
|
||||
search_len = disk_num_bytes;
|
||||
}
|
||||
ret = count_csum_range(gfs_info, search_start, search_len,
|
||||
&csum_found);
|
||||
ret = count_csum_range(search_start, search_len, &csum_found);
|
||||
if (csum_found > 0 && nodatasum) {
|
||||
err |= ODD_CSUM_ITEM;
|
||||
error("root %llu EXTENT_DATA[%llu %llu] nodatasum shouldn't have datasum",
|
||||
@ -2118,8 +2111,7 @@ static int check_file_extent(struct btrfs_root *root, struct btrfs_path *path,
|
||||
csum_found, search_len);
|
||||
} else if (extent_type == BTRFS_FILE_EXTENT_PREALLOC &&
|
||||
csum_found > 0) {
|
||||
ret = check_prealloc_extent_written(gfs_info,
|
||||
disk_bytenr, disk_num_bytes);
|
||||
ret = check_prealloc_extent_written(disk_bytenr, disk_num_bytes);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (ret == 0) {
|
||||
@ -3276,7 +3268,7 @@ static int repair_extent_data_item(struct btrfs_root *root,
|
||||
}
|
||||
need_insert = ret;
|
||||
|
||||
ret = avoid_extents_overwrite(gfs_info);
|
||||
ret = avoid_extents_overwrite();
|
||||
if (ret)
|
||||
goto out;
|
||||
trans = btrfs_start_transaction(root, 1);
|
||||
@ -3535,8 +3527,7 @@ out:
|
||||
* Check a block group item with its referener (chunk) and its used space
|
||||
* with extent/metadata item
|
||||
*/
|
||||
static int check_block_group_item(struct btrfs_fs_info *fs_info,
|
||||
struct extent_buffer *eb, int slot)
|
||||
static int check_block_group_item(struct extent_buffer *eb, int slot)
|
||||
{
|
||||
struct btrfs_root *extent_root = gfs_info->extent_root;
|
||||
struct btrfs_root *chunk_root = gfs_info->chunk_root;
|
||||
@ -3665,7 +3656,7 @@ out:
|
||||
* Return >= 0 as tree level
|
||||
* Return <0 for error
|
||||
*/
|
||||
static int query_tree_block_level(struct btrfs_fs_info *fs_info, u64 bytenr)
|
||||
static int query_tree_block_level(u64 bytenr)
|
||||
{
|
||||
struct extent_buffer *eb;
|
||||
struct btrfs_path path;
|
||||
@ -3740,8 +3731,7 @@ release_out:
|
||||
* if level == -1, level will be resolved
|
||||
* Return >0 for any error found and print error message
|
||||
*/
|
||||
static int check_tree_block_backref(struct btrfs_fs_info *fs_info, u64 root_id,
|
||||
u64 bytenr, int level)
|
||||
static int check_tree_block_backref(u64 root_id, u64 bytenr, int level)
|
||||
{
|
||||
struct btrfs_root *root;
|
||||
struct btrfs_key key;
|
||||
@ -3754,7 +3744,7 @@ static int check_tree_block_backref(struct btrfs_fs_info *fs_info, u64 root_id,
|
||||
|
||||
/* Query level for level == -1 special case */
|
||||
if (level == -1)
|
||||
level = query_tree_block_level(gfs_info, bytenr);
|
||||
level = query_tree_block_level(bytenr);
|
||||
if (level < 0) {
|
||||
err |= REFERENCER_MISSING;
|
||||
goto out;
|
||||
@ -3837,8 +3827,7 @@ out:
|
||||
* Return 0 if it's not or any problem happens
|
||||
* Return 1 if it's a tree reloc root
|
||||
*/
|
||||
static int is_tree_reloc_root(struct btrfs_fs_info *fs_info,
|
||||
struct extent_buffer *eb)
|
||||
static int is_tree_reloc_root(struct extent_buffer *eb)
|
||||
{
|
||||
struct btrfs_root *tree_reloc_root;
|
||||
struct btrfs_key key;
|
||||
@ -3864,8 +3853,7 @@ static int is_tree_reloc_root(struct btrfs_fs_info *fs_info,
|
||||
* Check referencer for shared block backref
|
||||
* If level == -1, this function will resolve the level.
|
||||
*/
|
||||
static int check_shared_block_backref(struct btrfs_fs_info *fs_info,
|
||||
u64 parent, u64 bytenr, int level)
|
||||
static int check_shared_block_backref(u64 parent, u64 bytenr, int level)
|
||||
{
|
||||
struct extent_buffer *eb;
|
||||
u32 nr;
|
||||
@ -3877,13 +3865,13 @@ static int check_shared_block_backref(struct btrfs_fs_info *fs_info,
|
||||
goto out;
|
||||
|
||||
if (level == -1)
|
||||
level = query_tree_block_level(gfs_info, bytenr);
|
||||
level = query_tree_block_level(bytenr);
|
||||
if (level < 0)
|
||||
goto out;
|
||||
|
||||
/* It's possible it's a tree reloc root */
|
||||
if (parent == bytenr) {
|
||||
if (is_tree_reloc_root(gfs_info, eb))
|
||||
if (is_tree_reloc_root(eb))
|
||||
found_parent = 1;
|
||||
goto out;
|
||||
}
|
||||
@ -3913,8 +3901,7 @@ out:
|
||||
* Check referencer for normal (inlined) data ref
|
||||
* If len == 0, it will be resolved by searching in extent tree
|
||||
*/
|
||||
static int check_extent_data_backref(struct btrfs_fs_info *fs_info,
|
||||
u64 root_id, u64 objectid, u64 offset,
|
||||
static int check_extent_data_backref(u64 root_id, u64 objectid, u64 offset,
|
||||
u64 bytenr, u64 len, u32 count)
|
||||
{
|
||||
struct btrfs_root *root;
|
||||
@ -4036,8 +4023,7 @@ out:
|
||||
/*
|
||||
* Check if the referencer of a shared data backref exists
|
||||
*/
|
||||
static int check_shared_data_backref(struct btrfs_fs_info *fs_info,
|
||||
u64 parent, u64 bytenr)
|
||||
static int check_shared_data_backref(u64 parent, u64 bytenr)
|
||||
{
|
||||
struct extent_buffer *eb;
|
||||
struct btrfs_key key;
|
||||
@ -4094,7 +4080,7 @@ static int repair_extent_item(struct btrfs_root *root, struct btrfs_path *path,
|
||||
|
||||
btrfs_item_key_to_cpu(path->nodes[0], &old_key, path->slots[0]);
|
||||
|
||||
ret = avoid_extents_overwrite(gfs_info);
|
||||
ret = avoid_extents_overwrite();
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -4151,8 +4137,7 @@ out:
|
||||
*
|
||||
* Since we don't use extent_record anymore, introduce new error bit
|
||||
*/
|
||||
static int check_extent_item(struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_path *path)
|
||||
static int check_extent_item(struct btrfs_path *path)
|
||||
{
|
||||
struct btrfs_extent_item *ei;
|
||||
struct btrfs_extent_inline_ref *iref;
|
||||
@ -4260,27 +4245,24 @@ next:
|
||||
case BTRFS_TREE_BLOCK_REF_KEY:
|
||||
root_objectid = offset;
|
||||
owner = level;
|
||||
tmp_err = check_tree_block_backref(gfs_info, offset,
|
||||
key.objectid, level);
|
||||
tmp_err = check_tree_block_backref(offset, key.objectid, level);
|
||||
break;
|
||||
case BTRFS_SHARED_BLOCK_REF_KEY:
|
||||
parent = offset;
|
||||
tmp_err = check_shared_block_backref(gfs_info, offset,
|
||||
key.objectid, level);
|
||||
tmp_err = check_shared_block_backref(offset, key.objectid, level);
|
||||
break;
|
||||
case BTRFS_EXTENT_DATA_REF_KEY:
|
||||
dref = (struct btrfs_extent_data_ref *)(&iref->offset);
|
||||
root_objectid = btrfs_extent_data_ref_root(eb, dref);
|
||||
owner = btrfs_extent_data_ref_objectid(eb, dref);
|
||||
owner_offset = btrfs_extent_data_ref_offset(eb, dref);
|
||||
tmp_err = check_extent_data_backref(gfs_info, root_objectid,
|
||||
tmp_err = check_extent_data_backref(root_objectid,
|
||||
owner, owner_offset, key.objectid, key.offset,
|
||||
btrfs_extent_data_ref_count(eb, dref));
|
||||
break;
|
||||
case BTRFS_SHARED_DATA_REF_KEY:
|
||||
parent = offset;
|
||||
tmp_err = check_shared_data_backref(gfs_info, offset,
|
||||
key.objectid);
|
||||
tmp_err = check_shared_data_backref(offset, key.objectid);
|
||||
break;
|
||||
default:
|
||||
error("extent[%llu %d %llu] has unknown ref type: %d",
|
||||
@ -4331,8 +4313,7 @@ out:
|
||||
/*
|
||||
* Check if a dev extent item is referred correctly by its chunk
|
||||
*/
|
||||
static int check_dev_extent_item(struct btrfs_fs_info *fs_info,
|
||||
struct extent_buffer *eb, int slot)
|
||||
static int check_dev_extent_item(struct extent_buffer *eb, int slot)
|
||||
{
|
||||
struct btrfs_root *chunk_root = gfs_info->chunk_root;
|
||||
struct btrfs_dev_extent *ptr;
|
||||
@ -4395,8 +4376,7 @@ out:
|
||||
/*
|
||||
* Check if the used space is correct with the dev item
|
||||
*/
|
||||
static int check_dev_item(struct btrfs_fs_info *fs_info,
|
||||
struct extent_buffer *eb, int slot)
|
||||
static int check_dev_item(struct extent_buffer *eb, int slot)
|
||||
{
|
||||
struct btrfs_root *dev_root = gfs_info->dev_root;
|
||||
struct btrfs_dev_item *dev_item;
|
||||
@ -4505,8 +4485,7 @@ next:
|
||||
* Return -ENOENT if not found.
|
||||
* Return <0 for fatal error.
|
||||
*/
|
||||
static int find_block_group_item(struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_path *path, u64 bytenr, u64 len,
|
||||
static int find_block_group_item(struct btrfs_path *path, u64 bytenr, u64 len,
|
||||
u64 type)
|
||||
{
|
||||
struct btrfs_block_group_item bgi;
|
||||
@ -4546,8 +4525,7 @@ out:
|
||||
* Check a chunk item.
|
||||
* Including checking all referred dev_extents and block group
|
||||
*/
|
||||
static int check_chunk_item(struct btrfs_fs_info *fs_info,
|
||||
struct extent_buffer *eb, int slot)
|
||||
static int check_chunk_item(struct extent_buffer *eb, int slot)
|
||||
{
|
||||
struct btrfs_root *dev_root = gfs_info->dev_root;
|
||||
struct btrfs_path path;
|
||||
@ -4582,8 +4560,7 @@ static int check_chunk_item(struct btrfs_fs_info *fs_info,
|
||||
type = btrfs_chunk_type(eb, chunk);
|
||||
|
||||
btrfs_init_path(&path);
|
||||
ret = find_block_group_item(gfs_info, &path, chunk_key.offset, length,
|
||||
type);
|
||||
ret = find_block_group_item(&path, chunk_key.offset, length, type);
|
||||
if (ret < 0)
|
||||
err |= REFERENCER_MISSING;
|
||||
|
||||
@ -4653,7 +4630,7 @@ static int repair_chunk_item(struct btrfs_root *chunk_root,
|
||||
if ((err & REFERENCER_MISSING) == 0)
|
||||
return err;
|
||||
|
||||
ret = avoid_extents_overwrite(gfs_info);
|
||||
ret = avoid_extents_overwrite();
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@ -4720,29 +4697,29 @@ again:
|
||||
err |= ret;
|
||||
break;
|
||||
case BTRFS_BLOCK_GROUP_ITEM_KEY:
|
||||
ret = check_block_group_item(gfs_info, eb, slot);
|
||||
ret = check_block_group_item(eb, slot);
|
||||
if (repair &&
|
||||
ret & REFERENCER_MISSING)
|
||||
ret = delete_item(root, path);
|
||||
err |= ret;
|
||||
break;
|
||||
case BTRFS_DEV_ITEM_KEY:
|
||||
ret = check_dev_item(gfs_info, eb, slot);
|
||||
ret = check_dev_item(eb, slot);
|
||||
err |= ret;
|
||||
break;
|
||||
case BTRFS_CHUNK_ITEM_KEY:
|
||||
ret = check_chunk_item(gfs_info, eb, slot);
|
||||
ret = check_chunk_item(eb, slot);
|
||||
if (repair && ret)
|
||||
ret = repair_chunk_item(root, path, ret);
|
||||
err |= ret;
|
||||
break;
|
||||
case BTRFS_DEV_EXTENT_KEY:
|
||||
ret = check_dev_extent_item(gfs_info, eb, slot);
|
||||
ret = check_dev_extent_item(eb, slot);
|
||||
err |= ret;
|
||||
break;
|
||||
case BTRFS_EXTENT_ITEM_KEY:
|
||||
case BTRFS_METADATA_ITEM_KEY:
|
||||
ret = check_extent_item(gfs_info, path);
|
||||
ret = check_extent_item(path);
|
||||
err |= ret;
|
||||
break;
|
||||
case BTRFS_EXTENT_CSUM_KEY:
|
||||
@ -4750,8 +4727,7 @@ again:
|
||||
err |= ret;
|
||||
break;
|
||||
case BTRFS_TREE_BLOCK_REF_KEY:
|
||||
ret = check_tree_block_backref(gfs_info, key.offset,
|
||||
key.objectid, -1);
|
||||
ret = check_tree_block_backref(key.offset, key.objectid, -1);
|
||||
if (repair &&
|
||||
ret & (REFERENCER_MISMATCH | REFERENCER_MISSING))
|
||||
ret = delete_item(root, path);
|
||||
@ -4759,7 +4735,7 @@ again:
|
||||
break;
|
||||
case BTRFS_EXTENT_DATA_REF_KEY:
|
||||
dref = btrfs_item_ptr(eb, slot, struct btrfs_extent_data_ref);
|
||||
ret = check_extent_data_backref(gfs_info,
|
||||
ret = check_extent_data_backref(
|
||||
btrfs_extent_data_ref_root(eb, dref),
|
||||
btrfs_extent_data_ref_objectid(eb, dref),
|
||||
btrfs_extent_data_ref_offset(eb, dref),
|
||||
@ -4771,16 +4747,14 @@ again:
|
||||
err |= ret;
|
||||
break;
|
||||
case BTRFS_SHARED_BLOCK_REF_KEY:
|
||||
ret = check_shared_block_backref(gfs_info, key.offset,
|
||||
key.objectid, -1);
|
||||
ret = check_shared_block_backref(key.offset, key.objectid, -1);
|
||||
if (repair &&
|
||||
ret & (REFERENCER_MISMATCH | REFERENCER_MISSING))
|
||||
ret = delete_item(root, path);
|
||||
err |= ret;
|
||||
break;
|
||||
case BTRFS_SHARED_DATA_REF_KEY:
|
||||
ret = check_shared_data_backref(gfs_info, key.offset,
|
||||
key.objectid);
|
||||
ret = check_shared_data_backref(key.offset, key.objectid);
|
||||
if (repair &&
|
||||
ret & (REFERENCER_MISMATCH | REFERENCER_MISSING))
|
||||
ret = delete_item(root, path);
|
||||
@ -5209,7 +5183,7 @@ out:
|
||||
*/
|
||||
static int check_fs_root(struct btrfs_root *root)
|
||||
{
|
||||
reset_cached_block_groups(gfs_info);
|
||||
reset_cached_block_groups();
|
||||
return check_btrfs_root(root, 0);
|
||||
}
|
||||
|
||||
@ -5312,7 +5286,7 @@ out:
|
||||
*
|
||||
* Return 0 if no error occurred.
|
||||
*/
|
||||
int check_fs_roots_lowmem(struct btrfs_fs_info *fs_info)
|
||||
int check_fs_roots_lowmem(void)
|
||||
{
|
||||
struct btrfs_root *tree_root = gfs_info->tree_root;
|
||||
struct btrfs_root *cur_root = NULL;
|
||||
@ -5345,7 +5319,7 @@ int check_fs_roots_lowmem(struct btrfs_fs_info *fs_info)
|
||||
goto out;
|
||||
if (key.type == BTRFS_INODE_ITEM_KEY &&
|
||||
is_fstree(key.objectid)) {
|
||||
ret = check_repair_free_space_inode(gfs_info, &path);
|
||||
ret = check_repair_free_space_inode(&path);
|
||||
/* Check if we still have a valid path to continue */
|
||||
if (ret < 0 && path.nodes[0]) {
|
||||
err |= ret;
|
||||
@ -5420,7 +5394,7 @@ out:
|
||||
/*
|
||||
* Low memory usage version check_chunks_and_extents.
|
||||
*/
|
||||
int check_chunks_and_extents_lowmem(struct btrfs_fs_info *fs_info)
|
||||
int check_chunks_and_extents_lowmem(void)
|
||||
{
|
||||
struct btrfs_path path;
|
||||
struct btrfs_key old_key;
|
||||
@ -5488,14 +5462,14 @@ next:
|
||||
out:
|
||||
|
||||
if (repair) {
|
||||
ret = end_avoid_extents_overwrite(gfs_info);
|
||||
ret = end_avoid_extents_overwrite();
|
||||
if (ret < 0)
|
||||
ret = FATAL_ERROR;
|
||||
err |= ret;
|
||||
|
||||
reset_cached_block_groups(gfs_info);
|
||||
reset_cached_block_groups();
|
||||
/* update block accounting */
|
||||
ret = repair_block_accounting(gfs_info);
|
||||
ret = repair_block_accounting();
|
||||
if (ret)
|
||||
err |= ret;
|
||||
else
|
||||
|
@ -66,9 +66,7 @@
|
||||
#define ACCOUNTING_MISMATCH (1 << 7) /* Used space accounting error */
|
||||
#define CHUNK_TYPE_MISMATCH (1 << 8)
|
||||
|
||||
int check_fs_roots_lowmem(struct btrfs_fs_info *fs_info);
|
||||
int check_chunks_and_extents_lowmem(struct btrfs_fs_info *fs_info);
|
||||
int check_repair_free_space_inode(struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_path *path);
|
||||
int check_fs_roots_lowmem(void);
|
||||
int check_chunks_and_extents_lowmem(void);
|
||||
|
||||
#endif
|
||||
|
3
ctree.h
3
ctree.h
@ -1201,8 +1201,7 @@ struct btrfs_fs_info {
|
||||
|
||||
int transaction_aborted;
|
||||
|
||||
int (*free_extent_hook)(struct btrfs_fs_info *fs_info,
|
||||
u64 bytenr, u64 num_bytes, u64 parent,
|
||||
int (*free_extent_hook)(u64 bytenr, u64 num_bytes, u64 parent,
|
||||
u64 root_objectid, u64 owner, u64 offset,
|
||||
int refs_to_drop);
|
||||
struct cache_tree *fsck_extent_cache;
|
||||
|
@ -1921,7 +1921,7 @@ static int __free_extent(struct btrfs_trans_handle *trans,
|
||||
btrfs_fs_incompat(extent_root->fs_info, SKINNY_METADATA);
|
||||
|
||||
if (trans->fs_info->free_extent_hook) {
|
||||
trans->fs_info->free_extent_hook(trans->fs_info, bytenr, num_bytes,
|
||||
trans->fs_info->free_extent_hook(bytenr, num_bytes,
|
||||
parent, root_objectid, owner_objectid,
|
||||
owner_offset, refs_to_drop);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user