Commit 68a7342c authored by Josef Bacik's avatar Josef Bacik

Btrfs: cleanup orphaned root orphan item

I hit a weird problem were my root item had been deleted but the orphan item had
not.  This isn't necessarily a problem, but it keeps the file system from being
mounted.  To fix this we just need to axe the orphan item if we can't find the
fs root when we're putting them altogether.  With this patch I was able to
successfully mount my file system.  Thanks,
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
parent a70c6172
...@@ -228,6 +228,10 @@ int btrfs_find_orphan_roots(struct btrfs_root *tree_root) ...@@ -228,6 +228,10 @@ int btrfs_find_orphan_roots(struct btrfs_root *tree_root)
struct btrfs_root *root; struct btrfs_root *root;
int err = 0; int err = 0;
int ret; int ret;
bool can_recover = true;
if (tree_root->fs_info->sb->s_flags & MS_RDONLY)
can_recover = false;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
...@@ -268,9 +272,32 @@ int btrfs_find_orphan_roots(struct btrfs_root *tree_root) ...@@ -268,9 +272,32 @@ int btrfs_find_orphan_roots(struct btrfs_root *tree_root)
key.offset++; key.offset++;
root = btrfs_read_fs_root(tree_root, &root_key); root = btrfs_read_fs_root(tree_root, &root_key);
if (IS_ERR(root)) { err = PTR_RET(root);
err = PTR_ERR(root); if (err && err != -ENOENT) {
break; break;
} else if (err == -ENOENT) {
struct btrfs_trans_handle *trans;
btrfs_release_path(path);
trans = btrfs_join_transaction(tree_root);
if (IS_ERR(trans)) {
err = PTR_ERR(trans);
btrfs_error(tree_root->fs_info, err,
"Failed to start trans to delete "
"orphan item");
break;
}
err = btrfs_del_orphan_item(trans, tree_root,
root_key.objectid);
btrfs_end_transaction(trans, tree_root);
if (err) {
btrfs_error(tree_root->fs_info, err,
"Failed to delete root orphan "
"item");
break;
}
continue;
} }
if (btrfs_root_refs(&root->root_item) == 0) { if (btrfs_root_refs(&root->root_item) == 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment