bcachefs: bch2_io_failures_to_text()
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 22 Apr 2025 09:45:48 +0000 (05:45 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:31 +0000 (20:14 -0400)
Pretty printer for bch_io_failures, to be used for better read error
messages.

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

index ef116c55f0a74965b9464d59d7d0012238ab8147..8a881b30fd4ce7171b96817f956cf91f14cde574 100644 (file)
@@ -45,6 +45,46 @@ static void bch2_extent_crc_pack(union bch_extent_crc *,
                                 struct bch_extent_crc_unpacked,
                                 enum bch_extent_entry_type);
 
+void bch2_io_failures_to_text(struct printbuf *out,
+                             struct bch_fs *c,
+                             struct bch_io_failures *failed)
+{
+       static const char * const error_types[] = {
+               "io", "checksum", "ec reconstruct", NULL
+       };
+
+       for (struct bch_dev_io_failures *f = failed->devs;
+            f < failed->devs + failed->nr;
+            f++) {
+               bch2_printbuf_make_room(out, 1024);
+               rcu_read_lock();
+               out->atomic++;
+               struct bch_dev *ca = bch2_dev_rcu_noerror(c, f->dev);
+               if (ca)
+                       prt_str(out, ca->name);
+               else
+                       prt_printf(out, "(invalid device %u)", f->dev);
+               --out->atomic;
+               rcu_read_unlock();
+
+               prt_char(out, ' ');
+
+               unsigned errflags =
+                       ((!!f->failed_io)       << 0) |
+                       ((!!f->failed_csum_nr)  << 1) |
+                       ((!!f->failed_ec)       << 2);
+
+               if (is_power_of_2(errflags)) {
+                       prt_bitflags(out, error_types, errflags);
+                       prt_str(out, " error");
+               } else {
+                       prt_str(out, "errors: ");
+                       prt_bitflags(out, error_types, errflags);
+               }
+               prt_newline(out);
+       }
+}
+
 struct bch_dev_io_failures *bch2_dev_io_failures(struct bch_io_failures *f,
                                                 unsigned dev)
 {
index 9fe153183b36ec92ab58419b123a3538777c027b..9dd2655a577444fadd9c9dc9d39cdd2d06a8eac3 100644 (file)
@@ -392,6 +392,8 @@ out:                                                                        \
 
 /* utility code common to all keys with pointers: */
 
+void bch2_io_failures_to_text(struct printbuf *, struct bch_fs *,
+                             struct bch_io_failures *);
 struct bch_dev_io_failures *bch2_dev_io_failures(struct bch_io_failures *,
                                                 unsigned);
 void bch2_mark_io_failure(struct bch_io_failures *,