Skip to content

Commit 902d696

Browse files
fdmananakdave
authored andcommitted
btrfs: move ticket wakeup and finalization to remove_ticket()
Instead of repeating the wakeup and setup of the ->bytes or ->error field, move those steps to remove_ticket() to avoid duplication. This is also needed for the next patch in the series, so that we avoid duplicating more logic. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent c128b39 commit 902d696

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

fs/btrfs/space-info.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,20 @@ bool btrfs_can_overcommit(const struct btrfs_space_info *space_info, u64 bytes,
515515
}
516516

517517
static void remove_ticket(struct btrfs_space_info *space_info,
518-
struct reserve_ticket *ticket)
518+
struct reserve_ticket *ticket, int error)
519519
{
520520
if (!list_empty(&ticket->list)) {
521521
list_del_init(&ticket->list);
522522
ASSERT(space_info->reclaim_size >= ticket->bytes);
523523
space_info->reclaim_size -= ticket->bytes;
524524
}
525+
526+
if (error)
527+
ticket->error = error;
528+
else
529+
ticket->bytes = 0;
530+
531+
wake_up(&ticket->wait);
525532
}
526533

527534
/*
@@ -549,10 +556,8 @@ void btrfs_try_granting_tickets(struct btrfs_space_info *space_info)
549556
if (used_after <= space_info->total_bytes ||
550557
can_overcommit(space_info, used, ticket->bytes, flush)) {
551558
btrfs_space_info_update_bytes_may_use(space_info, ticket->bytes);
552-
remove_ticket(space_info, ticket);
553-
ticket->bytes = 0;
559+
remove_ticket(space_info, ticket, 0);
554560
space_info->tickets_id++;
555-
wake_up(&ticket->wait);
556561
used = used_after;
557562
} else {
558563
break;
@@ -1066,9 +1071,7 @@ static bool steal_from_global_rsv(struct btrfs_space_info *space_info,
10661071
global_rsv->full = false;
10671072
spin_unlock(&global_rsv->lock);
10681073

1069-
remove_ticket(space_info, ticket);
1070-
ticket->bytes = 0;
1071-
wake_up(&ticket->wait);
1074+
remove_ticket(space_info, ticket, 0);
10721075
space_info->tickets_id++;
10731076

10741077
return true;
@@ -1115,12 +1118,10 @@ static bool maybe_fail_all_tickets(struct btrfs_space_info *space_info)
11151118
btrfs_info(fs_info, "failing ticket with %llu bytes",
11161119
ticket->bytes);
11171120

1118-
remove_ticket(space_info, ticket);
11191121
if (abort_error)
1120-
ticket->error = abort_error;
1122+
remove_ticket(space_info, ticket, abort_error);
11211123
else
1122-
ticket->error = -ENOSPC;
1123-
wake_up(&ticket->wait);
1124+
remove_ticket(space_info, ticket, -ENOSPC);
11241125

11251126
/*
11261127
* We're just throwing tickets away, so more flushing may not
@@ -1536,13 +1537,10 @@ static void priority_reclaim_metadata_space(struct btrfs_space_info *space_info,
15361537
* just to have caller fail immediately instead of later when trying to
15371538
* modify the fs, making it easier to debug -ENOSPC problems.
15381539
*/
1539-
if (BTRFS_FS_ERROR(fs_info)) {
1540-
ticket->error = BTRFS_FS_ERROR(fs_info);
1541-
remove_ticket(space_info, ticket);
1542-
} else if (!steal_from_global_rsv(space_info, ticket)) {
1543-
ticket->error = -ENOSPC;
1544-
remove_ticket(space_info, ticket);
1545-
}
1540+
if (BTRFS_FS_ERROR(fs_info))
1541+
remove_ticket(space_info, ticket, BTRFS_FS_ERROR(fs_info));
1542+
else if (!steal_from_global_rsv(space_info, ticket))
1543+
remove_ticket(space_info, ticket, -ENOSPC);
15461544

15471545
/*
15481546
* We must run try_granting_tickets here because we could be a large
@@ -1574,8 +1572,7 @@ static void priority_reclaim_data_space(struct btrfs_space_info *space_info,
15741572
}
15751573
}
15761574

1577-
ticket->error = -ENOSPC;
1578-
remove_ticket(space_info, ticket);
1575+
remove_ticket(space_info, ticket, -ENOSPC);
15791576
btrfs_try_granting_tickets(space_info);
15801577
spin_unlock(&space_info->lock);
15811578
}
@@ -1599,8 +1596,7 @@ static void wait_reserve_ticket(struct btrfs_space_info *space_info,
15991596
* despite getting an error, resulting in a space leak
16001597
* (bytes_may_use counter of our space_info).
16011598
*/
1602-
remove_ticket(space_info, ticket);
1603-
ticket->error = -EINTR;
1599+
remove_ticket(space_info, ticket, -EINTR);
16041600
break;
16051601
}
16061602
spin_unlock(&space_info->lock);

0 commit comments

Comments
 (0)