]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/opts.h
Update bcachefs sources to f05b3c1af9 bcachefs: Improve bucket_alloc_fail tracepoint
[bcachefs-tools-debian] / libbcachefs / opts.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_OPTS_H
3 #define _BCACHEFS_OPTS_H
4
5 #include <linux/bug.h>
6 #include <linux/log2.h>
7 #include <linux/string.h>
8 #include <linux/sysfs.h>
9 #include "bcachefs_format.h"
10
11 extern const char * const bch2_error_actions[];
12 extern const char * const bch2_sb_features[];
13 extern const char * const bch2_sb_compat[];
14 extern const char * const bch2_btree_ids[];
15 extern const char * const bch2_csum_types[];
16 extern const char * const bch2_csum_opts[];
17 extern const char * const bch2_compression_types[];
18 extern const char * const bch2_compression_opts[];
19 extern const char * const bch2_str_hash_types[];
20 extern const char * const bch2_str_hash_opts[];
21 extern const char * const bch2_data_types[];
22 extern const char * const bch2_member_states[];
23 extern const char * const bch2_jset_entry_types[];
24 extern const char * const bch2_fs_usage_types[];
25 extern const char * const bch2_d_types[];
26
27 static inline const char *bch2_d_type_str(unsigned d_type)
28 {
29         return (d_type < BCH_DT_MAX ? bch2_d_types[d_type] : NULL) ?: "(bad d_type)";
30 }
31
32 /*
33  * Mount options; we also store defaults in the superblock.
34  *
35  * Also exposed via sysfs: if an option is writeable, and it's also stored in
36  * the superblock, changing it via sysfs (currently? might change this) also
37  * updates the superblock.
38  *
39  * We store options as signed integers, where -1 means undefined. This means we
40  * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only
41  * apply the options from that struct that are defined.
42  */
43
44 /* dummy option, for options that aren't stored in the superblock */
45 u64 BCH2_NO_SB_OPT(const struct bch_sb *);
46 void SET_BCH2_NO_SB_OPT(struct bch_sb *, u64);
47
48 /* When can be set: */
49 enum opt_flags {
50         OPT_FS          = (1 << 0),     /* Filesystem option */
51         OPT_DEVICE      = (1 << 1),     /* Device option */
52         OPT_INODE       = (1 << 2),     /* Inode option */
53         OPT_FORMAT      = (1 << 3),     /* May be specified at format time */
54         OPT_MOUNT       = (1 << 4),     /* May be specified at mount time */
55         OPT_RUNTIME     = (1 << 5),     /* May be specified at runtime */
56         OPT_HUMAN_READABLE = (1 << 6),
57         OPT_MUST_BE_POW_2 = (1 << 7),   /* Must be power of 2 */
58         OPT_SB_FIELD_SECTORS = (1 << 8),/* Superblock field is >> 9 of actual value */
59         OPT_SB_FIELD_ILOG2 = (1 << 9),  /* Superblock field is ilog2 of actual value */
60 };
61
62 enum opt_type {
63         BCH_OPT_BOOL,
64         BCH_OPT_UINT,
65         BCH_OPT_STR,
66         BCH_OPT_FN,
67 };
68
69 /**
70  * x(name, shortopt, type, in mem type, mode, sb_opt)
71  *
72  * @name        - name of mount option, sysfs attribute, and struct bch_opts
73  *                member
74  *
75  * @mode        - when opt may be set
76  *
77  * @sb_option   - name of corresponding superblock option
78  *
79  * @type        - one of OPT_BOOL, OPT_UINT, OPT_STR
80  */
81
82 /*
83  * XXX: add fields for
84  *  - default value
85  *  - helptext
86  */
87
88 #ifdef __KERNEL__
89 #define RATELIMIT_ERRORS_DEFAULT true
90 #else
91 #define RATELIMIT_ERRORS_DEFAULT false
92 #endif
93
94 #define BCH_OPTS()                                                      \
95         x(block_size,                   u16,                            \
96           OPT_FS|OPT_FORMAT|                                            \
97           OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS,    \
98           OPT_UINT(512, 1U << 16),                                      \
99           BCH_SB_BLOCK_SIZE,            8,                              \
100           "size",       NULL)                                           \
101         x(btree_node_size,              u32,                            \
102           OPT_FS|OPT_FORMAT|                                            \
103           OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS,    \
104           OPT_UINT(512, 1U << 20),                                      \
105           BCH_SB_BTREE_NODE_SIZE,       512,                            \
106           "size",       "Btree node size, default 256k")                \
107         x(errors,                       u8,                             \
108           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
109           OPT_STR(bch2_error_actions),                                  \
110           BCH_SB_ERROR_ACTION,          BCH_ON_ERROR_ro,                \
111           NULL,         "Action to take on filesystem error")           \
112         x(metadata_replicas,            u8,                             \
113           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
114           OPT_UINT(1, BCH_REPLICAS_MAX),                                \
115           BCH_SB_META_REPLICAS_WANT,    1,                              \
116           "#",          "Number of metadata replicas")                  \
117         x(data_replicas,                u8,                             \
118           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
119           OPT_UINT(1, BCH_REPLICAS_MAX),                                \
120           BCH_SB_DATA_REPLICAS_WANT,    1,                              \
121           "#",          "Number of data replicas")                      \
122         x(metadata_replicas_required, u8,                               \
123           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
124           OPT_UINT(1, BCH_REPLICAS_MAX),                                \
125           BCH_SB_META_REPLICAS_REQ,     1,                              \
126           "#",          NULL)                                           \
127         x(data_replicas_required,       u8,                             \
128           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
129           OPT_UINT(1, BCH_REPLICAS_MAX),                                \
130           BCH_SB_DATA_REPLICAS_REQ,     1,                              \
131           "#",          NULL)                                           \
132         x(encoded_extent_max,           u32,                            \
133           OPT_FS|OPT_FORMAT|                                            \
134           OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\
135           OPT_UINT(4096, 2U << 20),                                     \
136           BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10,                     \
137           "size",       "Maximum size of checksummed/compressed extents")\
138         x(metadata_checksum,            u8,                             \
139           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
140           OPT_STR(bch2_csum_opts),                                      \
141           BCH_SB_META_CSUM_TYPE,        BCH_CSUM_OPT_crc32c,            \
142           NULL,         NULL)                                           \
143         x(data_checksum,                u8,                             \
144           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
145           OPT_STR(bch2_csum_opts),                                      \
146           BCH_SB_DATA_CSUM_TYPE,        BCH_CSUM_OPT_crc32c,            \
147           NULL,         NULL)                                           \
148         x(compression,                  u8,                             \
149           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
150           OPT_STR(bch2_compression_opts),                               \
151           BCH_SB_COMPRESSION_TYPE,      BCH_COMPRESSION_OPT_none,       \
152           NULL,         NULL)                                           \
153         x(background_compression,       u8,                             \
154           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
155           OPT_STR(bch2_compression_opts),                               \
156           BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none,  \
157           NULL,         NULL)                                           \
158         x(str_hash,                     u8,                             \
159           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
160           OPT_STR(bch2_str_hash_opts),                                  \
161           BCH_SB_STR_HASH_TYPE,         BCH_STR_HASH_OPT_siphash,       \
162           NULL,         "Hash function for directory entries and xattrs")\
163         x(metadata_target,              u16,                            \
164           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
165           OPT_FN(bch2_opt_target),                                      \
166           BCH_SB_METADATA_TARGET,       0,                              \
167           "(target)",   "Device or disk group for metadata writes")     \
168         x(foreground_target,            u16,                            \
169           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
170           OPT_FN(bch2_opt_target),                                      \
171           BCH_SB_FOREGROUND_TARGET,     0,                              \
172           "(target)",   "Device or disk group for foreground writes")   \
173         x(background_target,            u16,                            \
174           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
175           OPT_FN(bch2_opt_target),                                      \
176           BCH_SB_BACKGROUND_TARGET,     0,                              \
177           "(target)",   "Device or disk group to move data to in the background")\
178         x(promote_target,               u16,                            \
179           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
180           OPT_FN(bch2_opt_target),                                      \
181           BCH_SB_PROMOTE_TARGET,        0,                              \
182           "(target)",   "Device or disk group to promote data to on read")\
183         x(erasure_code,                 u16,                            \
184           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
185           OPT_BOOL(),                                                   \
186           BCH_SB_ERASURE_CODE,          false,                          \
187           NULL,         "Enable erasure coding (DO NOT USE YET)")       \
188         x(inodes_32bit,                 u8,                             \
189           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
190           OPT_BOOL(),                                                   \
191           BCH_SB_INODE_32BIT,           true,                           \
192           NULL,         "Constrain inode numbers to 32 bits")           \
193         x(shard_inode_numbers,          u8,                             \
194           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
195           OPT_BOOL(),                                                   \
196           BCH_SB_SHARD_INUMS,           true,                           \
197           NULL,         "Shard new inode numbers by CPU id")            \
198         x(inodes_use_key_cache, u8,                                     \
199           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
200           OPT_BOOL(),                                                   \
201           BCH_SB_INODES_USE_KEY_CACHE,  true,                           \
202           NULL,         "Use the btree key cache for the inodes btree") \
203         x(btree_node_mem_ptr_optimization, u8,                          \
204           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
205           OPT_BOOL(),                                                   \
206           BCH2_NO_SB_OPT,               true,                           \
207           NULL,         "Stash pointer to in memory btree node in btree ptr")\
208         x(gc_reserve_percent,           u8,                             \
209           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
210           OPT_UINT(5, 21),                                              \
211           BCH_SB_GC_RESERVE,            8,                              \
212           "%",          "Percentage of disk space to reserve for copygc")\
213         x(gc_reserve_bytes,             u64,                            \
214           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|                      \
215           OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS,                      \
216           OPT_UINT(0, U64_MAX),                                         \
217           BCH_SB_GC_RESERVE_BYTES,      0,                              \
218           "%",          "Amount of disk space to reserve for copygc\n"  \
219                         "Takes precedence over gc_reserve_percent if set")\
220         x(root_reserve_percent,         u8,                             \
221           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
222           OPT_UINT(0, 100),                                             \
223           BCH_SB_ROOT_RESERVE,          0,                              \
224           "%",          "Percentage of disk space to reserve for superuser")\
225         x(wide_macs,                    u8,                             \
226           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
227           OPT_BOOL(),                                                   \
228           BCH_SB_128_BIT_MACS,          false,                          \
229           NULL,         "Store full 128 bits of cryptographic MACs, instead of 80")\
230         x(inline_data,                  u8,                             \
231           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
232           OPT_BOOL(),                                                   \
233           BCH2_NO_SB_OPT,               true,                           \
234           NULL,         "Enable inline data extents")                   \
235         x(acl,                          u8,                             \
236           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
237           OPT_BOOL(),                                                   \
238           BCH_SB_POSIX_ACL,             true,                           \
239           NULL,         "Enable POSIX acls")                            \
240         x(usrquota,                     u8,                             \
241           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
242           OPT_BOOL(),                                                   \
243           BCH_SB_USRQUOTA,              false,                          \
244           NULL,         "Enable user quotas")                           \
245         x(grpquota,                     u8,                             \
246           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
247           OPT_BOOL(),                                                   \
248           BCH_SB_GRPQUOTA,              false,                          \
249           NULL,         "Enable group quotas")                          \
250         x(prjquota,                     u8,                             \
251           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
252           OPT_BOOL(),                                                   \
253           BCH_SB_PRJQUOTA,              false,                          \
254           NULL,         "Enable project quotas")                        \
255         x(degraded,                     u8,                             \
256           OPT_FS|OPT_MOUNT,                                             \
257           OPT_BOOL(),                                                   \
258           BCH2_NO_SB_OPT,               false,                          \
259           NULL,         "Allow mounting in degraded mode")              \
260         x(very_degraded,                u8,                             \
261           OPT_FS|OPT_MOUNT,                                             \
262           OPT_BOOL(),                                                   \
263           BCH2_NO_SB_OPT,               false,                          \
264           NULL,         "Allow mounting in when data will be missing")  \
265         x(discard,                      u8,                             \
266           OPT_FS|OPT_MOUNT|OPT_DEVICE,                                  \
267           OPT_BOOL(),                                                   \
268           BCH2_NO_SB_OPT,               true,                           \
269           NULL,         "Enable discard/TRIM support")                  \
270         x(verbose,                      u8,                             \
271           OPT_FS|OPT_MOUNT,                                             \
272           OPT_BOOL(),                                                   \
273           BCH2_NO_SB_OPT,               false,                          \
274           NULL,         "Extra debugging information during mount/recovery")\
275         x(journal_flush_delay,          u32,                            \
276           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
277           OPT_UINT(0, U32_MAX),                                         \
278           BCH_SB_JOURNAL_FLUSH_DELAY,   1000,                           \
279           NULL,         "Delay in milliseconds before automatic journal commits")\
280         x(journal_flush_disabled,       u8,                             \
281           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
282           OPT_BOOL(),                                                   \
283           BCH_SB_JOURNAL_FLUSH_DISABLED,false,                          \
284           NULL,         "Disable journal flush on sync/fsync\n"         \
285                         "If enabled, writes can be lost, but only since the\n"\
286                         "last journal write (default 1 second)")        \
287         x(journal_reclaim_delay,        u32,                            \
288           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
289           OPT_UINT(0, U32_MAX),                                         \
290           BCH_SB_JOURNAL_RECLAIM_DELAY, 100,                            \
291           NULL,         "Delay in milliseconds before automatic journal reclaim")\
292         x(fsck,                         u8,                             \
293           OPT_FS|OPT_MOUNT,                                             \
294           OPT_BOOL(),                                                   \
295           BCH2_NO_SB_OPT,               false,                          \
296           NULL,         "Run fsck on mount")                            \
297         x(fix_errors,                   u8,                             \
298           OPT_FS|OPT_MOUNT,                                             \
299           OPT_BOOL(),                                                   \
300           BCH2_NO_SB_OPT,               false,                          \
301           NULL,         "Fix errors during fsck without asking")        \
302         x(ratelimit_errors,             u8,                             \
303           OPT_FS|OPT_MOUNT,                                             \
304           OPT_BOOL(),                                                   \
305           BCH2_NO_SB_OPT,               RATELIMIT_ERRORS_DEFAULT,       \
306           NULL,         "Ratelimit error messages during fsck")         \
307         x(nochanges,                    u8,                             \
308           OPT_FS|OPT_MOUNT,                                             \
309           OPT_BOOL(),                                                   \
310           BCH2_NO_SB_OPT,               false,                          \
311           NULL,         "Super read only mode - no writes at all will be issued,\n"\
312                         "even if we have to replay the journal")        \
313         x(norecovery,                   u8,                             \
314           OPT_FS|OPT_MOUNT,                                             \
315           OPT_BOOL(),                                                   \
316           BCH2_NO_SB_OPT,                       false,                          \
317           NULL,         "Don't replay the journal")                     \
318         x(rebuild_replicas,             u8,                             \
319           OPT_FS|OPT_MOUNT,                                             \
320           OPT_BOOL(),                                                   \
321           BCH2_NO_SB_OPT,                       false,                          \
322           NULL,         "Rebuild the superblock replicas section")      \
323         x(keep_journal,                 u8,                             \
324           0,                                                            \
325           OPT_BOOL(),                                                   \
326           BCH2_NO_SB_OPT,                       false,                          \
327           NULL,         "Don't free journal entries/keys after startup")\
328         x(read_entire_journal,          u8,                             \
329           0,                                                            \
330           OPT_BOOL(),                                                   \
331           BCH2_NO_SB_OPT,                       false,                          \
332           NULL,         "Read all journal entries, not just dirty ones")\
333         x(read_journal_only,            u8,                             \
334           0,                                                            \
335           OPT_BOOL(),                                                   \
336           BCH2_NO_SB_OPT,                       false,                          \
337           NULL,         "Only read the journal, skip the rest of recovery")\
338         x(journal_transaction_names,    u8,                             \
339           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
340           OPT_BOOL(),                                                   \
341           BCH_SB_JOURNAL_TRANSACTION_NAMES, true,                       \
342           NULL,         "Log transaction function names in journal")    \
343         x(noexcl,                       u8,                             \
344           OPT_FS|OPT_MOUNT,                                             \
345           OPT_BOOL(),                                                   \
346           BCH2_NO_SB_OPT,                       false,                          \
347           NULL,         "Don't open device in exclusive mode")          \
348         x(sb,                           u64,                            \
349           OPT_MOUNT,                                                    \
350           OPT_UINT(0, S64_MAX),                                         \
351           BCH2_NO_SB_OPT,                       BCH_SB_SECTOR,                  \
352           "offset",     "Sector offset of superblock")                  \
353         x(read_only,                    u8,                             \
354           OPT_FS,                                                       \
355           OPT_BOOL(),                                                   \
356           BCH2_NO_SB_OPT,                       false,                          \
357           NULL,         NULL)                                           \
358         x(nostart,                      u8,                             \
359           0,                                                            \
360           OPT_BOOL(),                                                   \
361           BCH2_NO_SB_OPT,                       false,                          \
362           NULL,         "Don\'t start filesystem, only open devices")   \
363         x(reconstruct_alloc,            u8,                             \
364           OPT_FS|OPT_MOUNT,                                             \
365           OPT_BOOL(),                                                   \
366           BCH2_NO_SB_OPT,                       false,                          \
367           NULL,         "Reconstruct alloc btree")                      \
368         x(version_upgrade,              u8,                             \
369           OPT_FS|OPT_MOUNT,                                             \
370           OPT_BOOL(),                                                   \
371           BCH2_NO_SB_OPT,                       false,                          \
372           NULL,         "Set superblock to latest version,\n"           \
373                         "allowing any new features to be used")         \
374         x(buckets_nouse,                u8,                             \
375           0,                                                            \
376           OPT_BOOL(),                                                   \
377           BCH2_NO_SB_OPT,                       false,                          \
378           NULL,         "Allocate the buckets_nouse bitmap")            \
379         x(project,                      u8,                             \
380           OPT_INODE,                                                    \
381           OPT_BOOL(),                                                   \
382           BCH2_NO_SB_OPT,                       false,                          \
383           NULL,         NULL)                                           \
384         x(fs_size,                      u64,                            \
385           OPT_DEVICE,                                                   \
386           OPT_UINT(0, S64_MAX),                                         \
387           BCH2_NO_SB_OPT,               0,                              \
388           "size",       "Size of filesystem on device")                 \
389         x(bucket,                       u32,                            \
390           OPT_DEVICE,                                                   \
391           OPT_UINT(0, S64_MAX),                                         \
392           BCH2_NO_SB_OPT,               0,                              \
393           "size",       "Size of filesystem on device")                 \
394         x(durability,                   u8,                             \
395           OPT_DEVICE,                                                   \
396           OPT_UINT(0, BCH_REPLICAS_MAX),                                \
397           BCH2_NO_SB_OPT,               1,                              \
398           "n",          "Data written to this device will be considered\n"\
399                         "to have already been replicated n times")
400
401 struct bch_opts {
402 #define x(_name, _bits, ...)    unsigned _name##_defined:1;
403         BCH_OPTS()
404 #undef x
405
406 #define x(_name, _bits, ...)    _bits   _name;
407         BCH_OPTS()
408 #undef x
409 };
410
411 static const struct bch_opts bch2_opts_default = {
412 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...)           \
413         ._name##_defined = true,                                        \
414         ._name = _default,                                              \
415
416         BCH_OPTS()
417 #undef x
418 };
419
420 #define opt_defined(_opts, _name)       ((_opts)._name##_defined)
421
422 #define opt_get(_opts, _name)                                           \
423         (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
424
425 #define opt_set(_opts, _name, _v)                                       \
426 do {                                                                    \
427         (_opts)._name##_defined = true;                                 \
428         (_opts)._name = _v;                                             \
429 } while (0)
430
431 static inline struct bch_opts bch2_opts_empty(void)
432 {
433         return (struct bch_opts) { 0 };
434 }
435
436 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
437
438 enum bch_opt_id {
439 #define x(_name, ...)   Opt_##_name,
440         BCH_OPTS()
441 #undef x
442         bch2_opts_nr
443 };
444
445 struct bch_fs;
446 struct printbuf;
447
448 struct bch_option {
449         struct attribute        attr;
450         u64                     (*get_sb)(const struct bch_sb *);
451         void                    (*set_sb)(struct bch_sb *, u64);
452         enum opt_type           type;
453         enum opt_flags          flags;
454         u64                     min, max;
455
456         union {
457         struct {
458         };
459         struct {
460                 const char * const *choices;
461         };
462         struct {
463                 int (*parse)(struct bch_fs *, const char *, u64 *);
464                 void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
465         };
466         };
467
468         const char              *hint;
469         const char              *help;
470
471 };
472
473 extern const struct bch_option bch2_opt_table[];
474
475 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
476 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
477 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
478
479 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id);
480 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
481 void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64);
482 void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64);
483
484 int bch2_opt_lookup(const char *);
485 int bch2_opt_parse(struct bch_fs *, const char *, const struct bch_option *,
486                    const char *, u64 *);
487
488 #define OPT_SHOW_FULL_LIST      (1 << 0)
489 #define OPT_SHOW_MOUNT_STYLE    (1 << 1)
490
491 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
492                       const struct bch_option *, u64, unsigned);
493
494 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
495 int bch2_opts_check_may_set(struct bch_fs *);
496 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
497
498 /* inode opts: */
499
500 struct bch_io_opts {
501 #define x(_name, _bits) unsigned _name##_defined:1;
502         BCH_INODE_OPTS()
503 #undef x
504
505 #define x(_name, _bits) u##_bits _name;
506         BCH_INODE_OPTS()
507 #undef x
508 };
509
510 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
511 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
512 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
513 bool bch2_opt_is_inode_opt(enum bch_opt_id);
514
515 #endif /* _BCACHEFS_OPTS_H */