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"
31 #include "nocow_locking.h"
33 #include "rebalance.h"
38 #include <linux/blkdev.h>
39 #include <linux/sort.h>
40 #include <linux/sched/clock.h>
44 #define SYSFS_OPS(type) \
45 const struct sysfs_ops type ## _sysfs_ops = { \
46 .show = type ## _show, \
47 .store = type ## _store \
51 static ssize_t fn ## _to_text(struct printbuf *, \
52 struct kobject *, struct attribute *); \
54 static ssize_t fn ## _show(struct kobject *kobj, struct attribute *attr,\
57 struct printbuf out = PRINTBUF; \
58 ssize_t ret = fn ## _to_text(&out, kobj, attr); \
60 if (out.pos && out.buf[out.pos - 1] != '\n') \
63 if (!ret && out.allocation_failure) \
67 ret = min_t(size_t, out.pos, PAGE_SIZE - 1); \
68 memcpy(buf, out.buf, ret); \
70 printbuf_exit(&out); \
71 return bch2_err_class(ret); \
74 static ssize_t fn ## _to_text(struct printbuf *out, struct kobject *kobj,\
75 struct attribute *attr)
78 static ssize_t fn ## _store_inner(struct kobject *, struct attribute *,\
79 const char *, size_t); \
81 static ssize_t fn ## _store(struct kobject *kobj, struct attribute *attr,\
82 const char *buf, size_t size) \
84 return bch2_err_class(fn##_store_inner(kobj, attr, buf, size)); \
87 static ssize_t fn ## _store_inner(struct kobject *kobj, struct attribute *attr,\
88 const char *buf, size_t size)
90 #define __sysfs_attribute(_name, _mode) \
91 static struct attribute sysfs_##_name = \
92 { .name = #_name, .mode = _mode }
94 #define write_attribute(n) __sysfs_attribute(n, 0200)
95 #define read_attribute(n) __sysfs_attribute(n, 0444)
96 #define rw_attribute(n) __sysfs_attribute(n, 0644)
98 #define sysfs_printf(file, fmt, ...) \
100 if (attr == &sysfs_ ## file) \
101 prt_printf(out, fmt "\n", __VA_ARGS__); \
104 #define sysfs_print(file, var) \
106 if (attr == &sysfs_ ## file) \
110 #define sysfs_hprint(file, val) \
112 if (attr == &sysfs_ ## file) \
113 prt_human_readable_s64(out, val); \
116 #define sysfs_strtoul(file, var) \
118 if (attr == &sysfs_ ## file) \
119 return strtoul_safe(buf, var) ?: (ssize_t) size; \
122 #define sysfs_strtoul_clamp(file, var, min, max) \
124 if (attr == &sysfs_ ## file) \
125 return strtoul_safe_clamp(buf, var, min, max) \
129 #define strtoul_or_return(cp) \
132 int _r = kstrtoul(cp, 10, &_v); \
138 write_attribute(trigger_gc);
139 write_attribute(trigger_discards);
140 write_attribute(trigger_invalidates);
141 write_attribute(prune_cache);
142 write_attribute(btree_wakeup);
143 rw_attribute(btree_gc_periodic);
144 rw_attribute(gc_gens_pos);
146 read_attribute(uuid);
147 read_attribute(minor);
148 read_attribute(flags);
149 read_attribute(bucket_size);
150 read_attribute(first_bucket);
151 read_attribute(nbuckets);
152 rw_attribute(durability);
153 read_attribute(io_done);
154 read_attribute(io_errors);
155 write_attribute(io_errors_reset);
157 read_attribute(io_latency_read);
158 read_attribute(io_latency_write);
159 read_attribute(io_latency_stats_read);
160 read_attribute(io_latency_stats_write);
161 read_attribute(congested);
163 read_attribute(btree_write_stats);
165 read_attribute(btree_cache_size);
166 read_attribute(compression_stats);
167 read_attribute(journal_debug);
168 read_attribute(btree_updates);
169 read_attribute(btree_cache);
170 read_attribute(btree_key_cache);
171 read_attribute(stripes_heap);
172 read_attribute(open_buckets);
173 read_attribute(open_buckets_partial);
174 read_attribute(write_points);
175 read_attribute(nocow_lock_table);
177 #ifdef BCH_WRITE_REF_DEBUG
178 read_attribute(write_refs);
180 static const char * const bch2_write_refs[] = {
187 static void bch2_write_refs_to_text(struct printbuf *out, struct bch_fs *c)
189 bch2_printbuf_tabstop_push(out, 24);
191 for (unsigned i = 0; i < ARRAY_SIZE(c->writes); i++) {
192 prt_str(out, bch2_write_refs[i]);
194 prt_printf(out, "%li", atomic_long_read(&c->writes[i]));
200 read_attribute(internal_uuid);
201 read_attribute(disk_groups);
203 read_attribute(has_data);
204 read_attribute(alloc_debug);
206 #define x(t, n, ...) read_attribute(t);
207 BCH_PERSISTENT_COUNTERS()
210 rw_attribute(discard);
213 rw_attribute(copy_gc_enabled);
214 read_attribute(copy_gc_wait);
216 rw_attribute(rebalance_enabled);
217 sysfs_pd_controller_attribute(rebalance);
218 read_attribute(rebalance_status);
219 rw_attribute(promote_whole_extents);
221 read_attribute(new_stripes);
223 read_attribute(io_timers_read);
224 read_attribute(io_timers_write);
226 read_attribute(moving_ctxts);
228 #ifdef CONFIG_BCACHEFS_TESTS
229 write_attribute(perf_test);
230 #endif /* CONFIG_BCACHEFS_TESTS */
233 static struct attribute sysfs_time_stat_##_name = \
234 { .name = #_name, .mode = 0444 };
238 static struct attribute sysfs_state_rw = {
243 static size_t bch2_btree_cache_size(struct bch_fs *c)
248 mutex_lock(&c->btree_cache.lock);
249 list_for_each_entry(b, &c->btree_cache.live, list)
250 ret += btree_bytes(c);
252 mutex_unlock(&c->btree_cache.lock);
256 static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c)
258 struct btree_trans *trans;
259 struct btree_iter iter;
262 struct compression_type_stats {
264 u64 sectors_compressed;
265 u64 sectors_uncompressed;
266 } s[BCH_COMPRESSION_TYPE_NR];
267 u64 compressed_incompressible = 0;
270 memset(s, 0, sizeof(s));
272 if (!test_bit(BCH_FS_started, &c->flags))
275 trans = bch2_trans_get(c);
277 for (id = 0; id < BTREE_ID_NR; id++) {
278 if (!btree_type_has_ptrs(id))
281 ret = for_each_btree_key2(trans, iter, id, POS_MIN,
282 BTREE_ITER_ALL_SNAPSHOTS, k, ({
283 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
284 struct bch_extent_crc_unpacked crc;
285 const union bch_extent_entry *entry;
286 bool compressed = false, incompressible = false;
288 bkey_for_each_crc(k.k, ptrs, crc, entry) {
289 incompressible |= crc.compression_type == BCH_COMPRESSION_TYPE_incompressible;
290 compressed |= crc_is_compressed(crc);
292 if (crc_is_compressed(crc)) {
293 s[crc.compression_type].nr_extents++;
294 s[crc.compression_type].sectors_compressed += crc.compressed_size;
295 s[crc.compression_type].sectors_uncompressed += crc.uncompressed_size;
299 compressed_incompressible += compressed && incompressible;
302 unsigned t = incompressible ? BCH_COMPRESSION_TYPE_incompressible : 0;
305 s[t].sectors_compressed += k.k->size;
306 s[t].sectors_uncompressed += k.k->size;
312 bch2_trans_put(trans);
317 prt_str(out, "type");
318 printbuf_tabstop_push(out, 12);
321 prt_str(out, "compressed");
322 printbuf_tabstop_push(out, 16);
325 prt_str(out, "uncompressed");
326 printbuf_tabstop_push(out, 16);
329 prt_str(out, "average extent size");
330 printbuf_tabstop_push(out, 24);
334 for (unsigned i = 0; i < ARRAY_SIZE(s); i++) {
335 prt_str(out, bch2_compression_types[i]);
338 prt_human_readable_u64(out, s[i].sectors_compressed << 9);
341 prt_human_readable_u64(out, s[i].sectors_uncompressed << 9);
344 prt_human_readable_u64(out, s[i].nr_extents
345 ? div_u64(s[i].sectors_uncompressed << 9, s[i].nr_extents)
351 if (compressed_incompressible) {
352 prt_printf(out, "%llu compressed & incompressible extents", compressed_incompressible);
359 static void bch2_gc_gens_pos_to_text(struct printbuf *out, struct bch_fs *c)
361 prt_printf(out, "%s: ", bch2_btree_id_str(c->gc_gens_btree));
362 bch2_bpos_to_text(out, c->gc_gens_pos);
363 prt_printf(out, "\n");
366 static void bch2_btree_wakeup_all(struct bch_fs *c)
368 struct btree_trans *trans;
370 seqmutex_lock(&c->btree_trans_lock);
371 list_for_each_entry(trans, &c->btree_trans_list, list) {
372 struct btree_bkey_cached_common *b = READ_ONCE(trans->locking);
375 six_lock_wakeup_all(&b->lock);
378 seqmutex_unlock(&c->btree_trans_lock);
383 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
385 sysfs_print(minor, c->minor);
386 sysfs_printf(internal_uuid, "%pU", c->sb.uuid.b);
388 if (attr == &sysfs_flags)
389 prt_bitflags(out, bch2_fs_flag_strs, c->flags);
391 sysfs_hprint(btree_cache_size, bch2_btree_cache_size(c));
393 if (attr == &sysfs_btree_write_stats)
394 bch2_btree_write_stats_to_text(out, c);
396 sysfs_printf(btree_gc_periodic, "%u", (int) c->btree_gc_periodic);
398 if (attr == &sysfs_gc_gens_pos)
399 bch2_gc_gens_pos_to_text(out, c);
401 sysfs_printf(copy_gc_enabled, "%i", c->copy_gc_enabled);
403 sysfs_printf(rebalance_enabled, "%i", c->rebalance.enabled);
404 sysfs_pd_controller_show(rebalance, &c->rebalance.pd); /* XXX */
406 if (attr == &sysfs_copy_gc_wait)
407 bch2_copygc_wait_to_text(out, c);
409 if (attr == &sysfs_rebalance_status)
410 bch2_rebalance_status_to_text(out, c);
412 sysfs_print(promote_whole_extents, c->promote_whole_extents);
416 if (attr == &sysfs_journal_debug)
417 bch2_journal_debug_to_text(out, &c->journal);
419 if (attr == &sysfs_btree_updates)
420 bch2_btree_updates_to_text(out, c);
422 if (attr == &sysfs_btree_cache)
423 bch2_btree_cache_to_text(out, c);
425 if (attr == &sysfs_btree_key_cache)
426 bch2_btree_key_cache_to_text(out, &c->btree_key_cache);
428 if (attr == &sysfs_stripes_heap)
429 bch2_stripes_heap_to_text(out, c);
431 if (attr == &sysfs_open_buckets)
432 bch2_open_buckets_to_text(out, c);
434 if (attr == &sysfs_open_buckets_partial)
435 bch2_open_buckets_partial_to_text(out, c);
437 if (attr == &sysfs_write_points)
438 bch2_write_points_to_text(out, c);
440 if (attr == &sysfs_compression_stats)
441 bch2_compression_stats_to_text(out, c);
443 if (attr == &sysfs_new_stripes)
444 bch2_new_stripes_to_text(out, c);
446 if (attr == &sysfs_io_timers_read)
447 bch2_io_timers_to_text(out, &c->io_clock[READ]);
449 if (attr == &sysfs_io_timers_write)
450 bch2_io_timers_to_text(out, &c->io_clock[WRITE]);
452 if (attr == &sysfs_moving_ctxts)
453 bch2_fs_moving_ctxts_to_text(out, c);
455 #ifdef BCH_WRITE_REF_DEBUG
456 if (attr == &sysfs_write_refs)
457 bch2_write_refs_to_text(out, c);
460 if (attr == &sysfs_nocow_lock_table)
461 bch2_nocow_locks_to_text(out, &c->nocow_locks);
463 if (attr == &sysfs_disk_groups)
464 bch2_disk_groups_to_text(out, c);
471 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
473 if (attr == &sysfs_btree_gc_periodic) {
474 ssize_t ret = strtoul_safe(buf, c->btree_gc_periodic)
477 wake_up_process(c->gc_thread);
481 if (attr == &sysfs_copy_gc_enabled) {
482 ssize_t ret = strtoul_safe(buf, c->copy_gc_enabled)
485 if (c->copygc_thread)
486 wake_up_process(c->copygc_thread);
490 if (attr == &sysfs_rebalance_enabled) {
491 ssize_t ret = strtoul_safe(buf, c->rebalance.enabled)
498 sysfs_pd_controller_store(rebalance, &c->rebalance.pd);
500 sysfs_strtoul(promote_whole_extents, c->promote_whole_extents);
504 if (!test_bit(BCH_FS_started, &c->flags))
509 if (!test_bit(BCH_FS_rw, &c->flags))
512 if (attr == &sysfs_prune_cache) {
513 struct shrink_control sc;
515 sc.gfp_mask = GFP_KERNEL;
516 sc.nr_to_scan = strtoul_or_return(buf);
517 c->btree_cache.shrink->scan_objects(c->btree_cache.shrink, &sc);
520 if (attr == &sysfs_btree_wakeup)
521 bch2_btree_wakeup_all(c);
523 if (attr == &sysfs_trigger_gc) {
525 * Full gc is currently incompatible with btree key cache:
528 down_read(&c->state_lock);
529 bch2_gc(c, false, false);
530 up_read(&c->state_lock);
536 if (attr == &sysfs_trigger_discards)
539 if (attr == &sysfs_trigger_invalidates)
540 bch2_do_invalidates(c);
542 #ifdef CONFIG_BCACHEFS_TESTS
543 if (attr == &sysfs_perf_test) {
544 char *tmp = kstrdup(buf, GFP_KERNEL), *p = tmp;
545 char *test = strsep(&p, " \t\n");
546 char *nr_str = strsep(&p, " \t\n");
547 char *threads_str = strsep(&p, " \t\n");
553 !(ret = kstrtouint(threads_str, 10, &threads)) &&
554 !(ret = bch2_strtoull_h(nr_str, &nr)))
555 ret = bch2_btree_perf_test(c, test, nr, threads);
566 struct attribute *bch2_fs_files[] = {
568 &sysfs_btree_cache_size,
569 &sysfs_btree_write_stats,
571 &sysfs_promote_whole_extents,
573 &sysfs_compression_stats,
575 #ifdef CONFIG_BCACHEFS_TESTS
583 SHOW(bch2_fs_counters)
585 struct bch_fs *c = container_of(kobj, struct bch_fs, counters_kobj);
587 u64 counter_since_mount = 0;
589 printbuf_tabstop_push(out, 32);
592 if (attr == &sysfs_##t) { \
593 counter = percpu_u64_get(&c->counters[BCH_COUNTER_##t]);\
594 counter_since_mount = counter - c->counters_on_mount[BCH_COUNTER_##t];\
595 prt_printf(out, "since mount:"); \
597 prt_human_readable_u64(out, counter_since_mount); \
600 prt_printf(out, "since filesystem creation:"); \
602 prt_human_readable_u64(out, counter); \
605 BCH_PERSISTENT_COUNTERS()
610 STORE(bch2_fs_counters) {
614 SYSFS_OPS(bch2_fs_counters);
616 struct attribute *bch2_fs_counters_files[] = {
619 BCH_PERSISTENT_COUNTERS()
623 /* internal dir - just a wrapper */
625 SHOW(bch2_fs_internal)
627 struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
629 return bch2_fs_to_text(out, &c->kobj, attr);
632 STORE(bch2_fs_internal)
634 struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
636 return bch2_fs_store(&c->kobj, attr, buf, size);
638 SYSFS_OPS(bch2_fs_internal);
640 struct attribute *bch2_fs_internal_files[] = {
642 &sysfs_journal_debug,
643 &sysfs_btree_updates,
645 &sysfs_btree_key_cache,
649 &sysfs_open_buckets_partial,
651 #ifdef BCH_WRITE_REF_DEBUG
654 &sysfs_nocow_lock_table,
655 &sysfs_io_timers_read,
656 &sysfs_io_timers_write,
659 &sysfs_trigger_discards,
660 &sysfs_trigger_invalidates,
666 &sysfs_copy_gc_enabled,
669 &sysfs_rebalance_enabled,
670 &sysfs_rebalance_status,
671 sysfs_pd_controller_files(rebalance),
675 &sysfs_internal_uuid,
683 SHOW(bch2_fs_opts_dir)
685 struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
686 const struct bch_option *opt = container_of(attr, struct bch_option, attr);
687 int id = opt - bch2_opt_table;
688 u64 v = bch2_opt_get_by_id(&c->opts, id);
690 bch2_opt_to_text(out, c, c->disk_sb.sb, opt, v, OPT_SHOW_FULL_LIST);
696 STORE(bch2_fs_opts_dir)
698 struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
699 const struct bch_option *opt = container_of(attr, struct bch_option, attr);
700 int ret, id = opt - bch2_opt_table;
705 * We don't need to take c->writes for correctness, but it eliminates an
706 * unsightly error message in the dmesg log when we're RO:
708 if (unlikely(!bch2_write_ref_tryget(c, BCH_WRITE_REF_sysfs)))
711 tmp = kstrdup(buf, GFP_KERNEL);
717 ret = bch2_opt_parse(c, opt, strim(tmp), &v, NULL);
723 ret = bch2_opt_check_may_set(c, id, v);
727 bch2_opt_set_sb(c, opt, v);
728 bch2_opt_set_by_id(&c->opts, id, v);
730 if ((id == Opt_background_target ||
731 id == Opt_background_compression) && v)
732 bch2_set_rebalance_needs_scan(c, 0);
736 bch2_write_ref_put(c, BCH_WRITE_REF_sysfs);
739 SYSFS_OPS(bch2_fs_opts_dir);
741 struct attribute *bch2_fs_opts_dir_files[] = { NULL };
743 int bch2_opts_create_sysfs_files(struct kobject *kobj)
745 const struct bch_option *i;
748 for (i = bch2_opt_table;
749 i < bch2_opt_table + bch2_opts_nr;
751 if (!(i->flags & OPT_FS))
754 ret = sysfs_create_file(kobj, &i->attr);
764 SHOW(bch2_fs_time_stats)
766 struct bch_fs *c = container_of(kobj, struct bch_fs, time_stats);
769 if (attr == &sysfs_time_stat_##name) \
770 bch2_time_stats_to_text(out, &c->times[BCH_TIME_##name]);
777 STORE(bch2_fs_time_stats)
781 SYSFS_OPS(bch2_fs_time_stats);
783 struct attribute *bch2_fs_time_stats_files[] = {
785 &sysfs_time_stat_##name,
791 static void dev_alloc_debug_to_text(struct printbuf *out, struct bch_dev *ca)
793 struct bch_fs *c = ca->fs;
794 struct bch_dev_usage stats = bch2_dev_usage_read(ca);
795 unsigned i, nr[BCH_DATA_NR];
797 memset(nr, 0, sizeof(nr));
799 for (i = 0; i < ARRAY_SIZE(c->open_buckets); i++)
800 nr[c->open_buckets[i].data_type]++;
802 printbuf_tabstop_push(out, 8);
803 printbuf_tabstop_push(out, 16);
804 printbuf_tabstop_push(out, 16);
805 printbuf_tabstop_push(out, 16);
806 printbuf_tabstop_push(out, 16);
808 bch2_dev_usage_to_text(out, &stats);
812 prt_printf(out, "reserves:");
814 for (i = 0; i < BCH_WATERMARK_NR; i++) {
815 prt_str(out, bch2_watermarks[i]);
817 prt_u64(out, bch2_dev_buckets_reserved(ca, i));
824 printbuf_tabstops_reset(out);
825 printbuf_tabstop_push(out, 24);
827 prt_str(out, "freelist_wait");
829 prt_str(out, c->freelist_wait.list.first ? "waiting" : "empty");
832 prt_str(out, "open buckets allocated");
834 prt_u64(out, OPEN_BUCKETS_COUNT - c->open_buckets_nr_free);
837 prt_str(out, "open buckets this dev");
839 prt_u64(out, ca->nr_open_buckets);
842 prt_str(out, "open buckets total");
844 prt_u64(out, OPEN_BUCKETS_COUNT);
847 prt_str(out, "open_buckets_wait");
849 prt_str(out, c->open_buckets_wait.list.first ? "waiting" : "empty");
852 prt_str(out, "open_buckets_btree");
854 prt_u64(out, nr[BCH_DATA_btree]);
857 prt_str(out, "open_buckets_user");
859 prt_u64(out, nr[BCH_DATA_user]);
862 prt_str(out, "buckets_to_invalidate");
864 prt_u64(out, should_invalidate_buckets(ca, stats));
867 prt_str(out, "btree reserve cache");
869 prt_u64(out, c->btree_reserve_cache_nr);
873 static const char * const bch2_rw[] = {
879 static void dev_io_done_to_text(struct printbuf *out, struct bch_dev *ca)
883 for (rw = 0; rw < 2; rw++) {
884 prt_printf(out, "%s:\n", bch2_rw[rw]);
886 for (i = 1; i < BCH_DATA_NR; i++)
887 prt_printf(out, "%-12s:%12llu\n",
889 percpu_u64_get(&ca->io_done->sectors[rw][i]) << 9);
895 struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
896 struct bch_fs *c = ca->fs;
898 sysfs_printf(uuid, "%pU\n", ca->uuid.b);
900 sysfs_print(bucket_size, bucket_bytes(ca));
901 sysfs_print(first_bucket, ca->mi.first_bucket);
902 sysfs_print(nbuckets, ca->mi.nbuckets);
903 sysfs_print(durability, ca->mi.durability);
904 sysfs_print(discard, ca->mi.discard);
906 if (attr == &sysfs_label) {
908 bch2_disk_path_to_text(out, c, ca->mi.group - 1);
912 if (attr == &sysfs_has_data) {
913 prt_bitflags(out, bch2_data_types, bch2_dev_has_data(c, ca));
917 if (attr == &sysfs_state_rw) {
918 prt_string_option(out, bch2_member_states, ca->mi.state);
922 if (attr == &sysfs_io_done)
923 dev_io_done_to_text(out, ca);
925 if (attr == &sysfs_io_errors)
926 bch2_dev_io_errors_to_text(out, ca);
928 sysfs_print(io_latency_read, atomic64_read(&ca->cur_latency[READ]));
929 sysfs_print(io_latency_write, atomic64_read(&ca->cur_latency[WRITE]));
931 if (attr == &sysfs_io_latency_stats_read)
932 bch2_time_stats_to_text(out, &ca->io_latency[READ]);
934 if (attr == &sysfs_io_latency_stats_write)
935 bch2_time_stats_to_text(out, &ca->io_latency[WRITE]);
937 sysfs_printf(congested, "%u%%",
938 clamp(atomic_read(&ca->congested), 0, CONGESTED_MAX)
939 * 100 / CONGESTED_MAX);
941 if (attr == &sysfs_alloc_debug)
942 dev_alloc_debug_to_text(out, ca);
949 struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
950 struct bch_fs *c = ca->fs;
951 struct bch_member *mi;
953 if (attr == &sysfs_discard) {
954 bool v = strtoul_or_return(buf);
956 mutex_lock(&c->sb_lock);
957 mi = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx);
959 if (v != BCH_MEMBER_DISCARD(mi)) {
960 SET_BCH_MEMBER_DISCARD(mi, v);
963 mutex_unlock(&c->sb_lock);
966 if (attr == &sysfs_durability) {
967 u64 v = strtoul_or_return(buf);
969 mutex_lock(&c->sb_lock);
970 mi = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx);
972 if (v + 1 != BCH_MEMBER_DURABILITY(mi)) {
973 SET_BCH_MEMBER_DURABILITY(mi, v + 1);
976 mutex_unlock(&c->sb_lock);
979 if (attr == &sysfs_label) {
983 tmp = kstrdup(buf, GFP_KERNEL);
987 ret = bch2_dev_group_set(c, ca, strim(tmp));
993 if (attr == &sysfs_io_errors_reset)
994 bch2_dev_errors_reset(ca);
1000 struct attribute *bch2_dev_files[] = {
1003 &sysfs_first_bucket,
1015 &sysfs_io_errors_reset,
1017 &sysfs_io_latency_read,
1018 &sysfs_io_latency_write,
1019 &sysfs_io_latency_stats_read,
1020 &sysfs_io_latency_stats_write,
1028 #endif /* _BCACHEFS_SYSFS_H_ */