X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libbcachefs%2Fsysfs.c;h=d78ffcc0e8a457cfef0790908938bda9bce765b0;hb=2aed686c235a7d08adf601f147f823eb62e697a1;hp=b56db15daf118bfcd7ce8e3d3437051ff09000bb;hpb=a4eb187a6f0af8041ae2128e6ee82ab7a43cb87c;p=bcachefs-tools-debian diff --git a/libbcachefs/sysfs.c b/libbcachefs/sysfs.c index b56db15..d78ffcc 100644 --- a/libbcachefs/sysfs.c +++ b/libbcachefs/sysfs.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 /* * bcache sysfs interfaces * @@ -17,6 +18,7 @@ #include "btree_update_interior.h" #include "btree_gc.h" #include "buckets.h" +#include "clock.h" #include "disk_groups.h" #include "ec.h" #include "inode.h" @@ -197,6 +199,9 @@ rw_attribute(pd_controllers_update_seconds); read_attribute(meta_replicas_have); read_attribute(data_replicas_have); +read_attribute(io_timers_read); +read_attribute(io_timers_write); + #ifdef CONFIG_BCACHEFS_TESTS write_attribute(perf_test); #endif /* CONFIG_BCACHEFS_TESTS */ @@ -235,44 +240,13 @@ static ssize_t show_fs_alloc_debug(struct bch_fs *c, char *buf) { struct printbuf out = _PBUF(buf, PAGE_SIZE); struct bch_fs_usage *fs_usage = bch2_fs_usage_read(c); - unsigned i; if (!fs_usage) return -ENOMEM; - pr_buf(&out, "capacity:\t\t\t%llu\n", c->capacity); - - pr_buf(&out, "hidden:\t\t\t\t%llu\n", - fs_usage->hidden); - pr_buf(&out, "data:\t\t\t\t%llu\n", - fs_usage->data); - pr_buf(&out, "cached:\t\t\t\t%llu\n", - fs_usage->cached); - pr_buf(&out, "reserved:\t\t\t%llu\n", - fs_usage->reserved); - pr_buf(&out, "nr_inodes:\t\t\t%llu\n", - fs_usage->nr_inodes); - pr_buf(&out, "online reserved:\t\t%llu\n", - fs_usage->online_reserved); - - for (i = 0; - i < ARRAY_SIZE(fs_usage->persistent_reserved); - i++) { - pr_buf(&out, "%u replicas:\n", i + 1); - pr_buf(&out, "\treserved:\t\t%llu\n", - fs_usage->persistent_reserved[i]); - } - - for (i = 0; i < c->replicas.nr; i++) { - struct bch_replicas_entry *e = - cpu_replicas_entry(&c->replicas, i); - - pr_buf(&out, "\t"); - bch2_replicas_entry_to_text(&out, e); - pr_buf(&out, ":\t%llu\n", fs_usage->replicas[i]); - } + bch2_fs_usage_to_text(&out, c, fs_usage); - percpu_up_read_preempt_enable(&c->mark_lock); + percpu_up_read(&c->mark_lock); kfree(fs_usage); @@ -281,24 +255,28 @@ static ssize_t show_fs_alloc_debug(struct bch_fs *c, char *buf) static ssize_t bch2_compression_stats(struct bch_fs *c, char *buf) { - struct btree_iter iter; + struct btree_trans trans; + struct btree_iter *iter; struct bkey_s_c k; u64 nr_uncompressed_extents = 0, uncompressed_sectors = 0, nr_compressed_extents = 0, compressed_sectors_compressed = 0, compressed_sectors_uncompressed = 0; + int ret; - if (!bch2_fs_running(c)) + if (!test_bit(BCH_FS_STARTED, &c->flags)) return -EPERM; - for_each_btree_key(&iter, c, BTREE_ID_EXTENTS, POS_MIN, 0, k) + bch2_trans_init(&trans, c, 0, 0); + + for_each_btree_key(&trans, iter, BTREE_ID_EXTENTS, POS_MIN, 0, k, ret) if (k.k->type == KEY_TYPE_extent) { struct bkey_s_c_extent e = bkey_s_c_to_extent(k); const union bch_extent_entry *entry; struct extent_ptr_decoded p; extent_for_each_ptr_decode(e, p, entry) { - if (p.crc.compression_type == BCH_COMPRESSION_NONE) { + if (!crc_is_compressed(p.crc)) { nr_uncompressed_extents++; uncompressed_sectors += e.k->size; } else { @@ -313,7 +291,10 @@ static ssize_t bch2_compression_stats(struct bch_fs *c, char *buf) break; } } - bch2_btree_iter_unlock(&iter); + + ret = bch2_trans_exit(&trans) ?: ret; + if (ret) + return ret; return scnprintf(buf, PAGE_SIZE, "uncompressed data:\n" @@ -427,6 +408,11 @@ SHOW(bch2_fs) if (attr == &sysfs_new_stripes) return bch2_new_stripes(c, buf); + if (attr == &sysfs_io_timers_read) + return bch2_io_timers_show(&c->io_clock[READ], buf); + if (attr == &sysfs_io_timers_write) + return bch2_io_timers_show(&c->io_clock[WRITE], buf); + #define BCH_DEBUG_PARAM(name, description) sysfs_print(name, c->name); BCH_DEBUG_PARAMS() #undef BCH_DEBUG_PARAM @@ -481,7 +467,7 @@ STORE(__bch2_fs) BCH_DEBUG_PARAMS() #undef BCH_DEBUG_PARAM - if (!bch2_fs_running(c)) + if (!test_bit(BCH_FS_STARTED, &c->flags)) return -EPERM; /* Debugging: */ @@ -493,12 +479,12 @@ STORE(__bch2_fs) bch2_coalesce(c); if (attr == &sysfs_trigger_gc) - bch2_gc(c, NULL, false); + bch2_gc(c, NULL, false, false); if (attr == &sysfs_trigger_alloc_write) { bool wrote; - bch2_alloc_write(c, false, &wrote); + bch2_alloc_write(c, 0, &wrote); } if (attr == &sysfs_prune_cache) { @@ -604,6 +590,9 @@ struct attribute *bch2_fs_internal_files[] = { &sysfs_new_stripes, + &sysfs_io_timers_read, + &sysfs_io_timers_write, + &sysfs_internal_uuid, #define BCH_DEBUG_PARAM(name, description) &sysfs_##name, @@ -747,10 +736,10 @@ static unsigned bucket_oldest_gen_fn(struct bch_fs *c, struct bch_dev *ca, static int unsigned_cmp(const void *_l, const void *_r) { - unsigned l = *((unsigned *) _l); - unsigned r = *((unsigned *) _r); + const unsigned *l = _l; + const unsigned *r = _r; - return (l > r) - (l < r); + return cmp_int(*l, *r); } static ssize_t show_quantiles(struct bch_fs *c, struct bch_dev *ca, @@ -798,7 +787,7 @@ static ssize_t show_reserve_stats(struct bch_dev *ca, char *buf) struct printbuf out = _PBUF(buf, PAGE_SIZE); enum alloc_reserve i; - spin_lock(&ca->freelist_lock); + spin_lock(&ca->fs->freelist_lock); pr_buf(&out, "free_inc:\t%zu\t%zu\n", fifo_used(&ca->free_inc), @@ -809,7 +798,7 @@ static ssize_t show_reserve_stats(struct bch_dev *ca, char *buf) fifo_used(&ca->free[i]), ca->free[i].size); - spin_unlock(&ca->freelist_lock); + spin_unlock(&ca->fs->freelist_lock); return out.pos - buf; } @@ -927,8 +916,6 @@ SHOW(bch2_dev) bch2_disk_path_to_text(&out, &c->disk_sb, ca->mi.group - 1); mutex_unlock(&c->sb_lock); - } else { - pr_buf(&out, "none"); } pr_buf(&out, "\n");