2 * bcache sysfs interfaces
4 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
5 * Copyright 2012 Google, Inc.
12 #include "btree_cache.h"
13 #include "btree_iter.h"
14 #include "btree_update.h"
25 #include <linux/blkdev.h>
26 #include <linux/sort.h>
27 #include <linux/sched/clock.h>
31 #define SYSFS_OPS(type) \
32 struct sysfs_ops type ## _sysfs_ops = { \
33 .show = type ## _show, \
34 .store = type ## _store \
38 static ssize_t fn ## _show(struct kobject *kobj, struct attribute *attr,\
42 static ssize_t fn ## _store(struct kobject *kobj, struct attribute *attr,\
43 const char *buf, size_t size) \
45 #define __sysfs_attribute(_name, _mode) \
46 static struct attribute sysfs_##_name = \
47 { .name = #_name, .mode = _mode }
49 #define write_attribute(n) __sysfs_attribute(n, S_IWUSR)
50 #define read_attribute(n) __sysfs_attribute(n, S_IRUGO)
51 #define rw_attribute(n) __sysfs_attribute(n, S_IRUGO|S_IWUSR)
53 #define sysfs_printf(file, fmt, ...) \
55 if (attr == &sysfs_ ## file) \
56 return snprintf(buf, PAGE_SIZE, fmt "\n", __VA_ARGS__); \
59 #define sysfs_print(file, var) \
61 if (attr == &sysfs_ ## file) \
62 return snprint(buf, PAGE_SIZE, var); \
65 #define sysfs_hprint(file, val) \
67 if (attr == &sysfs_ ## file) { \
68 ssize_t ret = bch2_hprint(buf, val); \
74 #define var_printf(_var, fmt) sysfs_printf(_var, fmt, var(_var))
75 #define var_print(_var) sysfs_print(_var, var(_var))
76 #define var_hprint(_var) sysfs_hprint(_var, var(_var))
78 #define sysfs_strtoul(file, var) \
80 if (attr == &sysfs_ ## file) \
81 return strtoul_safe(buf, var) ?: (ssize_t) size; \
84 #define sysfs_strtoul_clamp(file, var, min, max) \
86 if (attr == &sysfs_ ## file) \
87 return strtoul_safe_clamp(buf, var, min, max) \
91 #define strtoul_or_return(cp) \
94 int _r = kstrtoul(cp, 10, &_v); \
100 #define strtoul_restrict_or_return(cp, min, max) \
102 unsigned long __v = 0; \
103 int _r = strtoul_safe_restrict(cp, __v, min, max); \
109 #define strtoi_h_or_return(cp) \
112 int _r = strtoi_h(cp, &_v); \
118 #define sysfs_hatoi(file, var) \
120 if (attr == &sysfs_ ## file) \
121 return strtoi_h(buf, &var) ?: (ssize_t) size; \
124 write_attribute(trigger_journal_flush);
125 write_attribute(trigger_btree_coalesce);
126 write_attribute(trigger_gc);
127 write_attribute(prune_cache);
128 rw_attribute(btree_gc_periodic);
130 read_attribute(uuid);
131 read_attribute(minor);
132 read_attribute(bucket_size);
133 read_attribute(block_size);
134 read_attribute(btree_node_size);
135 read_attribute(first_bucket);
136 read_attribute(nbuckets);
137 read_attribute(read_priority_stats);
138 read_attribute(write_priority_stats);
139 read_attribute(fragmentation_stats);
140 read_attribute(oldest_gen_stats);
141 read_attribute(reserve_stats);
142 read_attribute(btree_cache_size);
143 read_attribute(compression_stats);
144 read_attribute(written);
145 read_attribute(btree_written);
146 read_attribute(metadata_written);
147 read_attribute(journal_debug);
148 read_attribute(journal_pins);
150 read_attribute(internal_uuid);
152 read_attribute(available_buckets);
153 read_attribute(free_buckets);
154 read_attribute(dirty_data);
155 read_attribute(dirty_bytes);
156 read_attribute(dirty_buckets);
157 read_attribute(cached_data);
158 read_attribute(cached_bytes);
159 read_attribute(cached_buckets);
160 read_attribute(meta_buckets);
161 read_attribute(alloc_buckets);
162 read_attribute(has_data);
163 read_attribute(has_metadata);
164 read_attribute(alloc_debug);
166 read_attribute(read_realloc_races);
168 rw_attribute(journal_write_delay_ms);
169 rw_attribute(journal_reclaim_delay_ms);
171 rw_attribute(discard);
172 rw_attribute(cache_replacement_policy);
174 rw_attribute(foreground_write_ratelimit_enabled);
175 rw_attribute(copy_gc_enabled);
176 sysfs_pd_controller_attribute(copy_gc);
179 rw_attribute(tiering_enabled);
180 rw_attribute(tiering_percent);
181 sysfs_pd_controller_attribute(tiering);
183 sysfs_pd_controller_attribute(foreground_write);
185 rw_attribute(pd_controllers_update_seconds);
187 rw_attribute(foreground_target_percent);
189 read_attribute(meta_replicas_have);
190 read_attribute(data_replicas_have);
192 #define BCH_DEBUG_PARAM(name, description) \
196 #undef BCH_DEBUG_PARAM
198 #define BCH_OPT(_name, _mode, ...) \
199 static struct attribute sysfs_opt_##_name = { \
200 .name = #_name, .mode = _mode, \
206 #define BCH_TIME_STAT(name, frequency_units, duration_units) \
207 sysfs_time_stats_attribute(name, frequency_units, duration_units);
211 static struct attribute sysfs_state_rw = {
216 static size_t bch2_btree_cache_size(struct bch_fs *c)
221 mutex_lock(&c->btree_cache_lock);
222 list_for_each_entry(b, &c->btree_cache, list)
223 ret += btree_bytes(c);
225 mutex_unlock(&c->btree_cache_lock);
229 static ssize_t show_fs_alloc_debug(struct bch_fs *c, char *buf)
231 struct bch_fs_usage stats = bch2_fs_usage_read(c);
233 return scnprintf(buf, PAGE_SIZE,
234 "capacity:\t\t%llu\n"
238 "\tcached:\t\t%llu\n"
242 "\tcached:\t\t%llu\n"
243 "persistent reserved sectors:\t%llu\n"
244 "online reserved sectors:\t%llu\n",
246 stats.s[S_COMPRESSED][S_META],
247 stats.s[S_COMPRESSED][S_DIRTY],
248 stats.s[S_COMPRESSED][S_CACHED],
249 stats.s[S_UNCOMPRESSED][S_META],
250 stats.s[S_UNCOMPRESSED][S_DIRTY],
251 stats.s[S_UNCOMPRESSED][S_CACHED],
252 stats.persistent_reserved,
253 stats.online_reserved);
256 static ssize_t bch2_compression_stats(struct bch_fs *c, char *buf)
258 struct btree_iter iter;
260 u64 nr_uncompressed_extents = 0, uncompressed_sectors = 0,
261 nr_compressed_extents = 0,
262 compressed_sectors_compressed = 0,
263 compressed_sectors_uncompressed = 0;
265 if (!bch2_fs_running(c))
268 for_each_btree_key(&iter, c, BTREE_ID_EXTENTS, POS_MIN, 0, k)
269 if (k.k->type == BCH_EXTENT) {
270 struct bkey_s_c_extent e = bkey_s_c_to_extent(k);
271 const struct bch_extent_ptr *ptr;
272 const union bch_extent_crc *crc;
274 extent_for_each_ptr_crc(e, ptr, crc) {
275 if (crc_compression_type(crc) == BCH_COMPRESSION_NONE) {
276 nr_uncompressed_extents++;
277 uncompressed_sectors += e.k->size;
279 nr_compressed_extents++;
280 compressed_sectors_compressed +=
281 crc_compressed_size(e.k, crc);
282 compressed_sectors_uncompressed +=
283 crc_uncompressed_size(e.k, crc);
286 /* only looking at the first ptr */
290 bch2_btree_iter_unlock(&iter);
292 return snprintf(buf, PAGE_SIZE,
293 "uncompressed data:\n"
294 " nr extents: %llu\n"
295 " size (bytes): %llu\n"
297 " nr extents: %llu\n"
298 " compressed size (bytes): %llu\n"
299 " uncompressed size (bytes): %llu\n",
300 nr_uncompressed_extents,
301 uncompressed_sectors << 9,
302 nr_compressed_extents,
303 compressed_sectors_compressed << 9,
304 compressed_sectors_uncompressed << 9);
309 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
311 sysfs_print(minor, c->minor);
312 sysfs_printf(internal_uuid, "%pU", c->sb.uuid.b);
314 sysfs_print(journal_write_delay_ms, c->journal.write_delay_ms);
315 sysfs_print(journal_reclaim_delay_ms, c->journal.reclaim_delay_ms);
317 sysfs_print(block_size, block_bytes(c));
318 sysfs_print(btree_node_size, btree_bytes(c));
319 sysfs_hprint(btree_cache_size, bch2_btree_cache_size(c));
321 sysfs_print(read_realloc_races,
322 atomic_long_read(&c->read_realloc_races));
324 sysfs_printf(btree_gc_periodic, "%u", (int) c->btree_gc_periodic);
326 sysfs_printf(foreground_write_ratelimit_enabled, "%i",
327 c->foreground_write_ratelimit_enabled);
328 sysfs_printf(copy_gc_enabled, "%i", c->copy_gc_enabled);
329 sysfs_pd_controller_show(foreground_write, &c->foreground_write_pd);
331 sysfs_print(pd_controllers_update_seconds,
332 c->pd_controllers_update_seconds);
333 sysfs_print(foreground_target_percent, c->foreground_target_percent);
335 sysfs_printf(tiering_enabled, "%i", c->tiering_enabled);
336 sysfs_print(tiering_percent, c->tiering_percent);
338 sysfs_pd_controller_show(tiering, &c->tiers[1].pd); /* XXX */
340 sysfs_printf(meta_replicas_have, "%u", c->sb.meta_replicas_have);
341 sysfs_printf(data_replicas_have, "%u", c->sb.data_replicas_have);
345 if (attr == &sysfs_alloc_debug)
346 return show_fs_alloc_debug(c, buf);
348 if (attr == &sysfs_journal_debug)
349 return bch2_journal_print_debug(&c->journal, buf);
351 if (attr == &sysfs_journal_pins)
352 return bch2_journal_print_pins(&c->journal, buf);
354 if (attr == &sysfs_compression_stats)
355 return bch2_compression_stats(c, buf);
357 #define BCH_DEBUG_PARAM(name, description) sysfs_print(name, c->name);
359 #undef BCH_DEBUG_PARAM
366 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
368 sysfs_strtoul(journal_write_delay_ms, c->journal.write_delay_ms);
369 sysfs_strtoul(journal_reclaim_delay_ms, c->journal.reclaim_delay_ms);
371 sysfs_strtoul(foreground_write_ratelimit_enabled,
372 c->foreground_write_ratelimit_enabled);
374 if (attr == &sysfs_btree_gc_periodic) {
375 ssize_t ret = strtoul_safe(buf, c->btree_gc_periodic)
378 wake_up_process(c->gc_thread);
382 if (attr == &sysfs_copy_gc_enabled) {
385 ssize_t ret = strtoul_safe(buf, c->copy_gc_enabled)
388 for_each_member_device(ca, c, i)
389 if (ca->moving_gc_read)
390 wake_up_process(ca->moving_gc_read);
394 if (attr == &sysfs_tiering_enabled) {
395 ssize_t ret = strtoul_safe(buf, c->tiering_enabled)
398 bch2_tiering_start(c); /* issue wakeups */
402 sysfs_pd_controller_store(foreground_write, &c->foreground_write_pd);
404 sysfs_strtoul(pd_controllers_update_seconds,
405 c->pd_controllers_update_seconds);
406 sysfs_strtoul(foreground_target_percent, c->foreground_target_percent);
408 sysfs_strtoul(tiering_percent, c->tiering_percent);
409 sysfs_pd_controller_store(tiering, &c->tiers[1].pd); /* XXX */
413 #define BCH_DEBUG_PARAM(name, description) sysfs_strtoul(name, c->name);
415 #undef BCH_DEBUG_PARAM
417 if (!bch2_fs_running(c))
422 if (attr == &sysfs_trigger_journal_flush)
423 bch2_journal_meta_async(&c->journal, NULL);
425 if (attr == &sysfs_trigger_btree_coalesce)
428 if (attr == &sysfs_trigger_gc)
431 if (attr == &sysfs_prune_cache) {
432 struct shrink_control sc;
434 sc.gfp_mask = GFP_KERNEL;
435 sc.nr_to_scan = strtoul_or_return(buf);
436 c->btree_cache_shrink.scan_objects(&c->btree_cache_shrink, &sc);
444 struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
446 mutex_lock(&c->state_lock);
447 size = __bch2_fs_store(kobj, attr, buf, size);
448 mutex_unlock(&c->state_lock);
454 struct attribute *bch2_fs_files[] = {
457 &sysfs_btree_node_size,
458 &sysfs_btree_cache_size,
460 &sysfs_meta_replicas_have,
461 &sysfs_data_replicas_have,
463 &sysfs_journal_write_delay_ms,
464 &sysfs_journal_reclaim_delay_ms,
466 &sysfs_foreground_target_percent,
467 &sysfs_tiering_percent,
469 &sysfs_compression_stats,
473 /* internal dir - just a wrapper */
475 SHOW(bch2_fs_internal)
477 struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
478 return bch2_fs_show(&c->kobj, attr, buf);
481 STORE(bch2_fs_internal)
483 struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
484 return bch2_fs_store(&c->kobj, attr, buf, size);
486 SYSFS_OPS(bch2_fs_internal);
488 struct attribute *bch2_fs_internal_files[] = {
490 &sysfs_journal_debug,
493 &sysfs_read_realloc_races,
495 &sysfs_trigger_journal_flush,
496 &sysfs_trigger_btree_coalesce,
500 &sysfs_foreground_write_ratelimit_enabled,
501 &sysfs_copy_gc_enabled,
502 &sysfs_tiering_enabled,
503 sysfs_pd_controller_files(tiering),
504 sysfs_pd_controller_files(foreground_write),
505 &sysfs_internal_uuid,
507 #define BCH_DEBUG_PARAM(name, description) &sysfs_##name,
509 #undef BCH_DEBUG_PARAM
516 SHOW(bch2_fs_opts_dir)
518 struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
520 return bch2_opt_show(&c->opts, attr->name, buf, PAGE_SIZE);
523 STORE(bch2_fs_opts_dir)
525 struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
526 const struct bch_option *opt;
530 id = bch2_parse_sysfs_opt(attr->name, buf, &v);
534 opt = &bch2_opt_table[id];
536 mutex_lock(&c->sb_lock);
538 if (id == Opt_compression) {
539 int ret = bch2_check_set_has_compressed_data(c, v);
541 mutex_unlock(&c->sb_lock);
546 if (opt->set_sb != SET_NO_SB_OPT) {
547 opt->set_sb(c->disk_sb, v);
551 bch2_opt_set(&c->opts, id, v);
553 mutex_unlock(&c->sb_lock);
557 SYSFS_OPS(bch2_fs_opts_dir);
559 struct attribute *bch2_fs_opts_dir_files[] = {
560 #define BCH_OPT(_name, ...) \
571 SHOW(bch2_fs_time_stats)
573 struct bch_fs *c = container_of(kobj, struct bch_fs, time_stats);
575 #define BCH_TIME_STAT(name, frequency_units, duration_units) \
576 sysfs_print_time_stats(&c->name##_time, name, \
577 frequency_units, duration_units);
584 STORE(bch2_fs_time_stats)
586 struct bch_fs *c = container_of(kobj, struct bch_fs, time_stats);
588 #define BCH_TIME_STAT(name, frequency_units, duration_units) \
589 sysfs_clear_time_stats(&c->name##_time, name);
595 SYSFS_OPS(bch2_fs_time_stats);
597 struct attribute *bch2_fs_time_stats_files[] = {
598 #define BCH_TIME_STAT(name, frequency_units, duration_units) \
599 sysfs_time_stats_attribute_list(name, frequency_units, duration_units)
606 typedef unsigned (bucket_map_fn)(struct bch_dev *, struct bucket *, void *);
608 static unsigned bucket_priority_fn(struct bch_dev *ca, struct bucket *g,
611 int rw = (private ? 1 : 0);
613 return ca->fs->prio_clock[rw].hand - g->prio[rw];
616 static unsigned bucket_sectors_used_fn(struct bch_dev *ca, struct bucket *g,
619 return bucket_sectors_used(g->mark);
622 static unsigned bucket_oldest_gen_fn(struct bch_dev *ca, struct bucket *g,
625 return bucket_gc_gen(ca, g);
628 static ssize_t show_quantiles(struct bch_dev *ca, char *buf,
629 bucket_map_fn *fn, void *private)
631 int cmp(const void *l, const void *r)
632 { return *((unsigned *) r) - *((unsigned *) l); }
634 size_t n = ca->mi.nbuckets, i;
635 /* Compute 31 quantiles */
639 p = vzalloc(ca->mi.nbuckets * sizeof(unsigned));
643 for (i = ca->mi.first_bucket; i < n; i++)
644 p[i] = fn(ca, &ca->buckets[i], private);
646 sort(p, n, sizeof(unsigned), cmp, NULL);
652 for (i = 0; i < ARRAY_SIZE(q); i++)
653 q[i] = p[n * (i + 1) / (ARRAY_SIZE(q) + 1)];
657 for (i = 0; i < ARRAY_SIZE(q); i++)
658 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
666 static ssize_t show_reserve_stats(struct bch_dev *ca, char *buf)
668 enum alloc_reserve i;
671 spin_lock(&ca->freelist_lock);
673 ret = scnprintf(buf, PAGE_SIZE,
674 "free_inc:\t%zu\t%zu\n",
675 fifo_used(&ca->free_inc),
678 for (i = 0; i < RESERVE_NR; i++)
679 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
680 "free[%u]:\t%zu\t%zu\n", i,
681 fifo_used(&ca->free[i]),
684 spin_unlock(&ca->freelist_lock);
689 static ssize_t show_dev_alloc_debug(struct bch_dev *ca, char *buf)
691 struct bch_fs *c = ca->fs;
692 struct bch_dev_usage stats = bch2_dev_usage_read(ca);
694 return scnprintf(buf, PAGE_SIZE,
695 "free_inc: %zu/%zu\n"
696 "free[RESERVE_PRIO]: %zu/%zu\n"
697 "free[RESERVE_BTREE]: %zu/%zu\n"
698 "free[RESERVE_MOVINGGC]: %zu/%zu\n"
699 "free[RESERVE_NONE]: %zu/%zu\n"
703 "available: %llu/%llu\n"
704 "freelist_wait: %s\n"
705 "open buckets: %u/%u (reserved %u)\n"
706 "open_buckets_wait: %s\n",
707 fifo_used(&ca->free_inc), ca->free_inc.size,
708 fifo_used(&ca->free[RESERVE_PRIO]), ca->free[RESERVE_PRIO].size,
709 fifo_used(&ca->free[RESERVE_BTREE]), ca->free[RESERVE_BTREE].size,
710 fifo_used(&ca->free[RESERVE_MOVINGGC]), ca->free[RESERVE_MOVINGGC].size,
711 fifo_used(&ca->free[RESERVE_NONE]), ca->free[RESERVE_NONE].size,
712 stats.buckets_alloc, ca->mi.nbuckets - ca->mi.first_bucket,
713 stats.buckets_meta, ca->mi.nbuckets - ca->mi.first_bucket,
714 stats.buckets_dirty, ca->mi.nbuckets - ca->mi.first_bucket,
715 __dev_buckets_available(ca, stats), ca->mi.nbuckets - ca->mi.first_bucket,
716 c->freelist_wait.list.first ? "waiting" : "empty",
717 c->open_buckets_nr_free, OPEN_BUCKETS_COUNT, BTREE_NODE_RESERVE,
718 c->open_buckets_wait.list.first ? "waiting" : "empty");
721 static u64 sectors_written(struct bch_dev *ca)
726 for_each_possible_cpu(cpu)
727 ret += *per_cpu_ptr(ca->sectors_written, cpu);
734 struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
735 struct bch_fs *c = ca->fs;
736 struct bch_dev_usage stats = bch2_dev_usage_read(ca);
738 sysfs_printf(uuid, "%pU\n", ca->uuid.b);
740 sysfs_print(bucket_size, bucket_bytes(ca));
741 sysfs_print(block_size, block_bytes(c));
742 sysfs_print(first_bucket, ca->mi.first_bucket);
743 sysfs_print(nbuckets, ca->mi.nbuckets);
744 sysfs_print(discard, ca->mi.discard);
745 sysfs_hprint(written, sectors_written(ca) << 9);
746 sysfs_hprint(btree_written,
747 atomic64_read(&ca->btree_sectors_written) << 9);
748 sysfs_hprint(metadata_written,
749 (atomic64_read(&ca->meta_sectors_written) +
750 atomic64_read(&ca->btree_sectors_written)) << 9);
752 sysfs_hprint(dirty_data, stats.sectors[S_DIRTY] << 9);
753 sysfs_print(dirty_bytes, stats.sectors[S_DIRTY] << 9);
754 sysfs_print(dirty_buckets, stats.buckets_dirty);
755 sysfs_hprint(cached_data, stats.sectors[S_CACHED] << 9);
756 sysfs_print(cached_bytes, stats.sectors[S_CACHED] << 9);
757 sysfs_print(cached_buckets, stats.buckets_cached);
758 sysfs_print(meta_buckets, stats.buckets_meta);
759 sysfs_print(alloc_buckets, stats.buckets_alloc);
760 sysfs_print(available_buckets, dev_buckets_available(ca));
761 sysfs_print(free_buckets, dev_buckets_free(ca));
762 sysfs_print(has_data, ca->mi.has_data);
763 sysfs_print(has_metadata, ca->mi.has_metadata);
765 sysfs_pd_controller_show(copy_gc, &ca->moving_gc_pd);
767 if (attr == &sysfs_cache_replacement_policy)
768 return bch2_snprint_string_list(buf, PAGE_SIZE,
769 bch2_cache_replacement_policies,
772 sysfs_print(tier, ca->mi.tier);
774 if (attr == &sysfs_state_rw)
775 return bch2_snprint_string_list(buf, PAGE_SIZE,
779 if (attr == &sysfs_read_priority_stats)
780 return show_quantiles(ca, buf, bucket_priority_fn, (void *) 0);
781 if (attr == &sysfs_write_priority_stats)
782 return show_quantiles(ca, buf, bucket_priority_fn, (void *) 1);
783 if (attr == &sysfs_fragmentation_stats)
784 return show_quantiles(ca, buf, bucket_sectors_used_fn, NULL);
785 if (attr == &sysfs_oldest_gen_stats)
786 return show_quantiles(ca, buf, bucket_oldest_gen_fn, NULL);
787 if (attr == &sysfs_reserve_stats)
788 return show_reserve_stats(ca, buf);
789 if (attr == &sysfs_alloc_debug)
790 return show_dev_alloc_debug(ca, buf);
797 struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
798 struct bch_fs *c = ca->fs;
799 struct bch_member *mi;
801 sysfs_pd_controller_store(copy_gc, &ca->moving_gc_pd);
803 if (attr == &sysfs_discard) {
804 bool v = strtoul_or_return(buf);
806 mutex_lock(&c->sb_lock);
807 mi = &bch2_sb_get_members(c->disk_sb)->members[ca->dev_idx];
809 if (v != BCH_MEMBER_DISCARD(mi)) {
810 SET_BCH_MEMBER_DISCARD(mi, v);
813 mutex_unlock(&c->sb_lock);
816 if (attr == &sysfs_cache_replacement_policy) {
817 ssize_t v = bch2_read_string_list(buf, bch2_cache_replacement_policies);
822 mutex_lock(&c->sb_lock);
823 mi = &bch2_sb_get_members(c->disk_sb)->members[ca->dev_idx];
825 if ((unsigned) v != BCH_MEMBER_REPLACEMENT(mi)) {
826 SET_BCH_MEMBER_REPLACEMENT(mi, v);
829 mutex_unlock(&c->sb_lock);
832 if (attr == &sysfs_tier) {
834 unsigned v = strtoul_restrict_or_return(buf,
835 0, BCH_TIER_MAX - 1);
837 mutex_lock(&c->sb_lock);
838 prev_tier = ca->mi.tier;
840 if (v == ca->mi.tier) {
841 mutex_unlock(&c->sb_lock);
845 mi = &bch2_sb_get_members(c->disk_sb)->members[ca->dev_idx];
846 SET_BCH_MEMBER_TIER(mi, v);
849 bch2_dev_group_remove(&c->tiers[prev_tier].devs, ca);
850 bch2_dev_group_add(&c->tiers[ca->mi.tier].devs, ca);
851 mutex_unlock(&c->sb_lock);
853 bch2_recalc_capacity(c);
854 bch2_tiering_start(c);
861 struct attribute *bch2_dev_files[] = {
870 &sysfs_cache_replacement_policy,
879 &sysfs_btree_written,
880 &sysfs_metadata_written,
882 /* alloc info - data: */
888 /* alloc info - buckets: */
889 &sysfs_available_buckets,
891 &sysfs_dirty_buckets,
892 &sysfs_cached_buckets,
894 &sysfs_alloc_buckets,
896 /* alloc info - other stats: */
897 &sysfs_read_priority_stats,
898 &sysfs_write_priority_stats,
899 &sysfs_fragmentation_stats,
900 &sysfs_oldest_gen_stats,
901 &sysfs_reserve_stats,
906 sysfs_pd_controller_files(copy_gc),