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_degraded_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_d_types[];
29
30 void bch2_prt_jset_entry_type(struct printbuf *, enum bch_jset_entry_type);
31 void bch2_prt_fs_usage_type(struct printbuf *, enum bch_fs_usage_type);
32 void bch2_prt_data_type(struct printbuf *, enum bch_data_type);
33 void bch2_prt_csum_opt(struct printbuf *, enum bch_csum_opt);
34 void bch2_prt_csum_type(struct printbuf *, enum bch_csum_type);
35 void bch2_prt_compression_type(struct printbuf *, enum bch_compression_type);
36 void bch2_prt_str_hash_type(struct printbuf *, enum bch_str_hash_type);
37
bch2_d_type_str(unsigned d_type)38 static inline const char *bch2_d_type_str(unsigned d_type)
39 {
40 return (d_type < BCH_DT_MAX ? bch2_d_types[d_type] : NULL) ?: "(bad d_type)";
41 }
42
43 /*
44 * Mount options; we also store defaults in the superblock.
45 *
46 * Also exposed via sysfs: if an option is writeable, and it's also stored in
47 * the superblock, changing it via sysfs (currently? might change this) also
48 * updates the superblock.
49 *
50 * We store options as signed integers, where -1 means undefined. This means we
51 * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only
52 * apply the options from that struct that are defined.
53 */
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, 4 << 10, \
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, 256 << 10, \
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(write_error_timeout, u16, \
147 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
148 OPT_UINT(1, 300), \
149 BCH_SB_WRITE_ERROR_TIMEOUT, 30, \
150 NULL, "Number of consecutive write errors allowed before kicking out a device")\
151 x(metadata_replicas, u8, \
152 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
153 OPT_UINT(1, BCH_REPLICAS_MAX), \
154 BCH_SB_META_REPLICAS_WANT, 1, \
155 "#", "Number of metadata replicas") \
156 x(data_replicas, u8, \
157 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
158 OPT_UINT(1, BCH_REPLICAS_MAX), \
159 BCH_SB_DATA_REPLICAS_WANT, 1, \
160 "#", "Number of data replicas") \
161 x(metadata_replicas_required, u8, \
162 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
163 OPT_UINT(1, BCH_REPLICAS_MAX), \
164 BCH_SB_META_REPLICAS_REQ, 1, \
165 "#", NULL) \
166 x(data_replicas_required, u8, \
167 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
168 OPT_UINT(1, BCH_REPLICAS_MAX), \
169 BCH_SB_DATA_REPLICAS_REQ, 1, \
170 "#", NULL) \
171 x(encoded_extent_max, u32, \
172 OPT_FS|OPT_FORMAT| \
173 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\
174 OPT_UINT(4096, 2U << 20), \
175 BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10, \
176 "size", "Maximum size of checksummed/compressed extents")\
177 x(metadata_checksum, u8, \
178 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
179 OPT_STR(__bch2_csum_opts), \
180 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
181 NULL, NULL) \
182 x(data_checksum, u8, \
183 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
184 OPT_STR(__bch2_csum_opts), \
185 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
186 NULL, NULL) \
187 x(checksum_err_retry_nr, u8, \
188 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
189 OPT_UINT(0, 32), \
190 BCH_SB_CSUM_ERR_RETRY_NR, 3, \
191 NULL, NULL) \
192 x(compression, u8, \
193 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
194 OPT_FN(bch2_opt_compression), \
195 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
196 NULL, NULL) \
197 x(background_compression, u8, \
198 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
199 OPT_FN(bch2_opt_compression), \
200 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
201 NULL, NULL) \
202 x(str_hash, u8, \
203 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
204 OPT_STR(bch2_str_hash_opts), \
205 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
206 NULL, "Hash function for directory entries and xattrs")\
207 x(metadata_target, u16, \
208 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
209 OPT_FN(bch2_opt_target), \
210 BCH_SB_METADATA_TARGET, 0, \
211 "(target)", "Device or label for metadata writes") \
212 x(foreground_target, u16, \
213 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
214 OPT_FN(bch2_opt_target), \
215 BCH_SB_FOREGROUND_TARGET, 0, \
216 "(target)", "Device or label for foreground writes") \
217 x(background_target, u16, \
218 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
219 OPT_FN(bch2_opt_target), \
220 BCH_SB_BACKGROUND_TARGET, 0, \
221 "(target)", "Device or label to move data to in the background")\
222 x(promote_target, u16, \
223 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
224 OPT_FN(bch2_opt_target), \
225 BCH_SB_PROMOTE_TARGET, 0, \
226 "(target)", "Device or label to promote data to on read") \
227 x(erasure_code, u16, \
228 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
229 OPT_BOOL(), \
230 BCH_SB_ERASURE_CODE, false, \
231 NULL, "Enable erasure coding (DO NOT USE YET)") \
232 x(casefold, u8, \
233 OPT_FS|OPT_INODE|OPT_FORMAT, \
234 OPT_BOOL(), \
235 BCH_SB_CASEFOLD, false, \
236 NULL, "Dirent lookups are casefolded") \
237 x(casefold_disabled, u8, \
238 OPT_FS|OPT_MOUNT, \
239 OPT_BOOL(), \
240 BCH2_NO_SB_OPT, false, \
241 NULL, "Disable casefolding filesystem wide") \
242 x(inodes_32bit, u8, \
243 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
244 OPT_BOOL(), \
245 BCH_SB_INODE_32BIT, true, \
246 NULL, "Constrain inode numbers to 32 bits") \
247 x(shard_inode_numbers_bits, u8, \
248 OPT_FS|OPT_FORMAT, \
249 OPT_UINT(0, 8), \
250 BCH_SB_SHARD_INUMS_NBITS, 0, \
251 NULL, "Shard new inode numbers by CPU id") \
252 x(inodes_use_key_cache, u8, \
253 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
254 OPT_BOOL(), \
255 BCH_SB_INODES_USE_KEY_CACHE, true, \
256 NULL, "Use the btree key cache for the inodes btree") \
257 x(btree_node_mem_ptr_optimization, u8, \
258 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
259 OPT_BOOL(), \
260 BCH2_NO_SB_OPT, true, \
261 NULL, "Stash pointer to in memory btree node in btree ptr")\
262 x(gc_reserve_percent, u8, \
263 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
264 OPT_UINT(5, 21), \
265 BCH_SB_GC_RESERVE, 8, \
266 "%", "Percentage of disk space to reserve for copygc")\
267 x(gc_reserve_bytes, u64, \
268 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME| \
269 OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \
270 OPT_UINT(0, U64_MAX), \
271 BCH_SB_GC_RESERVE_BYTES, 0, \
272 "%", "Amount of disk space to reserve for copygc\n" \
273 "Takes precedence over gc_reserve_percent if set")\
274 x(root_reserve_percent, u8, \
275 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
276 OPT_UINT(0, 100), \
277 BCH_SB_ROOT_RESERVE, 0, \
278 "%", "Percentage of disk space to reserve for superuser")\
279 x(wide_macs, u8, \
280 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
281 OPT_BOOL(), \
282 BCH_SB_128_BIT_MACS, false, \
283 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
284 x(inline_data, u8, \
285 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
286 OPT_BOOL(), \
287 BCH2_NO_SB_OPT, true, \
288 NULL, "Enable inline data extents") \
289 x(promote_whole_extents, u8, \
290 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
291 OPT_BOOL(), \
292 BCH_SB_PROMOTE_WHOLE_EXTENTS, true, \
293 NULL, "Promote whole extents, instead of just part being read")\
294 x(acl, u8, \
295 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
296 OPT_BOOL(), \
297 BCH_SB_POSIX_ACL, true, \
298 NULL, "Enable POSIX acls") \
299 x(usrquota, u8, \
300 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
301 OPT_BOOL(), \
302 BCH_SB_USRQUOTA, false, \
303 NULL, "Enable user quotas") \
304 x(grpquota, u8, \
305 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
306 OPT_BOOL(), \
307 BCH_SB_GRPQUOTA, false, \
308 NULL, "Enable group quotas") \
309 x(prjquota, u8, \
310 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
311 OPT_BOOL(), \
312 BCH_SB_PRJQUOTA, false, \
313 NULL, "Enable project quotas") \
314 x(degraded, u8, \
315 OPT_FS|OPT_MOUNT, \
316 OPT_STR(bch2_degraded_actions), \
317 BCH_SB_DEGRADED_ACTION, BCH_DEGRADED_ask, \
318 NULL, "Allow mounting in degraded mode") \
319 x(no_splitbrain_check, u8, \
320 OPT_FS|OPT_MOUNT, \
321 OPT_BOOL(), \
322 BCH2_NO_SB_OPT, false, \
323 NULL, "Don't kick drives out when splitbrain detected")\
324 x(verbose, u8, \
325 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
326 OPT_BOOL(), \
327 BCH2_NO_SB_OPT, BCACHEFS_VERBOSE_DEFAULT, \
328 NULL, "Extra debugging information during mount/recovery")\
329 x(journal_flush_delay, u32, \
330 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
331 OPT_UINT(1, U32_MAX), \
332 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \
333 NULL, "Delay in milliseconds before automatic journal commits")\
334 x(journal_flush_disabled, u8, \
335 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
336 OPT_BOOL(), \
337 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \
338 NULL, "Disable journal flush on sync/fsync\n" \
339 "If enabled, writes can be lost, but only since the\n"\
340 "last journal write (default 1 second)") \
341 x(journal_reclaim_delay, u32, \
342 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
343 OPT_UINT(0, U32_MAX), \
344 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \
345 NULL, "Delay in milliseconds before automatic journal reclaim")\
346 x(move_bytes_in_flight, u32, \
347 OPT_HUMAN_READABLE|OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
348 OPT_UINT(1024, U32_MAX), \
349 BCH2_NO_SB_OPT, 1U << 20, \
350 NULL, "Maximum Amount of IO to keep in flight by the move path")\
351 x(move_ios_in_flight, u32, \
352 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
353 OPT_UINT(1, 1024), \
354 BCH2_NO_SB_OPT, 32, \
355 NULL, "Maximum number of IOs to keep in flight by the move path")\
356 x(fsck, u8, \
357 OPT_FS|OPT_MOUNT, \
358 OPT_BOOL(), \
359 BCH2_NO_SB_OPT, false, \
360 NULL, "Run fsck on mount") \
361 x(fsck_memory_usage_percent, u8, \
362 OPT_FS|OPT_MOUNT, \
363 OPT_UINT(20, 70), \
364 BCH2_NO_SB_OPT, 50, \
365 NULL, "Maximum percentage of system ram fsck is allowed to pin")\
366 x(fix_errors, u8, \
367 OPT_FS|OPT_MOUNT, \
368 OPT_FN(bch2_opt_fix_errors), \
369 BCH2_NO_SB_OPT, FSCK_FIX_exit, \
370 NULL, "Fix errors during fsck without asking") \
371 x(ratelimit_errors, u8, \
372 OPT_FS|OPT_MOUNT, \
373 OPT_BOOL(), \
374 BCH2_NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \
375 NULL, "Ratelimit error messages during fsck") \
376 x(nochanges, u8, \
377 OPT_FS|OPT_MOUNT, \
378 OPT_BOOL(), \
379 BCH2_NO_SB_OPT, false, \
380 NULL, "Super read only mode - no writes at all will be issued,\n"\
381 "even if we have to replay the journal") \
382 x(norecovery, u8, \
383 OPT_FS|OPT_MOUNT, \
384 OPT_BOOL(), \
385 BCH2_NO_SB_OPT, false, \
386 NULL, "Exit recovery immediately prior to journal replay")\
387 x(journal_rewind, u64, \
388 OPT_FS|OPT_MOUNT, \
389 OPT_UINT(0, U64_MAX), \
390 BCH2_NO_SB_OPT, 0, \
391 NULL, "Rewind journal") \
392 x(recovery_passes, u64, \
393 OPT_FS|OPT_MOUNT, \
394 OPT_BITFIELD(bch2_recovery_passes), \
395 BCH2_NO_SB_OPT, 0, \
396 NULL, "Recovery passes to run explicitly") \
397 x(recovery_passes_exclude, u64, \
398 OPT_FS|OPT_MOUNT, \
399 OPT_BITFIELD(bch2_recovery_passes), \
400 BCH2_NO_SB_OPT, 0, \
401 NULL, "Recovery passes to exclude") \
402 x(recovery_pass_last, u8, \
403 OPT_FS|OPT_MOUNT, \
404 OPT_STR_NOLIMIT(bch2_recovery_passes), \
405 BCH2_NO_SB_OPT, 0, \
406 NULL, "Exit recovery after specified pass") \
407 x(retain_recovery_info, u8, \
408 0, \
409 OPT_BOOL(), \
410 BCH2_NO_SB_OPT, false, \
411 NULL, "Don't free journal entries/keys, scanned btree nodes after startup")\
412 x(read_entire_journal, u8, \
413 0, \
414 OPT_BOOL(), \
415 BCH2_NO_SB_OPT, false, \
416 NULL, "Read all journal entries, not just dirty ones")\
417 x(read_journal_only, u8, \
418 0, \
419 OPT_BOOL(), \
420 BCH2_NO_SB_OPT, false, \
421 NULL, "Only read the journal, skip the rest of recovery")\
422 x(journal_transaction_names, u8, \
423 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
424 OPT_BOOL(), \
425 BCH_SB_JOURNAL_TRANSACTION_NAMES, true, \
426 NULL, "Log transaction function names in journal") \
427 x(allocator_stuck_timeout, u16, \
428 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
429 OPT_UINT(0, U16_MAX), \
430 BCH_SB_ALLOCATOR_STUCK_TIMEOUT, 30, \
431 NULL, "Default timeout in seconds for stuck allocator messages")\
432 x(noexcl, u8, \
433 OPT_FS|OPT_MOUNT, \
434 OPT_BOOL(), \
435 BCH2_NO_SB_OPT, false, \
436 NULL, "Don't open device in exclusive mode") \
437 x(direct_io, u8, \
438 OPT_FS|OPT_MOUNT, \
439 OPT_BOOL(), \
440 BCH2_NO_SB_OPT, true, \
441 NULL, "Use O_DIRECT (userspace only)") \
442 x(sb, u64, \
443 OPT_MOUNT, \
444 OPT_UINT(0, S64_MAX), \
445 BCH2_NO_SB_OPT, BCH_SB_SECTOR, \
446 "offset", "Sector offset of superblock") \
447 x(read_only, u8, \
448 OPT_FS|OPT_MOUNT|OPT_HIDDEN, \
449 OPT_BOOL(), \
450 BCH2_NO_SB_OPT, false, \
451 NULL, NULL) \
452 x(nostart, u8, \
453 0, \
454 OPT_BOOL(), \
455 BCH2_NO_SB_OPT, false, \
456 NULL, "Don\'t start filesystem, only open devices") \
457 x(reconstruct_alloc, u8, \
458 OPT_FS|OPT_MOUNT, \
459 OPT_BOOL(), \
460 BCH2_NO_SB_OPT, false, \
461 NULL, "Reconstruct alloc btree") \
462 x(version_upgrade, u8, \
463 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
464 OPT_STR(bch2_version_upgrade_opts), \
465 BCH_SB_VERSION_UPGRADE, BCH_VERSION_UPGRADE_compatible, \
466 NULL, "Set superblock to latest version,\n" \
467 "allowing any new features to be used") \
468 x(stdio, u64, \
469 0, \
470 OPT_UINT(0, S64_MAX), \
471 BCH2_NO_SB_OPT, false, \
472 NULL, "Pointer to a struct stdio_redirect") \
473 x(project, u8, \
474 OPT_INODE, \
475 OPT_BOOL(), \
476 BCH2_NO_SB_OPT, false, \
477 NULL, NULL) \
478 x(nocow, u8, \
479 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
480 OPT_BOOL(), \
481 BCH_SB_NOCOW, false, \
482 NULL, "Nocow mode: Writes will be done in place when possible.\n"\
483 "Snapshots and reflink will still caused writes to be COW\n"\
484 "Implicitly disables data checksumming, compression and encryption")\
485 x(nocow_enabled, u8, \
486 OPT_FS|OPT_MOUNT, \
487 OPT_BOOL(), \
488 BCH2_NO_SB_OPT, true, \
489 NULL, "Enable nocow mode: enables runtime locking in\n"\
490 "data move path needed if nocow will ever be in use\n")\
491 x(copygc_enabled, u8, \
492 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
493 OPT_BOOL(), \
494 BCH2_NO_SB_OPT, true, \
495 NULL, "Enable copygc: disable for debugging, or to\n"\
496 "quiet the system when doing performance testing\n")\
497 x(rebalance_enabled, u8, \
498 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
499 OPT_BOOL(), \
500 BCH2_NO_SB_OPT, true, \
501 NULL, "Enable rebalance: disable for debugging, or to\n"\
502 "quiet the system when doing performance testing\n")\
503 x(rebalance_on_ac_only, u8, \
504 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
505 OPT_BOOL(), \
506 BCH_SB_REBALANCE_AC_ONLY, false, \
507 NULL, "Enable rebalance while on mains power only\n") \
508 x(auto_snapshot_deletion, u8, \
509 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
510 OPT_BOOL(), \
511 BCH2_NO_SB_OPT, true, \
512 NULL, "Enable automatic snapshot deletion: disable for debugging, or to\n"\
513 "quiet the system when doing performance testing\n")\
514 x(no_data_io, u8, \
515 OPT_MOUNT, \
516 OPT_BOOL(), \
517 BCH2_NO_SB_OPT, false, \
518 NULL, "Skip submit_bio() for data reads and writes, " \
519 "for performance testing purposes") \
520 x(state, u64, \
521 OPT_DEVICE|OPT_RUNTIME, \
522 OPT_STR(bch2_member_states), \
523 BCH_MEMBER_STATE, BCH_MEMBER_STATE_rw, \
524 "state", "rw,ro,failed,spare") \
525 x(bucket_size, u32, \
526 OPT_DEVICE|OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \
527 OPT_UINT(0, S64_MAX), \
528 BCH_MEMBER_BUCKET_SIZE, 0, \
529 "size", "Specifies the bucket size; must be greater than the btree node size")\
530 x(durability, u8, \
531 OPT_DEVICE|OPT_RUNTIME|OPT_SB_FIELD_ONE_BIAS, \
532 OPT_UINT(0, BCH_REPLICAS_MAX), \
533 BCH_MEMBER_DURABILITY, 1, \
534 "n", "Data written to this device will be considered\n"\
535 "to have already been replicated n times") \
536 x(data_allowed, u8, \
537 OPT_DEVICE, \
538 OPT_BITFIELD(__bch2_data_types), \
539 BCH_MEMBER_DATA_ALLOWED, BIT(BCH_DATA_journal)|BIT(BCH_DATA_btree)|BIT(BCH_DATA_user),\
540 "types", "Allowed data types for this device: journal, btree, and/or user")\
541 x(discard, u8, \
542 OPT_MOUNT|OPT_FS|OPT_DEVICE|OPT_RUNTIME, \
543 OPT_BOOL(), \
544 BCH_MEMBER_DISCARD, true, \
545 NULL, "Enable discard/TRIM support") \
546 x(btree_node_prefetch, u8, \
547 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
548 OPT_BOOL(), \
549 BCH2_NO_SB_OPT, true, \
550 NULL, "BTREE_ITER_prefetch causes btree nodes to be\n"\
551 " prefetched sequentially")
552
553 struct bch_opts {
554 #define x(_name, _bits, ...) unsigned _name##_defined:1;
555 BCH_OPTS()
556 #undef x
557
558 #define x(_name, _bits, ...) _bits _name;
559 BCH_OPTS()
560 #undef x
561 };
562
563 struct bch2_opts_parse {
564 struct bch_opts opts;
565
566 /* to save opts that can't be parsed before the FS is opened: */
567 struct printbuf parse_later;
568 };
569
570 static const __maybe_unused struct bch_opts bch2_opts_default = {
571 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
572 ._name##_defined = true, \
573 ._name = _default, \
574
575 BCH_OPTS()
576 #undef x
577 };
578
579 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
580
581 #define opt_get(_opts, _name) \
582 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
583
584 #define opt_set(_opts, _name, _v) \
585 do { \
586 (_opts)._name##_defined = true; \
587 (_opts)._name = _v; \
588 } while (0)
589
bch2_opts_empty(void)590 static inline struct bch_opts bch2_opts_empty(void)
591 {
592 return (struct bch_opts) { 0 };
593 }
594
595 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
596
597 enum bch_opt_id {
598 #define x(_name, ...) Opt_##_name,
599 BCH_OPTS()
600 #undef x
601 bch2_opts_nr
602 };
603
604 struct bch_fs;
605 struct printbuf;
606
607 struct bch_option {
608 struct attribute attr;
609 enum opt_type type;
610 enum opt_flags flags;
611 u64 min, max;
612
613 const char * const *choices;
614
615 struct bch_opt_fn fn;
616
617 const char *hint;
618 const char *help;
619
620 u64 (*get_sb)(const struct bch_sb *);
621 void (*set_sb)(struct bch_sb *, u64);
622
623 u64 (*get_member)(const struct bch_member *);
624 void (*set_member)(struct bch_member *, u64);
625
626 };
627
628 extern const struct bch_option bch2_opt_table[];
629
630 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
631 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
632 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
633
634 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id, int);
635 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
636 bool __bch2_opt_set_sb(struct bch_sb *, int, const struct bch_option *, u64);
637
638 struct bch_dev;
639 bool bch2_opt_set_sb(struct bch_fs *, struct bch_dev *, const struct bch_option *, u64);
640
641 int bch2_opt_lookup(const char *);
642 int bch2_opt_validate(const struct bch_option *, u64, struct printbuf *);
643 int bch2_opt_parse(struct bch_fs *, const struct bch_option *,
644 const char *, u64 *, struct printbuf *);
645
646 #define OPT_SHOW_FULL_LIST (1 << 0)
647 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
648
649 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
650 const struct bch_option *, u64, unsigned);
651 void bch2_opts_to_text(struct printbuf *,
652 struct bch_opts,
653 struct bch_fs *, struct bch_sb *,
654 unsigned, unsigned, unsigned);
655
656 int bch2_opt_hook_pre_set(struct bch_fs *, struct bch_dev *, enum bch_opt_id, u64);
657 int bch2_opts_hooks_pre_set(struct bch_fs *);
658 void bch2_opt_hook_post_set(struct bch_fs *, struct bch_dev *, u64,
659 struct bch_opts *, enum bch_opt_id);
660
661 int bch2_parse_one_mount_opt(struct bch_fs *, struct bch_opts *,
662 struct printbuf *, const char *, const char *);
663 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, struct printbuf *,
664 char *, bool);
665
666 /* inode opts: */
667
668 struct bch_io_opts {
669 #define x(_name, _bits) u##_bits _name;
670 BCH_INODE_OPTS()
671 #undef x
672 #define x(_name, _bits) u64 _name##_from_inode:1;
673 BCH_INODE_OPTS()
674 #undef x
675 };
676
bch2_io_opts_fixups(struct bch_io_opts * opts)677 static inline void bch2_io_opts_fixups(struct bch_io_opts *opts)
678 {
679 if (!opts->background_target)
680 opts->background_target = opts->foreground_target;
681 if (!opts->background_compression)
682 opts->background_compression = opts->compression;
683 if (opts->nocow) {
684 opts->compression = opts->background_compression = 0;
685 opts->data_checksum = 0;
686 opts->erasure_code = 0;
687 }
688 }
689
690 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
691 bool bch2_opt_is_inode_opt(enum bch_opt_id);
692
693 #endif /* _BCACHEFS_OPTS_H */
694