From: Filipe Manana Date: Mon, 20 Oct 2025 21:59:03 +0000 (+0100) Subject: btrfs: move ticket wakeup and finalization to remove_ticket() X-Git-Tag: v6.19-rc1~167^2~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50a51b53782af2f9eabe77b1f0d5a3b339ee4531;p=thirdparty%2Fkernel%2Flinux.git 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 Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba --- diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index be58f702cc61c..86cd87c5884a8 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -515,13 +515,20 @@ bool btrfs_can_overcommit(const struct btrfs_space_info *space_info, u64 bytes, } static void remove_ticket(struct btrfs_space_info *space_info, - struct reserve_ticket *ticket) + struct reserve_ticket *ticket, int error) { if (!list_empty(&ticket->list)) { list_del_init(&ticket->list); ASSERT(space_info->reclaim_size >= ticket->bytes); space_info->reclaim_size -= ticket->bytes; } + + if (error) + ticket->error = error; + else + ticket->bytes = 0; + + wake_up(&ticket->wait); } /* @@ -549,10 +556,8 @@ again: if (used_after <= space_info->total_bytes || can_overcommit(space_info, used, ticket->bytes, flush)) { btrfs_space_info_update_bytes_may_use(space_info, ticket->bytes); - remove_ticket(space_info, ticket); - ticket->bytes = 0; + remove_ticket(space_info, ticket, 0); space_info->tickets_id++; - wake_up(&ticket->wait); used = used_after; } else { break; @@ -1066,9 +1071,7 @@ static bool steal_from_global_rsv(struct btrfs_space_info *space_info, global_rsv->full = false; spin_unlock(&global_rsv->lock); - remove_ticket(space_info, ticket); - ticket->bytes = 0; - wake_up(&ticket->wait); + remove_ticket(space_info, ticket, 0); space_info->tickets_id++; return true; @@ -1115,12 +1118,10 @@ static bool maybe_fail_all_tickets(struct btrfs_space_info *space_info) btrfs_info(fs_info, "failing ticket with %llu bytes", ticket->bytes); - remove_ticket(space_info, ticket); if (abort_error) - ticket->error = abort_error; + remove_ticket(space_info, ticket, abort_error); else - ticket->error = -ENOSPC; - wake_up(&ticket->wait); + remove_ticket(space_info, ticket, -ENOSPC); /* * 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, * just to have caller fail immediately instead of later when trying to * modify the fs, making it easier to debug -ENOSPC problems. */ - if (BTRFS_FS_ERROR(fs_info)) { - ticket->error = BTRFS_FS_ERROR(fs_info); - remove_ticket(space_info, ticket); - } else if (!steal_from_global_rsv(space_info, ticket)) { - ticket->error = -ENOSPC; - remove_ticket(space_info, ticket); - } + if (BTRFS_FS_ERROR(fs_info)) + remove_ticket(space_info, ticket, BTRFS_FS_ERROR(fs_info)); + else if (!steal_from_global_rsv(space_info, ticket)) + remove_ticket(space_info, ticket, -ENOSPC); /* * 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, } } - ticket->error = -ENOSPC; - remove_ticket(space_info, ticket); + remove_ticket(space_info, ticket, -ENOSPC); btrfs_try_granting_tickets(space_info); spin_unlock(&space_info->lock); } @@ -1599,8 +1596,7 @@ static void wait_reserve_ticket(struct btrfs_space_info *space_info, * despite getting an error, resulting in a space leak * (bytes_may_use counter of our space_info). */ - remove_ticket(space_info, ticket); - ticket->error = -EINTR; + remove_ticket(space_info, ticket, -EINTR); break; } spin_unlock(&space_info->lock);