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_iops_measurements[];
14 extern const char * const bch2_error_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_jset_entry_types[];
29 extern const char * const bch2_fs_usage_types[];
30 extern const char * const bch2_d_types[];
32 static inline const char *bch2_d_type_str(unsigned d_type)
34 return (d_type < BCH_DT_MAX ? bch2_d_types[d_type] : NULL) ?: "(bad d_type)";
38 * Mount options; we also store defaults in the superblock.
40 * Also exposed via sysfs: if an option is writeable, and it's also stored in
41 * the superblock, changing it via sysfs (currently? might change this) also
42 * updates the superblock.
44 * We store options as signed integers, where -1 means undefined. This means we
45 * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only
46 * apply the options from that struct that are defined.
49 /* dummy option, for options that aren't stored in the superblock */
50 u64 BCH2_NO_SB_OPT(const struct bch_sb *);
51 void SET_BCH2_NO_SB_OPT(struct bch_sb *, u64);
53 /* When can be set: */
55 OPT_FS = (1 << 0), /* Filesystem option */
56 OPT_DEVICE = (1 << 1), /* Device option */
57 OPT_INODE = (1 << 2), /* Inode option */
58 OPT_FORMAT = (1 << 3), /* May be specified at format time */
59 OPT_MOUNT = (1 << 4), /* May be specified at mount time */
60 OPT_RUNTIME = (1 << 5), /* May be specified at runtime */
61 OPT_HUMAN_READABLE = (1 << 6),
62 OPT_MUST_BE_POW_2 = (1 << 7), /* Must be power of 2 */
63 OPT_SB_FIELD_SECTORS = (1 << 8),/* Superblock field is >> 9 of actual value */
64 OPT_SB_FIELD_ILOG2 = (1 << 9), /* Superblock field is ilog2 of actual value */
75 int (*parse)(struct bch_fs *, const char *, u64 *, struct printbuf *);
76 void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
77 int (*validate)(u64, struct printbuf *);
81 * x(name, shortopt, type, in mem type, mode, sb_opt)
83 * @name - name of mount option, sysfs attribute, and struct bch_opts
86 * @mode - when opt may be set
88 * @sb_option - name of corresponding superblock option
90 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
100 #define RATELIMIT_ERRORS_DEFAULT true
102 #define RATELIMIT_ERRORS_DEFAULT false
105 #ifdef CONFIG_BCACHEFS_DEBUG
106 #define BCACHEFS_VERBOSE_DEFAULT true
108 #define BCACHEFS_VERBOSE_DEFAULT false
111 #define BCH_FIX_ERRORS_OPTS() \
118 #define x(t, n) FSCK_FIX_##t,
119 BCH_FIX_ERRORS_OPTS()
126 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
127 OPT_UINT(512, 1U << 16), \
128 BCH_SB_BLOCK_SIZE, 8, \
130 x(btree_node_size, u32, \
132 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
133 OPT_UINT(512, 1U << 20), \
134 BCH_SB_BTREE_NODE_SIZE, 512, \
135 "size", "Btree node size, default 256k") \
137 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
138 OPT_STR(bch2_error_actions), \
139 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \
140 NULL, "Action to take on filesystem error") \
141 x(metadata_replicas, u8, \
142 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
143 OPT_UINT(1, BCH_REPLICAS_MAX), \
144 BCH_SB_META_REPLICAS_WANT, 1, \
145 "#", "Number of metadata replicas") \
146 x(data_replicas, u8, \
147 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
148 OPT_UINT(1, BCH_REPLICAS_MAX), \
149 BCH_SB_DATA_REPLICAS_WANT, 1, \
150 "#", "Number of data replicas") \
151 x(metadata_replicas_required, u8, \
152 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
153 OPT_UINT(1, BCH_REPLICAS_MAX), \
154 BCH_SB_META_REPLICAS_REQ, 1, \
156 x(data_replicas_required, u8, \
157 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
158 OPT_UINT(1, BCH_REPLICAS_MAX), \
159 BCH_SB_DATA_REPLICAS_REQ, 1, \
161 x(encoded_extent_max, u32, \
163 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\
164 OPT_UINT(4096, 2U << 20), \
165 BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10, \
166 "size", "Maximum size of checksummed/compressed extents")\
167 x(metadata_checksum, u8, \
168 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
169 OPT_STR(bch2_csum_opts), \
170 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
172 x(data_checksum, u8, \
173 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
174 OPT_STR(bch2_csum_opts), \
175 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
178 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
179 OPT_FN(bch2_opt_compression), \
180 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
182 x(background_compression, u8, \
183 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
184 OPT_FN(bch2_opt_compression), \
185 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
188 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
189 OPT_STR(bch2_str_hash_opts), \
190 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
191 NULL, "Hash function for directory entries and xattrs")\
192 x(metadata_target, u16, \
193 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
194 OPT_FN(bch2_opt_target), \
195 BCH_SB_METADATA_TARGET, 0, \
196 "(target)", "Device or label for metadata writes") \
197 x(foreground_target, u16, \
198 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
199 OPT_FN(bch2_opt_target), \
200 BCH_SB_FOREGROUND_TARGET, 0, \
201 "(target)", "Device or label for foreground writes") \
202 x(background_target, u16, \
203 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
204 OPT_FN(bch2_opt_target), \
205 BCH_SB_BACKGROUND_TARGET, 0, \
206 "(target)", "Device or label to move data to in the background")\
207 x(promote_target, u16, \
208 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
209 OPT_FN(bch2_opt_target), \
210 BCH_SB_PROMOTE_TARGET, 0, \
211 "(target)", "Device or label to promote data to on read") \
212 x(erasure_code, u16, \
213 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
215 BCH_SB_ERASURE_CODE, false, \
216 NULL, "Enable erasure coding (DO NOT USE YET)") \
217 x(inodes_32bit, u8, \
218 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
220 BCH_SB_INODE_32BIT, true, \
221 NULL, "Constrain inode numbers to 32 bits") \
222 x(shard_inode_numbers, u8, \
223 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
225 BCH_SB_SHARD_INUMS, true, \
226 NULL, "Shard new inode numbers by CPU id") \
227 x(inodes_use_key_cache, u8, \
228 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
230 BCH_SB_INODES_USE_KEY_CACHE, true, \
231 NULL, "Use the btree key cache for the inodes btree") \
232 x(btree_node_mem_ptr_optimization, u8, \
233 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
235 BCH2_NO_SB_OPT, true, \
236 NULL, "Stash pointer to in memory btree node in btree ptr")\
237 x(btree_write_buffer_size, u32, \
239 OPT_UINT(16, (1U << 20) - 1), \
240 BCH2_NO_SB_OPT, 1U << 13, \
241 NULL, "Number of btree write buffer entries") \
242 x(gc_reserve_percent, u8, \
243 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
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, \
257 BCH_SB_ROOT_RESERVE, 0, \
258 "%", "Percentage of disk space to reserve for superuser")\
260 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
262 BCH_SB_128_BIT_MACS, false, \
263 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
265 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
267 BCH2_NO_SB_OPT, true, \
268 NULL, "Enable inline data extents") \
270 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
272 BCH_SB_POSIX_ACL, true, \
273 NULL, "Enable POSIX acls") \
275 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
277 BCH_SB_USRQUOTA, false, \
278 NULL, "Enable user quotas") \
280 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
282 BCH_SB_GRPQUOTA, false, \
283 NULL, "Enable group quotas") \
285 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
287 BCH_SB_PRJQUOTA, false, \
288 NULL, "Enable project quotas") \
292 BCH2_NO_SB_OPT, false, \
293 NULL, "Allow mounting in degraded mode") \
294 x(very_degraded, u8, \
297 BCH2_NO_SB_OPT, false, \
298 NULL, "Allow mounting in when data will be missing") \
300 OPT_FS|OPT_MOUNT|OPT_DEVICE, \
302 BCH2_NO_SB_OPT, true, \
303 NULL, "Enable discard/TRIM support") \
305 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
307 BCH2_NO_SB_OPT, BCACHEFS_VERBOSE_DEFAULT, \
308 NULL, "Extra debugging information during mount/recovery")\
309 x(journal_flush_delay, u32, \
310 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
311 OPT_UINT(1, U32_MAX), \
312 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \
313 NULL, "Delay in milliseconds before automatic journal commits")\
314 x(journal_flush_disabled, u8, \
315 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
317 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \
318 NULL, "Disable journal flush on sync/fsync\n" \
319 "If enabled, writes can be lost, but only since the\n"\
320 "last journal write (default 1 second)") \
321 x(journal_reclaim_delay, u32, \
322 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
323 OPT_UINT(0, U32_MAX), \
324 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \
325 NULL, "Delay in milliseconds before automatic journal reclaim")\
326 x(move_bytes_in_flight, u32, \
327 OPT_HUMAN_READABLE|OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
328 OPT_UINT(1024, U32_MAX), \
329 BCH2_NO_SB_OPT, 1U << 20, \
330 NULL, "Maximum Amount of IO to keep in flight by the move path")\
331 x(move_ios_in_flight, u32, \
332 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
334 BCH2_NO_SB_OPT, 32, \
335 NULL, "Maximum number of IOs to keep in flight by the move path")\
339 BCH2_NO_SB_OPT, false, \
340 NULL, "Run fsck on mount") \
343 OPT_FN(bch2_opt_fix_errors), \
344 BCH2_NO_SB_OPT, FSCK_FIX_exit, \
345 NULL, "Fix errors during fsck without asking") \
346 x(ratelimit_errors, u8, \
349 BCH2_NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \
350 NULL, "Ratelimit error messages during fsck") \
354 BCH2_NO_SB_OPT, false, \
355 NULL, "Super read only mode - no writes at all will be issued,\n"\
356 "even if we have to replay the journal") \
360 BCH2_NO_SB_OPT, false, \
361 NULL, "Don't replay the journal") \
362 x(keep_journal, u8, \
365 BCH2_NO_SB_OPT, false, \
366 NULL, "Don't free journal entries/keys after startup")\
367 x(read_entire_journal, u8, \
370 BCH2_NO_SB_OPT, false, \
371 NULL, "Read all journal entries, not just dirty ones")\
372 x(read_journal_only, u8, \
375 BCH2_NO_SB_OPT, false, \
376 NULL, "Only read the journal, skip the rest of recovery")\
377 x(journal_transaction_names, u8, \
378 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
380 BCH_SB_JOURNAL_TRANSACTION_NAMES, true, \
381 NULL, "Log transaction function names in journal") \
385 BCH2_NO_SB_OPT, false, \
386 NULL, "Don't open device in exclusive mode") \
390 BCH2_NO_SB_OPT, true, \
391 NULL, "Use O_DIRECT (userspace only)") \
394 OPT_UINT(0, S64_MAX), \
395 BCH2_NO_SB_OPT, BCH_SB_SECTOR, \
396 "offset", "Sector offset of superblock") \
400 BCH2_NO_SB_OPT, false, \
405 BCH2_NO_SB_OPT, false, \
406 NULL, "Don\'t start filesystem, only open devices") \
407 x(reconstruct_alloc, u8, \
410 BCH2_NO_SB_OPT, false, \
411 NULL, "Reconstruct alloc btree") \
412 x(version_upgrade, u8, \
414 OPT_STR(bch2_version_upgrade_opts), \
415 BCH_SB_VERSION_UPGRADE, BCH_VERSION_UPGRADE_compatible, \
416 NULL, "Set superblock to latest version,\n" \
417 "allowing any new features to be used") \
418 x(buckets_nouse, u8, \
421 BCH2_NO_SB_OPT, false, \
422 NULL, "Allocate the buckets_nouse bitmap") \
426 BCH2_NO_SB_OPT, false, \
429 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
431 BCH_SB_NOCOW, false, \
432 NULL, "Nocow mode: Writes will be done in place when possible.\n"\
433 "Snapshots and reflink will still caused writes to be COW\n"\
434 "Implicitly disables data checksumming, compression and encryption")\
435 x(nocow_enabled, u8, \
438 BCH2_NO_SB_OPT, true, \
439 NULL, "Enable nocow mode: enables runtime locking in\n"\
440 "data move path needed if nocow will ever be in use\n")\
444 BCH2_NO_SB_OPT, false, \
445 NULL, "Skip submit_bio() for data reads and writes, " \
446 "for performance testing purposes") \
449 OPT_UINT(0, S64_MAX), \
451 "size", "Size of filesystem on device") \
454 OPT_UINT(0, S64_MAX), \
456 "size", "Size of filesystem on device") \
459 OPT_UINT(0, BCH_REPLICAS_MAX), \
461 "n", "Data written to this device will be considered\n"\
462 "to have already been replicated n times")
465 #define x(_name, _bits, ...) unsigned _name##_defined:1;
469 #define x(_name, _bits, ...) _bits _name;
474 static const __maybe_unused struct bch_opts bch2_opts_default = {
475 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
476 ._name##_defined = true, \
483 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
485 #define opt_get(_opts, _name) \
486 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
488 #define opt_set(_opts, _name, _v) \
490 (_opts)._name##_defined = true; \
491 (_opts)._name = _v; \
494 static inline struct bch_opts bch2_opts_empty(void)
496 return (struct bch_opts) { 0 };
499 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
502 #define x(_name, ...) Opt_##_name,
512 struct attribute attr;
513 u64 (*get_sb)(const struct bch_sb *);
514 void (*set_sb)(struct bch_sb *, u64);
516 enum opt_flags flags;
519 const char * const *choices;
521 struct bch_opt_fn fn;
528 extern const struct bch_option bch2_opt_table[];
530 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
531 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
532 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
534 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id);
535 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
536 void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64);
537 void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64);
539 int bch2_opt_lookup(const char *);
540 int bch2_opt_validate(const struct bch_option *, u64, struct printbuf *);
541 int bch2_opt_parse(struct bch_fs *, const struct bch_option *,
542 const char *, u64 *, struct printbuf *);
544 #define OPT_SHOW_FULL_LIST (1 << 0)
545 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
547 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
548 const struct bch_option *, u64, unsigned);
550 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
551 int bch2_opts_check_may_set(struct bch_fs *);
552 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
557 #define x(_name, _bits) u##_bits _name;
562 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
563 bool bch2_opt_is_inode_opt(enum bch_opt_id);
565 #endif /* _BCACHEFS_OPTS_H */