Commit 38227933 authored by Josef Bacik's avatar Josef Bacik

Btrfs: set trans to null in reserve_metadata_bytes if we commit the transaction

btrfs_commit_transaction will free our trans, but because we pass trans to
shrink_delalloc we could possibly have a use after free situation.  So instead
if we commit the transaction, set trans to null and set committed to true so we
don't keep trying to commit a transaction.  This fixes a panic I could reproduce
at will.  Thanks,
Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
parent 0e78340f
...@@ -3157,6 +3157,7 @@ static int reserve_metadata_bytes(struct btrfs_trans_handle *trans, ...@@ -3157,6 +3157,7 @@ static int reserve_metadata_bytes(struct btrfs_trans_handle *trans,
int retries = 0; int retries = 0;
int ret = 0; int ret = 0;
bool reserved = false; bool reserved = false;
bool committed = false;
again: again:
ret = -ENOSPC; ret = -ENOSPC;
...@@ -3249,17 +3250,19 @@ static int reserve_metadata_bytes(struct btrfs_trans_handle *trans, ...@@ -3249,17 +3250,19 @@ static int reserve_metadata_bytes(struct btrfs_trans_handle *trans,
goto out; goto out;
ret = -EAGAIN; ret = -EAGAIN;
if (trans) if (trans || committed)
goto out; goto out;
ret = -ENOSPC; ret = -ENOSPC;
trans = btrfs_join_transaction(root, 1); trans = btrfs_join_transaction(root, 1);
if (IS_ERR(trans)) if (IS_ERR(trans))
goto out; goto out;
ret = btrfs_commit_transaction(trans, root); ret = btrfs_commit_transaction(trans, root);
if (!ret) if (!ret) {
trans = NULL;
committed = true;
goto again; goto again;
}
out: out:
if (reserved) { if (reserved) {
......
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