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
98 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
99 OPT_UINT(512, 1U << 16), \
100 BCH_SB_BLOCK_SIZE, 8, \
102 x(btree_node_size, u32, \
104 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
105 OPT_UINT(512, 1U << 20), \
106 BCH_SB_BTREE_NODE_SIZE, 512, \
107 "size", "Btree node size, default 256k") \
109 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
110 OPT_STR(bch2_error_actions), \
111 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \
112 NULL, "Action to take on filesystem error") \
113 x(metadata_replicas, u8, \
114 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
115 OPT_UINT(1, BCH_REPLICAS_MAX), \
116 BCH_SB_META_REPLICAS_WANT, 1, \
117 "#", "Number of metadata replicas") \
118 x(data_replicas, u8, \
119 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
120 OPT_UINT(1, BCH_REPLICAS_MAX), \
121 BCH_SB_DATA_REPLICAS_WANT, 1, \
122 "#", "Number of data replicas") \
123 x(metadata_replicas_required, u8, \
124 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
125 OPT_UINT(1, BCH_REPLICAS_MAX), \
126 BCH_SB_META_REPLICAS_REQ, 1, \
128 x(data_replicas_required, u8, \
129 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
130 OPT_UINT(1, BCH_REPLICAS_MAX), \
131 BCH_SB_DATA_REPLICAS_REQ, 1, \
133 x(encoded_extent_max, u32, \
135 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\
136 OPT_UINT(4096, 2U << 20), \
137 BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10, \
138 "size", "Maximum size of checksummed/compressed extents")\
139 x(metadata_checksum, u8, \
140 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
141 OPT_STR(bch2_csum_opts), \
142 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
144 x(data_checksum, u8, \
145 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
146 OPT_STR(bch2_csum_opts), \
147 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
150 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
151 OPT_STR(bch2_compression_opts), \
152 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
154 x(background_compression, u8, \
155 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
156 OPT_STR(bch2_compression_opts), \
157 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
160 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
161 OPT_STR(bch2_str_hash_opts), \
162 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
163 NULL, "Hash function for directory entries and xattrs")\
164 x(metadata_target, u16, \
165 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
166 OPT_FN(bch2_opt_target), \
167 BCH_SB_METADATA_TARGET, 0, \
168 "(target)", "Device or label for metadata writes") \
169 x(foreground_target, u16, \
170 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
171 OPT_FN(bch2_opt_target), \
172 BCH_SB_FOREGROUND_TARGET, 0, \
173 "(target)", "Device or label for foreground writes") \
174 x(background_target, u16, \
175 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
176 OPT_FN(bch2_opt_target), \
177 BCH_SB_BACKGROUND_TARGET, 0, \
178 "(target)", "Device or label to move data to in the background")\
179 x(promote_target, u16, \
180 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
181 OPT_FN(bch2_opt_target), \
182 BCH_SB_PROMOTE_TARGET, 0, \
183 "(target)", "Device or label to promote data to on read") \
184 x(erasure_code, u16, \
185 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
187 BCH_SB_ERASURE_CODE, false, \
188 NULL, "Enable erasure coding (DO NOT USE YET)") \
189 x(inodes_32bit, u8, \
190 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
192 BCH_SB_INODE_32BIT, true, \
193 NULL, "Constrain inode numbers to 32 bits") \
194 x(shard_inode_numbers, u8, \
195 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
197 BCH_SB_SHARD_INUMS, true, \
198 NULL, "Shard new inode numbers by CPU id") \
199 x(inodes_use_key_cache, u8, \
200 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
202 BCH_SB_INODES_USE_KEY_CACHE, true, \
203 NULL, "Use the btree key cache for the inodes btree") \
204 x(btree_node_mem_ptr_optimization, u8, \
205 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
207 BCH2_NO_SB_OPT, true, \
208 NULL, "Stash pointer to in memory btree node in btree ptr")\
209 x(btree_write_buffer_size, u32, \
211 OPT_UINT(16, (1U << 20) - 1), \
212 BCH2_NO_SB_OPT, 1U << 13, \
213 NULL, "Number of btree write buffer entries") \
214 x(gc_reserve_percent, u8, \
215 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
217 BCH_SB_GC_RESERVE, 8, \
218 "%", "Percentage of disk space to reserve for copygc")\
219 x(gc_reserve_bytes, u64, \
220 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME| \
221 OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \
222 OPT_UINT(0, U64_MAX), \
223 BCH_SB_GC_RESERVE_BYTES, 0, \
224 "%", "Amount of disk space to reserve for copygc\n" \
225 "Takes precedence over gc_reserve_percent if set")\
226 x(root_reserve_percent, u8, \
227 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
229 BCH_SB_ROOT_RESERVE, 0, \
230 "%", "Percentage of disk space to reserve for superuser")\
232 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
234 BCH_SB_128_BIT_MACS, false, \
235 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
237 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
239 BCH2_NO_SB_OPT, true, \
240 NULL, "Enable inline data extents") \
242 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
244 BCH_SB_POSIX_ACL, true, \
245 NULL, "Enable POSIX acls") \
247 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
249 BCH_SB_USRQUOTA, false, \
250 NULL, "Enable user quotas") \
252 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
254 BCH_SB_GRPQUOTA, false, \
255 NULL, "Enable group quotas") \
257 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
259 BCH_SB_PRJQUOTA, false, \
260 NULL, "Enable project quotas") \
264 BCH2_NO_SB_OPT, false, \
265 NULL, "Allow mounting in degraded mode") \
266 x(very_degraded, u8, \
269 BCH2_NO_SB_OPT, false, \
270 NULL, "Allow mounting in when data will be missing") \
272 OPT_FS|OPT_MOUNT|OPT_DEVICE, \
274 BCH2_NO_SB_OPT, true, \
275 NULL, "Enable discard/TRIM support") \
277 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
279 BCH2_NO_SB_OPT, false, \
280 NULL, "Extra debugging information during mount/recovery")\
281 x(journal_flush_delay, u32, \
282 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
283 OPT_UINT(1, U32_MAX), \
284 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \
285 NULL, "Delay in milliseconds before automatic journal commits")\
286 x(journal_flush_disabled, u8, \
287 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
289 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \
290 NULL, "Disable journal flush on sync/fsync\n" \
291 "If enabled, writes can be lost, but only since the\n"\
292 "last journal write (default 1 second)") \
293 x(journal_reclaim_delay, u32, \
294 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
295 OPT_UINT(0, U32_MAX), \
296 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \
297 NULL, "Delay in milliseconds before automatic journal reclaim")\
298 x(move_bytes_in_flight, u32, \
299 OPT_HUMAN_READABLE|OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
300 OPT_UINT(1024, U32_MAX), \
301 BCH2_NO_SB_OPT, 1U << 20, \
302 NULL, "Maximum Amount of IO to keep in flight by the move path")\
303 x(move_ios_in_flight, u32, \
304 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
306 BCH2_NO_SB_OPT, 32, \
307 NULL, "Maximum number of IOs to keep in flight by the move path")\
311 BCH2_NO_SB_OPT, false, \
312 NULL, "Run fsck on mount") \
316 BCH2_NO_SB_OPT, false, \
317 NULL, "Fix errors during fsck without asking") \
318 x(ratelimit_errors, u8, \
321 BCH2_NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \
322 NULL, "Ratelimit error messages during fsck") \
326 BCH2_NO_SB_OPT, false, \
327 NULL, "Super read only mode - no writes at all will be issued,\n"\
328 "even if we have to replay the journal") \
332 BCH2_NO_SB_OPT, false, \
333 NULL, "Don't replay the journal") \
334 x(keep_journal, u8, \
337 BCH2_NO_SB_OPT, false, \
338 NULL, "Don't free journal entries/keys after startup")\
339 x(read_entire_journal, u8, \
342 BCH2_NO_SB_OPT, false, \
343 NULL, "Read all journal entries, not just dirty ones")\
344 x(read_journal_only, u8, \
347 BCH2_NO_SB_OPT, false, \
348 NULL, "Only read the journal, skip the rest of recovery")\
349 x(journal_transaction_names, u8, \
350 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
352 BCH_SB_JOURNAL_TRANSACTION_NAMES, true, \
353 NULL, "Log transaction function names in journal") \
357 BCH2_NO_SB_OPT, false, \
358 NULL, "Don't open device in exclusive mode") \
362 BCH2_NO_SB_OPT, true, \
363 NULL, "Use O_DIRECT (userspace only)") \
366 OPT_UINT(0, S64_MAX), \
367 BCH2_NO_SB_OPT, BCH_SB_SECTOR, \
368 "offset", "Sector offset of superblock") \
372 BCH2_NO_SB_OPT, false, \
377 BCH2_NO_SB_OPT, false, \
378 NULL, "Don\'t start filesystem, only open devices") \
379 x(reconstruct_alloc, u8, \
382 BCH2_NO_SB_OPT, false, \
383 NULL, "Reconstruct alloc btree") \
384 x(version_upgrade, u8, \
387 BCH2_NO_SB_OPT, false, \
388 NULL, "Set superblock to latest version,\n" \
389 "allowing any new features to be used") \
390 x(buckets_nouse, u8, \
393 BCH2_NO_SB_OPT, false, \
394 NULL, "Allocate the buckets_nouse bitmap") \
398 BCH2_NO_SB_OPT, false, \
401 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
403 BCH_SB_NOCOW, false, \
404 NULL, "Nocow mode: Writes will be done in place when possible.\n"\
405 "Snapshots and reflink will still caused writes to be COW\n"\
406 "Implicitly disables data checksumming, compression and encryption")\
407 x(nocow_enabled, u8, \
410 BCH2_NO_SB_OPT, true, \
411 NULL, "Enable nocow mode: enables runtime locking in\n"\
412 "data move path needed if nocow will ever be in use\n")\
416 BCH2_NO_SB_OPT, false, \
417 NULL, "Skip submit_bio() for data reads and writes, " \
418 "for performance testing purposes") \
421 OPT_UINT(0, S64_MAX), \
423 "size", "Size of filesystem on device") \
426 OPT_UINT(0, S64_MAX), \
428 "size", "Size of filesystem on device") \
431 OPT_UINT(0, BCH_REPLICAS_MAX), \
433 "n", "Data written to this device will be considered\n"\
434 "to have already been replicated n times")
437 #define x(_name, _bits, ...) unsigned _name##_defined:1;
441 #define x(_name, _bits, ...) _bits _name;
446 static const struct bch_opts bch2_opts_default = {
447 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
448 ._name##_defined = true, \
455 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
457 #define opt_get(_opts, _name) \
458 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
460 #define opt_set(_opts, _name, _v) \
462 (_opts)._name##_defined = true; \
463 (_opts)._name = _v; \
466 static inline struct bch_opts bch2_opts_empty(void)
468 return (struct bch_opts) { 0 };
471 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
474 #define x(_name, ...) Opt_##_name,
484 struct attribute attr;
485 u64 (*get_sb)(const struct bch_sb *);
486 void (*set_sb)(struct bch_sb *, u64);
488 enum opt_flags flags;
491 const char * const *choices;
492 int (*parse)(struct bch_fs *, const char *, u64 *);
493 void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
500 extern const struct bch_option bch2_opt_table[];
502 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
503 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
504 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
506 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id);
507 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
508 void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64);
509 void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64);
511 int bch2_opt_lookup(const char *);
512 int bch2_opt_validate(const struct bch_option *, u64, struct printbuf *);
513 int bch2_opt_parse(struct bch_fs *, const struct bch_option *,
514 const char *, u64 *, struct printbuf *);
516 #define OPT_SHOW_FULL_LIST (1 << 0)
517 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
519 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
520 const struct bch_option *, u64, unsigned);
522 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
523 int bch2_opts_check_may_set(struct bch_fs *);
524 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
529 #define x(_name, _bits) u##_bits _name;
534 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
535 bool bch2_opt_is_inode_opt(enum bch_opt_id);
537 #endif /* _BCACHEFS_OPTS_H */