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"
11 extern const char * const bch2_error_actions[];
12 extern const char * const bch2_sb_features[];
13 extern const char * const bch2_sb_compat[];
14 extern const char * const bch2_btree_ids[];
15 extern const char * const bch2_csum_types[];
16 extern const char * const bch2_csum_opts[];
17 extern const char * const bch2_compression_types[];
18 extern const char * const bch2_compression_opts[];
19 extern const char * const bch2_str_hash_types[];
20 extern const char * const bch2_str_hash_opts[];
21 extern const char * const bch2_data_types[];
22 extern const char * const bch2_member_states[];
23 extern const char * const bch2_jset_entry_types[];
24 extern const char * const bch2_fs_usage_types[];
25 extern const char * const bch2_d_types[];
27 static inline const char *bch2_d_type_str(unsigned d_type)
29 return (d_type < BCH_DT_MAX ? bch2_d_types[d_type] : NULL) ?: "(bad d_type)";
33 * Mount options; we also store defaults in the superblock.
35 * Also exposed via sysfs: if an option is writeable, and it's also stored in
36 * the superblock, changing it via sysfs (currently? might change this) also
37 * updates the superblock.
39 * We store options as signed integers, where -1 means undefined. This means we
40 * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only
41 * apply the options from that struct that are defined.
44 /* dummy option, for options that aren't stored in the superblock */
45 u64 BCH2_NO_SB_OPT(const struct bch_sb *);
46 void SET_BCH2_NO_SB_OPT(struct bch_sb *, u64);
48 /* When can be set: */
50 OPT_FS = (1 << 0), /* Filesystem option */
51 OPT_DEVICE = (1 << 1), /* Device option */
52 OPT_INODE = (1 << 2), /* Inode option */
53 OPT_FORMAT = (1 << 3), /* May be specified at format time */
54 OPT_MOUNT = (1 << 4), /* May be specified at mount time */
55 OPT_RUNTIME = (1 << 5), /* May be specified at runtime */
56 OPT_HUMAN_READABLE = (1 << 6),
57 OPT_MUST_BE_POW_2 = (1 << 7), /* Must be power of 2 */
58 OPT_SB_FIELD_SECTORS = (1 << 8),/* Superblock field is >> 9 of actual value */
59 OPT_SB_FIELD_ILOG2 = (1 << 9), /* Superblock field is ilog2 of actual value */
70 * x(name, shortopt, type, in mem type, mode, sb_opt)
72 * @name - name of mount option, sysfs attribute, and struct bch_opts
75 * @mode - when opt may be set
77 * @sb_option - name of corresponding superblock option
79 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
89 #define RATELIMIT_ERRORS_DEFAULT true
91 #define RATELIMIT_ERRORS_DEFAULT false
94 #ifdef CONFIG_BCACHEFS_DEBUG
95 #define BCACHEFS_VERBOSE_DEFAULT true
97 #define BCACHEFS_VERBOSE_DEFAULT false
103 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
104 OPT_UINT(512, 1U << 16), \
105 BCH_SB_BLOCK_SIZE, 8, \
107 x(btree_node_size, u32, \
109 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
110 OPT_UINT(512, 1U << 20), \
111 BCH_SB_BTREE_NODE_SIZE, 512, \
112 "size", "Btree node size, default 256k") \
114 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
115 OPT_STR(bch2_error_actions), \
116 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \
117 NULL, "Action to take on filesystem error") \
118 x(metadata_replicas, u8, \
119 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
120 OPT_UINT(1, BCH_REPLICAS_MAX), \
121 BCH_SB_META_REPLICAS_WANT, 1, \
122 "#", "Number of metadata replicas") \
123 x(data_replicas, u8, \
124 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
125 OPT_UINT(1, BCH_REPLICAS_MAX), \
126 BCH_SB_DATA_REPLICAS_WANT, 1, \
127 "#", "Number of data replicas") \
128 x(metadata_replicas_required, u8, \
129 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
130 OPT_UINT(1, BCH_REPLICAS_MAX), \
131 BCH_SB_META_REPLICAS_REQ, 1, \
133 x(data_replicas_required, u8, \
134 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
135 OPT_UINT(1, BCH_REPLICAS_MAX), \
136 BCH_SB_DATA_REPLICAS_REQ, 1, \
138 x(encoded_extent_max, u32, \
140 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\
141 OPT_UINT(4096, 2U << 20), \
142 BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10, \
143 "size", "Maximum size of checksummed/compressed extents")\
144 x(metadata_checksum, u8, \
145 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
146 OPT_STR(bch2_csum_opts), \
147 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
149 x(data_checksum, u8, \
150 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
151 OPT_STR(bch2_csum_opts), \
152 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
155 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
156 OPT_STR(bch2_compression_opts), \
157 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
159 x(background_compression, u8, \
160 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
161 OPT_STR(bch2_compression_opts), \
162 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
165 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
166 OPT_STR(bch2_str_hash_opts), \
167 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
168 NULL, "Hash function for directory entries and xattrs")\
169 x(metadata_target, u16, \
170 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
171 OPT_FN(bch2_opt_target), \
172 BCH_SB_METADATA_TARGET, 0, \
173 "(target)", "Device or label for metadata writes") \
174 x(foreground_target, u16, \
175 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
176 OPT_FN(bch2_opt_target), \
177 BCH_SB_FOREGROUND_TARGET, 0, \
178 "(target)", "Device or label for foreground writes") \
179 x(background_target, u16, \
180 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
181 OPT_FN(bch2_opt_target), \
182 BCH_SB_BACKGROUND_TARGET, 0, \
183 "(target)", "Device or label to move data to in the background")\
184 x(promote_target, u16, \
185 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
186 OPT_FN(bch2_opt_target), \
187 BCH_SB_PROMOTE_TARGET, 0, \
188 "(target)", "Device or label to promote data to on read") \
189 x(erasure_code, u16, \
190 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
192 BCH_SB_ERASURE_CODE, false, \
193 NULL, "Enable erasure coding (DO NOT USE YET)") \
194 x(inodes_32bit, u8, \
195 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
197 BCH_SB_INODE_32BIT, true, \
198 NULL, "Constrain inode numbers to 32 bits") \
199 x(shard_inode_numbers, u8, \
200 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
202 BCH_SB_SHARD_INUMS, true, \
203 NULL, "Shard new inode numbers by CPU id") \
204 x(inodes_use_key_cache, u8, \
205 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
207 BCH_SB_INODES_USE_KEY_CACHE, true, \
208 NULL, "Use the btree key cache for the inodes btree") \
209 x(btree_node_mem_ptr_optimization, u8, \
210 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
212 BCH2_NO_SB_OPT, true, \
213 NULL, "Stash pointer to in memory btree node in btree ptr")\
214 x(btree_write_buffer_size, u32, \
216 OPT_UINT(16, (1U << 20) - 1), \
217 BCH2_NO_SB_OPT, 1U << 13, \
218 NULL, "Number of btree write buffer entries") \
219 x(gc_reserve_percent, u8, \
220 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
222 BCH_SB_GC_RESERVE, 8, \
223 "%", "Percentage of disk space to reserve for copygc")\
224 x(gc_reserve_bytes, u64, \
225 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME| \
226 OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \
227 OPT_UINT(0, U64_MAX), \
228 BCH_SB_GC_RESERVE_BYTES, 0, \
229 "%", "Amount of disk space to reserve for copygc\n" \
230 "Takes precedence over gc_reserve_percent if set")\
231 x(root_reserve_percent, u8, \
232 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
234 BCH_SB_ROOT_RESERVE, 0, \
235 "%", "Percentage of disk space to reserve for superuser")\
237 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
239 BCH_SB_128_BIT_MACS, false, \
240 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
242 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
244 BCH2_NO_SB_OPT, true, \
245 NULL, "Enable inline data extents") \
247 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
249 BCH_SB_POSIX_ACL, true, \
250 NULL, "Enable POSIX acls") \
252 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
254 BCH_SB_USRQUOTA, false, \
255 NULL, "Enable user quotas") \
257 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
259 BCH_SB_GRPQUOTA, false, \
260 NULL, "Enable group quotas") \
262 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
264 BCH_SB_PRJQUOTA, false, \
265 NULL, "Enable project quotas") \
269 BCH2_NO_SB_OPT, false, \
270 NULL, "Allow mounting in degraded mode") \
271 x(very_degraded, u8, \
274 BCH2_NO_SB_OPT, false, \
275 NULL, "Allow mounting in when data will be missing") \
277 OPT_FS|OPT_MOUNT|OPT_DEVICE, \
279 BCH2_NO_SB_OPT, true, \
280 NULL, "Enable discard/TRIM support") \
282 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
284 BCH2_NO_SB_OPT, BCACHEFS_VERBOSE_DEFAULT, \
285 NULL, "Extra debugging information during mount/recovery")\
286 x(journal_flush_delay, u32, \
287 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
288 OPT_UINT(1, U32_MAX), \
289 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \
290 NULL, "Delay in milliseconds before automatic journal commits")\
291 x(journal_flush_disabled, u8, \
292 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
294 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \
295 NULL, "Disable journal flush on sync/fsync\n" \
296 "If enabled, writes can be lost, but only since the\n"\
297 "last journal write (default 1 second)") \
298 x(journal_reclaim_delay, u32, \
299 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
300 OPT_UINT(0, U32_MAX), \
301 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \
302 NULL, "Delay in milliseconds before automatic journal reclaim")\
303 x(move_bytes_in_flight, u32, \
304 OPT_HUMAN_READABLE|OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
305 OPT_UINT(1024, U32_MAX), \
306 BCH2_NO_SB_OPT, 1U << 20, \
307 NULL, "Maximum Amount of IO to keep in flight by the move path")\
308 x(move_ios_in_flight, u32, \
309 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
311 BCH2_NO_SB_OPT, 32, \
312 NULL, "Maximum number of IOs to keep in flight by the move path")\
316 BCH2_NO_SB_OPT, false, \
317 NULL, "Run fsck on mount") \
321 BCH2_NO_SB_OPT, false, \
322 NULL, "Fix errors during fsck without asking") \
323 x(ratelimit_errors, u8, \
326 BCH2_NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \
327 NULL, "Ratelimit error messages during fsck") \
331 BCH2_NO_SB_OPT, false, \
332 NULL, "Super read only mode - no writes at all will be issued,\n"\
333 "even if we have to replay the journal") \
337 BCH2_NO_SB_OPT, false, \
338 NULL, "Don't replay the journal") \
339 x(keep_journal, u8, \
342 BCH2_NO_SB_OPT, false, \
343 NULL, "Don't free journal entries/keys after startup")\
344 x(read_entire_journal, u8, \
347 BCH2_NO_SB_OPT, false, \
348 NULL, "Read all journal entries, not just dirty ones")\
349 x(read_journal_only, u8, \
352 BCH2_NO_SB_OPT, false, \
353 NULL, "Only read the journal, skip the rest of recovery")\
354 x(journal_transaction_names, u8, \
355 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
357 BCH_SB_JOURNAL_TRANSACTION_NAMES, true, \
358 NULL, "Log transaction function names in journal") \
362 BCH2_NO_SB_OPT, false, \
363 NULL, "Don't open device in exclusive mode") \
367 BCH2_NO_SB_OPT, true, \
368 NULL, "Use O_DIRECT (userspace only)") \
371 OPT_UINT(0, S64_MAX), \
372 BCH2_NO_SB_OPT, BCH_SB_SECTOR, \
373 "offset", "Sector offset of superblock") \
377 BCH2_NO_SB_OPT, false, \
382 BCH2_NO_SB_OPT, false, \
383 NULL, "Don\'t start filesystem, only open devices") \
384 x(reconstruct_alloc, u8, \
387 BCH2_NO_SB_OPT, false, \
388 NULL, "Reconstruct alloc btree") \
389 x(version_upgrade, u8, \
392 BCH2_NO_SB_OPT, false, \
393 NULL, "Set superblock to latest version,\n" \
394 "allowing any new features to be used") \
395 x(buckets_nouse, u8, \
398 BCH2_NO_SB_OPT, false, \
399 NULL, "Allocate the buckets_nouse bitmap") \
403 BCH2_NO_SB_OPT, false, \
406 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
408 BCH_SB_NOCOW, false, \
409 NULL, "Nocow mode: Writes will be done in place when possible.\n"\
410 "Snapshots and reflink will still caused writes to be COW\n"\
411 "Implicitly disables data checksumming, compression and encryption")\
412 x(nocow_enabled, u8, \
415 BCH2_NO_SB_OPT, true, \
416 NULL, "Enable nocow mode: enables runtime locking in\n"\
417 "data move path needed if nocow will ever be in use\n")\
421 BCH2_NO_SB_OPT, false, \
422 NULL, "Skip submit_bio() for data reads and writes, " \
423 "for performance testing purposes") \
426 OPT_UINT(0, S64_MAX), \
428 "size", "Size of filesystem on device") \
431 OPT_UINT(0, S64_MAX), \
433 "size", "Size of filesystem on device") \
436 OPT_UINT(0, BCH_REPLICAS_MAX), \
438 "n", "Data written to this device will be considered\n"\
439 "to have already been replicated n times")
442 #define x(_name, _bits, ...) unsigned _name##_defined:1;
446 #define x(_name, _bits, ...) _bits _name;
451 static const struct bch_opts bch2_opts_default = {
452 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
453 ._name##_defined = true, \
460 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
462 #define opt_get(_opts, _name) \
463 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
465 #define opt_set(_opts, _name, _v) \
467 (_opts)._name##_defined = true; \
468 (_opts)._name = _v; \
471 static inline struct bch_opts bch2_opts_empty(void)
473 return (struct bch_opts) { 0 };
476 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
479 #define x(_name, ...) Opt_##_name,
489 struct attribute attr;
490 u64 (*get_sb)(const struct bch_sb *);
491 void (*set_sb)(struct bch_sb *, u64);
493 enum opt_flags flags;
496 const char * const *choices;
497 int (*parse)(struct bch_fs *, const char *, u64 *);
498 void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
505 extern const struct bch_option bch2_opt_table[];
507 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
508 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
509 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
511 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id);
512 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
513 void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64);
514 void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64);
516 int bch2_opt_lookup(const char *);
517 int bch2_opt_validate(const struct bch_option *, u64, struct printbuf *);
518 int bch2_opt_parse(struct bch_fs *, const struct bch_option *,
519 const char *, u64 *, struct printbuf *);
521 #define OPT_SHOW_FULL_LIST (1 << 0)
522 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
524 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
525 const struct bch_option *, u64, unsigned);
527 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
528 int bch2_opts_check_may_set(struct bch_fs *);
529 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
534 #define x(_name, _bits) u##_bits _name;
539 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
540 bool bch2_opt_is_inode_opt(enum bch_opt_id);
542 #endif /* _BCACHEFS_OPTS_H */