Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+28
+28
fs/bcachefs/data_update.c
··· 239 239 240 240 next_pos = insert->k.p; 241 241 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 + 242 270 ret = bch2_insert_snapshot_whiteouts(trans, m->btree_id, 243 271 k.k->p, bkey_start_pos(&insert->k)) ?: 244 272 bch2_insert_snapshot_whiteouts(trans, m->btree_id,