Skip to content

Commit 00c0135

Browse files
josefbacikkdave
authored andcommitted
btrfs: fix may_commit_transaction to deal with no partial filling
Now that we aren't partially filling tickets we may have some slack space left in the space_info. We need to account for this in may_commit_transaction, otherwise we may choose to not commit the transaction despite it actually having enough space to satisfy our ticket. Calculate the free space we have in the space_info, if any, and subtract this from the ticket we have and use that amount to determine if we will need to commit to reclaim enough space. Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2341ccd commit 00c0135

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

fs/btrfs/space-info.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,19 +473,31 @@ static int may_commit_transaction(struct btrfs_fs_info *fs_info,
473473
struct btrfs_trans_handle *trans;
474474
u64 bytes_needed;
475475
u64 reclaim_bytes = 0;
476+
u64 cur_free_bytes = 0;
476477

477478
trans = (struct btrfs_trans_handle *)current->journal_info;
478479
if (trans)
479480
return -EAGAIN;
480481

481482
spin_lock(&space_info->lock);
483+
cur_free_bytes = btrfs_space_info_used(space_info, true);
484+
if (cur_free_bytes < space_info->total_bytes)
485+
cur_free_bytes = space_info->total_bytes - cur_free_bytes;
486+
else
487+
cur_free_bytes = 0;
488+
482489
if (!list_empty(&space_info->priority_tickets))
483490
ticket = list_first_entry(&space_info->priority_tickets,
484491
struct reserve_ticket, list);
485492
else if (!list_empty(&space_info->tickets))
486493
ticket = list_first_entry(&space_info->tickets,
487494
struct reserve_ticket, list);
488495
bytes_needed = (ticket) ? ticket->bytes : 0;
496+
497+
if (bytes_needed > cur_free_bytes)
498+
bytes_needed -= cur_free_bytes;
499+
else
500+
bytes_needed = 0;
489501
spin_unlock(&space_info->lock);
490502

491503
if (!bytes_needed)

0 commit comments

Comments
 (0)