Skip to content

Commit 701ff57

Browse files
author
Kent Overstreet
committed
bcachefs: Check for nonce offset inconsistency in data_update path
We've rarely been seeing a nonce offset inconsistency that doesn't show up in tests: this adds some extra verification code to the data update path that prints out more relevant info when it occurs. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 09b0283 commit 701ff57

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

fs/bcachefs/data_update.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,34 @@ static int __bch2_data_update_index_update(struct btree_trans *trans,
239239

240240
next_pos = insert->k.p;
241241

242+
/*
243+
* Check for nonce offset inconsistency:
244+
* This is debug code - we've been seeing this bug rarely, and
245+
* it's been hard to reproduce, so this should give us some more
246+
* information when it does occur:
247+
*/
248+
struct printbuf err = PRINTBUF;
249+
int invalid = bch2_bkey_invalid(c, bkey_i_to_s_c(insert), __btree_node_type(0, m->btree_id), 0, &err);
250+
printbuf_exit(&err);
251+
252+
if (invalid) {
253+
struct printbuf buf = PRINTBUF;
254+
255+
prt_str(&buf, "about to insert invalid key in data update path");
256+
prt_str(&buf, "\nold: ");
257+
bch2_bkey_val_to_text(&buf, c, old);
258+
prt_str(&buf, "\nk: ");
259+
bch2_bkey_val_to_text(&buf, c, k);
260+
prt_str(&buf, "\nnew: ");
261+
bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(insert));
262+
263+
bch2_print_string_as_lines(KERN_ERR, buf.buf);
264+
printbuf_exit(&buf);
265+
266+
bch2_fatal_error(c);
267+
goto out;
268+
}
269+
242270
ret = bch2_insert_snapshot_whiteouts(trans, m->btree_id,
243271
k.k->p, bkey_start_pos(&insert->k)) ?:
244272
bch2_insert_snapshot_whiteouts(trans, m->btree_id,

0 commit comments

Comments
 (0)