Skip to content

Commit f93bb76

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_fs_accounting_to_text()
Helper to show raw accounting in sysfs, mainly for debugging. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 91f4478 commit f93bb76

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

fs/bcachefs/disk_accounting.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,32 @@ int bch2_fs_replicas_usage_read(struct bch_fs *c, darray_char *usage)
308308
return ret;
309309
}
310310

311+
void bch2_fs_accounting_to_text(struct printbuf *out, struct bch_fs *c)
312+
{
313+
struct bch_accounting_mem *acc = &c->accounting[0];
314+
315+
percpu_down_read(&c->mark_lock);
316+
out->atomic++;
317+
318+
eytzinger0_for_each(i, acc->k.nr) {
319+
struct disk_accounting_pos acc_k;
320+
bpos_to_disk_accounting_pos(&acc_k, acc->k.data[i].pos);
321+
322+
bch2_accounting_key_to_text(out, &acc_k);
323+
324+
u64 v[BCH_ACCOUNTING_MAX_COUNTERS];
325+
bch2_accounting_mem_read_counters(c, i, v, ARRAY_SIZE(v), false);
326+
327+
prt_str(out, ":");
328+
for (unsigned j = 0; j < acc->k.data[i].nr_counters; j++)
329+
prt_printf(out, " %llu", v[j]);
330+
prt_newline(out);
331+
}
332+
333+
--out->atomic;
334+
percpu_up_read(&c->mark_lock);
335+
}
336+
311337
/* Ensures all counters in @src exist in @dst: */
312338
static int copy_counters(struct bch_accounting_mem *dst,
313339
struct bch_accounting_mem *src)

fs/bcachefs/disk_accounting.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ static inline void bch2_accounting_mem_read(struct bch_fs *c, struct bpos p,
193193
}
194194

195195
int bch2_fs_replicas_usage_read(struct bch_fs *, darray_char *);
196+
void bch2_fs_accounting_to_text(struct printbuf *, struct bch_fs *);
196197

197198
int bch2_accounting_gc_done(struct bch_fs *);
198199

fs/bcachefs/sysfs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ read_attribute(disk_groups);
203203

204204
read_attribute(has_data);
205205
read_attribute(alloc_debug);
206+
read_attribute(accounting);
206207

207208
#define x(t, n, ...) read_attribute(t);
208209
BCH_PERSISTENT_COUNTERS()
@@ -388,6 +389,9 @@ SHOW(bch2_fs)
388389
if (attr == &sysfs_alloc_debug)
389390
bch2_fs_alloc_debug_to_text(out, c);
390391

392+
if (attr == &sysfs_accounting)
393+
bch2_fs_accounting_to_text(out, c);
394+
391395
return 0;
392396
}
393397

@@ -601,6 +605,7 @@ struct attribute *bch2_fs_internal_files[] = {
601605

602606
&sysfs_disk_groups,
603607
&sysfs_alloc_debug,
608+
&sysfs_accounting,
604609
NULL
605610
};
606611

0 commit comments

Comments
 (0)