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(inodes_32bit, u8, \
238 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
239 OPT_BOOL(), \
240 BCH_SB_INODE_32BIT, true, \
241 NULL, "Constrain inode numbers to 32 bits") \
242 x(shard_inode_numbers_bits, u8, \
243 OPT_FS|OPT_FORMAT, \
244 OPT_UINT(0, 8), \
245 BCH_SB_SHARD_INUMS_NBITS, 0, \
246 NULL, "Shard new inode numbers by CPU id") \
247 x(inodes_use_key_cache, u8, \
248 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
249 OPT_BOOL(), \
250 BCH_SB_INODES_USE_KEY_CACHE, true, \
251 NULL, "Use the btree key cache for the inodes btree") \
252 x(btree_node_mem_ptr_optimization, u8, \
253 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
254 OPT_BOOL(), \
255 BCH2_NO_SB_OPT, true, \
256 NULL, "Stash pointer to in memory btree node in btree ptr")\
257 x(gc_reserve_percent, u8, \
258 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
259 OPT_UINT(5, 21), \
260 BCH_SB_GC_RESERVE, 8, \
261 "%", "Percentage of disk space to reserve for copygc")\
262 x(gc_reserve_bytes, u64, \
263 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME| \
264 OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \
265 OPT_UINT(0, U64_MAX), \
266 BCH_SB_GC_RESERVE_BYTES, 0, \
267 "%", "Amount of disk space to reserve for copygc\n" \
268 "Takes precedence over gc_reserve_percent if set")\
269 x(root_reserve_percent, u8, \
270 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
271 OPT_UINT(0, 100), \
272 BCH_SB_ROOT_RESERVE, 0, \
273 "%", "Percentage of disk space to reserve for superuser")\
274 x(wide_macs, u8, \
275 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
276 OPT_BOOL(), \
277 BCH_SB_128_BIT_MACS, false, \
278 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
279 x(inline_data, u8, \
280 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
281 OPT_BOOL(), \
282 BCH2_NO_SB_OPT, true, \
283 NULL, "Enable inline data extents") \
284 x(promote_whole_extents, u8, \
285 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
286 OPT_BOOL(), \
287 BCH_SB_PROMOTE_WHOLE_EXTENTS, true, \
288 NULL, "Promote whole extents, instead of just part being read")\
289 x(acl, u8, \
290 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
291 OPT_BOOL(), \
292 BCH_SB_POSIX_ACL, true, \
293 NULL, "Enable POSIX acls") \
294 x(usrquota, u8, \
295 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
296 OPT_BOOL(), \
297 BCH_SB_USRQUOTA, false, \
298 NULL, "Enable user quotas") \
299 x(grpquota, u8, \
300 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
301 OPT_BOOL(), \
302 BCH_SB_GRPQUOTA, false, \
303 NULL, "Enable group quotas") \
304 x(prjquota, u8, \
305 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
306 OPT_BOOL(), \
307 BCH_SB_PRJQUOTA, false, \
308 NULL, "Enable project quotas") \
309 x(degraded, u8, \
310 OPT_FS|OPT_MOUNT, \
311 OPT_STR(bch2_degraded_actions), \
312 BCH_SB_DEGRADED_ACTION, BCH_DEGRADED_ask, \
313 NULL, "Allow mounting in degraded mode") \
314 x(no_splitbrain_check, u8, \
315 OPT_FS|OPT_MOUNT, \
316 OPT_BOOL(), \
317 BCH2_NO_SB_OPT, false, \
318 NULL, "Don't kick drives out when splitbrain detected")\
319 x(verbose, u8, \
320 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
321 OPT_BOOL(), \
322 BCH2_NO_SB_OPT, BCACHEFS_VERBOSE_DEFAULT, \
323 NULL, "Extra debugging information during mount/recovery")\
324 x(journal_flush_delay, u32, \
325 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
326 OPT_UINT(1, U32_MAX), \
327 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \
328 NULL, "Delay in milliseconds before automatic journal commits")\
329 x(journal_flush_disabled, u8, \
330 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
331 OPT_BOOL(), \
332 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \
333 NULL, "Disable journal flush on sync/fsync\n" \
334 "If enabled, writes can be lost, but only since the\n"\
335 "last journal write (default 1 second)") \
336 x(journal_reclaim_delay, u32, \
337 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
338 OPT_UINT(0, U32_MAX), \
339 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \
340 NULL, "Delay in milliseconds before automatic journal reclaim")\
341 x(move_bytes_in_flight, u32, \
342 OPT_HUMAN_READABLE|OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
343 OPT_UINT(1024, U32_MAX), \
344 BCH2_NO_SB_OPT, 1U << 20, \
345 NULL, "Maximum Amount of IO to keep in flight by the move path")\
346 x(move_ios_in_flight, u32, \
347 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
348 OPT_UINT(1, 1024), \
349 BCH2_NO_SB_OPT, 32, \
350 NULL, "Maximum number of IOs to keep in flight by the move path")\
351 x(fsck, u8, \
352 OPT_FS|OPT_MOUNT, \
353 OPT_BOOL(), \
354 BCH2_NO_SB_OPT, false, \
355 NULL, "Run fsck on mount") \
356 x(fsck_memory_usage_percent, u8, \
357 OPT_FS|OPT_MOUNT, \
358 OPT_UINT(20, 70), \
359 BCH2_NO_SB_OPT, 50, \
360 NULL, "Maximum percentage of system ram fsck is allowed to pin")\
361 x(fix_errors, u8, \
362 OPT_FS|OPT_MOUNT, \
363 OPT_FN(bch2_opt_fix_errors), \
364 BCH2_NO_SB_OPT, FSCK_FIX_exit, \
365 NULL, "Fix errors during fsck without asking") \
366 x(ratelimit_errors, u8, \
367 OPT_FS|OPT_MOUNT, \
368 OPT_BOOL(), \
369 BCH2_NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \
370 NULL, "Ratelimit error messages during fsck") \
371 x(nochanges, u8, \
372 OPT_FS|OPT_MOUNT, \
373 OPT_BOOL(), \
374 BCH2_NO_SB_OPT, false, \
375 NULL, "Super read only mode - no writes at all will be issued,\n"\
376 "even if we have to replay the journal") \
377 x(norecovery, u8, \
378 OPT_FS|OPT_MOUNT, \
379 OPT_BOOL(), \
380 BCH2_NO_SB_OPT, false, \
381 NULL, "Exit recovery immediately prior to journal replay")\
382 x(journal_rewind, u64, \
383 OPT_FS|OPT_MOUNT, \
384 OPT_UINT(0, U64_MAX), \
385 BCH2_NO_SB_OPT, 0, \
386 NULL, "Rewind journal") \
387 x(recovery_passes, u64, \
388 OPT_FS|OPT_MOUNT, \
389 OPT_BITFIELD(bch2_recovery_passes), \
390 BCH2_NO_SB_OPT, 0, \
391 NULL, "Recovery passes to run explicitly") \
392 x(recovery_passes_exclude, u64, \
393 OPT_FS|OPT_MOUNT, \
394 OPT_BITFIELD(bch2_recovery_passes), \
395 BCH2_NO_SB_OPT, 0, \
396 NULL, "Recovery passes to exclude") \
397 x(recovery_pass_last, u8, \
398 OPT_FS|OPT_MOUNT, \
399 OPT_STR_NOLIMIT(bch2_recovery_passes), \
400 BCH2_NO_SB_OPT, 0, \
401 NULL, "Exit recovery after specified pass") \
402 x(retain_recovery_info, u8, \
403 0, \
404 OPT_BOOL(), \
405 BCH2_NO_SB_OPT, false, \
406 NULL, "Don't free journal entries/keys, scanned btree nodes after startup")\
407 x(read_entire_journal, u8, \
408 0, \
409 OPT_BOOL(), \
410 BCH2_NO_SB_OPT, false, \
411 NULL, "Read all journal entries, not just dirty ones")\
412 x(read_journal_only, u8, \
413 0, \
414 OPT_BOOL(), \
415 BCH2_NO_SB_OPT, false, \
416 NULL, "Only read the journal, skip the rest of recovery")\
417 x(journal_transaction_names, u8, \
418 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
419 OPT_BOOL(), \
420 BCH_SB_JOURNAL_TRANSACTION_NAMES, true, \
421 NULL, "Log transaction function names in journal") \
422 x(allocator_stuck_timeout, u16, \
423 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
424 OPT_UINT(0, U16_MAX), \
425 BCH_SB_ALLOCATOR_STUCK_TIMEOUT, 30, \
426 NULL, "Default timeout in seconds for stuck allocator messages")\
427 x(noexcl, u8, \
428 OPT_FS|OPT_MOUNT, \
429 OPT_BOOL(), \
430 BCH2_NO_SB_OPT, false, \
431 NULL, "Don't open device in exclusive mode") \
432 x(direct_io, u8, \
433 OPT_FS|OPT_MOUNT, \
434 OPT_BOOL(), \
435 BCH2_NO_SB_OPT, true, \
436 NULL, "Use O_DIRECT (userspace only)") \
437 x(sb, u64, \
438 OPT_MOUNT, \
439 OPT_UINT(0, S64_MAX), \
440 BCH2_NO_SB_OPT, BCH_SB_SECTOR, \
441 "offset", "Sector offset of superblock") \
442 x(read_only, u8, \
443 OPT_FS|OPT_MOUNT|OPT_HIDDEN, \
444 OPT_BOOL(), \
445 BCH2_NO_SB_OPT, false, \
446 NULL, NULL) \
447 x(nostart, u8, \
448 0, \
449 OPT_BOOL(), \
450 BCH2_NO_SB_OPT, false, \
451 NULL, "Don\'t start filesystem, only open devices") \
452 x(reconstruct_alloc, u8, \
453 OPT_FS|OPT_MOUNT, \
454 OPT_BOOL(), \
455 BCH2_NO_SB_OPT, false, \
456 NULL, "Reconstruct alloc btree") \
457 x(version_upgrade, u8, \
458 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
459 OPT_STR(bch2_version_upgrade_opts), \
460 BCH_SB_VERSION_UPGRADE, BCH_VERSION_UPGRADE_compatible, \
461 NULL, "Set superblock to latest version,\n" \
462 "allowing any new features to be used") \
463 x(stdio, u64, \
464 0, \
465 OPT_UINT(0, S64_MAX), \
466 BCH2_NO_SB_OPT, false, \
467 NULL, "Pointer to a struct stdio_redirect") \
468 x(project, u8, \
469 OPT_INODE, \
470 OPT_BOOL(), \
471 BCH2_NO_SB_OPT, false, \
472 NULL, NULL) \
473 x(nocow, u8, \
474 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
475 OPT_BOOL(), \
476 BCH_SB_NOCOW, false, \
477 NULL, "Nocow mode: Writes will be done in place when possible.\n"\
478 "Snapshots and reflink will still caused writes to be COW\n"\
479 "Implicitly disables data checksumming, compression and encryption")\
480 x(nocow_enabled, u8, \
481 OPT_FS|OPT_MOUNT, \
482 OPT_BOOL(), \
483 BCH2_NO_SB_OPT, true, \
484 NULL, "Enable nocow mode: enables runtime locking in\n"\
485 "data move path needed if nocow will ever be in use\n")\
486 x(copygc_enabled, u8, \
487 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
488 OPT_BOOL(), \
489 BCH2_NO_SB_OPT, true, \
490 NULL, "Enable copygc: disable for debugging, or to\n"\
491 "quiet the system when doing performance testing\n")\
492 x(rebalance_enabled, u8, \
493 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
494 OPT_BOOL(), \
495 BCH2_NO_SB_OPT, true, \
496 NULL, "Enable rebalance: disable for debugging, or to\n"\
497 "quiet the system when doing performance testing\n")\
498 x(rebalance_on_ac_only, u8, \
499 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
500 OPT_BOOL(), \
501 BCH_SB_REBALANCE_AC_ONLY, false, \
502 NULL, "Enable rebalance while on mains power only\n") \
503 x(auto_snapshot_deletion, u8, \
504 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
505 OPT_BOOL(), \
506 BCH2_NO_SB_OPT, true, \
507 NULL, "Enable automatic snapshot deletion: disable for debugging, or to\n"\
508 "quiet the system when doing performance testing\n")\
509 x(no_data_io, u8, \
510 OPT_MOUNT, \
511 OPT_BOOL(), \
512 BCH2_NO_SB_OPT, false, \
513 NULL, "Skip submit_bio() for data reads and writes, " \
514 "for performance testing purposes") \
515 x(state, u64, \
516 OPT_DEVICE|OPT_RUNTIME, \
517 OPT_STR(bch2_member_states), \
518 BCH_MEMBER_STATE, BCH_MEMBER_STATE_rw, \
519 "state", "rw,ro,failed,spare") \
520 x(bucket_size, u32, \
521 OPT_DEVICE|OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \
522 OPT_UINT(0, S64_MAX), \
523 BCH_MEMBER_BUCKET_SIZE, 0, \
524 "size", "Specifies the bucket size; must be greater than the btree node size")\
525 x(durability, u8, \
526 OPT_DEVICE|OPT_RUNTIME|OPT_SB_FIELD_ONE_BIAS, \
527 OPT_UINT(0, BCH_REPLICAS_MAX), \
528 BCH_MEMBER_DURABILITY, 1, \
529 "n", "Data written to this device will be considered\n"\
530 "to have already been replicated n times") \
531 x(data_allowed, u8, \
532 OPT_DEVICE, \
533 OPT_BITFIELD(__bch2_data_types), \
534 BCH_MEMBER_DATA_ALLOWED, BIT(BCH_DATA_journal)|BIT(BCH_DATA_btree)|BIT(BCH_DATA_user),\
535 "types", "Allowed data types for this device: journal, btree, and/or user")\
536 x(discard, u8, \
537 OPT_MOUNT|OPT_FS|OPT_DEVICE|OPT_RUNTIME, \
538 OPT_BOOL(), \
539 BCH_MEMBER_DISCARD, true, \
540 NULL, "Enable discard/TRIM support") \
541 x(btree_node_prefetch, u8, \
542 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
543 OPT_BOOL(), \
544 BCH2_NO_SB_OPT, true, \
545 NULL, "BTREE_ITER_prefetch causes btree nodes to be\n"\
546 " prefetched sequentially")
547
548 struct bch_opts {
549 #define x(_name, _bits, ...) unsigned _name##_defined:1;
550 BCH_OPTS()
551 #undef x
552
553 #define x(_name, _bits, ...) _bits _name;
554 BCH_OPTS()
555 #undef x
556 };
557
558 struct bch2_opts_parse {
559 struct bch_opts opts;
560
561 /* to save opts that can't be parsed before the FS is opened: */
562 struct printbuf parse_later;
563 };
564
565 static const __maybe_unused struct bch_opts bch2_opts_default = {
566 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
567 ._name##_defined = true, \
568 ._name = _default, \
569
570 BCH_OPTS()
571 #undef x
572 };
573
574 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
575
576 #define opt_get(_opts, _name) \
577 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
578
579 #define opt_set(_opts, _name, _v) \
580 do { \
581 (_opts)._name##_defined = true; \
582 (_opts)._name = _v; \
583 } while (0)
584
bch2_opts_empty(void)585 static inline struct bch_opts bch2_opts_empty(void)
586 {
587 return (struct bch_opts) { 0 };
588 }
589
590 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
591
592 enum bch_opt_id {
593 #define x(_name, ...) Opt_##_name,
594 BCH_OPTS()
595 #undef x
596 bch2_opts_nr
597 };
598
599 struct bch_fs;
600 struct printbuf;
601
602 struct bch_option {
603 struct attribute attr;
604 enum opt_type type;
605 enum opt_flags flags;
606 u64 min, max;
607
608 const char * const *choices;
609
610 struct bch_opt_fn fn;
611
612 const char *hint;
613 const char *help;
614
615 u64 (*get_sb)(const struct bch_sb *);
616 void (*set_sb)(struct bch_sb *, u64);
617
618 u64 (*get_member)(const struct bch_member *);
619 void (*set_member)(struct bch_member *, u64);
620
621 };
622
623 extern const struct bch_option bch2_opt_table[];
624
625 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
626 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
627 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
628
629 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id, int);
630 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
631 bool __bch2_opt_set_sb(struct bch_sb *, int, const struct bch_option *, u64);
632
633 struct bch_dev;
634 bool bch2_opt_set_sb(struct bch_fs *, struct bch_dev *, const struct bch_option *, u64);
635
636 int bch2_opt_lookup(const char *);
637 int bch2_opt_validate(const struct bch_option *, u64, struct printbuf *);
638 int bch2_opt_parse(struct bch_fs *, const struct bch_option *,
639 const char *, u64 *, struct printbuf *);
640
641 #define OPT_SHOW_FULL_LIST (1 << 0)
642 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
643
644 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
645 const struct bch_option *, u64, unsigned);
646 void bch2_opts_to_text(struct printbuf *,
647 struct bch_opts,
648 struct bch_fs *, struct bch_sb *,
649 unsigned, unsigned, unsigned);
650
651 int bch2_opt_hook_pre_set(struct bch_fs *, struct bch_dev *, enum bch_opt_id, u64);
652 int bch2_opts_hooks_pre_set(struct bch_fs *);
653 void bch2_opt_hook_post_set(struct bch_fs *, struct bch_dev *, u64,
654 struct bch_opts *, enum bch_opt_id);
655
656 int bch2_parse_one_mount_opt(struct bch_fs *, struct bch_opts *,
657 struct printbuf *, const char *, const char *);
658 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, struct printbuf *,
659 char *, bool);
660
661 /* inode opts: */
662
663 struct bch_io_opts {
664 #define x(_name, _bits) u##_bits _name;
665 BCH_INODE_OPTS()
666 #undef x
667 #define x(_name, _bits) u64 _name##_from_inode:1;
668 BCH_INODE_OPTS()
669 #undef x
670 };
671
bch2_io_opts_fixups(struct bch_io_opts * opts)672 static inline void bch2_io_opts_fixups(struct bch_io_opts *opts)
673 {
674 if (!opts->background_target)
675 opts->background_target = opts->foreground_target;
676 if (!opts->background_compression)
677 opts->background_compression = opts->compression;
678 if (opts->nocow) {
679 opts->compression = opts->background_compression = 0;
680 opts->data_checksum = 0;
681 opts->erasure_code = 0;
682 }
683 }
684
685 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
686 bool bch2_opt_is_inode_opt(enum bch_opt_id);
687
688 #endif /* _BCACHEFS_OPTS_H */
689