Skip to content

Commit

Permalink
btrfs: hold a ref on the root in btrfs_recover_relocation
Browse files Browse the repository at this point in the history
We look up the fs root in various places in here when recovering from a
crashed relcoation.  Make sure we hold a ref on the root whenever we
look them up.

Signed-off-by: Josef Bacik <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
josefbacik authored and kdave committed Mar 23, 2020
1 parent 76deacf commit 932fd26
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions fs/btrfs/relocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -4647,6 +4647,12 @@ int btrfs_recover_relocation(struct btrfs_root *root)
err = ret;
goto out;
}
} else {
if (!btrfs_grab_fs_root(fs_root)) {
err = -ENOENT;
goto out;
}
btrfs_put_fs_root(fs_root);
}
}

Expand Down Expand Up @@ -4696,10 +4702,15 @@ int btrfs_recover_relocation(struct btrfs_root *root)
list_add_tail(&reloc_root->root_list, &reloc_roots);
goto out_free;
}
if (!btrfs_grab_fs_root(fs_root)) {
err = -ENOENT;
goto out_free;
}

err = __add_reloc_root(reloc_root);
BUG_ON(err < 0); /* -ENOMEM or logic error */
fs_root->reloc_root = reloc_root;
btrfs_put_fs_root(fs_root);
}

err = btrfs_commit_transaction(trans);
Expand Down Expand Up @@ -4731,10 +4742,14 @@ int btrfs_recover_relocation(struct btrfs_root *root)
if (err == 0) {
/* cleanup orphan inode in data relocation tree */
fs_root = read_fs_root(fs_info, BTRFS_DATA_RELOC_TREE_OBJECTID);
if (IS_ERR(fs_root))
if (IS_ERR(fs_root)) {
err = PTR_ERR(fs_root);
else
err = btrfs_orphan_cleanup(fs_root);
} else {
if (btrfs_grab_fs_root(fs_root)) {
err = btrfs_orphan_cleanup(fs_root);
btrfs_put_fs_root(fs_root);
}
}
}
return err;
}
Expand Down

0 comments on commit 932fd26

Please sign in to comment.