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