summaryrefslogtreecommitdiff
path: root/fs/bcachefs/sysfs.c
diff options
context:
space:
mode:
authorDaniel Hill <daniel@gluo.nz>2022-03-15 21:36:33 +1300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:32 -0400
commit104c69745fdf7e5f8aa022f60bc9d568987bd8b8 (patch)
tree09fc07cf3d1bbe991c7a586fbac4ee24c31d1b98 /fs/bcachefs/sysfs.c
parent1f93726e6347938343190913cb959623e67ecf78 (diff)
bcachefs: Add persistent counters
This adds a new superblock field for persisting counters and adds a sysfs interface in counters/ exposing these counters. The superblock field is ignored by older versions letting us avoid an on disk version bump. Each sysfs file outputs a counter that tracks since filesystem creation and a counter for the current mount session. Signed-off-by: Daniel Hill <daniel@gluo.nz> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/sysfs.c')
-rw-r--r--fs/bcachefs/sysfs.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c
index 24180d98fe81..6b5b20d18012 100644
--- a/fs/bcachefs/sysfs.c
+++ b/fs/bcachefs/sysfs.c
@@ -40,7 +40,7 @@
#include "util.h"
#define SYSFS_OPS(type) \
-struct sysfs_ops type ## _sysfs_ops = { \
+const struct sysfs_ops type ## _sysfs_ops = { \
.show = type ## _show, \
.store = type ## _store \
}
@@ -195,6 +195,10 @@ read_attribute(extent_migrate_done);
read_attribute(extent_migrate_raced);
read_attribute(bucket_alloc_fail);
+#define x(t, n, ...) read_attribute(t);
+BCH_PERSISTENT_COUNTERS()
+#undef x
+
rw_attribute(discard);
rw_attribute(label);
@@ -551,6 +555,47 @@ struct attribute *bch2_fs_files[] = {
NULL
};
+/* counters dir */
+
+SHOW(bch2_fs_counters)
+{
+ struct bch_fs *c = container_of(kobj, struct bch_fs, counters_kobj);
+ u64 counter = 0;
+ u64 counter_since_mount = 0;
+
+ out->tabstops[0] = 32;
+ #define x(t, ...) \
+ if (attr == &sysfs_##t) { \
+ counter = percpu_u64_get(&c->counters[BCH_COUNTER_##t]);\
+ counter_since_mount = counter - c->counters_on_mount[BCH_COUNTER_##t];\
+ pr_buf(out, "since mount:"); \
+ pr_tab(out); \
+ bch2_hprint(out, counter_since_mount << 9); \
+ pr_newline(out); \
+ \
+ pr_buf(out, "since filesystem creation:"); \
+ pr_tab(out); \
+ bch2_hprint(out, counter << 9); \
+ pr_newline(out); \
+ }
+ BCH_PERSISTENT_COUNTERS()
+ #undef x
+ return 0;
+}
+
+STORE(bch2_fs_counters) {
+ return 0;
+}
+
+SYSFS_OPS(bch2_fs_counters);
+
+struct attribute *bch2_fs_counters_files[] = {
+#define x(t, ...) \
+ &sysfs_##t,
+ BCH_PERSISTENT_COUNTERS()
+#undef x
+ NULL
+};
/* internal dir - just a wrapper */
SHOW(bch2_fs_internal)