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(gc_reserve_percent, u8, \
210 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
212 BCH_SB_GC_RESERVE, 8, \
213 "%", "Percentage of disk space to reserve for copygc")\
214 x(gc_reserve_bytes, u64, \
215 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME| \
216 OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \
217 OPT_UINT(0, U64_MAX), \
218 BCH_SB_GC_RESERVE_BYTES, 0, \
219 "%", "Amount of disk space to reserve for copygc\n" \
220 "Takes precedence over gc_reserve_percent if set")\
221 x(root_reserve_percent, u8, \
222 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
224 BCH_SB_ROOT_RESERVE, 0, \
225 "%", "Percentage of disk space to reserve for superuser")\
227 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
229 BCH_SB_128_BIT_MACS, false, \
230 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
232 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
234 BCH2_NO_SB_OPT, true, \
235 NULL, "Enable inline data extents") \
237 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
239 BCH_SB_POSIX_ACL, true, \
240 NULL, "Enable POSIX acls") \
242 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
244 BCH_SB_USRQUOTA, false, \
245 NULL, "Enable user quotas") \
247 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
249 BCH_SB_GRPQUOTA, false, \
250 NULL, "Enable group quotas") \
252 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
254 BCH_SB_PRJQUOTA, false, \
255 NULL, "Enable project quotas") \
259 BCH2_NO_SB_OPT, false, \
260 NULL, "Allow mounting in degraded mode") \
261 x(very_degraded, u8, \
264 BCH2_NO_SB_OPT, false, \
265 NULL, "Allow mounting in when data will be missing") \
267 OPT_FS|OPT_MOUNT|OPT_DEVICE, \
269 BCH2_NO_SB_OPT, true, \
270 NULL, "Enable discard/TRIM support") \
272 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
274 BCH2_NO_SB_OPT, false, \
275 NULL, "Extra debugging information during mount/recovery")\
276 x(journal_flush_delay, u32, \
277 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
278 OPT_UINT(1, U32_MAX), \
279 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \
280 NULL, "Delay in milliseconds before automatic journal commits")\
281 x(journal_flush_disabled, u8, \
282 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
284 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \
285 NULL, "Disable journal flush on sync/fsync\n" \
286 "If enabled, writes can be lost, but only since the\n"\
287 "last journal write (default 1 second)") \
288 x(journal_reclaim_delay, u32, \
289 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
290 OPT_UINT(0, U32_MAX), \
291 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \
292 NULL, "Delay in milliseconds before automatic journal reclaim")\
293 x(move_bytes_in_flight, u32, \
294 OPT_HUMAN_READABLE|OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
295 OPT_UINT(1024, U32_MAX), \
296 BCH2_NO_SB_OPT, 1U << 20, \
297 NULL, "Maximum Amount of IO to keep in flight by the move path")\
298 x(move_ios_in_flight, u32, \
299 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
301 BCH2_NO_SB_OPT, 32, \
302 NULL, "Maximum number of IOs to keep in flight by the move path")\
306 BCH2_NO_SB_OPT, false, \
307 NULL, "Run fsck on mount") \
311 BCH2_NO_SB_OPT, false, \
312 NULL, "Fix errors during fsck without asking") \
313 x(ratelimit_errors, u8, \
316 BCH2_NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \
317 NULL, "Ratelimit error messages during fsck") \
321 BCH2_NO_SB_OPT, false, \
322 NULL, "Super read only mode - no writes at all will be issued,\n"\
323 "even if we have to replay the journal") \
327 BCH2_NO_SB_OPT, false, \
328 NULL, "Don't replay the journal") \
329 x(keep_journal, u8, \
332 BCH2_NO_SB_OPT, false, \
333 NULL, "Don't free journal entries/keys after startup")\
334 x(read_entire_journal, u8, \
337 BCH2_NO_SB_OPT, false, \
338 NULL, "Read all journal entries, not just dirty ones")\
339 x(read_journal_only, u8, \
342 BCH2_NO_SB_OPT, false, \
343 NULL, "Only read the journal, skip the rest of recovery")\
344 x(journal_transaction_names, u8, \
345 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
347 BCH_SB_JOURNAL_TRANSACTION_NAMES, true, \
348 NULL, "Log transaction function names in journal") \
352 BCH2_NO_SB_OPT, false, \
353 NULL, "Don't open device in exclusive mode") \
357 BCH2_NO_SB_OPT, true, \
358 NULL, "Use O_DIRECT (userspace only)") \
361 OPT_UINT(0, S64_MAX), \
362 BCH2_NO_SB_OPT, BCH_SB_SECTOR, \
363 "offset", "Sector offset of superblock") \
367 BCH2_NO_SB_OPT, false, \
372 BCH2_NO_SB_OPT, false, \
373 NULL, "Don\'t start filesystem, only open devices") \
374 x(reconstruct_alloc, u8, \
377 BCH2_NO_SB_OPT, false, \
378 NULL, "Reconstruct alloc btree") \
379 x(version_upgrade, u8, \
382 BCH2_NO_SB_OPT, false, \
383 NULL, "Set superblock to latest version,\n" \
384 "allowing any new features to be used") \
385 x(buckets_nouse, u8, \
388 BCH2_NO_SB_OPT, false, \
389 NULL, "Allocate the buckets_nouse bitmap") \
393 BCH2_NO_SB_OPT, false, \
396 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
398 BCH_SB_NOCOW, false, \
399 NULL, "Nocow mode: Writes will be done in place when possible.\n"\
400 "Snapshots and reflink will still caused writes to be COW\n"\
401 "Implicitly disables data checksumming, compression and encryption")\
404 OPT_UINT(0, S64_MAX), \
406 "size", "Size of filesystem on device") \
409 OPT_UINT(0, S64_MAX), \
411 "size", "Size of filesystem on device") \
414 OPT_UINT(0, BCH_REPLICAS_MAX), \
416 "n", "Data written to this device will be considered\n"\
417 "to have already been replicated n times")
420 #define x(_name, _bits, ...) unsigned _name##_defined:1;
424 #define x(_name, _bits, ...) _bits _name;
429 static const struct bch_opts bch2_opts_default = {
430 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
431 ._name##_defined = true, \
438 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
440 #define opt_get(_opts, _name) \
441 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
443 #define opt_set(_opts, _name, _v) \
445 (_opts)._name##_defined = true; \
446 (_opts)._name = _v; \
449 static inline struct bch_opts bch2_opts_empty(void)
451 return (struct bch_opts) { 0 };
454 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
457 #define x(_name, ...) Opt_##_name,
467 struct attribute attr;
468 u64 (*get_sb)(const struct bch_sb *);
469 void (*set_sb)(struct bch_sb *, u64);
471 enum opt_flags flags;
474 const char * const *choices;
475 int (*parse)(struct bch_fs *, const char *, u64 *);
476 void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
483 extern const struct bch_option bch2_opt_table[];
485 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
486 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
487 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
489 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id);
490 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
491 void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64);
492 void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64);
494 int bch2_opt_lookup(const char *);
495 int bch2_opt_validate(const struct bch_option *, u64, struct printbuf *);
496 int bch2_opt_parse(struct bch_fs *, const struct bch_option *,
497 const char *, u64 *, struct printbuf *);
499 #define OPT_SHOW_FULL_LIST (1 << 0)
500 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
502 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
503 const struct bch_option *, u64, unsigned);
505 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
506 int bch2_opts_check_may_set(struct bch_fs *);
507 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
512 #define x(_name, _bits) u##_bits _name;
517 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
518 bool bch2_opt_is_inode_opt(enum bch_opt_id);
520 #endif /* _BCACHEFS_OPTS_H */