2 * bcache sysfs interfaces
4 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
5 * Copyright 2012 Google, Inc.
8 #ifndef NO_BCACHEFS_SYSFS
11 #include "alloc_background.h"
14 #include "btree_cache.h"
16 #include "btree_iter.h"
17 #include "btree_update.h"
18 #include "btree_update_interior.h"
21 #include "disk_groups.h"
27 #include "rebalance.h"
32 #include <linux/blkdev.h>
33 #include <linux/sort.h>
34 #include <linux/sched/clock.h>
38 #define SYSFS_OPS(type) \
39 struct sysfs_ops type ## _sysfs_ops = { \
40 .show = type ## _show, \
41 .store = type ## _store \
45 static ssize_t fn ## _show(struct kobject *kobj, struct attribute *attr,\
49 static ssize_t fn ## _store(struct kobject *kobj, struct attribute *attr,\
50 const char *buf, size_t size) \
52 #define __sysfs_attribute(_name, _mode) \
53 static struct attribute sysfs_##_name = \
54 { .name = #_name, .mode = _mode }
56 #define write_attribute(n) __sysfs_attribute(n, S_IWUSR)
57 #define read_attribute(n) __sysfs_attribute(n, S_IRUGO)
58 #define rw_attribute(n) __sysfs_attribute(n, S_IRUGO|S_IWUSR)
60 #define sysfs_printf(file, fmt, ...) \
62 if (attr == &sysfs_ ## file) \
63 return scnprintf(buf, PAGE_SIZE, fmt "\n", __VA_ARGS__);\
66 #define sysfs_print(file, var) \
68 if (attr == &sysfs_ ## file) \
69 return snprint(buf, PAGE_SIZE, var); \
72 #define sysfs_hprint(file, val) \
74 if (attr == &sysfs_ ## file) { \
75 ssize_t ret = bch2_hprint(buf, val); \
81 #define var_printf(_var, fmt) sysfs_printf(_var, fmt, var(_var))
82 #define var_print(_var) sysfs_print(_var, var(_var))
83 #define var_hprint(_var) sysfs_hprint(_var, var(_var))
85 #define sysfs_strtoul(file, var) \
87 if (attr == &sysfs_ ## file) \
88 return strtoul_safe(buf, var) ?: (ssize_t) size; \
91 #define sysfs_strtoul_clamp(file, var, min, max) \
93 if (attr == &sysfs_ ## file) \
94 return strtoul_safe_clamp(buf, var, min, max) \
98 #define strtoul_or_return(cp) \
101 int _r = kstrtoul(cp, 10, &_v); \
107 #define strtoul_restrict_or_return(cp, min, max) \
109 unsigned long __v = 0; \
110 int _r = strtoul_safe_restrict(cp, __v, min, max); \
116 #define strtoi_h_or_return(cp) \
119 int _r = strtoi_h(cp, &_v); \
125 #define sysfs_hatoi(file, var) \
127 if (attr == &sysfs_ ## file) \
128 return strtoi_h(buf, &var) ?: (ssize_t) size; \
131 write_attribute(trigger_journal_flush);
132 write_attribute(trigger_btree_coalesce);
133 write_attribute(trigger_gc);
134 write_attribute(prune_cache);
135 rw_attribute(btree_gc_periodic);
137 read_attribute(uuid);
138 read_attribute(minor);
139 read_attribute(bucket_size);
140 read_attribute(block_size);
141 read_attribute(btree_node_size);
142 read_attribute(first_bucket);
143 read_attribute(nbuckets);
144 read_attribute(durability);
145 read_attribute(iodone);
147 read_attribute(io_latency_read);
148 read_attribute(io_latency_write);
149 read_attribute(io_latency_stats_read);
150 read_attribute(io_latency_stats_write);
151 read_attribute(congested);
153 read_attribute(bucket_quantiles_last_read);
154 read_attribute(bucket_quantiles_last_write);
155 read_attribute(bucket_quantiles_fragmentation);
156 read_attribute(bucket_quantiles_oldest_gen);
158 read_attribute(reserve_stats);
159 read_attribute(btree_cache_size);
160 read_attribute(compression_stats);
161 read_attribute(journal_debug);
162 read_attribute(journal_pins);
163 read_attribute(btree_updates);
164 read_attribute(dirty_btree_nodes);
166 read_attribute(internal_uuid);
168 read_attribute(has_data);
169 read_attribute(alloc_debug);
170 write_attribute(wake_allocator);
172 read_attribute(read_realloc_races);
173 read_attribute(extent_migrate_done);
174 read_attribute(extent_migrate_raced);
176 rw_attribute(journal_write_delay_ms);
177 rw_attribute(journal_reclaim_delay_ms);
179 rw_attribute(discard);
180 rw_attribute(cache_replacement_policy);
183 rw_attribute(copy_gc_enabled);
184 sysfs_pd_controller_attribute(copy_gc);
186 rw_attribute(rebalance_enabled);
187 sysfs_pd_controller_attribute(rebalance);
188 read_attribute(rebalance_work);
189 rw_attribute(promote_whole_extents);
191 rw_attribute(pd_controllers_update_seconds);
193 read_attribute(meta_replicas_have);
194 read_attribute(data_replicas_have);
196 #ifdef CONFIG_BCACHEFS_TESTS
197 write_attribute(perf_test);
198 #endif /* CONFIG_BCACHEFS_TESTS */
200 #define BCH_DEBUG_PARAM(name, description) \
204 #undef BCH_DEBUG_PARAM
207 static struct attribute sysfs_time_stat_##_name = \
208 { .name = #_name, .mode = S_IRUGO };
212 static struct attribute sysfs_state_rw = {
217 static size_t bch2_btree_cache_size(struct bch_fs *c)
222 mutex_lock(&c->btree_cache.lock);
223 list_for_each_entry(b, &c->btree_cache.live, list)
224 ret += btree_bytes(c);
226 mutex_unlock(&c->btree_cache.lock);
230 static ssize_t show_fs_alloc_debug(struct bch_fs *c, char *buf)
232 char *out = buf, *end = buf + PAGE_SIZE;
233 struct bch_fs_usage stats = bch2_fs_usage_read(c);
234 unsigned replicas, type;
236 out += scnprintf(out, end - out,
237 "capacity:\t\t%llu\n",
240 for (replicas = 0; replicas < ARRAY_SIZE(stats.replicas); replicas++) {
241 out += scnprintf(out, end - out,
245 for (type = BCH_DATA_SB; type < BCH_DATA_NR; type++)
246 out += scnprintf(out, end - out,
248 bch2_data_types[type],
249 stats.replicas[replicas].data[type]);
250 out += scnprintf(out, end - out,
251 "\treserved:\t%llu\n",
252 stats.replicas[replicas].persistent_reserved);
255 out += scnprintf(out, end - out, "bucket usage\n");
257 for (type = BCH_DATA_SB; type < BCH_DATA_NR; type++)
258 out += scnprintf(out, end - out,
260 bch2_data_types[type],
261 stats.buckets[type]);
263 out += scnprintf(out, end - out,
264 "online reserved:\t%llu\n",
265 stats.online_reserved);
270 static ssize_t bch2_compression_stats(struct bch_fs *c, char *buf)
272 struct btree_iter iter;
274 u64 nr_uncompressed_extents = 0, uncompressed_sectors = 0,
275 nr_compressed_extents = 0,
276 compressed_sectors_compressed = 0,
277 compressed_sectors_uncompressed = 0;
279 if (!bch2_fs_running(c))
282 for_each_btree_key(&iter, c, BTREE_ID_EXTENTS, POS_MIN, 0, k)
283 if (k.k->type == BCH_EXTENT) {
284 struct bkey_s_c_extent e = bkey_s_c_to_extent(k);
285 const struct bch_extent_ptr *ptr;
286 struct bch_extent_crc_unpacked crc;
288 extent_for_each_ptr_crc(e, ptr, crc) {
289 if (crc.compression_type == BCH_COMPRESSION_NONE) {
290 nr_uncompressed_extents++;
291 uncompressed_sectors += e.k->size;
293 nr_compressed_extents++;
294 compressed_sectors_compressed +=
296 compressed_sectors_uncompressed +=
297 crc.uncompressed_size;
300 /* only looking at the first ptr */
304 bch2_btree_iter_unlock(&iter);
306 return scnprintf(buf, PAGE_SIZE,
307 "uncompressed data:\n"
308 " nr extents: %llu\n"
309 " size (bytes): %llu\n"
311 " nr extents: %llu\n"
312 " compressed size (bytes): %llu\n"
313 " uncompressed size (bytes): %llu\n",
314 nr_uncompressed_extents,
315 uncompressed_sectors << 9,
316 nr_compressed_extents,
317 compressed_sectors_compressed << 9,
318 compressed_sectors_uncompressed << 9);
323 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
325 sysfs_print(minor, c->minor);
326 sysfs_printf(internal_uuid, "%pU", c->sb.uuid.b);
328 sysfs_print(journal_write_delay_ms, c->journal.write_delay_ms);
329 sysfs_print(journal_reclaim_delay_ms, c->journal.reclaim_delay_ms);
331 sysfs_print(block_size, block_bytes(c));
332 sysfs_print(btree_node_size, btree_bytes(c));
333 sysfs_hprint(btree_cache_size, bch2_btree_cache_size(c));
335 sysfs_print(read_realloc_races,
336 atomic_long_read(&c->read_realloc_races));
337 sysfs_print(extent_migrate_done,
338 atomic_long_read(&c->extent_migrate_done));
339 sysfs_print(extent_migrate_raced,
340 atomic_long_read(&c->extent_migrate_raced));
342 sysfs_printf(btree_gc_periodic, "%u", (int) c->btree_gc_periodic);
344 sysfs_printf(copy_gc_enabled, "%i", c->copy_gc_enabled);
346 sysfs_print(pd_controllers_update_seconds,
347 c->pd_controllers_update_seconds);
349 sysfs_printf(rebalance_enabled, "%i", c->rebalance.enabled);
350 sysfs_pd_controller_show(rebalance, &c->rebalance.pd); /* XXX */
352 if (attr == &sysfs_rebalance_work)
353 return bch2_rebalance_work_show(c, buf);
355 sysfs_print(promote_whole_extents, c->promote_whole_extents);
357 sysfs_printf(meta_replicas_have, "%u", bch2_replicas_online(c, true));
358 sysfs_printf(data_replicas_have, "%u", bch2_replicas_online(c, false));
362 if (attr == &sysfs_alloc_debug)
363 return show_fs_alloc_debug(c, buf);
365 if (attr == &sysfs_journal_debug)
366 return bch2_journal_print_debug(&c->journal, buf);
368 if (attr == &sysfs_journal_pins)
369 return bch2_journal_print_pins(&c->journal, buf);
371 if (attr == &sysfs_btree_updates)
372 return bch2_btree_updates_print(c, buf);
374 if (attr == &sysfs_dirty_btree_nodes)
375 return bch2_dirty_btree_nodes_print(c, buf);
377 if (attr == &sysfs_compression_stats)
378 return bch2_compression_stats(c, buf);
380 #define BCH_DEBUG_PARAM(name, description) sysfs_print(name, c->name);
382 #undef BCH_DEBUG_PARAM
389 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
391 sysfs_strtoul(journal_write_delay_ms, c->journal.write_delay_ms);
392 sysfs_strtoul(journal_reclaim_delay_ms, c->journal.reclaim_delay_ms);
394 if (attr == &sysfs_btree_gc_periodic) {
395 ssize_t ret = strtoul_safe(buf, c->btree_gc_periodic)
398 wake_up_process(c->gc_thread);
402 if (attr == &sysfs_copy_gc_enabled) {
405 ssize_t ret = strtoul_safe(buf, c->copy_gc_enabled)
408 for_each_member_device(ca, c, i)
409 if (ca->copygc_thread)
410 wake_up_process(ca->copygc_thread);
414 if (attr == &sysfs_rebalance_enabled) {
415 ssize_t ret = strtoul_safe(buf, c->rebalance.enabled)
422 sysfs_strtoul(pd_controllers_update_seconds,
423 c->pd_controllers_update_seconds);
424 sysfs_pd_controller_store(rebalance, &c->rebalance.pd);
426 sysfs_strtoul(promote_whole_extents, c->promote_whole_extents);
430 #define BCH_DEBUG_PARAM(name, description) sysfs_strtoul(name, c->name);
432 #undef BCH_DEBUG_PARAM
434 if (!bch2_fs_running(c))
439 if (attr == &sysfs_trigger_journal_flush)
440 bch2_journal_meta_async(&c->journal, NULL);
442 if (attr == &sysfs_trigger_btree_coalesce)
445 if (attr == &sysfs_trigger_gc)
448 if (attr == &sysfs_prune_cache) {
449 struct shrink_control sc;
451 sc.gfp_mask = GFP_KERNEL;
452 sc.nr_to_scan = strtoul_or_return(buf);
453 c->btree_cache.shrink.scan_objects(&c->btree_cache.shrink, &sc);
455 #ifdef CONFIG_BCACHEFS_TESTS
456 if (attr == &sysfs_perf_test) {
457 char *tmp = kstrdup(buf, GFP_KERNEL), *p = tmp;
458 char *test = strsep(&p, " \t\n");
459 char *nr_str = strsep(&p, " \t\n");
460 char *threads_str = strsep(&p, " \t\n");
466 !(ret = kstrtouint(threads_str, 10, &threads)) &&
467 !(ret = bch2_strtoull_h(nr_str, &nr)))
468 bch2_btree_perf_test(c, test, nr, threads);
479 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
481 mutex_lock(&c->state_lock);
482 size = __bch2_fs_store(kobj, attr, buf, size);
483 mutex_unlock(&c->state_lock);
489 struct attribute *bch2_fs_files[] = {
492 &sysfs_btree_node_size,
493 &sysfs_btree_cache_size,
495 &sysfs_meta_replicas_have,
496 &sysfs_data_replicas_have,
498 &sysfs_journal_write_delay_ms,
499 &sysfs_journal_reclaim_delay_ms,
501 &sysfs_promote_whole_extents,
503 &sysfs_compression_stats,
505 #ifdef CONFIG_BCACHEFS_TESTS
511 /* internal dir - just a wrapper */
513 SHOW(bch2_fs_internal)
515 struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
516 return bch2_fs_show(&c->kobj, attr, buf);
519 STORE(bch2_fs_internal)
521 struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
522 return bch2_fs_store(&c->kobj, attr, buf, size);
524 SYSFS_OPS(bch2_fs_internal);
526 struct attribute *bch2_fs_internal_files[] = {
528 &sysfs_journal_debug,
530 &sysfs_btree_updates,
531 &sysfs_dirty_btree_nodes,
533 &sysfs_read_realloc_races,
534 &sysfs_extent_migrate_done,
535 &sysfs_extent_migrate_raced,
537 &sysfs_trigger_journal_flush,
538 &sysfs_trigger_btree_coalesce,
542 &sysfs_copy_gc_enabled,
544 &sysfs_rebalance_enabled,
545 &sysfs_rebalance_work,
546 sysfs_pd_controller_files(rebalance),
548 &sysfs_internal_uuid,
550 #define BCH_DEBUG_PARAM(name, description) &sysfs_##name,
552 #undef BCH_DEBUG_PARAM
559 SHOW(bch2_fs_opts_dir)
561 char *out = buf, *end = buf + PAGE_SIZE;
562 struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
563 const struct bch_option *opt = container_of(attr, struct bch_option, attr);
564 int id = opt - bch2_opt_table;
565 u64 v = bch2_opt_get_by_id(&c->opts, id);
567 out += bch2_opt_to_text(c, out, end - out, opt, v, OPT_SHOW_FULL_LIST);
568 out += scnprintf(out, end - out, "\n");
573 STORE(bch2_fs_opts_dir)
575 struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
576 const struct bch_option *opt = container_of(attr, struct bch_option, attr);
577 int ret, id = opt - bch2_opt_table;
581 tmp = kstrdup(buf, GFP_KERNEL);
585 ret = bch2_opt_parse(c, opt, strim(tmp), &v);
591 if (id == Opt_compression ||
592 id == Opt_background_compression) {
593 int ret = bch2_check_set_has_compressed_data(c, v);
595 mutex_unlock(&c->sb_lock);
600 if (opt->set_sb != SET_NO_SB_OPT) {
601 mutex_lock(&c->sb_lock);
602 opt->set_sb(c->disk_sb.sb, v);
604 mutex_unlock(&c->sb_lock);
607 bch2_opt_set_by_id(&c->opts, id, v);
609 if ((id == Opt_background_target ||
610 id == Opt_background_compression) && v) {
611 bch2_rebalance_add_work(c, S64_MAX);
617 SYSFS_OPS(bch2_fs_opts_dir);
619 struct attribute *bch2_fs_opts_dir_files[] = { NULL };
621 int bch2_opts_create_sysfs_files(struct kobject *kobj)
623 const struct bch_option *i;
626 for (i = bch2_opt_table;
627 i < bch2_opt_table + bch2_opts_nr;
629 if (i->mode == OPT_INTERNAL)
632 ret = sysfs_create_file(kobj, &i->attr);
642 SHOW(bch2_fs_time_stats)
644 struct bch_fs *c = container_of(kobj, struct bch_fs, time_stats);
647 if (attr == &sysfs_time_stat_##name) \
648 return bch2_time_stats_print(&c->times[BCH_TIME_##name],\
656 STORE(bch2_fs_time_stats)
660 SYSFS_OPS(bch2_fs_time_stats);
662 struct attribute *bch2_fs_time_stats_files[] = {
664 &sysfs_time_stat_##name,
670 typedef unsigned (bucket_map_fn)(struct bch_fs *, struct bch_dev *,
673 static unsigned bucket_last_io_fn(struct bch_fs *c, struct bch_dev *ca,
674 size_t b, void *private)
676 int rw = (private ? 1 : 0);
678 return bucket_last_io(c, bucket(ca, b), rw);
681 static unsigned bucket_sectors_used_fn(struct bch_fs *c, struct bch_dev *ca,
682 size_t b, void *private)
684 struct bucket *g = bucket(ca, b);
685 return bucket_sectors_used(g->mark);
688 static unsigned bucket_oldest_gen_fn(struct bch_fs *c, struct bch_dev *ca,
689 size_t b, void *private)
691 return bucket_gc_gen(ca, b);
694 static int unsigned_cmp(const void *_l, const void *_r)
696 unsigned l = *((unsigned *) _l);
697 unsigned r = *((unsigned *) _r);
699 return (l > r) - (l < r);
702 static ssize_t show_quantiles(struct bch_fs *c, struct bch_dev *ca,
703 char *buf, bucket_map_fn *fn, void *private)
706 /* Compute 31 quantiles */
710 down_read(&ca->bucket_lock);
713 p = vzalloc(n * sizeof(unsigned));
715 up_read(&ca->bucket_lock);
719 for (i = ca->mi.first_bucket; i < n; i++)
720 p[i] = fn(c, ca, i, private);
722 sort(p, n, sizeof(unsigned), unsigned_cmp, NULL);
723 up_read(&ca->bucket_lock);
729 for (i = 0; i < ARRAY_SIZE(q); i++)
730 q[i] = p[n * (i + 1) / (ARRAY_SIZE(q) + 1)];
734 for (i = 0; i < ARRAY_SIZE(q); i++)
735 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
742 static ssize_t show_reserve_stats(struct bch_dev *ca, char *buf)
744 enum alloc_reserve i;
747 spin_lock(&ca->freelist_lock);
749 ret = scnprintf(buf, PAGE_SIZE,
750 "free_inc:\t%zu\t%zu\n",
751 fifo_used(&ca->free_inc),
754 for (i = 0; i < RESERVE_NR; i++)
755 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
756 "free[%u]:\t%zu\t%zu\n", i,
757 fifo_used(&ca->free[i]),
760 spin_unlock(&ca->freelist_lock);
765 static ssize_t show_dev_alloc_debug(struct bch_dev *ca, char *buf)
767 struct bch_fs *c = ca->fs;
768 struct bch_dev_usage stats = bch2_dev_usage_read(c, ca);
770 return scnprintf(buf, PAGE_SIZE,
771 "free_inc: %zu/%zu\n"
772 "free[RESERVE_BTREE]: %zu/%zu\n"
773 "free[RESERVE_MOVINGGC]: %zu/%zu\n"
774 "free[RESERVE_NONE]: %zu/%zu\n"
790 " fragmented: %llu\n"
791 " copygc threshold: %llu\n"
792 "freelist_wait: %s\n"
793 "open buckets: %u/%u (reserved %u)\n"
794 "open_buckets_wait: %s\n",
795 fifo_used(&ca->free_inc), ca->free_inc.size,
796 fifo_used(&ca->free[RESERVE_BTREE]), ca->free[RESERVE_BTREE].size,
797 fifo_used(&ca->free[RESERVE_MOVINGGC]), ca->free[RESERVE_MOVINGGC].size,
798 fifo_used(&ca->free[RESERVE_NONE]), ca->free[RESERVE_NONE].size,
799 ca->mi.nbuckets - ca->mi.first_bucket,
801 stats.buckets[BCH_DATA_SB],
802 stats.buckets[BCH_DATA_JOURNAL],
803 stats.buckets[BCH_DATA_BTREE],
804 stats.buckets[BCH_DATA_USER],
805 stats.buckets[BCH_DATA_CACHED],
806 ca->mi.nbuckets - ca->mi.first_bucket - stats.buckets_unavailable,
807 stats.sectors[BCH_DATA_SB],
808 stats.sectors[BCH_DATA_JOURNAL],
809 stats.sectors[BCH_DATA_BTREE],
810 stats.sectors[BCH_DATA_USER],
811 stats.sectors[BCH_DATA_CACHED],
812 stats.sectors_fragmented,
813 ca->copygc_threshold,
814 c->freelist_wait.list.first ? "waiting" : "empty",
815 c->open_buckets_nr_free, OPEN_BUCKETS_COUNT, BTREE_NODE_RESERVE,
816 c->open_buckets_wait.list.first ? "waiting" : "empty");
819 static const char * const bch2_rw[] = {
825 static ssize_t show_dev_iodone(struct bch_dev *ca, char *buf)
827 char *out = buf, *end = buf + PAGE_SIZE;
830 for (rw = 0; rw < 2; rw++) {
831 out += scnprintf(out, end - out, "%s:\n", bch2_rw[rw]);
833 for (i = 1; i < BCH_DATA_NR; i++) {
836 for_each_possible_cpu(cpu)
837 n += per_cpu_ptr(ca->io_done, cpu)->sectors[rw][i];
839 out += scnprintf(out, end - out, "%-12s:%12llu\n",
840 bch2_data_types[i], n << 9);
849 struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
850 struct bch_fs *c = ca->fs;
851 char *out = buf, *end = buf + PAGE_SIZE;
853 sysfs_printf(uuid, "%pU\n", ca->uuid.b);
855 sysfs_print(bucket_size, bucket_bytes(ca));
856 sysfs_print(block_size, block_bytes(c));
857 sysfs_print(first_bucket, ca->mi.first_bucket);
858 sysfs_print(nbuckets, ca->mi.nbuckets);
859 sysfs_print(durability, ca->mi.durability);
860 sysfs_print(discard, ca->mi.discard);
862 if (attr == &sysfs_label) {
864 mutex_lock(&c->sb_lock);
865 out += bch2_disk_path_print(&c->disk_sb, out, end - out,
867 mutex_unlock(&c->sb_lock);
869 out += scnprintf(out, end - out, "none");
872 out += scnprintf(out, end - out, "\n");
876 if (attr == &sysfs_has_data) {
877 out += bch2_scnprint_flag_list(out, end - out,
879 bch2_dev_has_data(c, ca));
880 out += scnprintf(out, end - out, "\n");
884 sysfs_pd_controller_show(copy_gc, &ca->copygc_pd);
886 if (attr == &sysfs_cache_replacement_policy) {
887 out += bch2_scnprint_string_list(out, end - out,
888 bch2_cache_replacement_policies,
890 out += scnprintf(out, end - out, "\n");
894 if (attr == &sysfs_state_rw) {
895 out += bch2_scnprint_string_list(out, end - out,
898 out += scnprintf(out, end - out, "\n");
902 if (attr == &sysfs_iodone)
903 return show_dev_iodone(ca, buf);
905 sysfs_print(io_latency_read, atomic64_read(&ca->cur_latency[READ]));
906 sysfs_print(io_latency_write, atomic64_read(&ca->cur_latency[WRITE]));
908 if (attr == &sysfs_io_latency_stats_read)
909 return bch2_time_stats_print(&ca->io_latency[READ], buf, PAGE_SIZE);
910 if (attr == &sysfs_io_latency_stats_write)
911 return bch2_time_stats_print(&ca->io_latency[WRITE], buf, PAGE_SIZE);
913 sysfs_printf(congested, "%u%%",
914 clamp(atomic_read(&ca->congested), 0, CONGESTED_MAX)
915 * 100 / CONGESTED_MAX);
917 if (attr == &sysfs_bucket_quantiles_last_read)
918 return show_quantiles(c, ca, buf, bucket_last_io_fn, (void *) 0);
919 if (attr == &sysfs_bucket_quantiles_last_write)
920 return show_quantiles(c, ca, buf, bucket_last_io_fn, (void *) 1);
921 if (attr == &sysfs_bucket_quantiles_fragmentation)
922 return show_quantiles(c, ca, buf, bucket_sectors_used_fn, NULL);
923 if (attr == &sysfs_bucket_quantiles_oldest_gen)
924 return show_quantiles(c, ca, buf, bucket_oldest_gen_fn, NULL);
926 if (attr == &sysfs_reserve_stats)
927 return show_reserve_stats(ca, buf);
928 if (attr == &sysfs_alloc_debug)
929 return show_dev_alloc_debug(ca, buf);
936 struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
937 struct bch_fs *c = ca->fs;
938 struct bch_member *mi;
940 sysfs_pd_controller_store(copy_gc, &ca->copygc_pd);
942 if (attr == &sysfs_discard) {
943 bool v = strtoul_or_return(buf);
945 mutex_lock(&c->sb_lock);
946 mi = &bch2_sb_get_members(c->disk_sb.sb)->members[ca->dev_idx];
948 if (v != BCH_MEMBER_DISCARD(mi)) {
949 SET_BCH_MEMBER_DISCARD(mi, v);
952 mutex_unlock(&c->sb_lock);
955 if (attr == &sysfs_cache_replacement_policy) {
956 ssize_t v = __sysfs_match_string(bch2_cache_replacement_policies, -1, buf);
961 mutex_lock(&c->sb_lock);
962 mi = &bch2_sb_get_members(c->disk_sb.sb)->members[ca->dev_idx];
964 if ((unsigned) v != BCH_MEMBER_REPLACEMENT(mi)) {
965 SET_BCH_MEMBER_REPLACEMENT(mi, v);
968 mutex_unlock(&c->sb_lock);
971 if (attr == &sysfs_label) {
975 tmp = kstrdup(buf, GFP_KERNEL);
979 ret = bch2_dev_group_set(c, ca, strim(tmp));
985 if (attr == &sysfs_wake_allocator)
986 bch2_wake_allocator(ca);
992 struct attribute *bch2_dev_files[] = {
1002 &sysfs_cache_replacement_policy,
1009 &sysfs_io_latency_read,
1010 &sysfs_io_latency_write,
1011 &sysfs_io_latency_stats_read,
1012 &sysfs_io_latency_stats_write,
1015 /* alloc info - other stats: */
1016 &sysfs_bucket_quantiles_last_read,
1017 &sysfs_bucket_quantiles_last_write,
1018 &sysfs_bucket_quantiles_fragmentation,
1019 &sysfs_bucket_quantiles_oldest_gen,
1021 &sysfs_reserve_stats,
1025 &sysfs_wake_allocator,
1027 sysfs_pd_controller_files(copy_gc),
1031 #endif /* _BCACHEFS_SYSFS_H_ */