Commit 90290e19 authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason

Btrfs: protect orphan block rsv with spin_lock

We've been seeing warnings coming out of the orphan commit stuff forever from
ceph.  Turns out it's because we're racing with checking if the orphan block
reserve is set, because we clear it outside of the spin_lock.  So leave the
normal fastpath checks where they are, but take the spin_lock and _recheck_ to
make sure we haven't had an orphan block rsv added in the meantime.  Then clear
the root's orphan block rsv and release the lock.  With this patch a user said
the warnings went away and they usually showed up pretty soon after he started
ceph.  Thanks,
Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
parent 3f7de037
...@@ -1951,12 +1951,28 @@ enum btrfs_orphan_cleanup_state { ...@@ -1951,12 +1951,28 @@ enum btrfs_orphan_cleanup_state {
void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans, void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans,
struct btrfs_root *root) struct btrfs_root *root)
{ {
struct btrfs_block_rsv *block_rsv;
int ret; int ret;
if (!list_empty(&root->orphan_list) || if (!list_empty(&root->orphan_list) ||
root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE) root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE)
return; return;
spin_lock(&root->orphan_lock);
if (!list_empty(&root->orphan_list)) {
spin_unlock(&root->orphan_lock);
return;
}
if (root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE) {
spin_unlock(&root->orphan_lock);
return;
}
block_rsv = root->orphan_block_rsv;
root->orphan_block_rsv = NULL;
spin_unlock(&root->orphan_lock);
if (root->orphan_item_inserted && if (root->orphan_item_inserted &&
btrfs_root_refs(&root->root_item) > 0) { btrfs_root_refs(&root->root_item) > 0) {
ret = btrfs_del_orphan_item(trans, root->fs_info->tree_root, ret = btrfs_del_orphan_item(trans, root->fs_info->tree_root,
...@@ -1965,10 +1981,9 @@ void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans, ...@@ -1965,10 +1981,9 @@ void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans,
root->orphan_item_inserted = 0; root->orphan_item_inserted = 0;
} }
if (root->orphan_block_rsv) { if (block_rsv) {
WARN_ON(root->orphan_block_rsv->size > 0); WARN_ON(block_rsv->size > 0);
btrfs_free_block_rsv(root, root->orphan_block_rsv); btrfs_free_block_rsv(root, block_rsv);
root->orphan_block_rsv = NULL;
} }
} }
......
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