]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/opts.h
Update bcachefs sources to 25de2b00dc bcachefs: Change check for invalid key types
[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 #ifdef CONFIG_BCACHEFS_DEBUG
95 #define BCACHEFS_VERBOSE_DEFAULT        true
96 #else
97 #define BCACHEFS_VERBOSE_DEFAULT        false
98 #endif
99
100 #define BCH_OPTS()                                                      \
101         x(block_size,                   u16,                            \
102           OPT_FS|OPT_FORMAT|                                            \
103           OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS,    \
104           OPT_UINT(512, 1U << 16),                                      \
105           BCH_SB_BLOCK_SIZE,            8,                              \
106           "size",       NULL)                                           \
107         x(btree_node_size,              u32,                            \
108           OPT_FS|OPT_FORMAT|                                            \
109           OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS,    \
110           OPT_UINT(512, 1U << 20),                                      \
111           BCH_SB_BTREE_NODE_SIZE,       512,                            \
112           "size",       "Btree node size, default 256k")                \
113         x(errors,                       u8,                             \
114           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
115           OPT_STR(bch2_error_actions),                                  \
116           BCH_SB_ERROR_ACTION,          BCH_ON_ERROR_ro,                \
117           NULL,         "Action to take on filesystem error")           \
118         x(metadata_replicas,            u8,                             \
119           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
120           OPT_UINT(1, BCH_REPLICAS_MAX),                                \
121           BCH_SB_META_REPLICAS_WANT,    1,                              \
122           "#",          "Number of metadata replicas")                  \
123         x(data_replicas,                u8,                             \
124           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
125           OPT_UINT(1, BCH_REPLICAS_MAX),                                \
126           BCH_SB_DATA_REPLICAS_WANT,    1,                              \
127           "#",          "Number of data replicas")                      \
128         x(metadata_replicas_required, u8,                               \
129           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
130           OPT_UINT(1, BCH_REPLICAS_MAX),                                \
131           BCH_SB_META_REPLICAS_REQ,     1,                              \
132           "#",          NULL)                                           \
133         x(data_replicas_required,       u8,                             \
134           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
135           OPT_UINT(1, BCH_REPLICAS_MAX),                                \
136           BCH_SB_DATA_REPLICAS_REQ,     1,                              \
137           "#",          NULL)                                           \
138         x(encoded_extent_max,           u32,                            \
139           OPT_FS|OPT_FORMAT|                                            \
140           OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\
141           OPT_UINT(4096, 2U << 20),                                     \
142           BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10,                     \
143           "size",       "Maximum size of checksummed/compressed extents")\
144         x(metadata_checksum,            u8,                             \
145           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
146           OPT_STR(bch2_csum_opts),                                      \
147           BCH_SB_META_CSUM_TYPE,        BCH_CSUM_OPT_crc32c,            \
148           NULL,         NULL)                                           \
149         x(data_checksum,                u8,                             \
150           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
151           OPT_STR(bch2_csum_opts),                                      \
152           BCH_SB_DATA_CSUM_TYPE,        BCH_CSUM_OPT_crc32c,            \
153           NULL,         NULL)                                           \
154         x(compression,                  u8,                             \
155           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
156           OPT_STR(bch2_compression_opts),                               \
157           BCH_SB_COMPRESSION_TYPE,      BCH_COMPRESSION_OPT_none,       \
158           NULL,         NULL)                                           \
159         x(background_compression,       u8,                             \
160           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
161           OPT_STR(bch2_compression_opts),                               \
162           BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none,  \
163           NULL,         NULL)                                           \
164         x(str_hash,                     u8,                             \
165           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
166           OPT_STR(bch2_str_hash_opts),                                  \
167           BCH_SB_STR_HASH_TYPE,         BCH_STR_HASH_OPT_siphash,       \
168           NULL,         "Hash function for directory entries and xattrs")\
169         x(metadata_target,              u16,                            \
170           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
171           OPT_FN(bch2_opt_target),                                      \
172           BCH_SB_METADATA_TARGET,       0,                              \
173           "(target)",   "Device or label for metadata writes")          \
174         x(foreground_target,            u16,                            \
175           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
176           OPT_FN(bch2_opt_target),                                      \
177           BCH_SB_FOREGROUND_TARGET,     0,                              \
178           "(target)",   "Device or label for foreground writes")        \
179         x(background_target,            u16,                            \
180           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
181           OPT_FN(bch2_opt_target),                                      \
182           BCH_SB_BACKGROUND_TARGET,     0,                              \
183           "(target)",   "Device or label to move data to in the background")\
184         x(promote_target,               u16,                            \
185           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
186           OPT_FN(bch2_opt_target),                                      \
187           BCH_SB_PROMOTE_TARGET,        0,                              \
188           "(target)",   "Device or label to promote data to on read")   \
189         x(erasure_code,                 u16,                            \
190           OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,            \
191           OPT_BOOL(),                                                   \
192           BCH_SB_ERASURE_CODE,          false,                          \
193           NULL,         "Enable erasure coding (DO NOT USE YET)")       \
194         x(inodes_32bit,                 u8,                             \
195           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
196           OPT_BOOL(),                                                   \
197           BCH_SB_INODE_32BIT,           true,                           \
198           NULL,         "Constrain inode numbers to 32 bits")           \
199         x(shard_inode_numbers,          u8,                             \
200           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
201           OPT_BOOL(),                                                   \
202           BCH_SB_SHARD_INUMS,           true,                           \
203           NULL,         "Shard new inode numbers by CPU id")            \
204         x(inodes_use_key_cache, u8,                                     \
205           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
206           OPT_BOOL(),                                                   \
207           BCH_SB_INODES_USE_KEY_CACHE,  true,                           \
208           NULL,         "Use the btree key cache for the inodes btree") \
209         x(btree_node_mem_ptr_optimization, u8,                          \
210           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
211           OPT_BOOL(),                                                   \
212           BCH2_NO_SB_OPT,               true,                           \
213           NULL,         "Stash pointer to in memory btree node in btree ptr")\
214         x(btree_write_buffer_size, u32,                                 \
215           OPT_FS|OPT_MOUNT,                                             \
216           OPT_UINT(16, (1U << 20) - 1),                                 \
217           BCH2_NO_SB_OPT,               1U << 13,                       \
218           NULL,         "Number of btree write buffer entries")         \
219         x(gc_reserve_percent,           u8,                             \
220           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
221           OPT_UINT(5, 21),                                              \
222           BCH_SB_GC_RESERVE,            8,                              \
223           "%",          "Percentage of disk space to reserve for copygc")\
224         x(gc_reserve_bytes,             u64,                            \
225           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|                      \
226           OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS,                      \
227           OPT_UINT(0, U64_MAX),                                         \
228           BCH_SB_GC_RESERVE_BYTES,      0,                              \
229           "%",          "Amount of disk space to reserve for copygc\n"  \
230                         "Takes precedence over gc_reserve_percent if set")\
231         x(root_reserve_percent,         u8,                             \
232           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
233           OPT_UINT(0, 100),                                             \
234           BCH_SB_ROOT_RESERVE,          0,                              \
235           "%",          "Percentage of disk space to reserve for superuser")\
236         x(wide_macs,                    u8,                             \
237           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
238           OPT_BOOL(),                                                   \
239           BCH_SB_128_BIT_MACS,          false,                          \
240           NULL,         "Store full 128 bits of cryptographic MACs, instead of 80")\
241         x(inline_data,                  u8,                             \
242           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
243           OPT_BOOL(),                                                   \
244           BCH2_NO_SB_OPT,               true,                           \
245           NULL,         "Enable inline data extents")                   \
246         x(acl,                          u8,                             \
247           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
248           OPT_BOOL(),                                                   \
249           BCH_SB_POSIX_ACL,             true,                           \
250           NULL,         "Enable POSIX acls")                            \
251         x(usrquota,                     u8,                             \
252           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
253           OPT_BOOL(),                                                   \
254           BCH_SB_USRQUOTA,              false,                          \
255           NULL,         "Enable user quotas")                           \
256         x(grpquota,                     u8,                             \
257           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
258           OPT_BOOL(),                                                   \
259           BCH_SB_GRPQUOTA,              false,                          \
260           NULL,         "Enable group quotas")                          \
261         x(prjquota,                     u8,                             \
262           OPT_FS|OPT_FORMAT|OPT_MOUNT,                                  \
263           OPT_BOOL(),                                                   \
264           BCH_SB_PRJQUOTA,              false,                          \
265           NULL,         "Enable project quotas")                        \
266         x(degraded,                     u8,                             \
267           OPT_FS|OPT_MOUNT,                                             \
268           OPT_BOOL(),                                                   \
269           BCH2_NO_SB_OPT,               false,                          \
270           NULL,         "Allow mounting in degraded mode")              \
271         x(very_degraded,                u8,                             \
272           OPT_FS|OPT_MOUNT,                                             \
273           OPT_BOOL(),                                                   \
274           BCH2_NO_SB_OPT,               false,                          \
275           NULL,         "Allow mounting in when data will be missing")  \
276         x(discard,                      u8,                             \
277           OPT_FS|OPT_MOUNT|OPT_DEVICE,                                  \
278           OPT_BOOL(),                                                   \
279           BCH2_NO_SB_OPT,               true,                           \
280           NULL,         "Enable discard/TRIM support")                  \
281         x(verbose,                      u8,                             \
282           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
283           OPT_BOOL(),                                                   \
284           BCH2_NO_SB_OPT,               BCACHEFS_VERBOSE_DEFAULT,       \
285           NULL,         "Extra debugging information during mount/recovery")\
286         x(journal_flush_delay,          u32,                            \
287           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
288           OPT_UINT(1, U32_MAX),                                         \
289           BCH_SB_JOURNAL_FLUSH_DELAY,   1000,                           \
290           NULL,         "Delay in milliseconds before automatic journal commits")\
291         x(journal_flush_disabled,       u8,                             \
292           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
293           OPT_BOOL(),                                                   \
294           BCH_SB_JOURNAL_FLUSH_DISABLED,false,                          \
295           NULL,         "Disable journal flush on sync/fsync\n"         \
296                         "If enabled, writes can be lost, but only since the\n"\
297                         "last journal write (default 1 second)")        \
298         x(journal_reclaim_delay,        u32,                            \
299           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
300           OPT_UINT(0, U32_MAX),                                         \
301           BCH_SB_JOURNAL_RECLAIM_DELAY, 100,                            \
302           NULL,         "Delay in milliseconds before automatic journal reclaim")\
303         x(move_bytes_in_flight,         u32,                            \
304           OPT_HUMAN_READABLE|OPT_FS|OPT_MOUNT|OPT_RUNTIME,              \
305           OPT_UINT(1024, U32_MAX),                                      \
306           BCH2_NO_SB_OPT,               1U << 20,                       \
307           NULL,         "Maximum Amount of IO to keep in flight by the move path")\
308         x(move_ios_in_flight,           u32,                            \
309           OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
310           OPT_UINT(1, 1024),                                            \
311           BCH2_NO_SB_OPT,               32,                             \
312           NULL,         "Maximum number of IOs to keep in flight by the move path")\
313         x(fsck,                         u8,                             \
314           OPT_FS|OPT_MOUNT,                                             \
315           OPT_BOOL(),                                                   \
316           BCH2_NO_SB_OPT,               false,                          \
317           NULL,         "Run fsck on mount")                            \
318         x(fix_errors,                   u8,                             \
319           OPT_FS|OPT_MOUNT,                                             \
320           OPT_BOOL(),                                                   \
321           BCH2_NO_SB_OPT,               false,                          \
322           NULL,         "Fix errors during fsck without asking")        \
323         x(ratelimit_errors,             u8,                             \
324           OPT_FS|OPT_MOUNT,                                             \
325           OPT_BOOL(),                                                   \
326           BCH2_NO_SB_OPT,               RATELIMIT_ERRORS_DEFAULT,       \
327           NULL,         "Ratelimit error messages during fsck")         \
328         x(nochanges,                    u8,                             \
329           OPT_FS|OPT_MOUNT,                                             \
330           OPT_BOOL(),                                                   \
331           BCH2_NO_SB_OPT,               false,                          \
332           NULL,         "Super read only mode - no writes at all will be issued,\n"\
333                         "even if we have to replay the journal")        \
334         x(norecovery,                   u8,                             \
335           OPT_FS|OPT_MOUNT,                                             \
336           OPT_BOOL(),                                                   \
337           BCH2_NO_SB_OPT,               false,                          \
338           NULL,         "Don't replay the journal")                     \
339         x(keep_journal,                 u8,                             \
340           0,                                                            \
341           OPT_BOOL(),                                                   \
342           BCH2_NO_SB_OPT,               false,                          \
343           NULL,         "Don't free journal entries/keys after startup")\
344         x(read_entire_journal,          u8,                             \
345           0,                                                            \
346           OPT_BOOL(),                                                   \
347           BCH2_NO_SB_OPT,               false,                          \
348           NULL,         "Read all journal entries, not just dirty ones")\
349         x(read_journal_only,            u8,                             \
350           0,                                                            \
351           OPT_BOOL(),                                                   \
352           BCH2_NO_SB_OPT,               false,                          \
353           NULL,         "Only read the journal, skip the rest of recovery")\
354         x(journal_transaction_names,    u8,                             \
355           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                      \
356           OPT_BOOL(),                                                   \
357           BCH_SB_JOURNAL_TRANSACTION_NAMES, true,                       \
358           NULL,         "Log transaction function names in journal")    \
359         x(noexcl,                       u8,                             \
360           OPT_FS|OPT_MOUNT,                                             \
361           OPT_BOOL(),                                                   \
362           BCH2_NO_SB_OPT,               false,                          \
363           NULL,         "Don't open device in exclusive mode")          \
364         x(direct_io,                    u8,                             \
365           OPT_FS|OPT_MOUNT,                                             \
366           OPT_BOOL(),                                                   \
367           BCH2_NO_SB_OPT,                       true,                   \
368           NULL,         "Use O_DIRECT (userspace only)")                \
369         x(sb,                           u64,                            \
370           OPT_MOUNT,                                                    \
371           OPT_UINT(0, S64_MAX),                                         \
372           BCH2_NO_SB_OPT,               BCH_SB_SECTOR,                  \
373           "offset",     "Sector offset of superblock")                  \
374         x(read_only,                    u8,                             \
375           OPT_FS,                                                       \
376           OPT_BOOL(),                                                   \
377           BCH2_NO_SB_OPT,               false,                          \
378           NULL,         NULL)                                           \
379         x(nostart,                      u8,                             \
380           0,                                                            \
381           OPT_BOOL(),                                                   \
382           BCH2_NO_SB_OPT,               false,                          \
383           NULL,         "Don\'t start filesystem, only open devices")   \
384         x(reconstruct_alloc,            u8,                             \
385           OPT_FS|OPT_MOUNT,                                             \
386           OPT_BOOL(),                                                   \
387           BCH2_NO_SB_OPT,               false,                          \
388           NULL,         "Reconstruct alloc btree")                      \
389         x(version_upgrade,              u8,                             \
390           OPT_FS|OPT_MOUNT,                                             \
391           OPT_BOOL(),                                                   \
392           BCH2_NO_SB_OPT,               false,                          \
393           NULL,         "Set superblock to latest version,\n"           \
394                         "allowing any new features to be used")         \
395         x(buckets_nouse,                u8,                             \
396           0,                                                            \
397           OPT_BOOL(),                                                   \
398           BCH2_NO_SB_OPT,               false,                          \
399           NULL,         "Allocate the buckets_nouse bitmap")            \
400         x(project,                      u8,                             \
401           OPT_INODE,                                                    \
402           OPT_BOOL(),                                                   \
403           BCH2_NO_SB_OPT,               false,                          \
404           NULL,         NULL)                                           \
405         x(nocow,                        u8,                             \
406           OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE,            \
407           OPT_BOOL(),                                                   \
408           BCH_SB_NOCOW,                 false,                          \
409           NULL,         "Nocow mode: Writes will be done in place when possible.\n"\
410                         "Snapshots and reflink will still caused writes to be COW\n"\
411                         "Implicitly disables data checksumming, compression and encryption")\
412         x(nocow_enabled,                u8,                             \
413           OPT_FS|OPT_MOUNT,                                             \
414           OPT_BOOL(),                                                   \
415           BCH2_NO_SB_OPT,                       true,                   \
416           NULL,         "Enable nocow mode: enables runtime locking in\n"\
417                         "data move path needed if nocow will ever be in use\n")\
418         x(no_data_io,                   u8,                             \
419           OPT_MOUNT,                                                    \
420           OPT_BOOL(),                                                   \
421           BCH2_NO_SB_OPT,               false,                          \
422           NULL,         "Skip submit_bio() for data reads and writes, " \
423                         "for performance testing purposes")             \
424         x(fs_size,                      u64,                            \
425           OPT_DEVICE,                                                   \
426           OPT_UINT(0, S64_MAX),                                         \
427           BCH2_NO_SB_OPT,               0,                              \
428           "size",       "Size of filesystem on device")                 \
429         x(bucket,                       u32,                            \
430           OPT_DEVICE,                                                   \
431           OPT_UINT(0, S64_MAX),                                         \
432           BCH2_NO_SB_OPT,               0,                              \
433           "size",       "Size of filesystem on device")                 \
434         x(durability,                   u8,                             \
435           OPT_DEVICE,                                                   \
436           OPT_UINT(0, BCH_REPLICAS_MAX),                                \
437           BCH2_NO_SB_OPT,               1,                              \
438           "n",          "Data written to this device will be considered\n"\
439                         "to have already been replicated n times")
440
441 struct bch_opts {
442 #define x(_name, _bits, ...)    unsigned _name##_defined:1;
443         BCH_OPTS()
444 #undef x
445
446 #define x(_name, _bits, ...)    _bits   _name;
447         BCH_OPTS()
448 #undef x
449 };
450
451 static const struct bch_opts bch2_opts_default = {
452 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...)           \
453         ._name##_defined = true,                                        \
454         ._name = _default,                                              \
455
456         BCH_OPTS()
457 #undef x
458 };
459
460 #define opt_defined(_opts, _name)       ((_opts)._name##_defined)
461
462 #define opt_get(_opts, _name)                                           \
463         (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
464
465 #define opt_set(_opts, _name, _v)                                       \
466 do {                                                                    \
467         (_opts)._name##_defined = true;                                 \
468         (_opts)._name = _v;                                             \
469 } while (0)
470
471 static inline struct bch_opts bch2_opts_empty(void)
472 {
473         return (struct bch_opts) { 0 };
474 }
475
476 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
477
478 enum bch_opt_id {
479 #define x(_name, ...)   Opt_##_name,
480         BCH_OPTS()
481 #undef x
482         bch2_opts_nr
483 };
484
485 struct bch_fs;
486 struct printbuf;
487
488 struct bch_option {
489         struct attribute        attr;
490         u64                     (*get_sb)(const struct bch_sb *);
491         void                    (*set_sb)(struct bch_sb *, u64);
492         enum opt_type           type;
493         enum opt_flags          flags;
494         u64                     min, max;
495
496         const char * const *choices;
497         int (*parse)(struct bch_fs *, const char *, u64 *);
498         void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
499
500         const char              *hint;
501         const char              *help;
502
503 };
504
505 extern const struct bch_option bch2_opt_table[];
506
507 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
508 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
509 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
510
511 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id);
512 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
513 void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64);
514 void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64);
515
516 int bch2_opt_lookup(const char *);
517 int bch2_opt_validate(const struct bch_option *, u64, struct printbuf *);
518 int bch2_opt_parse(struct bch_fs *, const struct bch_option *,
519                    const char *, u64 *, struct printbuf *);
520
521 #define OPT_SHOW_FULL_LIST      (1 << 0)
522 #define OPT_SHOW_MOUNT_STYLE    (1 << 1)
523
524 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
525                       const struct bch_option *, u64, unsigned);
526
527 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
528 int bch2_opts_check_may_set(struct bch_fs *);
529 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
530
531 /* inode opts: */
532
533 struct bch_io_opts {
534 #define x(_name, _bits) u##_bits _name;
535         BCH_INODE_OPTS()
536 #undef x
537 };
538
539 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
540 bool bch2_opt_is_inode_opt(enum bch_opt_id);
541
542 #endif /* _BCACHEFS_OPTS_H */