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