bcachefs: Change __journal_entry_close() assert to ERO
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 18 Apr 2025 17:38:23 +0000 (13:38 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 20 Apr 2025 23:41:38 +0000 (19:41 -0400)
We've got some reports of this happening in the wild, and need a bit
more info to debug it:

https://github.com/koverstreet/bcachefs/issues/854
https://www.reddit.com/r/bcachefs/comments/1k28kjm/surprise_soft_lockup/

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/journal.c

index 84cb74ba91e621b0eeb01a4b34938e278be56a8b..bb45d363419488624028668eaea476f9b34d3cce 100644 (file)
@@ -281,7 +281,24 @@ static void __journal_entry_close(struct journal *j, unsigned closed_val, bool t
 
        sectors = vstruct_blocks_plus(buf->data, c->block_bits,
                                      buf->u64s_reserved) << c->block_bits;
-       BUG_ON(sectors > buf->sectors);
+       if (unlikely(sectors > buf->sectors)) {
+               struct printbuf err = PRINTBUF;
+               err.atomic++;
+
+               prt_printf(&err, "journal entry overran reserved space: %u > %u\n",
+                          sectors, buf->sectors);
+               prt_printf(&err, "buf u64s %u u64s reserved %u cur_entry_u64s %u block_bits %u\n",
+                          le32_to_cpu(buf->data->u64s), buf->u64s_reserved,
+                          j->cur_entry_u64s,
+                          c->block_bits);
+               prt_printf(&err, "fatal error - emergency read only");
+               bch2_journal_halt_locked(j);
+
+               bch_err(c, "%s", err.buf);
+               printbuf_exit(&err);
+               return;
+       }
+
        buf->sectors = sectors;
 
        /*