From 4a2e5d7ba5b8208ea5a20eeb274b2b0333ab5dcf Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Fri, 12 May 2023 20:28:54 -0400 Subject: bcachefs: Replace a BUG_ON() with fatal error A user hit this BUG_ON() - it's unclear how it happened, so replace it with a fatal error that will cause us to go read only, and print out more information. Signed-off-by: Kent Overstreet --- fs/bcachefs/journal_io.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'fs/bcachefs/journal_io.c') diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c index ede9d198bb85..b455ef041dfe 100644 --- a/fs/bcachefs/journal_io.c +++ b/fs/bcachefs/journal_io.c @@ -1743,7 +1743,16 @@ void bch2_journal_write(struct closure *cl) BUG_ON(u64s > j->entry_u64s_reserved); le32_add_cpu(&jset->u64s, u64s); - BUG_ON(vstruct_sectors(jset, c->block_bits) > w->sectors); + + sectors = vstruct_sectors(jset, c->block_bits); + bytes = vstruct_bytes(jset); + + if (sectors > w->sectors) { + bch2_fs_fatal_error(c, "aieeee! journal write overran available space, %zu > %u (extra %u reserved %u/%u)", + vstruct_bytes(jset), w->sectors << 9, + u64s, w->u64s_reserved, j->entry_u64s_reserved); + goto err; + } jset->magic = cpu_to_le64(jset_magic(c)); jset->version = c->sb.version < bcachefs_metadata_version_bkey_renumber @@ -1780,10 +1789,6 @@ void bch2_journal_write(struct closure *cl) jset_validate(c, NULL, jset, 0, WRITE)) goto err; - sectors = vstruct_sectors(jset, c->block_bits); - BUG_ON(sectors > w->sectors); - - bytes = vstruct_bytes(jset); memset((void *) jset + bytes, 0, (sectors << 9) - bytes); retry_alloc: -- cgit v1.2.3