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