diff mbox series

btrfs: do not try to handle a ticket for FLUSH_EMERGENCY

Message ID 1f314a6e586b0725b84eb906efbfdafd10890c59.1668696886.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs: do not try to handle a ticket for FLUSH_EMERGENCY | expand

Commit Message

Josef Bacik Nov. 17, 2022, 2:54 p.m. UTC
Even though it is unlikely, we can still fail
BTRFS_RESERVE_FLUSH_EMERGENCY sometimes.  Unfortunately the condition to
check if we should just return the error only checks for NO_FLUSH, and
thus we could get into handle_reserve_ticket with FLUSH_EMERGENCY, which
has the equivalent assertion of ASSERT(flush != FLUSH_EMERGENCY && flush
!= NO_FLUSH).  Fix this by changing the condition at the end of
__reserve_bytes to check !can_ticket(flush) to handle both of these
cases properly.

Fixes: dfed100c66b2 ("btrfs: introduce BTRFS_RESERVE_FLUSH_EMERGENCY")
Reported-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/space-info.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Sterba Nov. 18, 2022, 3:54 p.m. UTC | #1
On Thu, Nov 17, 2022 at 09:54:56AM -0500, Josef Bacik wrote:
> Even though it is unlikely, we can still fail
> BTRFS_RESERVE_FLUSH_EMERGENCY sometimes.  Unfortunately the condition to
> check if we should just return the error only checks for NO_FLUSH, and
> thus we could get into handle_reserve_ticket with FLUSH_EMERGENCY, which
> has the equivalent assertion of ASSERT(flush != FLUSH_EMERGENCY && flush
> != NO_FLUSH).  Fix this by changing the condition at the end of
> __reserve_bytes to check !can_ticket(flush) to handle both of these
> cases properly.
> 
> Fixes: dfed100c66b2 ("btrfs: introduce BTRFS_RESERVE_FLUSH_EMERGENCY")
> Reported-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Folded to the patch, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c
index a1384357f7a5..d28ee4e36f3d 100644
--- a/fs/btrfs/space-info.c
+++ b/fs/btrfs/space-info.c
@@ -1729,7 +1729,7 @@  static int __reserve_bytes(struct btrfs_fs_info *fs_info,
 		}
 	}
 	spin_unlock(&space_info->lock);
-	if (!ret || flush == BTRFS_RESERVE_NO_FLUSH)
+	if (!ret || !can_ticket(flush))
 		return ret;
 
 	return handle_reserve_ticket(fs_info, space_info, &ticket, start_ns,