1 // SPDX-License-Identifier: GPL-2.0
3 * bcache sysfs interfaces
5 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
6 * Copyright 2012 Google, Inc.
9 #ifndef NO_BCACHEFS_SYSFS
12 #include "alloc_background.h"
13 #include "alloc_foreground.h"
15 #include "btree_cache.h"
17 #include "btree_iter.h"
18 #include "btree_key_cache.h"
19 #include "btree_update.h"
20 #include "btree_update_interior.h"
24 #include "disk_groups.h"
30 #include "nocow_locking.h"
32 #include "rebalance.h"
37 #include <linux/blkdev.h>
38 #include <linux/sort.h>
39 #include <linux/sched/clock.h>
43 #define SYSFS_OPS(type) \
44 const struct sysfs_ops type ## _sysfs_ops = { \
45 .show = type ## _show, \
46 .store = type ## _store \
50 static ssize_t fn ## _to_text(struct printbuf *, \
51 struct kobject *, struct attribute *); \
53 static ssize_t fn ## _show(struct kobject *kobj, struct attribute *attr,\
56 struct printbuf out = PRINTBUF; \
57 ssize_t ret = fn ## _to_text(&out, kobj, attr); \
59 if (out.pos && out.buf[out.pos - 1] != '\n') \
62 if (!ret && out.allocation_failure) \
66 ret = min_t(size_t, out.pos, PAGE_SIZE - 1); \
67 memcpy(buf, out.buf, ret); \
69 printbuf_exit(&out); \
70 return bch2_err_class(ret); \
73 static ssize_t fn ## _to_text(struct printbuf *out, struct kobject *kobj,\
74 struct attribute *attr)
77 static ssize_t fn ## _store_inner(struct kobject *, struct attribute *,\
78 const char *, size_t); \
80 static ssize_t fn ## _store(struct kobject *kobj, struct attribute *attr,\
81 const char *buf, size_t size) \
83 return bch2_err_class(fn##_store_inner(kobj, attr, buf, size)); \
86 static ssize_t fn ## _store_inner(struct kobject *kobj, struct attribute *attr,\
87 const char *buf, size_t size)
89 #define __sysfs_attribute(_name, _mode) \
90 static struct attribute sysfs_##_name = \
91 { .name = #_name, .mode = _mode }
93 #define write_attribute(n) __sysfs_attribute(n, 0200)
94 #define read_attribute(n) __sysfs_attribute(n, 0444)
95 #define rw_attribute(n) __sysfs_attribute(n, 0644)
97 #define sysfs_printf(file, fmt, ...) \
99 if (attr == &sysfs_ ## file) \
100 prt_printf(out, fmt "\n", __VA_ARGS__); \
103 #define sysfs_print(file, var) \
105 if (attr == &sysfs_ ## file) \
109 #define sysfs_hprint(file, val) \
111 if (attr == &sysfs_ ## file) \
112 prt_human_readable_s64(out, val); \
115 #define var_printf(_var, fmt) sysfs_printf(_var, fmt, var(_var))
116 #define var_print(_var) sysfs_print(_var, var(_var))
117 #define var_hprint(_var) sysfs_hprint(_var, var(_var))
119 #define sysfs_strtoul(file, var) \
121 if (attr == &sysfs_ ## file) \
122 return strtoul_safe(buf, var) ?: (ssize_t) size; \
125 #define sysfs_strtoul_clamp(file, var, min, max) \
127 if (attr == &sysfs_ ## file) \
128 return strtoul_safe_clamp(buf, var, min, max) \
132 #define strtoul_or_return(cp) \
135 int _r = kstrtoul(cp, 10, &_v); \
141 #define strtoul_restrict_or_return(cp, min, max) \
143 unsigned long __v = 0; \
144 int _r = strtoul_safe_restrict(cp, __v, min, max); \
150 #define strtoi_h_or_return(cp) \
153 int _r = strtoi_h(cp, &_v); \
159 #define sysfs_hatoi(file, var) \
161 if (attr == &sysfs_ ## file) \
162 return strtoi_h(buf, &var) ?: (ssize_t) size; \
165 write_attribute(trigger_gc);
166 write_attribute(trigger_discards);
167 write_attribute(trigger_invalidates);
168 write_attribute(prune_cache);
169 write_attribute(btree_wakeup);
170 rw_attribute(btree_gc_periodic);
171 rw_attribute(gc_gens_pos);
173 read_attribute(uuid);
174 read_attribute(minor);
175 read_attribute(bucket_size);
176 read_attribute(first_bucket);
177 read_attribute(nbuckets);
178 rw_attribute(durability);
179 read_attribute(iodone);
181 read_attribute(io_latency_read);
182 read_attribute(io_latency_write);
183 read_attribute(io_latency_stats_read);
184 read_attribute(io_latency_stats_write);
185 read_attribute(congested);
187 read_attribute(btree_write_stats);
189 read_attribute(btree_cache_size);
190 read_attribute(compression_stats);
191 read_attribute(journal_debug);
192 read_attribute(btree_updates);
193 read_attribute(btree_cache);
194 read_attribute(btree_key_cache);
195 read_attribute(stripes_heap);
196 read_attribute(open_buckets);
197 read_attribute(open_buckets_partial);
198 read_attribute(write_points);
199 read_attribute(nocow_lock_table);
201 #ifdef BCH_WRITE_REF_DEBUG
202 read_attribute(write_refs);
204 const char * const bch2_write_refs[] = {
211 static void bch2_write_refs_to_text(struct printbuf *out, struct bch_fs *c)
213 bch2_printbuf_tabstop_push(out, 24);
215 for (unsigned i = 0; i < ARRAY_SIZE(c->writes); i++) {
216 prt_str(out, bch2_write_refs[i]);
218 prt_printf(out, "%li", atomic_long_read(&c->writes[i]));
224 read_attribute(internal_uuid);
226 read_attribute(has_data);
227 read_attribute(alloc_debug);
229 #define x(t, n, ...) read_attribute(t);
230 BCH_PERSISTENT_COUNTERS()
233 rw_attribute(discard);
236 rw_attribute(copy_gc_enabled);
237 read_attribute(copy_gc_wait);
239 rw_attribute(rebalance_enabled);
240 sysfs_pd_controller_attribute(rebalance);
241 read_attribute(rebalance_work);
242 rw_attribute(promote_whole_extents);
244 read_attribute(new_stripes);
246 read_attribute(io_timers_read);
247 read_attribute(io_timers_write);
249 read_attribute(data_jobs);
251 #ifdef CONFIG_BCACHEFS_TESTS
252 write_attribute(perf_test);
253 #endif /* CONFIG_BCACHEFS_TESTS */
256 static struct attribute sysfs_time_stat_##_name = \
257 { .name = #_name, .mode = 0444 };
261 static struct attribute sysfs_state_rw = {
266 static size_t bch2_btree_cache_size(struct bch_fs *c)
271 mutex_lock(&c->btree_cache.lock);
272 list_for_each_entry(b, &c->btree_cache.live, list)
273 ret += btree_bytes(c);
275 mutex_unlock(&c->btree_cache.lock);
279 static long data_progress_to_text(struct printbuf *out, struct bch_fs *c)
282 struct bch_move_stats *stats;
284 mutex_lock(&c->data_progress_lock);
285 list_for_each_entry(stats, &c->data_progress_list, list) {
286 prt_printf(out, "%s: data type %s btree_id %s position: ",
288 bch2_data_types[stats->data_type],
289 bch2_btree_ids[stats->btree_id]);
290 bch2_bpos_to_text(out, stats->pos);
291 prt_printf(out, "%s", "\n");
294 mutex_unlock(&c->data_progress_lock);
298 static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c)
300 struct btree_trans trans;
301 struct btree_iter iter;
304 u64 nr_uncompressed_extents = 0,
305 nr_compressed_extents = 0,
306 nr_incompressible_extents = 0,
307 uncompressed_sectors = 0,
308 incompressible_sectors = 0,
309 compressed_sectors_compressed = 0,
310 compressed_sectors_uncompressed = 0;
313 if (!test_bit(BCH_FS_STARTED, &c->flags))
316 bch2_trans_init(&trans, c, 0, 0);
318 for (id = 0; id < BTREE_ID_NR; id++) {
319 if (!btree_type_has_ptrs(id))
322 for_each_btree_key(&trans, iter, id, POS_MIN,
323 BTREE_ITER_ALL_SNAPSHOTS, k, ret) {
324 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
325 const union bch_extent_entry *entry;
326 struct extent_ptr_decoded p;
327 bool compressed = false, uncompressed = false, incompressible = false;
329 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
330 switch (p.crc.compression_type) {
331 case BCH_COMPRESSION_TYPE_none:
333 uncompressed_sectors += k.k->size;
335 case BCH_COMPRESSION_TYPE_incompressible:
336 incompressible = true;
337 incompressible_sectors += k.k->size;
340 compressed_sectors_compressed +=
341 p.crc.compressed_size;
342 compressed_sectors_uncompressed +=
343 p.crc.uncompressed_size;
350 nr_incompressible_extents++;
351 else if (uncompressed)
352 nr_uncompressed_extents++;
354 nr_compressed_extents++;
356 bch2_trans_iter_exit(&trans, &iter);
359 bch2_trans_exit(&trans);
364 prt_printf(out, "uncompressed:\n");
365 prt_printf(out, " nr extents: %llu\n", nr_uncompressed_extents);
366 prt_printf(out, " size: ");
367 prt_human_readable_u64(out, uncompressed_sectors << 9);
368 prt_printf(out, "\n");
370 prt_printf(out, "compressed:\n");
371 prt_printf(out, " nr extents: %llu\n", nr_compressed_extents);
372 prt_printf(out, " compressed size: ");
373 prt_human_readable_u64(out, compressed_sectors_compressed << 9);
374 prt_printf(out, "\n");
375 prt_printf(out, " uncompressed size: ");
376 prt_human_readable_u64(out, compressed_sectors_uncompressed << 9);
377 prt_printf(out, "\n");
379 prt_printf(out, "incompressible:\n");
380 prt_printf(out, " nr extents: %llu\n", nr_incompressible_extents);
381 prt_printf(out, " size: ");
382 prt_human_readable_u64(out, incompressible_sectors << 9);
383 prt_printf(out, "\n");
387 static void bch2_gc_gens_pos_to_text(struct printbuf *out, struct bch_fs *c)
389 prt_printf(out, "%s: ", bch2_btree_ids[c->gc_gens_btree]);
390 bch2_bpos_to_text(out, c->gc_gens_pos);
391 prt_printf(out, "\n");
394 static void bch2_btree_wakeup_all(struct bch_fs *c)
396 struct btree_trans *trans;
398 mutex_lock(&c->btree_trans_lock);
399 list_for_each_entry(trans, &c->btree_trans_list, list) {
400 struct btree_bkey_cached_common *b = READ_ONCE(trans->locking);
403 six_lock_wakeup_all(&b->lock);
406 mutex_unlock(&c->btree_trans_lock);
411 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
413 sysfs_print(minor, c->minor);
414 sysfs_printf(internal_uuid, "%pU", c->sb.uuid.b);
416 sysfs_hprint(btree_cache_size, bch2_btree_cache_size(c));
418 if (attr == &sysfs_btree_write_stats)
419 bch2_btree_write_stats_to_text(out, c);
421 sysfs_printf(btree_gc_periodic, "%u", (int) c->btree_gc_periodic);
423 if (attr == &sysfs_gc_gens_pos)
424 bch2_gc_gens_pos_to_text(out, c);
426 sysfs_printf(copy_gc_enabled, "%i", c->copy_gc_enabled);
428 sysfs_printf(rebalance_enabled, "%i", c->rebalance.enabled);
429 sysfs_pd_controller_show(rebalance, &c->rebalance.pd); /* XXX */
430 sysfs_hprint(copy_gc_wait,
431 max(0LL, c->copygc_wait -
432 atomic64_read(&c->io_clock[WRITE].now)) << 9);
434 if (attr == &sysfs_rebalance_work)
435 bch2_rebalance_work_to_text(out, c);
437 sysfs_print(promote_whole_extents, c->promote_whole_extents);
441 if (attr == &sysfs_journal_debug)
442 bch2_journal_debug_to_text(out, &c->journal);
444 if (attr == &sysfs_btree_updates)
445 bch2_btree_updates_to_text(out, c);
447 if (attr == &sysfs_btree_cache)
448 bch2_btree_cache_to_text(out, &c->btree_cache);
450 if (attr == &sysfs_btree_key_cache)
451 bch2_btree_key_cache_to_text(out, &c->btree_key_cache);
453 if (attr == &sysfs_stripes_heap)
454 bch2_stripes_heap_to_text(out, c);
456 if (attr == &sysfs_open_buckets)
457 bch2_open_buckets_to_text(out, c);
459 if (attr == &sysfs_open_buckets_partial)
460 bch2_open_buckets_partial_to_text(out, c);
462 if (attr == &sysfs_write_points)
463 bch2_write_points_to_text(out, c);
465 if (attr == &sysfs_compression_stats)
466 bch2_compression_stats_to_text(out, c);
468 if (attr == &sysfs_new_stripes)
469 bch2_new_stripes_to_text(out, c);
471 if (attr == &sysfs_io_timers_read)
472 bch2_io_timers_to_text(out, &c->io_clock[READ]);
474 if (attr == &sysfs_io_timers_write)
475 bch2_io_timers_to_text(out, &c->io_clock[WRITE]);
477 if (attr == &sysfs_data_jobs)
478 data_progress_to_text(out, c);
480 #ifdef BCH_WRITE_REF_DEBUG
481 if (attr == &sysfs_write_refs)
482 bch2_write_refs_to_text(out, c);
485 if (attr == &sysfs_nocow_lock_table)
486 bch2_nocow_locks_to_text(out, &c->nocow_locks);
493 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
495 if (attr == &sysfs_btree_gc_periodic) {
496 ssize_t ret = strtoul_safe(buf, c->btree_gc_periodic)
499 wake_up_process(c->gc_thread);
503 if (attr == &sysfs_copy_gc_enabled) {
504 ssize_t ret = strtoul_safe(buf, c->copy_gc_enabled)
507 if (c->copygc_thread)
508 wake_up_process(c->copygc_thread);
512 if (attr == &sysfs_rebalance_enabled) {
513 ssize_t ret = strtoul_safe(buf, c->rebalance.enabled)
520 sysfs_pd_controller_store(rebalance, &c->rebalance.pd);
522 sysfs_strtoul(promote_whole_extents, c->promote_whole_extents);
526 if (!test_bit(BCH_FS_STARTED, &c->flags))
531 if (!test_bit(BCH_FS_RW, &c->flags))
534 if (attr == &sysfs_prune_cache) {
535 struct shrink_control sc;
537 sc.gfp_mask = GFP_KERNEL;
538 sc.nr_to_scan = strtoul_or_return(buf);
539 c->btree_cache.shrink.scan_objects(&c->btree_cache.shrink, &sc);
542 if (attr == &sysfs_btree_wakeup)
543 bch2_btree_wakeup_all(c);
545 if (attr == &sysfs_trigger_gc) {
547 * Full gc is currently incompatible with btree key cache:
550 down_read(&c->state_lock);
551 bch2_gc(c, false, false);
552 up_read(&c->state_lock);
558 if (attr == &sysfs_trigger_discards)
561 if (attr == &sysfs_trigger_invalidates)
562 bch2_do_invalidates(c);
564 #ifdef CONFIG_BCACHEFS_TESTS
565 if (attr == &sysfs_perf_test) {
566 char *tmp = kstrdup(buf, GFP_KERNEL), *p = tmp;
567 char *test = strsep(&p, " \t\n");
568 char *nr_str = strsep(&p, " \t\n");
569 char *threads_str = strsep(&p, " \t\n");
575 !(ret = kstrtouint(threads_str, 10, &threads)) &&
576 !(ret = bch2_strtoull_h(nr_str, &nr)))
577 ret = bch2_btree_perf_test(c, test, nr, threads);
588 struct attribute *bch2_fs_files[] = {
590 &sysfs_btree_cache_size,
591 &sysfs_btree_write_stats,
593 &sysfs_promote_whole_extents,
595 &sysfs_compression_stats,
597 #ifdef CONFIG_BCACHEFS_TESTS
605 SHOW(bch2_fs_counters)
607 struct bch_fs *c = container_of(kobj, struct bch_fs, counters_kobj);
609 u64 counter_since_mount = 0;
611 printbuf_tabstop_push(out, 32);
614 if (attr == &sysfs_##t) { \
615 counter = percpu_u64_get(&c->counters[BCH_COUNTER_##t]);\
616 counter_since_mount = counter - c->counters_on_mount[BCH_COUNTER_##t];\
617 prt_printf(out, "since mount:"); \
619 prt_human_readable_u64(out, counter_since_mount << 9); \
622 prt_printf(out, "since filesystem creation:"); \
624 prt_human_readable_u64(out, counter << 9); \
627 BCH_PERSISTENT_COUNTERS()
632 STORE(bch2_fs_counters) {
636 SYSFS_OPS(bch2_fs_counters);
638 struct attribute *bch2_fs_counters_files[] = {
641 BCH_PERSISTENT_COUNTERS()
645 /* internal dir - just a wrapper */
647 SHOW(bch2_fs_internal)
649 struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
651 return bch2_fs_to_text(out, &c->kobj, attr);
654 STORE(bch2_fs_internal)
656 struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
658 return bch2_fs_store(&c->kobj, attr, buf, size);
660 SYSFS_OPS(bch2_fs_internal);
662 struct attribute *bch2_fs_internal_files[] = {
663 &sysfs_journal_debug,
664 &sysfs_btree_updates,
666 &sysfs_btree_key_cache,
670 &sysfs_open_buckets_partial,
672 #ifdef BCH_WRITE_REF_DEBUG
675 &sysfs_nocow_lock_table,
676 &sysfs_io_timers_read,
677 &sysfs_io_timers_write,
680 &sysfs_trigger_discards,
681 &sysfs_trigger_invalidates,
687 &sysfs_copy_gc_enabled,
690 &sysfs_rebalance_enabled,
691 &sysfs_rebalance_work,
692 sysfs_pd_controller_files(rebalance),
696 &sysfs_internal_uuid,
702 SHOW(bch2_fs_opts_dir)
704 struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
705 const struct bch_option *opt = container_of(attr, struct bch_option, attr);
706 int id = opt - bch2_opt_table;
707 u64 v = bch2_opt_get_by_id(&c->opts, id);
709 bch2_opt_to_text(out, c, c->disk_sb.sb, opt, v, OPT_SHOW_FULL_LIST);
715 STORE(bch2_fs_opts_dir)
717 struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
718 const struct bch_option *opt = container_of(attr, struct bch_option, attr);
719 int ret, id = opt - bch2_opt_table;
724 * We don't need to take c->writes for correctness, but it eliminates an
725 * unsightly error message in the dmesg log when we're RO:
727 if (unlikely(!bch2_write_ref_tryget(c, BCH_WRITE_REF_sysfs)))
730 tmp = kstrdup(buf, GFP_KERNEL);
736 ret = bch2_opt_parse(c, opt, strim(tmp), &v, NULL);
742 ret = bch2_opt_check_may_set(c, id, v);
746 bch2_opt_set_sb(c, opt, v);
747 bch2_opt_set_by_id(&c->opts, id, v);
749 if ((id == Opt_background_target ||
750 id == Opt_background_compression) && v) {
751 bch2_rebalance_add_work(c, S64_MAX);
757 bch2_write_ref_put(c, BCH_WRITE_REF_sysfs);
760 SYSFS_OPS(bch2_fs_opts_dir);
762 struct attribute *bch2_fs_opts_dir_files[] = { NULL };
764 int bch2_opts_create_sysfs_files(struct kobject *kobj)
766 const struct bch_option *i;
769 for (i = bch2_opt_table;
770 i < bch2_opt_table + bch2_opts_nr;
772 if (!(i->flags & OPT_FS))
775 ret = sysfs_create_file(kobj, &i->attr);
785 SHOW(bch2_fs_time_stats)
787 struct bch_fs *c = container_of(kobj, struct bch_fs, time_stats);
790 if (attr == &sysfs_time_stat_##name) \
791 bch2_time_stats_to_text(out, &c->times[BCH_TIME_##name]);
798 STORE(bch2_fs_time_stats)
802 SYSFS_OPS(bch2_fs_time_stats);
804 struct attribute *bch2_fs_time_stats_files[] = {
806 &sysfs_time_stat_##name,
812 static void dev_alloc_debug_to_text(struct printbuf *out, struct bch_dev *ca)
814 struct bch_fs *c = ca->fs;
815 struct bch_dev_usage stats = bch2_dev_usage_read(ca);
816 unsigned i, nr[BCH_DATA_NR];
818 memset(nr, 0, sizeof(nr));
820 for (i = 0; i < ARRAY_SIZE(c->open_buckets); i++)
821 nr[c->open_buckets[i].data_type]++;
824 "\t\t\t buckets\t sectors fragmented\n"
825 "capacity\t%16llu\n",
826 ca->mi.nbuckets - ca->mi.first_bucket);
828 for (i = 0; i < BCH_DATA_NR; i++)
829 prt_printf(out, "%-16s%16llu%16llu%16llu\n",
830 bch2_data_types[i], stats.d[i].buckets,
831 stats.d[i].sectors, stats.d[i].fragmented);
836 "freelist_wait\t\t%s\n"
837 "open buckets allocated\t%u\n"
838 "open buckets this dev\t%u\n"
839 "open buckets total\t%u\n"
840 "open_buckets_wait\t%s\n"
841 "open_buckets_btree\t%u\n"
842 "open_buckets_user\t%u\n"
843 "buckets_to_invalidate\t%llu\n"
844 "btree reserve cache\t%u\n",
846 c->freelist_wait.list.first ? "waiting" : "empty",
847 OPEN_BUCKETS_COUNT - c->open_buckets_nr_free,
850 c->open_buckets_wait.list.first ? "waiting" : "empty",
853 should_invalidate_buckets(ca, stats),
854 c->btree_reserve_cache_nr);
857 static const char * const bch2_rw[] = {
863 static void dev_iodone_to_text(struct printbuf *out, struct bch_dev *ca)
867 for (rw = 0; rw < 2; rw++) {
868 prt_printf(out, "%s:\n", bch2_rw[rw]);
870 for (i = 1; i < BCH_DATA_NR; i++)
871 prt_printf(out, "%-12s:%12llu\n",
873 percpu_u64_get(&ca->io_done->sectors[rw][i]) << 9);
879 struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
880 struct bch_fs *c = ca->fs;
882 sysfs_printf(uuid, "%pU\n", ca->uuid.b);
884 sysfs_print(bucket_size, bucket_bytes(ca));
885 sysfs_print(first_bucket, ca->mi.first_bucket);
886 sysfs_print(nbuckets, ca->mi.nbuckets);
887 sysfs_print(durability, ca->mi.durability);
888 sysfs_print(discard, ca->mi.discard);
890 if (attr == &sysfs_label) {
892 mutex_lock(&c->sb_lock);
893 bch2_disk_path_to_text(out, c->disk_sb.sb,
895 mutex_unlock(&c->sb_lock);
901 if (attr == &sysfs_has_data) {
902 prt_bitflags(out, bch2_data_types, bch2_dev_has_data(c, ca));
906 if (attr == &sysfs_state_rw) {
907 prt_string_option(out, bch2_member_states, ca->mi.state);
911 if (attr == &sysfs_iodone)
912 dev_iodone_to_text(out, ca);
914 sysfs_print(io_latency_read, atomic64_read(&ca->cur_latency[READ]));
915 sysfs_print(io_latency_write, atomic64_read(&ca->cur_latency[WRITE]));
917 if (attr == &sysfs_io_latency_stats_read)
918 bch2_time_stats_to_text(out, &ca->io_latency[READ]);
920 if (attr == &sysfs_io_latency_stats_write)
921 bch2_time_stats_to_text(out, &ca->io_latency[WRITE]);
923 sysfs_printf(congested, "%u%%",
924 clamp(atomic_read(&ca->congested), 0, CONGESTED_MAX)
925 * 100 / CONGESTED_MAX);
927 if (attr == &sysfs_alloc_debug)
928 dev_alloc_debug_to_text(out, ca);
935 struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
936 struct bch_fs *c = ca->fs;
937 struct bch_member *mi;
939 if (attr == &sysfs_discard) {
940 bool v = strtoul_or_return(buf);
942 mutex_lock(&c->sb_lock);
943 mi = &bch2_sb_get_members(c->disk_sb.sb)->members[ca->dev_idx];
945 if (v != BCH_MEMBER_DISCARD(mi)) {
946 SET_BCH_MEMBER_DISCARD(mi, v);
949 mutex_unlock(&c->sb_lock);
952 if (attr == &sysfs_durability) {
953 u64 v = strtoul_or_return(buf);
955 mutex_lock(&c->sb_lock);
956 mi = &bch2_sb_get_members(c->disk_sb.sb)->members[ca->dev_idx];
958 if (v != BCH_MEMBER_DURABILITY(mi)) {
959 SET_BCH_MEMBER_DURABILITY(mi, v + 1);
962 mutex_unlock(&c->sb_lock);
965 if (attr == &sysfs_label) {
969 tmp = kstrdup(buf, GFP_KERNEL);
973 ret = bch2_dev_group_set(c, ca, strim(tmp));
983 struct attribute *bch2_dev_files[] = {
998 &sysfs_io_latency_read,
999 &sysfs_io_latency_write,
1000 &sysfs_io_latency_stats_read,
1001 &sysfs_io_latency_stats_write,
1009 #endif /* _BCACHEFS_SYSFS_H_ */