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