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(write_points);
198 read_attribute(nocow_lock_table);
200 #ifdef BCH_WRITE_REF_DEBUG
201 read_attribute(write_refs);
203 const char * const bch2_write_refs[] = {
210 static void bch2_write_refs_to_text(struct printbuf *out, struct bch_fs *c)
212 bch2_printbuf_tabstop_push(out, 24);
214 for (unsigned i = 0; i < ARRAY_SIZE(c->writes); i++) {
215 prt_str(out, bch2_write_refs[i]);
217 prt_printf(out, "%li", atomic_long_read(&c->writes[i]));
223 read_attribute(internal_uuid);
225 read_attribute(has_data);
226 read_attribute(alloc_debug);
228 #define x(t, n, ...) read_attribute(t);
229 BCH_PERSISTENT_COUNTERS()
232 rw_attribute(discard);
235 rw_attribute(copy_gc_enabled);
236 read_attribute(copy_gc_wait);
238 rw_attribute(rebalance_enabled);
239 sysfs_pd_controller_attribute(rebalance);
240 read_attribute(rebalance_work);
241 rw_attribute(promote_whole_extents);
243 read_attribute(new_stripes);
245 read_attribute(io_timers_read);
246 read_attribute(io_timers_write);
248 read_attribute(data_jobs);
250 #ifdef CONFIG_BCACHEFS_TESTS
251 write_attribute(perf_test);
252 #endif /* CONFIG_BCACHEFS_TESTS */
255 static struct attribute sysfs_time_stat_##_name = \
256 { .name = #_name, .mode = 0444 };
260 static struct attribute sysfs_state_rw = {
265 static size_t bch2_btree_cache_size(struct bch_fs *c)
270 mutex_lock(&c->btree_cache.lock);
271 list_for_each_entry(b, &c->btree_cache.live, list)
272 ret += btree_bytes(c);
274 mutex_unlock(&c->btree_cache.lock);
278 static long data_progress_to_text(struct printbuf *out, struct bch_fs *c)
281 struct bch_move_stats *stats;
283 mutex_lock(&c->data_progress_lock);
284 list_for_each_entry(stats, &c->data_progress_list, list) {
285 prt_printf(out, "%s: data type %s btree_id %s position: ",
287 bch2_data_types[stats->data_type],
288 bch2_btree_ids[stats->btree_id]);
289 bch2_bpos_to_text(out, stats->pos);
290 prt_printf(out, "%s", "\n");
293 mutex_unlock(&c->data_progress_lock);
297 static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c)
299 struct btree_trans trans;
300 struct btree_iter iter;
303 u64 nr_uncompressed_extents = 0,
304 nr_compressed_extents = 0,
305 nr_incompressible_extents = 0,
306 uncompressed_sectors = 0,
307 incompressible_sectors = 0,
308 compressed_sectors_compressed = 0,
309 compressed_sectors_uncompressed = 0;
312 if (!test_bit(BCH_FS_STARTED, &c->flags))
315 bch2_trans_init(&trans, c, 0, 0);
317 for (id = 0; id < BTREE_ID_NR; id++) {
318 if (!btree_type_has_ptrs(id))
321 for_each_btree_key(&trans, iter, id, POS_MIN,
322 BTREE_ITER_ALL_SNAPSHOTS, k, ret) {
323 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
324 const union bch_extent_entry *entry;
325 struct extent_ptr_decoded p;
326 bool compressed = false, uncompressed = false, incompressible = false;
328 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
329 switch (p.crc.compression_type) {
330 case BCH_COMPRESSION_TYPE_none:
332 uncompressed_sectors += k.k->size;
334 case BCH_COMPRESSION_TYPE_incompressible:
335 incompressible = true;
336 incompressible_sectors += k.k->size;
339 compressed_sectors_compressed +=
340 p.crc.compressed_size;
341 compressed_sectors_uncompressed +=
342 p.crc.uncompressed_size;
349 nr_incompressible_extents++;
350 else if (uncompressed)
351 nr_uncompressed_extents++;
353 nr_compressed_extents++;
355 bch2_trans_iter_exit(&trans, &iter);
358 bch2_trans_exit(&trans);
363 prt_printf(out, "uncompressed:\n");
364 prt_printf(out, " nr extents: %llu\n", nr_uncompressed_extents);
365 prt_printf(out, " size: ");
366 prt_human_readable_u64(out, uncompressed_sectors << 9);
367 prt_printf(out, "\n");
369 prt_printf(out, "compressed:\n");
370 prt_printf(out, " nr extents: %llu\n", nr_compressed_extents);
371 prt_printf(out, " compressed size: ");
372 prt_human_readable_u64(out, compressed_sectors_compressed << 9);
373 prt_printf(out, "\n");
374 prt_printf(out, " uncompressed size: ");
375 prt_human_readable_u64(out, compressed_sectors_uncompressed << 9);
376 prt_printf(out, "\n");
378 prt_printf(out, "incompressible:\n");
379 prt_printf(out, " nr extents: %llu\n", nr_incompressible_extents);
380 prt_printf(out, " size: ");
381 prt_human_readable_u64(out, incompressible_sectors << 9);
382 prt_printf(out, "\n");
386 static void bch2_gc_gens_pos_to_text(struct printbuf *out, struct bch_fs *c)
388 prt_printf(out, "%s: ", bch2_btree_ids[c->gc_gens_btree]);
389 bch2_bpos_to_text(out, c->gc_gens_pos);
390 prt_printf(out, "\n");
393 static void bch2_btree_wakeup_all(struct bch_fs *c)
395 struct btree_trans *trans;
397 mutex_lock(&c->btree_trans_lock);
398 list_for_each_entry(trans, &c->btree_trans_list, list) {
399 struct btree_bkey_cached_common *b = READ_ONCE(trans->locking);
402 six_lock_wakeup_all(&b->lock);
405 mutex_unlock(&c->btree_trans_lock);
410 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
412 sysfs_print(minor, c->minor);
413 sysfs_printf(internal_uuid, "%pU", c->sb.uuid.b);
415 sysfs_hprint(btree_cache_size, bch2_btree_cache_size(c));
417 if (attr == &sysfs_btree_write_stats)
418 bch2_btree_write_stats_to_text(out, c);
420 sysfs_printf(btree_gc_periodic, "%u", (int) c->btree_gc_periodic);
422 if (attr == &sysfs_gc_gens_pos)
423 bch2_gc_gens_pos_to_text(out, c);
425 sysfs_printf(copy_gc_enabled, "%i", c->copy_gc_enabled);
427 sysfs_printf(rebalance_enabled, "%i", c->rebalance.enabled);
428 sysfs_pd_controller_show(rebalance, &c->rebalance.pd); /* XXX */
429 sysfs_hprint(copy_gc_wait,
430 max(0LL, c->copygc_wait -
431 atomic64_read(&c->io_clock[WRITE].now)) << 9);
433 if (attr == &sysfs_rebalance_work)
434 bch2_rebalance_work_to_text(out, c);
436 sysfs_print(promote_whole_extents, c->promote_whole_extents);
440 if (attr == &sysfs_journal_debug)
441 bch2_journal_debug_to_text(out, &c->journal);
443 if (attr == &sysfs_btree_updates)
444 bch2_btree_updates_to_text(out, c);
446 if (attr == &sysfs_btree_cache)
447 bch2_btree_cache_to_text(out, &c->btree_cache);
449 if (attr == &sysfs_btree_key_cache)
450 bch2_btree_key_cache_to_text(out, &c->btree_key_cache);
452 if (attr == &sysfs_stripes_heap)
453 bch2_stripes_heap_to_text(out, c);
455 if (attr == &sysfs_open_buckets)
456 bch2_open_buckets_to_text(out, c);
458 if (attr == &sysfs_write_points)
459 bch2_write_points_to_text(out, c);
461 if (attr == &sysfs_compression_stats)
462 bch2_compression_stats_to_text(out, c);
464 if (attr == &sysfs_new_stripes)
465 bch2_new_stripes_to_text(out, c);
467 if (attr == &sysfs_io_timers_read)
468 bch2_io_timers_to_text(out, &c->io_clock[READ]);
470 if (attr == &sysfs_io_timers_write)
471 bch2_io_timers_to_text(out, &c->io_clock[WRITE]);
473 if (attr == &sysfs_data_jobs)
474 data_progress_to_text(out, c);
476 #ifdef BCH_WRITE_REF_DEBUG
477 if (attr == &sysfs_write_refs)
478 bch2_write_refs_to_text(out, c);
481 if (attr == &sysfs_nocow_lock_table)
482 bch2_nocow_locks_to_text(out, &c->nocow_locks);
489 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
491 if (attr == &sysfs_btree_gc_periodic) {
492 ssize_t ret = strtoul_safe(buf, c->btree_gc_periodic)
495 wake_up_process(c->gc_thread);
499 if (attr == &sysfs_copy_gc_enabled) {
500 ssize_t ret = strtoul_safe(buf, c->copy_gc_enabled)
503 if (c->copygc_thread)
504 wake_up_process(c->copygc_thread);
508 if (attr == &sysfs_rebalance_enabled) {
509 ssize_t ret = strtoul_safe(buf, c->rebalance.enabled)
516 sysfs_pd_controller_store(rebalance, &c->rebalance.pd);
518 sysfs_strtoul(promote_whole_extents, c->promote_whole_extents);
522 if (!test_bit(BCH_FS_STARTED, &c->flags))
527 if (!test_bit(BCH_FS_RW, &c->flags))
530 if (attr == &sysfs_prune_cache) {
531 struct shrink_control sc;
533 sc.gfp_mask = GFP_KERNEL;
534 sc.nr_to_scan = strtoul_or_return(buf);
535 c->btree_cache.shrink.scan_objects(&c->btree_cache.shrink, &sc);
538 if (attr == &sysfs_btree_wakeup)
539 bch2_btree_wakeup_all(c);
541 if (attr == &sysfs_trigger_gc) {
543 * Full gc is currently incompatible with btree key cache:
546 down_read(&c->state_lock);
547 bch2_gc(c, false, false);
548 up_read(&c->state_lock);
554 if (attr == &sysfs_trigger_discards)
557 if (attr == &sysfs_trigger_invalidates)
558 bch2_do_invalidates(c);
560 #ifdef CONFIG_BCACHEFS_TESTS
561 if (attr == &sysfs_perf_test) {
562 char *tmp = kstrdup(buf, GFP_KERNEL), *p = tmp;
563 char *test = strsep(&p, " \t\n");
564 char *nr_str = strsep(&p, " \t\n");
565 char *threads_str = strsep(&p, " \t\n");
571 !(ret = kstrtouint(threads_str, 10, &threads)) &&
572 !(ret = bch2_strtoull_h(nr_str, &nr)))
573 ret = bch2_btree_perf_test(c, test, nr, threads);
584 struct attribute *bch2_fs_files[] = {
586 &sysfs_btree_cache_size,
587 &sysfs_btree_write_stats,
589 &sysfs_promote_whole_extents,
591 &sysfs_compression_stats,
593 #ifdef CONFIG_BCACHEFS_TESTS
601 SHOW(bch2_fs_counters)
603 struct bch_fs *c = container_of(kobj, struct bch_fs, counters_kobj);
605 u64 counter_since_mount = 0;
607 printbuf_tabstop_push(out, 32);
610 if (attr == &sysfs_##t) { \
611 counter = percpu_u64_get(&c->counters[BCH_COUNTER_##t]);\
612 counter_since_mount = counter - c->counters_on_mount[BCH_COUNTER_##t];\
613 prt_printf(out, "since mount:"); \
615 prt_human_readable_u64(out, counter_since_mount << 9); \
618 prt_printf(out, "since filesystem creation:"); \
620 prt_human_readable_u64(out, counter << 9); \
623 BCH_PERSISTENT_COUNTERS()
628 STORE(bch2_fs_counters) {
632 SYSFS_OPS(bch2_fs_counters);
634 struct attribute *bch2_fs_counters_files[] = {
637 BCH_PERSISTENT_COUNTERS()
641 /* internal dir - just a wrapper */
643 SHOW(bch2_fs_internal)
645 struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
647 return bch2_fs_to_text(out, &c->kobj, attr);
650 STORE(bch2_fs_internal)
652 struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
654 return bch2_fs_store(&c->kobj, attr, buf, size);
656 SYSFS_OPS(bch2_fs_internal);
658 struct attribute *bch2_fs_internal_files[] = {
659 &sysfs_journal_debug,
660 &sysfs_btree_updates,
662 &sysfs_btree_key_cache,
667 #ifdef BCH_WRITE_REF_DEBUG
670 &sysfs_nocow_lock_table,
671 &sysfs_io_timers_read,
672 &sysfs_io_timers_write,
675 &sysfs_trigger_discards,
676 &sysfs_trigger_invalidates,
682 &sysfs_copy_gc_enabled,
685 &sysfs_rebalance_enabled,
686 &sysfs_rebalance_work,
687 sysfs_pd_controller_files(rebalance),
691 &sysfs_internal_uuid,
697 SHOW(bch2_fs_opts_dir)
699 struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
700 const struct bch_option *opt = container_of(attr, struct bch_option, attr);
701 int id = opt - bch2_opt_table;
702 u64 v = bch2_opt_get_by_id(&c->opts, id);
704 bch2_opt_to_text(out, c, c->disk_sb.sb, opt, v, OPT_SHOW_FULL_LIST);
710 STORE(bch2_fs_opts_dir)
712 struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
713 const struct bch_option *opt = container_of(attr, struct bch_option, attr);
714 int ret, id = opt - bch2_opt_table;
719 * We don't need to take c->writes for correctness, but it eliminates an
720 * unsightly error message in the dmesg log when we're RO:
722 if (unlikely(!bch2_write_ref_tryget(c, BCH_WRITE_REF_sysfs)))
725 tmp = kstrdup(buf, GFP_KERNEL);
731 ret = bch2_opt_parse(c, opt, strim(tmp), &v, NULL);
737 ret = bch2_opt_check_may_set(c, id, v);
741 bch2_opt_set_sb(c, opt, v);
742 bch2_opt_set_by_id(&c->opts, id, v);
744 if ((id == Opt_background_target ||
745 id == Opt_background_compression) && v) {
746 bch2_rebalance_add_work(c, S64_MAX);
752 bch2_write_ref_put(c, BCH_WRITE_REF_sysfs);
755 SYSFS_OPS(bch2_fs_opts_dir);
757 struct attribute *bch2_fs_opts_dir_files[] = { NULL };
759 int bch2_opts_create_sysfs_files(struct kobject *kobj)
761 const struct bch_option *i;
764 for (i = bch2_opt_table;
765 i < bch2_opt_table + bch2_opts_nr;
767 if (!(i->flags & OPT_FS))
770 ret = sysfs_create_file(kobj, &i->attr);
780 SHOW(bch2_fs_time_stats)
782 struct bch_fs *c = container_of(kobj, struct bch_fs, time_stats);
785 if (attr == &sysfs_time_stat_##name) \
786 bch2_time_stats_to_text(out, &c->times[BCH_TIME_##name]);
793 STORE(bch2_fs_time_stats)
797 SYSFS_OPS(bch2_fs_time_stats);
799 struct attribute *bch2_fs_time_stats_files[] = {
801 &sysfs_time_stat_##name,
807 static void dev_alloc_debug_to_text(struct printbuf *out, struct bch_dev *ca)
809 struct bch_fs *c = ca->fs;
810 struct bch_dev_usage stats = bch2_dev_usage_read(ca);
811 unsigned i, nr[BCH_DATA_NR];
813 memset(nr, 0, sizeof(nr));
815 for (i = 0; i < ARRAY_SIZE(c->open_buckets); i++)
816 nr[c->open_buckets[i].data_type]++;
819 "\t\t\t buckets\t sectors fragmented\n"
820 "capacity\t%16llu\n",
821 ca->mi.nbuckets - ca->mi.first_bucket);
823 for (i = 0; i < BCH_DATA_NR; i++)
824 prt_printf(out, "%-16s%16llu%16llu%16llu\n",
825 bch2_data_types[i], stats.d[i].buckets,
826 stats.d[i].sectors, stats.d[i].fragmented);
831 "freelist_wait\t\t%s\n"
832 "open buckets allocated\t%u\n"
833 "open buckets this dev\t%u\n"
834 "open buckets total\t%u\n"
835 "open_buckets_wait\t%s\n"
836 "open_buckets_btree\t%u\n"
837 "open_buckets_user\t%u\n"
838 "buckets_to_invalidate\t%llu\n"
839 "btree reserve cache\t%u\n",
841 c->freelist_wait.list.first ? "waiting" : "empty",
842 OPEN_BUCKETS_COUNT - c->open_buckets_nr_free,
845 c->open_buckets_wait.list.first ? "waiting" : "empty",
848 should_invalidate_buckets(ca, stats),
849 c->btree_reserve_cache_nr);
852 static const char * const bch2_rw[] = {
858 static void dev_iodone_to_text(struct printbuf *out, struct bch_dev *ca)
862 for (rw = 0; rw < 2; rw++) {
863 prt_printf(out, "%s:\n", bch2_rw[rw]);
865 for (i = 1; i < BCH_DATA_NR; i++)
866 prt_printf(out, "%-12s:%12llu\n",
868 percpu_u64_get(&ca->io_done->sectors[rw][i]) << 9);
874 struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
875 struct bch_fs *c = ca->fs;
877 sysfs_printf(uuid, "%pU\n", ca->uuid.b);
879 sysfs_print(bucket_size, bucket_bytes(ca));
880 sysfs_print(first_bucket, ca->mi.first_bucket);
881 sysfs_print(nbuckets, ca->mi.nbuckets);
882 sysfs_print(durability, ca->mi.durability);
883 sysfs_print(discard, ca->mi.discard);
885 if (attr == &sysfs_label) {
887 mutex_lock(&c->sb_lock);
888 bch2_disk_path_to_text(out, c->disk_sb.sb,
890 mutex_unlock(&c->sb_lock);
896 if (attr == &sysfs_has_data) {
897 prt_bitflags(out, bch2_data_types, bch2_dev_has_data(c, ca));
901 if (attr == &sysfs_state_rw) {
902 prt_string_option(out, bch2_member_states, ca->mi.state);
906 if (attr == &sysfs_iodone)
907 dev_iodone_to_text(out, ca);
909 sysfs_print(io_latency_read, atomic64_read(&ca->cur_latency[READ]));
910 sysfs_print(io_latency_write, atomic64_read(&ca->cur_latency[WRITE]));
912 if (attr == &sysfs_io_latency_stats_read)
913 bch2_time_stats_to_text(out, &ca->io_latency[READ]);
915 if (attr == &sysfs_io_latency_stats_write)
916 bch2_time_stats_to_text(out, &ca->io_latency[WRITE]);
918 sysfs_printf(congested, "%u%%",
919 clamp(atomic_read(&ca->congested), 0, CONGESTED_MAX)
920 * 100 / CONGESTED_MAX);
922 if (attr == &sysfs_alloc_debug)
923 dev_alloc_debug_to_text(out, ca);
930 struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
931 struct bch_fs *c = ca->fs;
932 struct bch_member *mi;
934 if (attr == &sysfs_discard) {
935 bool v = strtoul_or_return(buf);
937 mutex_lock(&c->sb_lock);
938 mi = &bch2_sb_get_members(c->disk_sb.sb)->members[ca->dev_idx];
940 if (v != BCH_MEMBER_DISCARD(mi)) {
941 SET_BCH_MEMBER_DISCARD(mi, v);
944 mutex_unlock(&c->sb_lock);
947 if (attr == &sysfs_durability) {
948 u64 v = strtoul_or_return(buf);
950 mutex_lock(&c->sb_lock);
951 mi = &bch2_sb_get_members(c->disk_sb.sb)->members[ca->dev_idx];
953 if (v != BCH_MEMBER_DURABILITY(mi)) {
954 SET_BCH_MEMBER_DURABILITY(mi, v + 1);
957 mutex_unlock(&c->sb_lock);
960 if (attr == &sysfs_label) {
964 tmp = kstrdup(buf, GFP_KERNEL);
968 ret = bch2_dev_group_set(c, ca, strim(tmp));
978 struct attribute *bch2_dev_files[] = {
993 &sysfs_io_latency_read,
994 &sysfs_io_latency_write,
995 &sysfs_io_latency_stats_read,
996 &sysfs_io_latency_stats_write,
1004 #endif /* _BCACHEFS_SYSFS_H_ */