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