Skip to content

Commit

Permalink
Btrfs: only retry transaction reservation once
Browse files Browse the repository at this point in the history
I saw a lockup where we kept getting into this start transaction->commit
transaction loop because of enospce.  The fact is if we fail to make our
reservation, we've tried _everything_ several times, so we only need to try and
commit the transaction once, and if that doesn't work then we really are out of
space and need to just exit.  Thanks,

Signed-off-by: Josef Bacik <[email protected]>
  • Loading branch information
Josef Bacik committed Apr 8, 2011
1 parent be1a12a commit 06d5a58
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion fs/btrfs/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
{
struct btrfs_trans_handle *h;
struct btrfs_transaction *cur_trans;
int retries = 0;
int ret;

if (root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR)
Expand Down Expand Up @@ -224,10 +225,18 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,

if (num_items > 0) {
ret = btrfs_trans_reserve_metadata(h, root, num_items);
if (ret == -EAGAIN) {
if (ret == -EAGAIN && !retries) {
retries++;
btrfs_commit_transaction(h, root);
goto again;
} else if (ret == -EAGAIN) {
/*
* We have already retried and got EAGAIN, so really we
* don't have space, so set ret to -ENOSPC.
*/
ret = -ENOSPC;
}

if (ret < 0) {
btrfs_end_transaction(h, root);
return ERR_PTR(ret);
Expand Down

0 comments on commit 06d5a58

Please sign in to comment.