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