bcachefs: Ensure we print output of run_recovery_pass if it errors
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 24 May 2025 18:37:20 +0000 (14:37 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Tue, 27 May 2025 04:02:44 +0000 (00:02 -0400)
Also, don't error out in bucket_ref_update_err(): we don't want to
return -BCH_ERR_cannot_rewind_recovery if it's not an insert, if it's an
overwrite we continue.

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

index 09eb5a543ae4393e46672eccab49a01f1a7fddb0..492a368a9993b663cc642e405e882fcf460d45b1 100644 (file)
@@ -406,7 +406,15 @@ static int bucket_ref_update_err(struct btree_trans *trans, struct printbuf *buf
        if (insert) {
                bch2_trans_updates_to_text(buf, trans);
                __bch2_inconsistent_error(c, buf);
-               ret = -BCH_ERR_bucket_ref_update;
+               /*
+                * If we're in recovery, run_explicit_recovery_pass might give
+                * us an error code for rewinding recovery
+                */
+               if (!ret)
+                       ret = -BCH_ERR_bucket_ref_update;
+       } else {
+               /* Always ignore overwrite errors, so that deletion works */
+               ret = 0;
        }
 
        if (print || insert)
@@ -971,15 +979,16 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
                           bch2_data_type_str(type),
                           bch2_data_type_str(type));
 
-               bool print = bch2_count_fsck_err(c, bucket_metadata_type_mismatch, &buf);
+               bch2_count_fsck_err(c, bucket_metadata_type_mismatch, &buf);
 
-               bch2_run_explicit_recovery_pass(c, &buf,
+               ret = bch2_run_explicit_recovery_pass(c, &buf,
                                        BCH_RECOVERY_PASS_check_allocations, 0);
 
-               if (print)
-                       bch2_print_str(c, KERN_ERR, buf.buf);
+               /* Always print, this is always fatal */
+               bch2_print_str(c, KERN_ERR, buf.buf);
                printbuf_exit(&buf);
-               ret = -BCH_ERR_metadata_bucket_inconsistency;
+               if (!ret)
+                       ret = -BCH_ERR_metadata_bucket_inconsistency;
                goto err;
        }