1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_OPTS_H
3 #define _BCACHEFS_OPTS_H
6 #include <linux/log2.h>
7 #include <linux/string.h>
8 #include <linux/sysfs.h>
9 #include "bcachefs_format.h"
13 extern const char * const bch2_error_actions[];
14 extern const char * const bch2_fsck_fix_opts[];
15 extern const char * const bch2_version_upgrade_opts[];
16 extern const char * const bch2_sb_features[];
17 extern const char * const bch2_sb_compat[];
18 extern const char * const bch2_btree_ids[];
19 extern const char * const bch2_csum_types[];
20 extern const char * const bch2_csum_opts[];
21 extern const char * const bch2_compression_types[];
22 extern const char * const bch2_compression_opts[];
23 extern const char * const bch2_str_hash_types[];
24 extern const char * const bch2_str_hash_opts[];
25 extern const char * const bch2_data_types[];
26 extern const char * const bch2_member_states[];
27 extern const char * const bch2_jset_entry_types[];
28 extern const char * const bch2_fs_usage_types[];
29 extern const char * const bch2_d_types[];
31 static inline const char *bch2_d_type_str(unsigned d_type)
33 return (d_type < BCH_DT_MAX ? bch2_d_types[d_type] : NULL) ?: "(bad d_type)";
37 * Mount options; we also store defaults in the superblock.
39 * Also exposed via sysfs: if an option is writeable, and it's also stored in
40 * the superblock, changing it via sysfs (currently? might change this) also
41 * updates the superblock.
43 * We store options as signed integers, where -1 means undefined. This means we
44 * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only
45 * apply the options from that struct that are defined.
48 /* dummy option, for options that aren't stored in the superblock */
49 u64 BCH2_NO_SB_OPT(const struct bch_sb *);
50 void SET_BCH2_NO_SB_OPT(struct bch_sb *, u64);
52 /* When can be set: */
54 OPT_FS = (1 << 0), /* Filesystem option */
55 OPT_DEVICE = (1 << 1), /* Device option */
56 OPT_INODE = (1 << 2), /* Inode option */
57 OPT_FORMAT = (1 << 3), /* May be specified at format time */
58 OPT_MOUNT = (1 << 4), /* May be specified at mount time */
59 OPT_RUNTIME = (1 << 5), /* May be specified at runtime */
60 OPT_HUMAN_READABLE = (1 << 6),
61 OPT_MUST_BE_POW_2 = (1 << 7), /* Must be power of 2 */
62 OPT_SB_FIELD_SECTORS = (1 << 8),/* Superblock field is >> 9 of actual value */
63 OPT_SB_FIELD_ILOG2 = (1 << 9), /* Superblock field is ilog2 of actual value */
74 int (*parse)(struct bch_fs *, const char *, u64 *, struct printbuf *);
75 void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
79 * x(name, shortopt, type, in mem type, mode, sb_opt)
81 * @name - name of mount option, sysfs attribute, and struct bch_opts
84 * @mode - when opt may be set
86 * @sb_option - name of corresponding superblock option
88 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
98 #define RATELIMIT_ERRORS_DEFAULT true
100 #define RATELIMIT_ERRORS_DEFAULT false
103 #ifdef CONFIG_BCACHEFS_DEBUG
104 #define BCACHEFS_VERBOSE_DEFAULT true
106 #define BCACHEFS_VERBOSE_DEFAULT false
109 #define BCH_FIX_ERRORS_OPTS() \
116 #define x(t, n) FSCK_FIX_##t,
117 BCH_FIX_ERRORS_OPTS()
124 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
125 OPT_UINT(512, 1U << 16), \
126 BCH_SB_BLOCK_SIZE, 8, \
128 x(btree_node_size, u32, \
130 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
131 OPT_UINT(512, 1U << 20), \
132 BCH_SB_BTREE_NODE_SIZE, 512, \
133 "size", "Btree node size, default 256k") \
135 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
136 OPT_STR(bch2_error_actions), \
137 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \
138 NULL, "Action to take on filesystem error") \
139 x(metadata_replicas, u8, \
140 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
141 OPT_UINT(1, BCH_REPLICAS_MAX), \
142 BCH_SB_META_REPLICAS_WANT, 1, \
143 "#", "Number of metadata replicas") \
144 x(data_replicas, u8, \
145 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
146 OPT_UINT(1, BCH_REPLICAS_MAX), \
147 BCH_SB_DATA_REPLICAS_WANT, 1, \
148 "#", "Number of data replicas") \
149 x(metadata_replicas_required, u8, \
150 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
151 OPT_UINT(1, BCH_REPLICAS_MAX), \
152 BCH_SB_META_REPLICAS_REQ, 1, \
154 x(data_replicas_required, u8, \
155 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
156 OPT_UINT(1, BCH_REPLICAS_MAX), \
157 BCH_SB_DATA_REPLICAS_REQ, 1, \
159 x(encoded_extent_max, u32, \
161 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\
162 OPT_UINT(4096, 2U << 20), \
163 BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10, \
164 "size", "Maximum size of checksummed/compressed extents")\
165 x(metadata_checksum, u8, \
166 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
167 OPT_STR(bch2_csum_opts), \
168 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
170 x(data_checksum, u8, \
171 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
172 OPT_STR(bch2_csum_opts), \
173 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
176 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
177 OPT_FN(bch2_opt_compression), \
178 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
180 x(background_compression, u8, \
181 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
182 OPT_FN(bch2_opt_compression), \
183 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
186 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
187 OPT_STR(bch2_str_hash_opts), \
188 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
189 NULL, "Hash function for directory entries and xattrs")\
190 x(metadata_target, u16, \
191 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
192 OPT_FN(bch2_opt_target), \
193 BCH_SB_METADATA_TARGET, 0, \
194 "(target)", "Device or label for metadata writes") \
195 x(foreground_target, u16, \
196 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
197 OPT_FN(bch2_opt_target), \
198 BCH_SB_FOREGROUND_TARGET, 0, \
199 "(target)", "Device or label for foreground writes") \
200 x(background_target, u16, \
201 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
202 OPT_FN(bch2_opt_target), \
203 BCH_SB_BACKGROUND_TARGET, 0, \
204 "(target)", "Device or label to move data to in the background")\
205 x(promote_target, u16, \
206 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
207 OPT_FN(bch2_opt_target), \
208 BCH_SB_PROMOTE_TARGET, 0, \
209 "(target)", "Device or label to promote data to on read") \
210 x(erasure_code, u16, \
211 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
213 BCH_SB_ERASURE_CODE, false, \
214 NULL, "Enable erasure coding (DO NOT USE YET)") \
215 x(inodes_32bit, u8, \
216 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
218 BCH_SB_INODE_32BIT, true, \
219 NULL, "Constrain inode numbers to 32 bits") \
220 x(shard_inode_numbers, u8, \
221 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
223 BCH_SB_SHARD_INUMS, true, \
224 NULL, "Shard new inode numbers by CPU id") \
225 x(inodes_use_key_cache, u8, \
226 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
228 BCH_SB_INODES_USE_KEY_CACHE, true, \
229 NULL, "Use the btree key cache for the inodes btree") \
230 x(btree_node_mem_ptr_optimization, u8, \
231 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
233 BCH2_NO_SB_OPT, true, \
234 NULL, "Stash pointer to in memory btree node in btree ptr")\
235 x(btree_write_buffer_size, u32, \
237 OPT_UINT(16, (1U << 20) - 1), \
238 BCH2_NO_SB_OPT, 1U << 13, \
239 NULL, "Number of btree write buffer entries") \
240 x(gc_reserve_percent, u8, \
241 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
243 BCH_SB_GC_RESERVE, 8, \
244 "%", "Percentage of disk space to reserve for copygc")\
245 x(gc_reserve_bytes, u64, \
246 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME| \
247 OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \
248 OPT_UINT(0, U64_MAX), \
249 BCH_SB_GC_RESERVE_BYTES, 0, \
250 "%", "Amount of disk space to reserve for copygc\n" \
251 "Takes precedence over gc_reserve_percent if set")\
252 x(root_reserve_percent, u8, \
253 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
255 BCH_SB_ROOT_RESERVE, 0, \
256 "%", "Percentage of disk space to reserve for superuser")\
258 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
260 BCH_SB_128_BIT_MACS, false, \
261 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
263 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
265 BCH2_NO_SB_OPT, true, \
266 NULL, "Enable inline data extents") \
268 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
270 BCH_SB_POSIX_ACL, true, \
271 NULL, "Enable POSIX acls") \
273 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
275 BCH_SB_USRQUOTA, false, \
276 NULL, "Enable user quotas") \
278 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
280 BCH_SB_GRPQUOTA, false, \
281 NULL, "Enable group quotas") \
283 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
285 BCH_SB_PRJQUOTA, false, \
286 NULL, "Enable project quotas") \
290 BCH2_NO_SB_OPT, false, \
291 NULL, "Allow mounting in degraded mode") \
292 x(very_degraded, u8, \
295 BCH2_NO_SB_OPT, false, \
296 NULL, "Allow mounting in when data will be missing") \
298 OPT_FS|OPT_MOUNT|OPT_DEVICE, \
300 BCH2_NO_SB_OPT, true, \
301 NULL, "Enable discard/TRIM support") \
303 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
305 BCH2_NO_SB_OPT, BCACHEFS_VERBOSE_DEFAULT, \
306 NULL, "Extra debugging information during mount/recovery")\
307 x(journal_flush_delay, u32, \
308 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
309 OPT_UINT(1, U32_MAX), \
310 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \
311 NULL, "Delay in milliseconds before automatic journal commits")\
312 x(journal_flush_disabled, u8, \
313 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
315 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \
316 NULL, "Disable journal flush on sync/fsync\n" \
317 "If enabled, writes can be lost, but only since the\n"\
318 "last journal write (default 1 second)") \
319 x(journal_reclaim_delay, u32, \
320 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
321 OPT_UINT(0, U32_MAX), \
322 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \
323 NULL, "Delay in milliseconds before automatic journal reclaim")\
324 x(move_bytes_in_flight, u32, \
325 OPT_HUMAN_READABLE|OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
326 OPT_UINT(1024, U32_MAX), \
327 BCH2_NO_SB_OPT, 1U << 20, \
328 NULL, "Maximum Amount of IO to keep in flight by the move path")\
329 x(move_ios_in_flight, u32, \
330 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
332 BCH2_NO_SB_OPT, 32, \
333 NULL, "Maximum number of IOs to keep in flight by the move path")\
337 BCH2_NO_SB_OPT, false, \
338 NULL, "Run fsck on mount") \
341 OPT_FN(bch2_opt_fix_errors), \
342 BCH2_NO_SB_OPT, FSCK_FIX_exit, \
343 NULL, "Fix errors during fsck without asking") \
344 x(ratelimit_errors, u8, \
347 BCH2_NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \
348 NULL, "Ratelimit error messages during fsck") \
352 BCH2_NO_SB_OPT, false, \
353 NULL, "Super read only mode - no writes at all will be issued,\n"\
354 "even if we have to replay the journal") \
358 BCH2_NO_SB_OPT, false, \
359 NULL, "Don't replay the journal") \
360 x(keep_journal, u8, \
363 BCH2_NO_SB_OPT, false, \
364 NULL, "Don't free journal entries/keys after startup")\
365 x(read_entire_journal, u8, \
368 BCH2_NO_SB_OPT, false, \
369 NULL, "Read all journal entries, not just dirty ones")\
370 x(read_journal_only, u8, \
373 BCH2_NO_SB_OPT, false, \
374 NULL, "Only read the journal, skip the rest of recovery")\
375 x(journal_transaction_names, u8, \
376 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
378 BCH_SB_JOURNAL_TRANSACTION_NAMES, true, \
379 NULL, "Log transaction function names in journal") \
383 BCH2_NO_SB_OPT, false, \
384 NULL, "Don't open device in exclusive mode") \
388 BCH2_NO_SB_OPT, true, \
389 NULL, "Use O_DIRECT (userspace only)") \
392 OPT_UINT(0, S64_MAX), \
393 BCH2_NO_SB_OPT, BCH_SB_SECTOR, \
394 "offset", "Sector offset of superblock") \
398 BCH2_NO_SB_OPT, false, \
403 BCH2_NO_SB_OPT, false, \
404 NULL, "Don\'t start filesystem, only open devices") \
405 x(reconstruct_alloc, u8, \
408 BCH2_NO_SB_OPT, false, \
409 NULL, "Reconstruct alloc btree") \
410 x(version_upgrade, u8, \
412 OPT_STR(bch2_version_upgrade_opts), \
413 BCH_SB_VERSION_UPGRADE, BCH_VERSION_UPGRADE_compatible, \
414 NULL, "Set superblock to latest version,\n" \
415 "allowing any new features to be used") \
416 x(buckets_nouse, u8, \
419 BCH2_NO_SB_OPT, false, \
420 NULL, "Allocate the buckets_nouse bitmap") \
424 BCH2_NO_SB_OPT, false, \
427 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
429 BCH_SB_NOCOW, false, \
430 NULL, "Nocow mode: Writes will be done in place when possible.\n"\
431 "Snapshots and reflink will still caused writes to be COW\n"\
432 "Implicitly disables data checksumming, compression and encryption")\
433 x(nocow_enabled, u8, \
436 BCH2_NO_SB_OPT, true, \
437 NULL, "Enable nocow mode: enables runtime locking in\n"\
438 "data move path needed if nocow will ever be in use\n")\
442 BCH2_NO_SB_OPT, false, \
443 NULL, "Skip submit_bio() for data reads and writes, " \
444 "for performance testing purposes") \
447 OPT_UINT(0, S64_MAX), \
449 "size", "Size of filesystem on device") \
452 OPT_UINT(0, S64_MAX), \
454 "size", "Size of filesystem on device") \
457 OPT_UINT(0, BCH_REPLICAS_MAX), \
459 "n", "Data written to this device will be considered\n"\
460 "to have already been replicated n times")
463 #define x(_name, _bits, ...) unsigned _name##_defined:1;
467 #define x(_name, _bits, ...) _bits _name;
472 static const struct bch_opts bch2_opts_default = {
473 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
474 ._name##_defined = true, \
481 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
483 #define opt_get(_opts, _name) \
484 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
486 #define opt_set(_opts, _name, _v) \
488 (_opts)._name##_defined = true; \
489 (_opts)._name = _v; \
492 static inline struct bch_opts bch2_opts_empty(void)
494 return (struct bch_opts) { 0 };
497 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
500 #define x(_name, ...) Opt_##_name,
510 struct attribute attr;
511 u64 (*get_sb)(const struct bch_sb *);
512 void (*set_sb)(struct bch_sb *, u64);
514 enum opt_flags flags;
517 const char * const *choices;
519 struct bch_opt_fn fn;
526 extern const struct bch_option bch2_opt_table[];
528 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
529 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
530 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
532 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id);
533 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
534 void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64);
535 void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64);
537 int bch2_opt_lookup(const char *);
538 int bch2_opt_validate(const struct bch_option *, u64, struct printbuf *);
539 int bch2_opt_parse(struct bch_fs *, const struct bch_option *,
540 const char *, u64 *, struct printbuf *);
542 #define OPT_SHOW_FULL_LIST (1 << 0)
543 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
545 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
546 const struct bch_option *, u64, unsigned);
548 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
549 int bch2_opts_check_may_set(struct bch_fs *);
550 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
555 #define x(_name, _bits) u##_bits _name;
560 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
561 bool bch2_opt_is_inode_opt(enum bch_opt_id);
563 #endif /* _BCACHEFS_OPTS_H */