~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/bcachefs/sysfs.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/bcachefs/sysfs.c (Architecture alpha) and /fs/bcachefs/sysfs.c (Architecture ppc)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  * bcache sysfs interfaces                          3  * bcache sysfs interfaces
  4  *                                                  4  *
  5  * Copyright 2010, 2011 Kent Overstreet <kent.      5  * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
  6  * Copyright 2012 Google, Inc.                      6  * Copyright 2012 Google, Inc.
  7  */                                                 7  */
  8                                                     8 
  9 #ifndef NO_BCACHEFS_SYSFS                           9 #ifndef NO_BCACHEFS_SYSFS
 10                                                    10 
 11 #include "bcachefs.h"                              11 #include "bcachefs.h"
 12 #include "alloc_background.h"                      12 #include "alloc_background.h"
 13 #include "alloc_foreground.h"                      13 #include "alloc_foreground.h"
 14 #include "sysfs.h"                                 14 #include "sysfs.h"
 15 #include "btree_cache.h"                           15 #include "btree_cache.h"
 16 #include "btree_io.h"                              16 #include "btree_io.h"
 17 #include "btree_iter.h"                            17 #include "btree_iter.h"
 18 #include "btree_key_cache.h"                       18 #include "btree_key_cache.h"
 19 #include "btree_update.h"                          19 #include "btree_update.h"
 20 #include "btree_update_interior.h"                 20 #include "btree_update_interior.h"
 21 #include "btree_gc.h"                              21 #include "btree_gc.h"
 22 #include "buckets.h"                               22 #include "buckets.h"
 23 #include "clock.h"                                 23 #include "clock.h"
 24 #include "compress.h"                              24 #include "compress.h"
 25 #include "disk_accounting.h"                       25 #include "disk_accounting.h"
 26 #include "disk_groups.h"                           26 #include "disk_groups.h"
 27 #include "ec.h"                                    27 #include "ec.h"
 28 #include "inode.h"                                 28 #include "inode.h"
 29 #include "journal.h"                               29 #include "journal.h"
 30 #include "journal_reclaim.h"                       30 #include "journal_reclaim.h"
 31 #include "keylist.h"                               31 #include "keylist.h"
 32 #include "move.h"                                  32 #include "move.h"
 33 #include "movinggc.h"                              33 #include "movinggc.h"
 34 #include "nocow_locking.h"                         34 #include "nocow_locking.h"
 35 #include "opts.h"                                  35 #include "opts.h"
 36 #include "rebalance.h"                             36 #include "rebalance.h"
 37 #include "replicas.h"                              37 #include "replicas.h"
 38 #include "super-io.h"                              38 #include "super-io.h"
 39 #include "tests.h"                                 39 #include "tests.h"
 40                                                    40 
 41 #include <linux/blkdev.h>                          41 #include <linux/blkdev.h>
 42 #include <linux/sort.h>                            42 #include <linux/sort.h>
 43 #include <linux/sched/clock.h>                     43 #include <linux/sched/clock.h>
 44                                                    44 
 45 #include "util.h"                                  45 #include "util.h"
 46                                                    46 
 47 #define SYSFS_OPS(type)                            47 #define SYSFS_OPS(type)                                                 \
 48 const struct sysfs_ops type ## _sysfs_ops = {      48 const struct sysfs_ops type ## _sysfs_ops = {                           \
 49         .show   = type ## _show,                   49         .show   = type ## _show,                                        \
 50         .store  = type ## _store                   50         .store  = type ## _store                                        \
 51 }                                                  51 }
 52                                                    52 
 53 #define SHOW(fn)                                   53 #define SHOW(fn)                                                        \
 54 static ssize_t fn ## _to_text(struct printbuf      54 static ssize_t fn ## _to_text(struct printbuf *,                        \
 55                               struct kobject *     55                               struct kobject *, struct attribute *);    \
 56                                                    56                                                                         \
 57 static ssize_t fn ## _show(struct kobject *kob     57 static ssize_t fn ## _show(struct kobject *kobj, struct attribute *attr,\
 58                            char *buf)              58                            char *buf)                                   \
 59 {                                                  59 {                                                                       \
 60         struct printbuf out = PRINTBUF;            60         struct printbuf out = PRINTBUF;                                 \
 61         ssize_t ret = fn ## _to_text(&out, kob     61         ssize_t ret = fn ## _to_text(&out, kobj, attr);                 \
 62                                                    62                                                                         \
 63         if (out.pos && out.buf[out.pos - 1] !=     63         if (out.pos && out.buf[out.pos - 1] != '\n')                    \
 64                 prt_newline(&out);                 64                 prt_newline(&out);                                      \
 65                                                    65                                                                         \
 66         if (!ret && out.allocation_failure)        66         if (!ret && out.allocation_failure)                             \
 67                 ret = -ENOMEM;                     67                 ret = -ENOMEM;                                          \
 68                                                    68                                                                         \
 69         if (!ret) {                                69         if (!ret) {                                                     \
 70                 ret = min_t(size_t, out.pos, P     70                 ret = min_t(size_t, out.pos, PAGE_SIZE - 1);            \
 71                 memcpy(buf, out.buf, ret);         71                 memcpy(buf, out.buf, ret);                              \
 72         }                                          72         }                                                               \
 73         printbuf_exit(&out);                       73         printbuf_exit(&out);                                            \
 74         return bch2_err_class(ret);                74         return bch2_err_class(ret);                                     \
 75 }                                                  75 }                                                                       \
 76                                                    76                                                                         \
 77 static ssize_t fn ## _to_text(struct printbuf      77 static ssize_t fn ## _to_text(struct printbuf *out, struct kobject *kobj,\
 78                               struct attribute     78                               struct attribute *attr)
 79                                                    79 
 80 #define STORE(fn)                                  80 #define STORE(fn)                                                       \
 81 static ssize_t fn ## _store_inner(struct kobje     81 static ssize_t fn ## _store_inner(struct kobject *, struct attribute *,\
 82                             const char *, size     82                             const char *, size_t);                      \
 83                                                    83                                                                         \
 84 static ssize_t fn ## _store(struct kobject *ko     84 static ssize_t fn ## _store(struct kobject *kobj, struct attribute *attr,\
 85                             const char *buf, s     85                             const char *buf, size_t size)               \
 86 {                                                  86 {                                                                       \
 87         return bch2_err_class(fn##_store_inner     87         return bch2_err_class(fn##_store_inner(kobj, attr, buf, size)); \
 88 }                                                  88 }                                                                       \
 89                                                    89                                                                         \
 90 static ssize_t fn ## _store_inner(struct kobje     90 static ssize_t fn ## _store_inner(struct kobject *kobj, struct attribute *attr,\
 91                                   const char *     91                                   const char *buf, size_t size)
 92                                                    92 
 93 #define __sysfs_attribute(_name, _mode)            93 #define __sysfs_attribute(_name, _mode)                                 \
 94         static struct attribute sysfs_##_name      94         static struct attribute sysfs_##_name =                         \
 95                 { .name = #_name, .mode = _mod     95                 { .name = #_name, .mode = _mode }
 96                                                    96 
 97 #define write_attribute(n)      __sysfs_attrib     97 #define write_attribute(n)      __sysfs_attribute(n, 0200)
 98 #define read_attribute(n)       __sysfs_attrib     98 #define read_attribute(n)       __sysfs_attribute(n, 0444)
 99 #define rw_attribute(n)         __sysfs_attrib     99 #define rw_attribute(n)         __sysfs_attribute(n, 0644)
100                                                   100 
101 #define sysfs_printf(file, fmt, ...)              101 #define sysfs_printf(file, fmt, ...)                                    \
102 do {                                              102 do {                                                                    \
103         if (attr == &sysfs_ ## file)              103         if (attr == &sysfs_ ## file)                                    \
104                 prt_printf(out, fmt "\n", __VA    104                 prt_printf(out, fmt "\n", __VA_ARGS__);                 \
105 } while (0)                                       105 } while (0)
106                                                   106 
107 #define sysfs_print(file, var)                    107 #define sysfs_print(file, var)                                          \
108 do {                                              108 do {                                                                    \
109         if (attr == &sysfs_ ## file)              109         if (attr == &sysfs_ ## file)                                    \
110                 snprint(out, var);                110                 snprint(out, var);                                      \
111 } while (0)                                       111 } while (0)
112                                                   112 
113 #define sysfs_hprint(file, val)                   113 #define sysfs_hprint(file, val)                                         \
114 do {                                              114 do {                                                                    \
115         if (attr == &sysfs_ ## file)              115         if (attr == &sysfs_ ## file)                                    \
116                 prt_human_readable_s64(out, va    116                 prt_human_readable_s64(out, val);                       \
117 } while (0)                                       117 } while (0)
118                                                   118 
119 #define sysfs_strtoul(file, var)                  119 #define sysfs_strtoul(file, var)                                        \
120 do {                                              120 do {                                                                    \
121         if (attr == &sysfs_ ## file)              121         if (attr == &sysfs_ ## file)                                    \
122                 return strtoul_safe(buf, var)     122                 return strtoul_safe(buf, var) ?: (ssize_t) size;        \
123 } while (0)                                       123 } while (0)
124                                                   124 
125 #define sysfs_strtoul_clamp(file, var, min, ma    125 #define sysfs_strtoul_clamp(file, var, min, max)                        \
126 do {                                              126 do {                                                                    \
127         if (attr == &sysfs_ ## file)              127         if (attr == &sysfs_ ## file)                                    \
128                 return strtoul_safe_clamp(buf,    128                 return strtoul_safe_clamp(buf, var, min, max)           \
129                         ?: (ssize_t) size;        129                         ?: (ssize_t) size;                              \
130 } while (0)                                       130 } while (0)
131                                                   131 
132 #define strtoul_or_return(cp)                     132 #define strtoul_or_return(cp)                                           \
133 ({                                                133 ({                                                                      \
134         unsigned long _v;                         134         unsigned long _v;                                               \
135         int _r = kstrtoul(cp, 10, &_v);           135         int _r = kstrtoul(cp, 10, &_v);                                 \
136         if (_r)                                   136         if (_r)                                                         \
137                 return _r;                        137                 return _r;                                              \
138         _v;                                       138         _v;                                                             \
139 })                                                139 })
140                                                   140 
141 write_attribute(trigger_gc);                      141 write_attribute(trigger_gc);
142 write_attribute(trigger_discards);                142 write_attribute(trigger_discards);
143 write_attribute(trigger_invalidates);             143 write_attribute(trigger_invalidates);
144 write_attribute(trigger_journal_flush);           144 write_attribute(trigger_journal_flush);
145 write_attribute(trigger_journal_writes);          145 write_attribute(trigger_journal_writes);
146 write_attribute(trigger_btree_cache_shrink);      146 write_attribute(trigger_btree_cache_shrink);
147 write_attribute(trigger_btree_key_cache_shrink    147 write_attribute(trigger_btree_key_cache_shrink);
148 write_attribute(trigger_freelist_wakeup);         148 write_attribute(trigger_freelist_wakeup);
149 rw_attribute(gc_gens_pos);                        149 rw_attribute(gc_gens_pos);
150                                                   150 
151 read_attribute(uuid);                             151 read_attribute(uuid);
152 read_attribute(minor);                            152 read_attribute(minor);
153 read_attribute(flags);                            153 read_attribute(flags);
154 read_attribute(bucket_size);                      154 read_attribute(bucket_size);
155 read_attribute(first_bucket);                     155 read_attribute(first_bucket);
156 read_attribute(nbuckets);                         156 read_attribute(nbuckets);
157 rw_attribute(durability);                         157 rw_attribute(durability);
158 read_attribute(io_done);                          158 read_attribute(io_done);
159 read_attribute(io_errors);                        159 read_attribute(io_errors);
160 write_attribute(io_errors_reset);                 160 write_attribute(io_errors_reset);
161                                                   161 
162 read_attribute(io_latency_read);                  162 read_attribute(io_latency_read);
163 read_attribute(io_latency_write);                 163 read_attribute(io_latency_write);
164 read_attribute(io_latency_stats_read);            164 read_attribute(io_latency_stats_read);
165 read_attribute(io_latency_stats_write);           165 read_attribute(io_latency_stats_write);
166 read_attribute(congested);                        166 read_attribute(congested);
167                                                   167 
168 read_attribute(btree_write_stats);                168 read_attribute(btree_write_stats);
169                                                   169 
170 read_attribute(btree_cache_size);                 170 read_attribute(btree_cache_size);
171 read_attribute(compression_stats);                171 read_attribute(compression_stats);
172 read_attribute(journal_debug);                    172 read_attribute(journal_debug);
173 read_attribute(btree_cache);                      173 read_attribute(btree_cache);
174 read_attribute(btree_key_cache);                  174 read_attribute(btree_key_cache);
175 read_attribute(btree_reserve_cache);              175 read_attribute(btree_reserve_cache);
176 read_attribute(stripes_heap);                     176 read_attribute(stripes_heap);
177 read_attribute(open_buckets);                     177 read_attribute(open_buckets);
178 read_attribute(open_buckets_partial);             178 read_attribute(open_buckets_partial);
179 read_attribute(write_points);                     179 read_attribute(write_points);
180 read_attribute(nocow_lock_table);                 180 read_attribute(nocow_lock_table);
181                                                   181 
182 #ifdef BCH_WRITE_REF_DEBUG                        182 #ifdef BCH_WRITE_REF_DEBUG
183 read_attribute(write_refs);                       183 read_attribute(write_refs);
184                                                   184 
185 static const char * const bch2_write_refs[] =     185 static const char * const bch2_write_refs[] = {
186 #define x(n)    #n,                               186 #define x(n)    #n,
187         BCH_WRITE_REFS()                          187         BCH_WRITE_REFS()
188 #undef x                                          188 #undef x
189         NULL                                      189         NULL
190 };                                                190 };
191                                                   191 
192 static void bch2_write_refs_to_text(struct pri    192 static void bch2_write_refs_to_text(struct printbuf *out, struct bch_fs *c)
193 {                                                 193 {
194         bch2_printbuf_tabstop_push(out, 24);      194         bch2_printbuf_tabstop_push(out, 24);
195                                                   195 
196         for (unsigned i = 0; i < ARRAY_SIZE(c-    196         for (unsigned i = 0; i < ARRAY_SIZE(c->writes); i++)
197                 prt_printf(out, "%s\t%li\n", b    197                 prt_printf(out, "%s\t%li\n", bch2_write_refs[i], atomic_long_read(&c->writes[i]));
198 }                                                 198 }
199 #endif                                            199 #endif
200                                                   200 
201 read_attribute(internal_uuid);                    201 read_attribute(internal_uuid);
202 read_attribute(disk_groups);                      202 read_attribute(disk_groups);
203                                                   203 
204 read_attribute(has_data);                         204 read_attribute(has_data);
205 read_attribute(alloc_debug);                      205 read_attribute(alloc_debug);
206 read_attribute(accounting);                       206 read_attribute(accounting);
207 read_attribute(usage_base);                       207 read_attribute(usage_base);
208                                                   208 
209 #define x(t, n, ...) read_attribute(t);           209 #define x(t, n, ...) read_attribute(t);
210 BCH_PERSISTENT_COUNTERS()                         210 BCH_PERSISTENT_COUNTERS()
211 #undef x                                          211 #undef x
212                                                   212 
213 rw_attribute(discard);                            213 rw_attribute(discard);
214 rw_attribute(label);                              214 rw_attribute(label);
215                                                   215 
216 rw_attribute(copy_gc_enabled);                    216 rw_attribute(copy_gc_enabled);
217 read_attribute(copy_gc_wait);                     217 read_attribute(copy_gc_wait);
218                                                   218 
219 rw_attribute(rebalance_enabled);                  219 rw_attribute(rebalance_enabled);
220 sysfs_pd_controller_attribute(rebalance);         220 sysfs_pd_controller_attribute(rebalance);
221 read_attribute(rebalance_status);                 221 read_attribute(rebalance_status);
222                                                   222 
223 read_attribute(new_stripes);                      223 read_attribute(new_stripes);
224                                                   224 
225 read_attribute(io_timers_read);                   225 read_attribute(io_timers_read);
226 read_attribute(io_timers_write);                  226 read_attribute(io_timers_write);
227                                                   227 
228 read_attribute(moving_ctxts);                     228 read_attribute(moving_ctxts);
229                                                   229 
230 #ifdef CONFIG_BCACHEFS_TESTS                      230 #ifdef CONFIG_BCACHEFS_TESTS
231 write_attribute(perf_test);                       231 write_attribute(perf_test);
232 #endif /* CONFIG_BCACHEFS_TESTS */                232 #endif /* CONFIG_BCACHEFS_TESTS */
233                                                   233 
234 #define x(_name)                                  234 #define x(_name)                                                \
235         static struct attribute sysfs_time_sta    235         static struct attribute sysfs_time_stat_##_name =               \
236                 { .name = #_name, .mode = 0644    236                 { .name = #_name, .mode = 0644 };
237         BCH_TIME_STATS()                          237         BCH_TIME_STATS()
238 #undef x                                          238 #undef x
239                                                   239 
240 static struct attribute sysfs_state_rw = {        240 static struct attribute sysfs_state_rw = {
241         .name = "state",                          241         .name = "state",
242         .mode =  0444,                            242         .mode =  0444,
243 };                                                243 };
244                                                   244 
245 static size_t bch2_btree_cache_size(struct bch    245 static size_t bch2_btree_cache_size(struct bch_fs *c)
246 {                                                 246 {
247         struct btree_cache *bc = &c->btree_cac    247         struct btree_cache *bc = &c->btree_cache;
248         size_t ret = 0;                           248         size_t ret = 0;
249         struct btree *b;                          249         struct btree *b;
250                                                   250 
251         mutex_lock(&bc->lock);                    251         mutex_lock(&bc->lock);
252         list_for_each_entry(b, &bc->live[0].li    252         list_for_each_entry(b, &bc->live[0].list, list)
253                 ret += btree_buf_bytes(b);        253                 ret += btree_buf_bytes(b);
254         list_for_each_entry(b, &bc->live[1].li    254         list_for_each_entry(b, &bc->live[1].list, list)
255                 ret += btree_buf_bytes(b);        255                 ret += btree_buf_bytes(b);
256         list_for_each_entry(b, &bc->freeable,     256         list_for_each_entry(b, &bc->freeable, list)
257                 ret += btree_buf_bytes(b);        257                 ret += btree_buf_bytes(b);
258         mutex_unlock(&bc->lock);                  258         mutex_unlock(&bc->lock);
259         return ret;                               259         return ret;
260 }                                                 260 }
261                                                   261 
262 static int bch2_compression_stats_to_text(stru    262 static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c)
263 {                                                 263 {
264         prt_str(out, "type");                     264         prt_str(out, "type");
265         printbuf_tabstop_push(out, 12);           265         printbuf_tabstop_push(out, 12);
266         printbuf_tabstop_push(out, 16);           266         printbuf_tabstop_push(out, 16);
267         printbuf_tabstop_push(out, 16);           267         printbuf_tabstop_push(out, 16);
268         printbuf_tabstop_push(out, 24);           268         printbuf_tabstop_push(out, 24);
269         prt_printf(out, "type\tcompressed\runc    269         prt_printf(out, "type\tcompressed\runcompressed\raverage extent size\r\n");
270                                                   270 
271         for (unsigned i = 1; i < BCH_COMPRESSI    271         for (unsigned i = 1; i < BCH_COMPRESSION_TYPE_NR; i++) {
272                 struct disk_accounting_pos a =    272                 struct disk_accounting_pos a = {
273                         .type                     273                         .type                   = BCH_DISK_ACCOUNTING_compression,
274                         .compression.type         274                         .compression.type       = i,
275                 };                                275                 };
276                 struct bpos p = disk_accountin    276                 struct bpos p = disk_accounting_pos_to_bpos(&a);
277                 u64 v[3];                         277                 u64 v[3];
278                 bch2_accounting_mem_read(c, p,    278                 bch2_accounting_mem_read(c, p, v, ARRAY_SIZE(v));
279                                                   279 
280                 u64 nr_extents                    280                 u64 nr_extents                  = v[0];
281                 u64 sectors_uncompressed          281                 u64 sectors_uncompressed        = v[1];
282                 u64 sectors_compressed            282                 u64 sectors_compressed          = v[2];
283                                                   283 
284                 bch2_prt_compression_type(out,    284                 bch2_prt_compression_type(out, i);
285                 prt_tab(out);                     285                 prt_tab(out);
286                                                   286 
287                 prt_human_readable_u64(out, se    287                 prt_human_readable_u64(out, sectors_compressed << 9);
288                 prt_tab_rjust(out);               288                 prt_tab_rjust(out);
289                                                   289 
290                 prt_human_readable_u64(out, se    290                 prt_human_readable_u64(out, sectors_uncompressed << 9);
291                 prt_tab_rjust(out);               291                 prt_tab_rjust(out);
292                                                   292 
293                 prt_human_readable_u64(out, nr    293                 prt_human_readable_u64(out, nr_extents
294                                        ? div64    294                                        ? div64_u64(sectors_uncompressed << 9, nr_extents)
295                                        : 0);      295                                        : 0);
296                 prt_tab_rjust(out);               296                 prt_tab_rjust(out);
297                 prt_newline(out);                 297                 prt_newline(out);
298         }                                         298         }
299                                                   299 
300         return 0;                                 300         return 0;
301 }                                                 301 }
302                                                   302 
303 static void bch2_gc_gens_pos_to_text(struct pr    303 static void bch2_gc_gens_pos_to_text(struct printbuf *out, struct bch_fs *c)
304 {                                                 304 {
305         prt_printf(out, "%s: ", bch2_btree_id_    305         prt_printf(out, "%s: ", bch2_btree_id_str(c->gc_gens_btree));
306         bch2_bpos_to_text(out, c->gc_gens_pos)    306         bch2_bpos_to_text(out, c->gc_gens_pos);
307         prt_printf(out, "\n");                    307         prt_printf(out, "\n");
308 }                                                 308 }
309                                                   309 
310 static void bch2_fs_usage_base_to_text(struct     310 static void bch2_fs_usage_base_to_text(struct printbuf *out, struct bch_fs *c)
311 {                                                 311 {
312         struct bch_fs_usage_base b = {};          312         struct bch_fs_usage_base b = {};
313                                                   313 
314         acc_u64s_percpu(&b.hidden, &c->usage->    314         acc_u64s_percpu(&b.hidden, &c->usage->hidden, sizeof(b) / sizeof(u64));
315                                                   315 
316         prt_printf(out, "hidden:\t\t%llu\n",      316         prt_printf(out, "hidden:\t\t%llu\n",    b.hidden);
317         prt_printf(out, "btree:\t\t%llu\n",       317         prt_printf(out, "btree:\t\t%llu\n",     b.btree);
318         prt_printf(out, "data:\t\t%llu\n",        318         prt_printf(out, "data:\t\t%llu\n",      b.data);
319         prt_printf(out, "cached:\t%llu\n",        319         prt_printf(out, "cached:\t%llu\n",      b.cached);
320         prt_printf(out, "reserved:\t\t%llu\n",    320         prt_printf(out, "reserved:\t\t%llu\n",  b.reserved);
321         prt_printf(out, "nr_inodes:\t%llu\n",     321         prt_printf(out, "nr_inodes:\t%llu\n",   b.nr_inodes);
322 }                                                 322 }
323                                                   323 
324 SHOW(bch2_fs)                                     324 SHOW(bch2_fs)
325 {                                                 325 {
326         struct bch_fs *c = container_of(kobj,     326         struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
327                                                   327 
328         sysfs_print(minor,                        328         sysfs_print(minor,                      c->minor);
329         sysfs_printf(internal_uuid, "%pU",        329         sysfs_printf(internal_uuid, "%pU",      c->sb.uuid.b);
330                                                   330 
331         if (attr == &sysfs_flags)                 331         if (attr == &sysfs_flags)
332                 prt_bitflags(out, bch2_fs_flag    332                 prt_bitflags(out, bch2_fs_flag_strs, c->flags);
333                                                   333 
334         sysfs_hprint(btree_cache_size,            334         sysfs_hprint(btree_cache_size,          bch2_btree_cache_size(c));
335                                                   335 
336         if (attr == &sysfs_btree_write_stats)     336         if (attr == &sysfs_btree_write_stats)
337                 bch2_btree_write_stats_to_text    337                 bch2_btree_write_stats_to_text(out, c);
338                                                   338 
339         if (attr == &sysfs_gc_gens_pos)           339         if (attr == &sysfs_gc_gens_pos)
340                 bch2_gc_gens_pos_to_text(out,     340                 bch2_gc_gens_pos_to_text(out, c);
341                                                   341 
342         sysfs_printf(copy_gc_enabled, "%i", c-    342         sysfs_printf(copy_gc_enabled, "%i", c->copy_gc_enabled);
343                                                   343 
344         sysfs_printf(rebalance_enabled,           344         sysfs_printf(rebalance_enabled,         "%i", c->rebalance.enabled);
345         sysfs_pd_controller_show(rebalance,       345         sysfs_pd_controller_show(rebalance,     &c->rebalance.pd); /* XXX */
346                                                   346 
347         if (attr == &sysfs_copy_gc_wait)          347         if (attr == &sysfs_copy_gc_wait)
348                 bch2_copygc_wait_to_text(out,     348                 bch2_copygc_wait_to_text(out, c);
349                                                   349 
350         if (attr == &sysfs_rebalance_status)      350         if (attr == &sysfs_rebalance_status)
351                 bch2_rebalance_status_to_text(    351                 bch2_rebalance_status_to_text(out, c);
352                                                   352 
353         /* Debugging: */                          353         /* Debugging: */
354                                                   354 
355         if (attr == &sysfs_journal_debug)         355         if (attr == &sysfs_journal_debug)
356                 bch2_journal_debug_to_text(out    356                 bch2_journal_debug_to_text(out, &c->journal);
357                                                   357 
358         if (attr == &sysfs_btree_cache)           358         if (attr == &sysfs_btree_cache)
359                 bch2_btree_cache_to_text(out,     359                 bch2_btree_cache_to_text(out, &c->btree_cache);
360                                                   360 
361         if (attr == &sysfs_btree_key_cache)       361         if (attr == &sysfs_btree_key_cache)
362                 bch2_btree_key_cache_to_text(o    362                 bch2_btree_key_cache_to_text(out, &c->btree_key_cache);
363                                                   363 
364         if (attr == &sysfs_btree_reserve_cache    364         if (attr == &sysfs_btree_reserve_cache)
365                 bch2_btree_reserve_cache_to_te    365                 bch2_btree_reserve_cache_to_text(out, c);
366                                                   366 
367         if (attr == &sysfs_stripes_heap)          367         if (attr == &sysfs_stripes_heap)
368                 bch2_stripes_heap_to_text(out,    368                 bch2_stripes_heap_to_text(out, c);
369                                                   369 
370         if (attr == &sysfs_open_buckets)          370         if (attr == &sysfs_open_buckets)
371                 bch2_open_buckets_to_text(out,    371                 bch2_open_buckets_to_text(out, c, NULL);
372                                                   372 
373         if (attr == &sysfs_open_buckets_partia    373         if (attr == &sysfs_open_buckets_partial)
374                 bch2_open_buckets_partial_to_t    374                 bch2_open_buckets_partial_to_text(out, c);
375                                                   375 
376         if (attr == &sysfs_write_points)          376         if (attr == &sysfs_write_points)
377                 bch2_write_points_to_text(out,    377                 bch2_write_points_to_text(out, c);
378                                                   378 
379         if (attr == &sysfs_compression_stats)     379         if (attr == &sysfs_compression_stats)
380                 bch2_compression_stats_to_text    380                 bch2_compression_stats_to_text(out, c);
381                                                   381 
382         if (attr == &sysfs_new_stripes)           382         if (attr == &sysfs_new_stripes)
383                 bch2_new_stripes_to_text(out,     383                 bch2_new_stripes_to_text(out, c);
384                                                   384 
385         if (attr == &sysfs_io_timers_read)        385         if (attr == &sysfs_io_timers_read)
386                 bch2_io_timers_to_text(out, &c    386                 bch2_io_timers_to_text(out, &c->io_clock[READ]);
387                                                   387 
388         if (attr == &sysfs_io_timers_write)       388         if (attr == &sysfs_io_timers_write)
389                 bch2_io_timers_to_text(out, &c    389                 bch2_io_timers_to_text(out, &c->io_clock[WRITE]);
390                                                   390 
391         if (attr == &sysfs_moving_ctxts)          391         if (attr == &sysfs_moving_ctxts)
392                 bch2_fs_moving_ctxts_to_text(o    392                 bch2_fs_moving_ctxts_to_text(out, c);
393                                                   393 
394 #ifdef BCH_WRITE_REF_DEBUG                        394 #ifdef BCH_WRITE_REF_DEBUG
395         if (attr == &sysfs_write_refs)            395         if (attr == &sysfs_write_refs)
396                 bch2_write_refs_to_text(out, c    396                 bch2_write_refs_to_text(out, c);
397 #endif                                            397 #endif
398                                                   398 
399         if (attr == &sysfs_nocow_lock_table)      399         if (attr == &sysfs_nocow_lock_table)
400                 bch2_nocow_locks_to_text(out,     400                 bch2_nocow_locks_to_text(out, &c->nocow_locks);
401                                                   401 
402         if (attr == &sysfs_disk_groups)           402         if (attr == &sysfs_disk_groups)
403                 bch2_disk_groups_to_text(out,     403                 bch2_disk_groups_to_text(out, c);
404                                                   404 
405         if (attr == &sysfs_alloc_debug)           405         if (attr == &sysfs_alloc_debug)
406                 bch2_fs_alloc_debug_to_text(ou    406                 bch2_fs_alloc_debug_to_text(out, c);
407                                                   407 
408         if (attr == &sysfs_accounting)            408         if (attr == &sysfs_accounting)
409                 bch2_fs_accounting_to_text(out    409                 bch2_fs_accounting_to_text(out, c);
410                                                   410 
411         if (attr == &sysfs_usage_base)            411         if (attr == &sysfs_usage_base)
412                 bch2_fs_usage_base_to_text(out    412                 bch2_fs_usage_base_to_text(out, c);
413                                                   413 
414         return 0;                                 414         return 0;
415 }                                                 415 }
416                                                   416 
417 STORE(bch2_fs)                                    417 STORE(bch2_fs)
418 {                                                 418 {
419         struct bch_fs *c = container_of(kobj,     419         struct bch_fs *c = container_of(kobj, struct bch_fs, kobj);
420                                                   420 
421         if (attr == &sysfs_copy_gc_enabled) {     421         if (attr == &sysfs_copy_gc_enabled) {
422                 ssize_t ret = strtoul_safe(buf    422                 ssize_t ret = strtoul_safe(buf, c->copy_gc_enabled)
423                         ?: (ssize_t) size;        423                         ?: (ssize_t) size;
424                                                   424 
425                 if (c->copygc_thread)             425                 if (c->copygc_thread)
426                         wake_up_process(c->cop    426                         wake_up_process(c->copygc_thread);
427                 return ret;                       427                 return ret;
428         }                                         428         }
429                                                   429 
430         if (attr == &sysfs_rebalance_enabled)     430         if (attr == &sysfs_rebalance_enabled) {
431                 ssize_t ret = strtoul_safe(buf    431                 ssize_t ret = strtoul_safe(buf, c->rebalance.enabled)
432                         ?: (ssize_t) size;        432                         ?: (ssize_t) size;
433                                                   433 
434                 rebalance_wakeup(c);              434                 rebalance_wakeup(c);
435                 return ret;                       435                 return ret;
436         }                                         436         }
437                                                   437 
438         sysfs_pd_controller_store(rebalance,      438         sysfs_pd_controller_store(rebalance,    &c->rebalance.pd);
439                                                   439 
440         /* Debugging: */                          440         /* Debugging: */
441                                                   441 
442         if (!test_bit(BCH_FS_started, &c->flag    442         if (!test_bit(BCH_FS_started, &c->flags))
443                 return -EPERM;                    443                 return -EPERM;
444                                                   444 
445         /* Debugging: */                          445         /* Debugging: */
446                                                   446 
447         if (!bch2_write_ref_tryget(c, BCH_WRIT    447         if (!bch2_write_ref_tryget(c, BCH_WRITE_REF_sysfs))
448                 return -EROFS;                    448                 return -EROFS;
449                                                   449 
450         if (attr == &sysfs_trigger_btree_cache    450         if (attr == &sysfs_trigger_btree_cache_shrink) {
451                 struct btree_cache *bc = &c->b    451                 struct btree_cache *bc = &c->btree_cache;
452                 struct shrink_control sc;         452                 struct shrink_control sc;
453                                                   453 
454                 sc.gfp_mask = GFP_KERNEL;         454                 sc.gfp_mask = GFP_KERNEL;
455                 sc.nr_to_scan = strtoul_or_ret    455                 sc.nr_to_scan = strtoul_or_return(buf);
456                 bc->live[0].shrink->scan_objec    456                 bc->live[0].shrink->scan_objects(bc->live[0].shrink, &sc);
457         }                                         457         }
458                                                   458 
459         if (attr == &sysfs_trigger_btree_key_c    459         if (attr == &sysfs_trigger_btree_key_cache_shrink) {
460                 struct shrink_control sc;         460                 struct shrink_control sc;
461                                                   461 
462                 sc.gfp_mask = GFP_KERNEL;         462                 sc.gfp_mask = GFP_KERNEL;
463                 sc.nr_to_scan = strtoul_or_ret    463                 sc.nr_to_scan = strtoul_or_return(buf);
464                 c->btree_key_cache.shrink->sca    464                 c->btree_key_cache.shrink->scan_objects(c->btree_key_cache.shrink, &sc);
465         }                                         465         }
466                                                   466 
467         if (attr == &sysfs_trigger_gc)            467         if (attr == &sysfs_trigger_gc)
468                 bch2_gc_gens(c);                  468                 bch2_gc_gens(c);
469                                                   469 
470         if (attr == &sysfs_trigger_discards)      470         if (attr == &sysfs_trigger_discards)
471                 bch2_do_discards(c);              471                 bch2_do_discards(c);
472                                                   472 
473         if (attr == &sysfs_trigger_invalidates    473         if (attr == &sysfs_trigger_invalidates)
474                 bch2_do_invalidates(c);           474                 bch2_do_invalidates(c);
475                                                   475 
476         if (attr == &sysfs_trigger_journal_flu    476         if (attr == &sysfs_trigger_journal_flush) {
477                 bch2_journal_flush_all_pins(&c    477                 bch2_journal_flush_all_pins(&c->journal);
478                 bch2_journal_meta(&c->journal)    478                 bch2_journal_meta(&c->journal);
479         }                                         479         }
480                                                   480 
481         if (attr == &sysfs_trigger_journal_wri    481         if (attr == &sysfs_trigger_journal_writes)
482                 bch2_journal_do_writes(&c->jou    482                 bch2_journal_do_writes(&c->journal);
483                                                   483 
484         if (attr == &sysfs_trigger_freelist_wa    484         if (attr == &sysfs_trigger_freelist_wakeup)
485                 closure_wake_up(&c->freelist_w    485                 closure_wake_up(&c->freelist_wait);
486                                                   486 
487 #ifdef CONFIG_BCACHEFS_TESTS                      487 #ifdef CONFIG_BCACHEFS_TESTS
488         if (attr == &sysfs_perf_test) {           488         if (attr == &sysfs_perf_test) {
489                 char *tmp = kstrdup(buf, GFP_K    489                 char *tmp = kstrdup(buf, GFP_KERNEL), *p = tmp;
490                 char *test              = strs    490                 char *test              = strsep(&p, " \t\n");
491                 char *nr_str            = strs    491                 char *nr_str            = strsep(&p, " \t\n");
492                 char *threads_str       = strs    492                 char *threads_str       = strsep(&p, " \t\n");
493                 unsigned threads;                 493                 unsigned threads;
494                 u64 nr;                           494                 u64 nr;
495                 int ret = -EINVAL;                495                 int ret = -EINVAL;
496                                                   496 
497                 if (threads_str &&                497                 if (threads_str &&
498                     !(ret = kstrtouint(threads    498                     !(ret = kstrtouint(threads_str, 10, &threads)) &&
499                     !(ret = bch2_strtoull_h(nr    499                     !(ret = bch2_strtoull_h(nr_str, &nr)))
500                         ret = bch2_btree_perf_    500                         ret = bch2_btree_perf_test(c, test, nr, threads);
501                 kfree(tmp);                       501                 kfree(tmp);
502                                                   502 
503                 if (ret)                          503                 if (ret)
504                         size = ret;               504                         size = ret;
505         }                                         505         }
506 #endif                                            506 #endif
507         bch2_write_ref_put(c, BCH_WRITE_REF_sy    507         bch2_write_ref_put(c, BCH_WRITE_REF_sysfs);
508         return size;                              508         return size;
509 }                                                 509 }
510 SYSFS_OPS(bch2_fs);                               510 SYSFS_OPS(bch2_fs);
511                                                   511 
512 struct attribute *bch2_fs_files[] = {             512 struct attribute *bch2_fs_files[] = {
513         &sysfs_minor,                             513         &sysfs_minor,
514         &sysfs_btree_cache_size,                  514         &sysfs_btree_cache_size,
515         &sysfs_btree_write_stats,                 515         &sysfs_btree_write_stats,
516                                                   516 
517         &sysfs_rebalance_status,                  517         &sysfs_rebalance_status,
518                                                   518 
519         &sysfs_compression_stats,                 519         &sysfs_compression_stats,
520                                                   520 
521 #ifdef CONFIG_BCACHEFS_TESTS                      521 #ifdef CONFIG_BCACHEFS_TESTS
522         &sysfs_perf_test,                         522         &sysfs_perf_test,
523 #endif                                            523 #endif
524         NULL                                      524         NULL
525 };                                                525 };
526                                                   526 
527 /* counters dir */                                527 /* counters dir */
528                                                   528 
529 SHOW(bch2_fs_counters)                            529 SHOW(bch2_fs_counters)
530 {                                                 530 {
531         struct bch_fs *c = container_of(kobj,     531         struct bch_fs *c = container_of(kobj, struct bch_fs, counters_kobj);
532         u64 counter = 0;                          532         u64 counter = 0;
533         u64 counter_since_mount = 0;              533         u64 counter_since_mount = 0;
534                                                   534 
535         printbuf_tabstop_push(out, 32);           535         printbuf_tabstop_push(out, 32);
536                                                   536 
537         #define x(t, ...) \                       537         #define x(t, ...) \
538                 if (attr == &sysfs_##t) {         538                 if (attr == &sysfs_##t) {                                       \
539                         counter             =     539                         counter             = percpu_u64_get(&c->counters[BCH_COUNTER_##t]);\
540                         counter_since_mount =     540                         counter_since_mount = counter - c->counters_on_mount[BCH_COUNTER_##t];\
541                         prt_printf(out, "since    541                         prt_printf(out, "since mount:\t");                      \
542                         prt_human_readable_u64    542                         prt_human_readable_u64(out, counter_since_mount);       \
543                         prt_newline(out);         543                         prt_newline(out);                                       \
544                                                   544                                                                                 \
545                         prt_printf(out, "since    545                         prt_printf(out, "since filesystem creation:\t");        \
546                         prt_human_readable_u64    546                         prt_human_readable_u64(out, counter);                   \
547                         prt_newline(out);         547                         prt_newline(out);                                       \
548                 }                                 548                 }
549         BCH_PERSISTENT_COUNTERS()                 549         BCH_PERSISTENT_COUNTERS()
550         #undef x                                  550         #undef x
551         return 0;                                 551         return 0;
552 }                                                 552 }
553                                                   553 
554 STORE(bch2_fs_counters) {                         554 STORE(bch2_fs_counters) {
555         return 0;                                 555         return 0;
556 }                                                 556 }
557                                                   557 
558 SYSFS_OPS(bch2_fs_counters);                      558 SYSFS_OPS(bch2_fs_counters);
559                                                   559 
560 struct attribute *bch2_fs_counters_files[] = {    560 struct attribute *bch2_fs_counters_files[] = {
561 #define x(t, ...) \                               561 #define x(t, ...) \
562         &sysfs_##t,                               562         &sysfs_##t,
563         BCH_PERSISTENT_COUNTERS()                 563         BCH_PERSISTENT_COUNTERS()
564 #undef x                                          564 #undef x
565         NULL                                      565         NULL
566 };                                                566 };
567 /* internal dir - just a wrapper */               567 /* internal dir - just a wrapper */
568                                                   568 
569 SHOW(bch2_fs_internal)                            569 SHOW(bch2_fs_internal)
570 {                                                 570 {
571         struct bch_fs *c = container_of(kobj,     571         struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
572                                                   572 
573         return bch2_fs_to_text(out, &c->kobj,     573         return bch2_fs_to_text(out, &c->kobj, attr);
574 }                                                 574 }
575                                                   575 
576 STORE(bch2_fs_internal)                           576 STORE(bch2_fs_internal)
577 {                                                 577 {
578         struct bch_fs *c = container_of(kobj,     578         struct bch_fs *c = container_of(kobj, struct bch_fs, internal);
579                                                   579 
580         return bch2_fs_store(&c->kobj, attr, b    580         return bch2_fs_store(&c->kobj, attr, buf, size);
581 }                                                 581 }
582 SYSFS_OPS(bch2_fs_internal);                      582 SYSFS_OPS(bch2_fs_internal);
583                                                   583 
584 struct attribute *bch2_fs_internal_files[] = {    584 struct attribute *bch2_fs_internal_files[] = {
585         &sysfs_flags,                             585         &sysfs_flags,
586         &sysfs_journal_debug,                     586         &sysfs_journal_debug,
587         &sysfs_btree_cache,                       587         &sysfs_btree_cache,
588         &sysfs_btree_key_cache,                   588         &sysfs_btree_key_cache,
589         &sysfs_btree_reserve_cache,               589         &sysfs_btree_reserve_cache,
590         &sysfs_new_stripes,                       590         &sysfs_new_stripes,
591         &sysfs_stripes_heap,                      591         &sysfs_stripes_heap,
592         &sysfs_open_buckets,                      592         &sysfs_open_buckets,
593         &sysfs_open_buckets_partial,              593         &sysfs_open_buckets_partial,
594         &sysfs_write_points,                      594         &sysfs_write_points,
595 #ifdef BCH_WRITE_REF_DEBUG                        595 #ifdef BCH_WRITE_REF_DEBUG
596         &sysfs_write_refs,                        596         &sysfs_write_refs,
597 #endif                                            597 #endif
598         &sysfs_nocow_lock_table,                  598         &sysfs_nocow_lock_table,
599         &sysfs_io_timers_read,                    599         &sysfs_io_timers_read,
600         &sysfs_io_timers_write,                   600         &sysfs_io_timers_write,
601                                                   601 
602         &sysfs_trigger_gc,                        602         &sysfs_trigger_gc,
603         &sysfs_trigger_discards,                  603         &sysfs_trigger_discards,
604         &sysfs_trigger_invalidates,               604         &sysfs_trigger_invalidates,
605         &sysfs_trigger_journal_flush,             605         &sysfs_trigger_journal_flush,
606         &sysfs_trigger_journal_writes,            606         &sysfs_trigger_journal_writes,
607         &sysfs_trigger_btree_cache_shrink,        607         &sysfs_trigger_btree_cache_shrink,
608         &sysfs_trigger_btree_key_cache_shrink,    608         &sysfs_trigger_btree_key_cache_shrink,
609         &sysfs_trigger_freelist_wakeup,           609         &sysfs_trigger_freelist_wakeup,
610                                                   610 
611         &sysfs_gc_gens_pos,                       611         &sysfs_gc_gens_pos,
612                                                   612 
613         &sysfs_copy_gc_enabled,                   613         &sysfs_copy_gc_enabled,
614         &sysfs_copy_gc_wait,                      614         &sysfs_copy_gc_wait,
615                                                   615 
616         &sysfs_rebalance_enabled,                 616         &sysfs_rebalance_enabled,
617         sysfs_pd_controller_files(rebalance),     617         sysfs_pd_controller_files(rebalance),
618                                                   618 
619         &sysfs_moving_ctxts,                      619         &sysfs_moving_ctxts,
620                                                   620 
621         &sysfs_internal_uuid,                     621         &sysfs_internal_uuid,
622                                                   622 
623         &sysfs_disk_groups,                       623         &sysfs_disk_groups,
624         &sysfs_alloc_debug,                       624         &sysfs_alloc_debug,
625         &sysfs_accounting,                        625         &sysfs_accounting,
626         &sysfs_usage_base,                        626         &sysfs_usage_base,
627         NULL                                      627         NULL
628 };                                                628 };
629                                                   629 
630 /* options */                                     630 /* options */
631                                                   631 
632 SHOW(bch2_fs_opts_dir)                            632 SHOW(bch2_fs_opts_dir)
633 {                                                 633 {
634         struct bch_fs *c = container_of(kobj,     634         struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
635         const struct bch_option *opt = contain    635         const struct bch_option *opt = container_of(attr, struct bch_option, attr);
636         int id = opt - bch2_opt_table;            636         int id = opt - bch2_opt_table;
637         u64 v = bch2_opt_get_by_id(&c->opts, i    637         u64 v = bch2_opt_get_by_id(&c->opts, id);
638                                                   638 
639         bch2_opt_to_text(out, c, c->disk_sb.sb    639         bch2_opt_to_text(out, c, c->disk_sb.sb, opt, v, OPT_SHOW_FULL_LIST);
640         prt_char(out, '\n');                      640         prt_char(out, '\n');
641                                                   641 
642         return 0;                                 642         return 0;
643 }                                                 643 }
644                                                   644 
645 STORE(bch2_fs_opts_dir)                           645 STORE(bch2_fs_opts_dir)
646 {                                                 646 {
647         struct bch_fs *c = container_of(kobj,     647         struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
648         const struct bch_option *opt = contain    648         const struct bch_option *opt = container_of(attr, struct bch_option, attr);
649         int ret, id = opt - bch2_opt_table;       649         int ret, id = opt - bch2_opt_table;
650         char *tmp;                                650         char *tmp;
651         u64 v;                                    651         u64 v;
652                                                   652 
653         /*                                        653         /*
654          * We don't need to take c->writes for    654          * We don't need to take c->writes for correctness, but it eliminates an
655          * unsightly error message in the dmes    655          * unsightly error message in the dmesg log when we're RO:
656          */                                       656          */
657         if (unlikely(!bch2_write_ref_tryget(c,    657         if (unlikely(!bch2_write_ref_tryget(c, BCH_WRITE_REF_sysfs)))
658                 return -EROFS;                    658                 return -EROFS;
659                                                   659 
660         tmp = kstrdup(buf, GFP_KERNEL);           660         tmp = kstrdup(buf, GFP_KERNEL);
661         if (!tmp) {                               661         if (!tmp) {
662                 ret = -ENOMEM;                    662                 ret = -ENOMEM;
663                 goto err;                         663                 goto err;
664         }                                         664         }
665                                                   665 
666         ret = bch2_opt_parse(c, opt, strim(tmp    666         ret = bch2_opt_parse(c, opt, strim(tmp), &v, NULL);
667         kfree(tmp);                               667         kfree(tmp);
668                                                   668 
669         if (ret < 0)                              669         if (ret < 0)
670                 goto err;                         670                 goto err;
671                                                   671 
672         ret = bch2_opt_check_may_set(c, id, v)    672         ret = bch2_opt_check_may_set(c, id, v);
673         if (ret < 0)                              673         if (ret < 0)
674                 goto err;                         674                 goto err;
675                                                   675 
676         bch2_opt_set_sb(c, NULL, opt, v);         676         bch2_opt_set_sb(c, NULL, opt, v);
677         bch2_opt_set_by_id(&c->opts, id, v);      677         bch2_opt_set_by_id(&c->opts, id, v);
678                                                   678 
679         if (v &&                                  679         if (v &&
680             (id == Opt_background_target ||       680             (id == Opt_background_target ||
681              id == Opt_background_compression     681              id == Opt_background_compression ||
682              (id == Opt_compression && !c->opt    682              (id == Opt_compression && !c->opts.background_compression)))
683                 bch2_set_rebalance_needs_scan(    683                 bch2_set_rebalance_needs_scan(c, 0);
684                                                   684 
685         ret = size;                               685         ret = size;
686 err:                                              686 err:
687         bch2_write_ref_put(c, BCH_WRITE_REF_sy    687         bch2_write_ref_put(c, BCH_WRITE_REF_sysfs);
688         return ret;                               688         return ret;
689 }                                                 689 }
690 SYSFS_OPS(bch2_fs_opts_dir);                      690 SYSFS_OPS(bch2_fs_opts_dir);
691                                                   691 
692 struct attribute *bch2_fs_opts_dir_files[] = {    692 struct attribute *bch2_fs_opts_dir_files[] = { NULL };
693                                                   693 
694 int bch2_opts_create_sysfs_files(struct kobjec    694 int bch2_opts_create_sysfs_files(struct kobject *kobj)
695 {                                                 695 {
696         const struct bch_option *i;               696         const struct bch_option *i;
697         int ret;                                  697         int ret;
698                                                   698 
699         for (i = bch2_opt_table;                  699         for (i = bch2_opt_table;
700              i < bch2_opt_table + bch2_opts_nr    700              i < bch2_opt_table + bch2_opts_nr;
701              i++) {                               701              i++) {
702                 if (!(i->flags & OPT_FS))         702                 if (!(i->flags & OPT_FS))
703                         continue;                 703                         continue;
704                                                   704 
705                 ret = sysfs_create_file(kobj,     705                 ret = sysfs_create_file(kobj, &i->attr);
706                 if (ret)                          706                 if (ret)
707                         return ret;               707                         return ret;
708         }                                         708         }
709                                                   709 
710         return 0;                                 710         return 0;
711 }                                                 711 }
712                                                   712 
713 /* time stats */                                  713 /* time stats */
714                                                   714 
715 SHOW(bch2_fs_time_stats)                          715 SHOW(bch2_fs_time_stats)
716 {                                                 716 {
717         struct bch_fs *c = container_of(kobj,     717         struct bch_fs *c = container_of(kobj, struct bch_fs, time_stats);
718                                                   718 
719 #define x(name)                                   719 #define x(name)                                                         \
720         if (attr == &sysfs_time_stat_##name)      720         if (attr == &sysfs_time_stat_##name)                            \
721                 bch2_time_stats_to_text(out, &    721                 bch2_time_stats_to_text(out, &c->times[BCH_TIME_##name]);
722         BCH_TIME_STATS()                          722         BCH_TIME_STATS()
723 #undef x                                          723 #undef x
724                                                   724 
725         return 0;                                 725         return 0;
726 }                                                 726 }
727                                                   727 
728 STORE(bch2_fs_time_stats)                         728 STORE(bch2_fs_time_stats)
729 {                                                 729 {
730         struct bch_fs *c = container_of(kobj,     730         struct bch_fs *c = container_of(kobj, struct bch_fs, time_stats);
731                                                   731 
732 #define x(name)                                   732 #define x(name)                                                         \
733         if (attr == &sysfs_time_stat_##name)      733         if (attr == &sysfs_time_stat_##name)                            \
734                 bch2_time_stats_reset(&c->time    734                 bch2_time_stats_reset(&c->times[BCH_TIME_##name]);
735         BCH_TIME_STATS()                          735         BCH_TIME_STATS()
736 #undef x                                          736 #undef x
737         return size;                              737         return size;
738 }                                                 738 }
739 SYSFS_OPS(bch2_fs_time_stats);                    739 SYSFS_OPS(bch2_fs_time_stats);
740                                                   740 
741 struct attribute *bch2_fs_time_stats_files[] =    741 struct attribute *bch2_fs_time_stats_files[] = {
742 #define x(name)                                   742 #define x(name)                                         \
743         &sysfs_time_stat_##name,                  743         &sysfs_time_stat_##name,
744         BCH_TIME_STATS()                          744         BCH_TIME_STATS()
745 #undef x                                          745 #undef x
746         NULL                                      746         NULL
747 };                                                747 };
748                                                   748 
749 static const char * const bch2_rw[] = {           749 static const char * const bch2_rw[] = {
750         "read",                                   750         "read",
751         "write",                                  751         "write",
752         NULL                                      752         NULL
753 };                                                753 };
754                                                   754 
755 static void dev_io_done_to_text(struct printbu    755 static void dev_io_done_to_text(struct printbuf *out, struct bch_dev *ca)
756 {                                                 756 {
757         int rw, i;                                757         int rw, i;
758                                                   758 
759         for (rw = 0; rw < 2; rw++) {              759         for (rw = 0; rw < 2; rw++) {
760                 prt_printf(out, "%s:\n", bch2_    760                 prt_printf(out, "%s:\n", bch2_rw[rw]);
761                                                   761 
762                 for (i = 1; i < BCH_DATA_NR; i    762                 for (i = 1; i < BCH_DATA_NR; i++)
763                         prt_printf(out, "%-12s    763                         prt_printf(out, "%-12s:%12llu\n",
764                                bch2_data_type_    764                                bch2_data_type_str(i),
765                                percpu_u64_get(    765                                percpu_u64_get(&ca->io_done->sectors[rw][i]) << 9);
766         }                                         766         }
767 }                                                 767 }
768                                                   768 
769 SHOW(bch2_dev)                                    769 SHOW(bch2_dev)
770 {                                                 770 {
771         struct bch_dev *ca = container_of(kobj    771         struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
772         struct bch_fs *c = ca->fs;                772         struct bch_fs *c = ca->fs;
773                                                   773 
774         sysfs_printf(uuid,              "%pU\n    774         sysfs_printf(uuid,              "%pU\n", ca->uuid.b);
775                                                   775 
776         sysfs_print(bucket_size,        bucket    776         sysfs_print(bucket_size,        bucket_bytes(ca));
777         sysfs_print(first_bucket,       ca->mi    777         sysfs_print(first_bucket,       ca->mi.first_bucket);
778         sysfs_print(nbuckets,           ca->mi    778         sysfs_print(nbuckets,           ca->mi.nbuckets);
779         sysfs_print(durability,         ca->mi    779         sysfs_print(durability,         ca->mi.durability);
780         sysfs_print(discard,            ca->mi    780         sysfs_print(discard,            ca->mi.discard);
781                                                   781 
782         if (attr == &sysfs_label) {               782         if (attr == &sysfs_label) {
783                 if (ca->mi.group)                 783                 if (ca->mi.group)
784                         bch2_disk_path_to_text    784                         bch2_disk_path_to_text(out, c, ca->mi.group - 1);
785                 prt_char(out, '\n');              785                 prt_char(out, '\n');
786         }                                         786         }
787                                                   787 
788         if (attr == &sysfs_has_data) {            788         if (attr == &sysfs_has_data) {
789                 prt_bitflags(out, __bch2_data_    789                 prt_bitflags(out, __bch2_data_types, bch2_dev_has_data(c, ca));
790                 prt_char(out, '\n');              790                 prt_char(out, '\n');
791         }                                         791         }
792                                                   792 
793         if (attr == &sysfs_state_rw) {            793         if (attr == &sysfs_state_rw) {
794                 prt_string_option(out, bch2_me    794                 prt_string_option(out, bch2_member_states, ca->mi.state);
795                 prt_char(out, '\n');              795                 prt_char(out, '\n');
796         }                                         796         }
797                                                   797 
798         if (attr == &sysfs_io_done)               798         if (attr == &sysfs_io_done)
799                 dev_io_done_to_text(out, ca);     799                 dev_io_done_to_text(out, ca);
800                                                   800 
801         if (attr == &sysfs_io_errors)             801         if (attr == &sysfs_io_errors)
802                 bch2_dev_io_errors_to_text(out    802                 bch2_dev_io_errors_to_text(out, ca);
803                                                   803 
804         sysfs_print(io_latency_read,              804         sysfs_print(io_latency_read,            atomic64_read(&ca->cur_latency[READ]));
805         sysfs_print(io_latency_write,             805         sysfs_print(io_latency_write,           atomic64_read(&ca->cur_latency[WRITE]));
806                                                   806 
807         if (attr == &sysfs_io_latency_stats_re    807         if (attr == &sysfs_io_latency_stats_read)
808                 bch2_time_stats_to_text(out, &    808                 bch2_time_stats_to_text(out, &ca->io_latency[READ].stats);
809                                                   809 
810         if (attr == &sysfs_io_latency_stats_wr    810         if (attr == &sysfs_io_latency_stats_write)
811                 bch2_time_stats_to_text(out, &    811                 bch2_time_stats_to_text(out, &ca->io_latency[WRITE].stats);
812                                                   812 
813         sysfs_printf(congested,                   813         sysfs_printf(congested,                 "%u%%",
814                      clamp(atomic_read(&ca->co    814                      clamp(atomic_read(&ca->congested), 0, CONGESTED_MAX)
815                      * 100 / CONGESTED_MAX);      815                      * 100 / CONGESTED_MAX);
816                                                   816 
817         if (attr == &sysfs_alloc_debug)           817         if (attr == &sysfs_alloc_debug)
818                 bch2_dev_alloc_debug_to_text(o    818                 bch2_dev_alloc_debug_to_text(out, ca);
819                                                   819 
820         if (attr == &sysfs_open_buckets)          820         if (attr == &sysfs_open_buckets)
821                 bch2_open_buckets_to_text(out,    821                 bch2_open_buckets_to_text(out, c, ca);
822                                                   822 
823         return 0;                                 823         return 0;
824 }                                                 824 }
825                                                   825 
826 STORE(bch2_dev)                                   826 STORE(bch2_dev)
827 {                                                 827 {
828         struct bch_dev *ca = container_of(kobj    828         struct bch_dev *ca = container_of(kobj, struct bch_dev, kobj);
829         struct bch_fs *c = ca->fs;                829         struct bch_fs *c = ca->fs;
830                                                   830 
831         if (attr == &sysfs_discard) {             831         if (attr == &sysfs_discard) {
832                 bool v = strtoul_or_return(buf    832                 bool v = strtoul_or_return(buf);
833                                                   833 
834                 bch2_opt_set_sb(c, ca, bch2_op    834                 bch2_opt_set_sb(c, ca, bch2_opt_table + Opt_discard, v);
835         }                                         835         }
836                                                   836 
837         if (attr == &sysfs_durability) {          837         if (attr == &sysfs_durability) {
838                 u64 v = strtoul_or_return(buf)    838                 u64 v = strtoul_or_return(buf);
839                                                   839 
840                 bch2_opt_set_sb(c, ca, bch2_op    840                 bch2_opt_set_sb(c, ca, bch2_opt_table + Opt_durability, v);
841         }                                         841         }
842                                                   842 
843         if (attr == &sysfs_label) {               843         if (attr == &sysfs_label) {
844                 char *tmp;                        844                 char *tmp;
845                 int ret;                          845                 int ret;
846                                                   846 
847                 tmp = kstrdup(buf, GFP_KERNEL)    847                 tmp = kstrdup(buf, GFP_KERNEL);
848                 if (!tmp)                         848                 if (!tmp)
849                         return -ENOMEM;           849                         return -ENOMEM;
850                                                   850 
851                 ret = bch2_dev_group_set(c, ca    851                 ret = bch2_dev_group_set(c, ca, strim(tmp));
852                 kfree(tmp);                       852                 kfree(tmp);
853                 if (ret)                          853                 if (ret)
854                         return ret;               854                         return ret;
855         }                                         855         }
856                                                   856 
857         if (attr == &sysfs_io_errors_reset)       857         if (attr == &sysfs_io_errors_reset)
858                 bch2_dev_errors_reset(ca);        858                 bch2_dev_errors_reset(ca);
859                                                   859 
860         return size;                              860         return size;
861 }                                                 861 }
862 SYSFS_OPS(bch2_dev);                              862 SYSFS_OPS(bch2_dev);
863                                                   863 
864 struct attribute *bch2_dev_files[] = {            864 struct attribute *bch2_dev_files[] = {
865         &sysfs_uuid,                              865         &sysfs_uuid,
866         &sysfs_bucket_size,                       866         &sysfs_bucket_size,
867         &sysfs_first_bucket,                      867         &sysfs_first_bucket,
868         &sysfs_nbuckets,                          868         &sysfs_nbuckets,
869         &sysfs_durability,                        869         &sysfs_durability,
870                                                   870 
871         /* settings: */                           871         /* settings: */
872         &sysfs_discard,                           872         &sysfs_discard,
873         &sysfs_state_rw,                          873         &sysfs_state_rw,
874         &sysfs_label,                             874         &sysfs_label,
875                                                   875 
876         &sysfs_has_data,                          876         &sysfs_has_data,
877         &sysfs_io_done,                           877         &sysfs_io_done,
878         &sysfs_io_errors,                         878         &sysfs_io_errors,
879         &sysfs_io_errors_reset,                   879         &sysfs_io_errors_reset,
880                                                   880 
881         &sysfs_io_latency_read,                   881         &sysfs_io_latency_read,
882         &sysfs_io_latency_write,                  882         &sysfs_io_latency_write,
883         &sysfs_io_latency_stats_read,             883         &sysfs_io_latency_stats_read,
884         &sysfs_io_latency_stats_write,            884         &sysfs_io_latency_stats_write,
885         &sysfs_congested,                         885         &sysfs_congested,
886                                                   886 
887         /* debug: */                              887         /* debug: */
888         &sysfs_alloc_debug,                       888         &sysfs_alloc_debug,
889         &sysfs_open_buckets,                      889         &sysfs_open_buckets,
890         NULL                                      890         NULL
891 };                                                891 };
892                                                   892 
893 #endif  /* _BCACHEFS_SYSFS_H_ */                  893 #endif  /* _BCACHEFS_SYSFS_H_ */
894                                                   894 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php