btrfs-progs: add root to dirty list when fixing bad keys

A user reported a WARN_ON() when trying to run btrfsck --repair on his fs with
bad key ordering.  This was because the root that was broken wasn't part of the
transaction yet.  We do this open coded thing in a few other places in fsck, so
just make it a helper function and make sure all the places that need to call it
do call it.  With this patch he was able to run repair without it dying.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
Josef Bacik 2014-09-29 12:39:46 -04:00 committed by David Sterba
parent f28ad306b3
commit 3fce2fa9a1

View file

@ -243,6 +243,17 @@ struct bad_item {
static void reset_cached_block_groups(struct btrfs_fs_info *fs_info); static void reset_cached_block_groups(struct btrfs_fs_info *fs_info);
static void record_root_in_trans(struct btrfs_trans_handle *trans,
struct btrfs_root *root)
{
if (root->last_trans != trans->transid) {
root->track_dirty = 1;
root->last_trans = trans->transid;
root->commit_root = root->node;
extent_buffer_get(root->node);
}
}
static u8 imode_to_type(u32 imode) static u8 imode_to_type(u32 imode)
{ {
#define S_SHIFT 12 #define S_SHIFT 12
@ -2429,6 +2440,8 @@ static int try_to_fix_bad_block(struct btrfs_trans_handle *trans,
if (IS_ERR(root)) if (IS_ERR(root))
return -EIO; return -EIO;
record_root_in_trans(trans, root);
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
return -EIO; return -EIO;
@ -4667,12 +4680,7 @@ static int repair_ref(struct btrfs_trans_handle *trans,
* Have to make sure that this root gets updated when we commit the * Have to make sure that this root gets updated when we commit the
* transaction * transaction
*/ */
root->track_dirty = 1; record_root_in_trans(trans, root);
if (root->last_trans != trans->transid) {
root->last_trans = trans->transid;
root->commit_root = root->node;
extent_buffer_get(root->node);
}
/* /*
* Ok we have the key of the file extent we want to fix, now we can cow * Ok we have the key of the file extent we want to fix, now we can cow
@ -6352,12 +6360,7 @@ reinit_data_reloc:
fprintf(stderr, "Error reading data reloc tree\n"); fprintf(stderr, "Error reading data reloc tree\n");
return PTR_ERR(root); return PTR_ERR(root);
} }
root->track_dirty = 1; record_root_in_trans(trans, root);
if (root->last_trans != trans->transid) {
root->last_trans = trans->transid;
root->commit_root = root->node;
extent_buffer_get(root->node);
}
ret = btrfs_fsck_reinit_root(trans, root, 0); ret = btrfs_fsck_reinit_root(trans, root, 0);
if (ret) if (ret)
goto out; goto out;