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