Skip to content

Commit f1dc067

Browse files
author
Kent Overstreet
committed
bcachefs: sysfs/errors
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 <[email protected]>
1 parent 66b7c51 commit f1dc067

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

fs/bcachefs/sb-errors.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ const struct bch_sb_field_ops bch_sb_field_ops_errors = {
7878
.to_text = bch2_sb_errors_to_text,
7979
};
8080

81+
void bch2_fs_errors_to_text(struct printbuf *out, struct bch_fs *c)
82+
{
83+
if (out->nr_tabstops < 1)
84+
printbuf_tabstop_push(out, 48);
85+
if (out->nr_tabstops < 2)
86+
printbuf_tabstop_push(out, 8);
87+
if (out->nr_tabstops < 3)
88+
printbuf_tabstop_push(out, 16);
89+
90+
guard(mutex)(&c->fsck_error_counts_lock);
91+
92+
bch_sb_errors_cpu *e = &c->fsck_error_counts;
93+
darray_for_each(*e, i) {
94+
bch2_sb_error_id_to_text(out, i->id);
95+
prt_tab(out);
96+
prt_u64(out, i->nr);
97+
prt_tab(out);
98+
bch2_prt_datetime(out, i->last_error_time);
99+
prt_newline(out);
100+
}
101+
}
102+
81103
void bch2_sb_error_count(struct bch_fs *c, enum bch_sb_error_id err)
82104
{
83105
bch_sb_errors_cpu *e = &c->fsck_error_counts;

fs/bcachefs/sb-errors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
extern const char * const bch2_sb_error_strs[];
88

99
void bch2_sb_error_id_to_text(struct printbuf *, enum bch_sb_error_id);
10+
void bch2_fs_errors_to_text(struct printbuf *, struct bch_fs *);
1011

1112
extern const struct bch_sb_field_ops bch_sb_field_ops_errors;
1213

fs/bcachefs/sysfs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "rebalance.h"
3838
#include "recovery_passes.h"
3939
#include "replicas.h"
40+
#include "sb-errors.h"
4041
#include "super-io.h"
4142
#include "tests.h"
4243

@@ -172,6 +173,7 @@ read_attribute(btree_write_stats);
172173

173174
read_attribute(btree_cache_size);
174175
read_attribute(compression_stats);
176+
read_attribute(errors);
175177
read_attribute(journal_debug);
176178
read_attribute(btree_cache);
177179
read_attribute(btree_key_cache);
@@ -353,6 +355,9 @@ SHOW(bch2_fs)
353355
if (attr == &sysfs_compression_stats)
354356
bch2_compression_stats_to_text(out, c);
355357

358+
if (attr == &sysfs_errors)
359+
bch2_fs_errors_to_text(out, c);
360+
356361
if (attr == &sysfs_new_stripes)
357362
bch2_new_stripes_to_text(out, c);
358363

@@ -483,6 +488,7 @@ struct attribute *bch2_fs_files[] = {
483488
&sysfs_recovery_status,
484489

485490
&sysfs_compression_stats,
491+
&sysfs_errors,
486492

487493
#ifdef CONFIG_BCACHEFS_TESTS
488494
&sysfs_perf_test,

0 commit comments

Comments
 (0)