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