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_metadata_versions[];
12 extern const char * const bch2_error_actions[];
13 extern const char * const bch2_sb_features[];
14 extern const char * const bch2_sb_compat[];
15 extern const char * const bch2_btree_ids[];
16 extern const char * const bch2_csum_types[];
17 extern const char * const bch2_csum_opts[];
18 extern const char * const bch2_compression_types[];
19 extern const char * const bch2_compression_opts[];
20 extern const char * const bch2_str_hash_types[];
21 extern const char * const bch2_str_hash_opts[];
22 extern const char * const bch2_data_types[];
23 extern const char * const bch2_member_states[];
24 extern const char * const bch2_jset_entry_types[];
25 extern const char * const bch2_fs_usage_types[];
26 extern const char * const bch2_d_types[];
28 static inline const char *bch2_d_type_str(unsigned d_type)
30 return (d_type < BCH_DT_MAX ? bch2_d_types[d_type] : NULL) ?: "(bad d_type)";
34 * Mount options; we also store defaults in the superblock.
36 * Also exposed via sysfs: if an option is writeable, and it's also stored in
37 * the superblock, changing it via sysfs (currently? might change this) also
38 * updates the superblock.
40 * We store options as signed integers, where -1 means undefined. This means we
41 * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only
42 * apply the options from that struct that are defined.
45 /* dummy option, for options that aren't stored in the superblock */
46 u64 BCH2_NO_SB_OPT(const struct bch_sb *);
47 void SET_BCH2_NO_SB_OPT(struct bch_sb *, u64);
49 /* When can be set: */
51 OPT_FS = (1 << 0), /* Filesystem option */
52 OPT_DEVICE = (1 << 1), /* Device option */
53 OPT_INODE = (1 << 2), /* Inode option */
54 OPT_FORMAT = (1 << 3), /* May be specified at format time */
55 OPT_MOUNT = (1 << 4), /* May be specified at mount time */
56 OPT_RUNTIME = (1 << 5), /* May be specified at runtime */
57 OPT_HUMAN_READABLE = (1 << 6),
58 OPT_MUST_BE_POW_2 = (1 << 7), /* Must be power of 2 */
59 OPT_SB_FIELD_SECTORS = (1 << 8),/* Superblock field is >> 9 of actual value */
60 OPT_SB_FIELD_ILOG2 = (1 << 9), /* Superblock field is ilog2 of actual value */
71 * x(name, shortopt, type, in mem type, mode, sb_opt)
73 * @name - name of mount option, sysfs attribute, and struct bch_opts
76 * @mode - when opt may be set
78 * @sb_option - name of corresponding superblock option
80 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
90 #define RATELIMIT_ERRORS_DEFAULT true
92 #define RATELIMIT_ERRORS_DEFAULT false
95 #ifdef CONFIG_BCACHEFS_DEBUG
96 #define BCACHEFS_VERBOSE_DEFAULT true
98 #define BCACHEFS_VERBOSE_DEFAULT false
104 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
105 OPT_UINT(512, 1U << 16), \
106 BCH_SB_BLOCK_SIZE, 8, \
108 x(btree_node_size, u32, \
110 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
111 OPT_UINT(512, 1U << 20), \
112 BCH_SB_BTREE_NODE_SIZE, 512, \
113 "size", "Btree node size, default 256k") \
115 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
116 OPT_STR(bch2_error_actions), \
117 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \
118 NULL, "Action to take on filesystem error") \
119 x(metadata_replicas, u8, \
120 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
121 OPT_UINT(1, BCH_REPLICAS_MAX), \
122 BCH_SB_META_REPLICAS_WANT, 1, \
123 "#", "Number of metadata replicas") \
124 x(data_replicas, u8, \
125 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
126 OPT_UINT(1, BCH_REPLICAS_MAX), \
127 BCH_SB_DATA_REPLICAS_WANT, 1, \
128 "#", "Number of data replicas") \
129 x(metadata_replicas_required, u8, \
130 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
131 OPT_UINT(1, BCH_REPLICAS_MAX), \
132 BCH_SB_META_REPLICAS_REQ, 1, \
134 x(data_replicas_required, u8, \
135 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
136 OPT_UINT(1, BCH_REPLICAS_MAX), \
137 BCH_SB_DATA_REPLICAS_REQ, 1, \
139 x(encoded_extent_max, u32, \
141 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\
142 OPT_UINT(4096, 2U << 20), \
143 BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10, \
144 "size", "Maximum size of checksummed/compressed extents")\
145 x(metadata_checksum, u8, \
146 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
147 OPT_STR(bch2_csum_opts), \
148 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
150 x(data_checksum, u8, \
151 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
152 OPT_STR(bch2_csum_opts), \
153 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
156 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
157 OPT_STR(bch2_compression_opts), \
158 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
160 x(background_compression, u8, \
161 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
162 OPT_STR(bch2_compression_opts), \
163 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
166 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
167 OPT_STR(bch2_str_hash_opts), \
168 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
169 NULL, "Hash function for directory entries and xattrs")\
170 x(metadata_target, u16, \
171 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
172 OPT_FN(bch2_opt_target), \
173 BCH_SB_METADATA_TARGET, 0, \
174 "(target)", "Device or label for metadata writes") \
175 x(foreground_target, u16, \
176 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
177 OPT_FN(bch2_opt_target), \
178 BCH_SB_FOREGROUND_TARGET, 0, \
179 "(target)", "Device or label for foreground writes") \
180 x(background_target, u16, \
181 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
182 OPT_FN(bch2_opt_target), \
183 BCH_SB_BACKGROUND_TARGET, 0, \
184 "(target)", "Device or label to move data to in the background")\
185 x(promote_target, u16, \
186 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
187 OPT_FN(bch2_opt_target), \
188 BCH_SB_PROMOTE_TARGET, 0, \
189 "(target)", "Device or label to promote data to on read") \
190 x(erasure_code, u16, \
191 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
193 BCH_SB_ERASURE_CODE, false, \
194 NULL, "Enable erasure coding (DO NOT USE YET)") \
195 x(inodes_32bit, u8, \
196 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
198 BCH_SB_INODE_32BIT, true, \
199 NULL, "Constrain inode numbers to 32 bits") \
200 x(shard_inode_numbers, u8, \
201 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
203 BCH_SB_SHARD_INUMS, true, \
204 NULL, "Shard new inode numbers by CPU id") \
205 x(inodes_use_key_cache, u8, \
206 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
208 BCH_SB_INODES_USE_KEY_CACHE, true, \
209 NULL, "Use the btree key cache for the inodes btree") \
210 x(btree_node_mem_ptr_optimization, u8, \
211 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
213 BCH2_NO_SB_OPT, true, \
214 NULL, "Stash pointer to in memory btree node in btree ptr")\
215 x(btree_write_buffer_size, u32, \
217 OPT_UINT(16, (1U << 20) - 1), \
218 BCH2_NO_SB_OPT, 1U << 13, \
219 NULL, "Number of btree write buffer entries") \
220 x(gc_reserve_percent, u8, \
221 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
223 BCH_SB_GC_RESERVE, 8, \
224 "%", "Percentage of disk space to reserve for copygc")\
225 x(gc_reserve_bytes, u64, \
226 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME| \
227 OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \
228 OPT_UINT(0, U64_MAX), \
229 BCH_SB_GC_RESERVE_BYTES, 0, \
230 "%", "Amount of disk space to reserve for copygc\n" \
231 "Takes precedence over gc_reserve_percent if set")\
232 x(root_reserve_percent, u8, \
233 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
235 BCH_SB_ROOT_RESERVE, 0, \
236 "%", "Percentage of disk space to reserve for superuser")\
238 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
240 BCH_SB_128_BIT_MACS, false, \
241 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
243 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
245 BCH2_NO_SB_OPT, true, \
246 NULL, "Enable inline data extents") \
248 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
250 BCH_SB_POSIX_ACL, true, \
251 NULL, "Enable POSIX acls") \
253 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
255 BCH_SB_USRQUOTA, false, \
256 NULL, "Enable user quotas") \
258 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
260 BCH_SB_GRPQUOTA, false, \
261 NULL, "Enable group quotas") \
263 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
265 BCH_SB_PRJQUOTA, false, \
266 NULL, "Enable project quotas") \
270 BCH2_NO_SB_OPT, false, \
271 NULL, "Allow mounting in degraded mode") \
272 x(very_degraded, u8, \
275 BCH2_NO_SB_OPT, false, \
276 NULL, "Allow mounting in when data will be missing") \
278 OPT_FS|OPT_MOUNT|OPT_DEVICE, \
280 BCH2_NO_SB_OPT, true, \
281 NULL, "Enable discard/TRIM support") \
283 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
285 BCH2_NO_SB_OPT, BCACHEFS_VERBOSE_DEFAULT, \
286 NULL, "Extra debugging information during mount/recovery")\
287 x(journal_flush_delay, u32, \
288 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
289 OPT_UINT(1, U32_MAX), \
290 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \
291 NULL, "Delay in milliseconds before automatic journal commits")\
292 x(journal_flush_disabled, u8, \
293 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
295 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \
296 NULL, "Disable journal flush on sync/fsync\n" \
297 "If enabled, writes can be lost, but only since the\n"\
298 "last journal write (default 1 second)") \
299 x(journal_reclaim_delay, u32, \
300 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
301 OPT_UINT(0, U32_MAX), \
302 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \
303 NULL, "Delay in milliseconds before automatic journal reclaim")\
304 x(move_bytes_in_flight, u32, \
305 OPT_HUMAN_READABLE|OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
306 OPT_UINT(1024, U32_MAX), \
307 BCH2_NO_SB_OPT, 1U << 20, \
308 NULL, "Maximum Amount of IO to keep in flight by the move path")\
309 x(move_ios_in_flight, u32, \
310 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
312 BCH2_NO_SB_OPT, 32, \
313 NULL, "Maximum number of IOs to keep in flight by the move path")\
317 BCH2_NO_SB_OPT, false, \
318 NULL, "Run fsck on mount") \
322 BCH2_NO_SB_OPT, false, \
323 NULL, "Fix errors during fsck without asking") \
324 x(ratelimit_errors, u8, \
327 BCH2_NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \
328 NULL, "Ratelimit error messages during fsck") \
332 BCH2_NO_SB_OPT, false, \
333 NULL, "Super read only mode - no writes at all will be issued,\n"\
334 "even if we have to replay the journal") \
338 BCH2_NO_SB_OPT, false, \
339 NULL, "Don't replay the journal") \
340 x(keep_journal, u8, \
343 BCH2_NO_SB_OPT, false, \
344 NULL, "Don't free journal entries/keys after startup")\
345 x(read_entire_journal, u8, \
348 BCH2_NO_SB_OPT, false, \
349 NULL, "Read all journal entries, not just dirty ones")\
350 x(read_journal_only, u8, \
353 BCH2_NO_SB_OPT, false, \
354 NULL, "Only read the journal, skip the rest of recovery")\
355 x(journal_transaction_names, u8, \
356 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
358 BCH_SB_JOURNAL_TRANSACTION_NAMES, true, \
359 NULL, "Log transaction function names in journal") \
363 BCH2_NO_SB_OPT, false, \
364 NULL, "Don't open device in exclusive mode") \
368 BCH2_NO_SB_OPT, true, \
369 NULL, "Use O_DIRECT (userspace only)") \
372 OPT_UINT(0, S64_MAX), \
373 BCH2_NO_SB_OPT, BCH_SB_SECTOR, \
374 "offset", "Sector offset of superblock") \
378 BCH2_NO_SB_OPT, false, \
383 BCH2_NO_SB_OPT, false, \
384 NULL, "Don\'t start filesystem, only open devices") \
385 x(reconstruct_alloc, u8, \
388 BCH2_NO_SB_OPT, false, \
389 NULL, "Reconstruct alloc btree") \
390 x(version_upgrade, u8, \
393 BCH2_NO_SB_OPT, false, \
394 NULL, "Set superblock to latest version,\n" \
395 "allowing any new features to be used") \
396 x(buckets_nouse, u8, \
399 BCH2_NO_SB_OPT, false, \
400 NULL, "Allocate the buckets_nouse bitmap") \
404 BCH2_NO_SB_OPT, false, \
407 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
409 BCH_SB_NOCOW, false, \
410 NULL, "Nocow mode: Writes will be done in place when possible.\n"\
411 "Snapshots and reflink will still caused writes to be COW\n"\
412 "Implicitly disables data checksumming, compression and encryption")\
413 x(nocow_enabled, u8, \
416 BCH2_NO_SB_OPT, true, \
417 NULL, "Enable nocow mode: enables runtime locking in\n"\
418 "data move path needed if nocow will ever be in use\n")\
422 BCH2_NO_SB_OPT, false, \
423 NULL, "Skip submit_bio() for data reads and writes, " \
424 "for performance testing purposes") \
427 OPT_UINT(0, S64_MAX), \
429 "size", "Size of filesystem on device") \
432 OPT_UINT(0, S64_MAX), \
434 "size", "Size of filesystem on device") \
437 OPT_UINT(0, BCH_REPLICAS_MAX), \
439 "n", "Data written to this device will be considered\n"\
440 "to have already been replicated n times")
443 #define x(_name, _bits, ...) unsigned _name##_defined:1;
447 #define x(_name, _bits, ...) _bits _name;
452 static const struct bch_opts bch2_opts_default = {
453 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
454 ._name##_defined = true, \
461 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
463 #define opt_get(_opts, _name) \
464 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
466 #define opt_set(_opts, _name, _v) \
468 (_opts)._name##_defined = true; \
469 (_opts)._name = _v; \
472 static inline struct bch_opts bch2_opts_empty(void)
474 return (struct bch_opts) { 0 };
477 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
480 #define x(_name, ...) Opt_##_name,
490 struct attribute attr;
491 u64 (*get_sb)(const struct bch_sb *);
492 void (*set_sb)(struct bch_sb *, u64);
494 enum opt_flags flags;
497 const char * const *choices;
498 int (*parse)(struct bch_fs *, const char *, u64 *);
499 void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
506 extern const struct bch_option bch2_opt_table[];
508 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
509 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
510 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
512 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id);
513 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
514 void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64);
515 void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64);
517 int bch2_opt_lookup(const char *);
518 int bch2_opt_validate(const struct bch_option *, u64, struct printbuf *);
519 int bch2_opt_parse(struct bch_fs *, const struct bch_option *,
520 const char *, u64 *, struct printbuf *);
522 #define OPT_SHOW_FULL_LIST (1 << 0)
523 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
525 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
526 const struct bch_option *, u64, unsigned);
528 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
529 int bch2_opts_check_may_set(struct bch_fs *);
530 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
535 #define x(_name, _bits) u##_bits _name;
540 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
541 bool bch2_opt_is_inode_opt(enum bch_opt_id);
543 #endif /* _BCACHEFS_OPTS_H */