bcachefs: sysfs/errors
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 28 May 2025 05:00:34 +0000 (01:00 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 30 May 2025 15:20:18 +0000 (11:20 -0400)
Make the superblock error counters available in sysfs; the only other
way they can be seen is 'show-super', but we don't write the superblock
every time the error count gets incremented.

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

index 013a96883b4e2808b482fa5b7dc1fe366fd04b88..48853efdc105d54c161ff15a467281dcb9c57ff5 100644 (file)
@@ -78,6 +78,28 @@ const struct bch_sb_field_ops bch_sb_field_ops_errors = {
        .to_text        = bch2_sb_errors_to_text,
 };
 
+void bch2_fs_errors_to_text(struct printbuf *out, struct bch_fs *c)
+{
+       if (out->nr_tabstops < 1)
+               printbuf_tabstop_push(out, 48);
+       if (out->nr_tabstops < 2)
+               printbuf_tabstop_push(out, 8);
+       if (out->nr_tabstops < 3)
+               printbuf_tabstop_push(out, 16);
+
+       guard(mutex)(&c->fsck_error_counts_lock);
+
+       bch_sb_errors_cpu *e = &c->fsck_error_counts;
+       darray_for_each(*e, i) {
+               bch2_sb_error_id_to_text(out, i->id);
+               prt_tab(out);
+               prt_u64(out, i->nr);
+               prt_tab(out);
+               bch2_prt_datetime(out, i->last_error_time);
+               prt_newline(out);
+       }
+}
+
 void bch2_sb_error_count(struct bch_fs *c, enum bch_sb_error_id err)
 {
        bch_sb_errors_cpu *e = &c->fsck_error_counts;
index b2357b8e6107ba95c13146e5be124871f8962204..e86267264692d1f84dc8547608b8248f4352a4b6 100644 (file)
@@ -7,6 +7,7 @@
 extern const char * const bch2_sb_error_strs[];
 
 void bch2_sb_error_id_to_text(struct printbuf *, enum bch_sb_error_id);
+void bch2_fs_errors_to_text(struct printbuf *, struct bch_fs *);
 
 extern const struct bch_sb_field_ops bch_sb_field_ops_errors;
 
index 1a55196d69f11b4d32e9fc369d4b1af30e298504..f93af1c45ae67006e27a97247a66e79c5b003e07 100644 (file)
@@ -37,6 +37,7 @@
 #include "rebalance.h"
 #include "recovery_passes.h"
 #include "replicas.h"
+#include "sb-errors.h"
 #include "super-io.h"
 #include "tests.h"
 
@@ -172,6 +173,7 @@ read_attribute(btree_write_stats);
 
 read_attribute(btree_cache_size);
 read_attribute(compression_stats);
+read_attribute(errors);
 read_attribute(journal_debug);
 read_attribute(btree_cache);
 read_attribute(btree_key_cache);
@@ -353,6 +355,9 @@ SHOW(bch2_fs)
        if (attr == &sysfs_compression_stats)
                bch2_compression_stats_to_text(out, c);
 
+       if (attr == &sysfs_errors)
+               bch2_fs_errors_to_text(out, c);
+
        if (attr == &sysfs_new_stripes)
                bch2_new_stripes_to_text(out, c);
 
@@ -483,6 +488,7 @@ struct attribute *bch2_fs_files[] = {
        &sysfs_recovery_status,
 
        &sysfs_compression_stats,
+       &sysfs_errors,
 
 #ifdef CONFIG_BCACHEFS_TESTS
        &sysfs_perf_test,