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
97 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
98 OPT_UINT(512, 1U << 16), \
99 BCH_SB_BLOCK_SIZE, 8, \
101 x(btree_node_size, u32, \
103 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
104 OPT_UINT(512, 1U << 20), \
105 BCH_SB_BTREE_NODE_SIZE, 512, \
106 "size", "Btree node size, default 256k") \
108 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
109 OPT_STR(bch2_error_actions), \
110 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \
111 NULL, "Action to take on filesystem error") \
112 x(metadata_replicas, u8, \
113 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
114 OPT_UINT(1, BCH_REPLICAS_MAX), \
115 BCH_SB_META_REPLICAS_WANT, 1, \
116 "#", "Number of metadata replicas") \
117 x(data_replicas, u8, \
118 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
119 OPT_UINT(1, BCH_REPLICAS_MAX), \
120 BCH_SB_DATA_REPLICAS_WANT, 1, \
121 "#", "Number of data replicas") \
122 x(metadata_replicas_required, u8, \
123 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
124 OPT_UINT(1, BCH_REPLICAS_MAX), \
125 BCH_SB_META_REPLICAS_REQ, 1, \
127 x(data_replicas_required, u8, \
128 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
129 OPT_UINT(1, BCH_REPLICAS_MAX), \
130 BCH_SB_DATA_REPLICAS_REQ, 1, \
132 x(encoded_extent_max, u32, \
134 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\
135 OPT_UINT(4096, 2U << 20), \
136 BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10, \
137 "size", "Maximum size of checksummed/compressed extents")\
138 x(metadata_checksum, u8, \
139 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
140 OPT_STR(bch2_csum_opts), \
141 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
143 x(data_checksum, u8, \
144 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
145 OPT_STR(bch2_csum_opts), \
146 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
149 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
150 OPT_STR(bch2_compression_opts), \
151 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
153 x(background_compression, u8, \
154 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
155 OPT_STR(bch2_compression_opts), \
156 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
159 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
160 OPT_STR(bch2_str_hash_opts), \
161 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
162 NULL, "Hash function for directory entries and xattrs")\
163 x(metadata_target, u16, \
164 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
165 OPT_FN(bch2_opt_target), \
166 BCH_SB_METADATA_TARGET, 0, \
167 "(target)", "Device or disk group for metadata writes") \
168 x(foreground_target, u16, \
169 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
170 OPT_FN(bch2_opt_target), \
171 BCH_SB_FOREGROUND_TARGET, 0, \
172 "(target)", "Device or disk group for foreground writes") \
173 x(background_target, u16, \
174 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
175 OPT_FN(bch2_opt_target), \
176 BCH_SB_BACKGROUND_TARGET, 0, \
177 "(target)", "Device or disk group to move data to in the background")\
178 x(promote_target, u16, \
179 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
180 OPT_FN(bch2_opt_target), \
181 BCH_SB_PROMOTE_TARGET, 0, \
182 "(target)", "Device or disk group to promote data to on read")\
183 x(erasure_code, u16, \
184 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
186 BCH_SB_ERASURE_CODE, false, \
187 NULL, "Enable erasure coding (DO NOT USE YET)") \
188 x(inodes_32bit, u8, \
189 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
191 BCH_SB_INODE_32BIT, true, \
192 NULL, "Constrain inode numbers to 32 bits") \
193 x(shard_inode_numbers, u8, \
194 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
196 BCH_SB_SHARD_INUMS, true, \
197 NULL, "Shard new inode numbers by CPU id") \
198 x(inodes_use_key_cache, u8, \
199 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
201 BCH_SB_INODES_USE_KEY_CACHE, true, \
202 NULL, "Use the btree key cache for the inodes btree") \
203 x(btree_node_mem_ptr_optimization, u8, \
204 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
206 BCH2_NO_SB_OPT, true, \
207 NULL, "Stash pointer to in memory btree node in btree ptr")\
208 x(gc_reserve_percent, u8, \
209 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
211 BCH_SB_GC_RESERVE, 8, \
212 "%", "Percentage of disk space to reserve for copygc")\
213 x(gc_reserve_bytes, u64, \
214 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME| \
215 OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \
216 OPT_UINT(0, U64_MAX), \
217 BCH_SB_GC_RESERVE_BYTES, 0, \
218 "%", "Amount of disk space to reserve for copygc\n" \
219 "Takes precedence over gc_reserve_percent if set")\
220 x(root_reserve_percent, u8, \
221 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
223 BCH_SB_ROOT_RESERVE, 0, \
224 "%", "Percentage of disk space to reserve for superuser")\
226 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
228 BCH_SB_128_BIT_MACS, false, \
229 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
231 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
233 BCH2_NO_SB_OPT, true, \
234 NULL, "Enable inline data extents") \
236 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
238 BCH_SB_POSIX_ACL, true, \
239 NULL, "Enable POSIX acls") \
241 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
243 BCH_SB_USRQUOTA, false, \
244 NULL, "Enable user quotas") \
246 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
248 BCH_SB_GRPQUOTA, false, \
249 NULL, "Enable group quotas") \
251 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
253 BCH_SB_PRJQUOTA, false, \
254 NULL, "Enable project quotas") \
258 BCH2_NO_SB_OPT, false, \
259 NULL, "Allow mounting in degraded mode") \
260 x(very_degraded, u8, \
263 BCH2_NO_SB_OPT, false, \
264 NULL, "Allow mounting in when data will be missing") \
266 OPT_FS|OPT_MOUNT|OPT_DEVICE, \
268 BCH2_NO_SB_OPT, true, \
269 NULL, "Enable discard/TRIM support") \
273 BCH2_NO_SB_OPT, false, \
274 NULL, "Extra debugging information during mount/recovery")\
275 x(journal_flush_delay, u32, \
276 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
277 OPT_UINT(0, U32_MAX), \
278 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \
279 NULL, "Delay in milliseconds before automatic journal commits")\
280 x(journal_flush_disabled, u8, \
281 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
283 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \
284 NULL, "Disable journal flush on sync/fsync\n" \
285 "If enabled, writes can be lost, but only since the\n"\
286 "last journal write (default 1 second)") \
287 x(journal_reclaim_delay, u32, \
288 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
289 OPT_UINT(0, U32_MAX), \
290 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \
291 NULL, "Delay in milliseconds before automatic journal reclaim")\
295 BCH2_NO_SB_OPT, false, \
296 NULL, "Run fsck on mount") \
300 BCH2_NO_SB_OPT, false, \
301 NULL, "Fix errors during fsck without asking") \
302 x(ratelimit_errors, u8, \
305 BCH2_NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \
306 NULL, "Ratelimit error messages during fsck") \
310 BCH2_NO_SB_OPT, false, \
311 NULL, "Super read only mode - no writes at all will be issued,\n"\
312 "even if we have to replay the journal") \
316 BCH2_NO_SB_OPT, false, \
317 NULL, "Don't replay the journal") \
318 x(rebuild_replicas, u8, \
321 BCH2_NO_SB_OPT, false, \
322 NULL, "Rebuild the superblock replicas section") \
323 x(keep_journal, u8, \
326 BCH2_NO_SB_OPT, false, \
327 NULL, "Don't free journal entries/keys after startup")\
328 x(read_entire_journal, u8, \
331 BCH2_NO_SB_OPT, false, \
332 NULL, "Read all journal entries, not just dirty ones")\
333 x(read_journal_only, u8, \
336 BCH2_NO_SB_OPT, false, \
337 NULL, "Only read the journal, skip the rest of recovery")\
338 x(journal_transaction_names, u8, \
339 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
341 BCH_SB_JOURNAL_TRANSACTION_NAMES, true, \
342 NULL, "Log transaction function names in journal") \
346 BCH2_NO_SB_OPT, false, \
347 NULL, "Don't open device in exclusive mode") \
350 OPT_UINT(0, S64_MAX), \
351 BCH2_NO_SB_OPT, BCH_SB_SECTOR, \
352 "offset", "Sector offset of superblock") \
356 BCH2_NO_SB_OPT, false, \
361 BCH2_NO_SB_OPT, false, \
362 NULL, "Don\'t start filesystem, only open devices") \
363 x(reconstruct_alloc, u8, \
366 BCH2_NO_SB_OPT, false, \
367 NULL, "Reconstruct alloc btree") \
368 x(version_upgrade, u8, \
371 BCH2_NO_SB_OPT, false, \
372 NULL, "Set superblock to latest version,\n" \
373 "allowing any new features to be used") \
374 x(buckets_nouse, u8, \
377 BCH2_NO_SB_OPT, false, \
378 NULL, "Allocate the buckets_nouse bitmap") \
382 BCH2_NO_SB_OPT, false, \
386 OPT_UINT(0, S64_MAX), \
388 "size", "Size of filesystem on device") \
391 OPT_UINT(0, S64_MAX), \
393 "size", "Size of filesystem on device") \
396 OPT_UINT(0, BCH_REPLICAS_MAX), \
398 "n", "Data written to this device will be considered\n"\
399 "to have already been replicated n times")
402 #define x(_name, _bits, ...) unsigned _name##_defined:1;
406 #define x(_name, _bits, ...) _bits _name;
411 static const struct bch_opts bch2_opts_default = {
412 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
413 ._name##_defined = true, \
420 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
422 #define opt_get(_opts, _name) \
423 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
425 #define opt_set(_opts, _name, _v) \
427 (_opts)._name##_defined = true; \
428 (_opts)._name = _v; \
431 static inline struct bch_opts bch2_opts_empty(void)
433 return (struct bch_opts) { 0 };
436 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
439 #define x(_name, ...) Opt_##_name,
449 struct attribute attr;
450 u64 (*get_sb)(const struct bch_sb *);
451 void (*set_sb)(struct bch_sb *, u64);
453 enum opt_flags flags;
460 const char * const *choices;
463 int (*parse)(struct bch_fs *, const char *, u64 *);
464 void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
473 extern const struct bch_option bch2_opt_table[];
475 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
476 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
477 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
479 u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id);
480 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
481 void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64);
482 void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64);
484 int bch2_opt_lookup(const char *);
485 int bch2_opt_parse(struct bch_fs *, const char *, const struct bch_option *,
486 const char *, u64 *);
488 #define OPT_SHOW_FULL_LIST (1 << 0)
489 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
491 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
492 const struct bch_option *, u64, unsigned);
494 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
495 int bch2_opts_check_may_set(struct bch_fs *);
496 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
501 #define x(_name, _bits) unsigned _name##_defined:1;
505 #define x(_name, _bits) u##_bits _name;
510 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
511 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
512 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
513 bool bch2_opt_is_inode_opt(enum bch_opt_id);
515 #endif /* _BCACHEFS_OPTS_H */