Commit 15e70000 authored by Sage Weil's avatar Sage Weil Committed by Chris Mason

Btrfs: avoid BUG when dropping root and reference in same transaction

If btrfs_ioctl_snap_destroy() deletes a snapshot but finishes
with end_transaction(), the cleaner kthread may come in and
drop the root in the same transaction.  If that's the case, the
root's refs still == 1 in the tree when btrfs_del_root() deletes
the item, because commit_fs_roots() hasn't updated it yet (that
happens during the commit).

This wasn't a problem before only because
btrfs_ioctl_snap_destroy() would commit the transaction before dropping
the dentry reference, so the dead root wouldn't get queued up until
after the fs root item was updated in the btree.

Since it is not an error to drop the root reference and the root in the
same transaction, just drop the BUG_ON() in btrfs_del_root().
Signed-off-by: default avatarSage Weil <sage@newdream.net>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 731e3d1b
...@@ -330,7 +330,6 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -330,7 +330,6 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
{ {
struct btrfs_path *path; struct btrfs_path *path;
int ret; int ret;
u32 refs;
struct btrfs_root_item *ri; struct btrfs_root_item *ri;
struct extent_buffer *leaf; struct extent_buffer *leaf;
...@@ -344,8 +343,6 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -344,8 +343,6 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
leaf = path->nodes[0]; leaf = path->nodes[0];
ri = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_item); ri = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_item);
refs = btrfs_disk_root_refs(leaf, ri);
BUG_ON(refs != 0);
ret = btrfs_del_item(trans, root, path); ret = btrfs_del_item(trans, root, path);
out: out:
btrfs_free_path(path); btrfs_free_path(path);
......
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