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 LE64_BITMASK(NO_SB_OPT, struct bch_sb, flags[0], 0, 0);
47 /* When can be set: */
49 OPT_FS = (1 << 0), /* Filesystem option */
50 OPT_DEVICE = (1 << 1), /* Device option */
51 OPT_INODE = (1 << 2), /* Inode option */
52 OPT_FORMAT = (1 << 3), /* May be specified at format time */
53 OPT_MOUNT = (1 << 4), /* May be specified at mount time */
54 OPT_RUNTIME = (1 << 5), /* May be specified at runtime */
55 OPT_HUMAN_READABLE = (1 << 6),
56 OPT_MUST_BE_POW_2 = (1 << 7), /* Must be power of 2 */
57 OPT_SB_FIELD_SECTORS = (1 << 8),/* Superblock field is >> 9 of actual value */
58 OPT_SB_FIELD_ILOG2 = (1 << 9), /* Superblock field is ilog2 of actual value */
69 * x(name, shortopt, type, in mem type, mode, sb_opt)
71 * @name - name of mount option, sysfs attribute, and struct bch_opts
74 * @mode - when opt may be set
76 * @sb_option - name of corresponding superblock option
78 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
88 #define RATELIMIT_ERRORS_DEFAULT true
90 #define RATELIMIT_ERRORS_DEFAULT false
96 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
97 OPT_UINT(512, 1U << 16), \
98 BCH_SB_BLOCK_SIZE, 8, \
100 x(btree_node_size, u32, \
102 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS, \
103 OPT_UINT(512, 1U << 20), \
104 BCH_SB_BTREE_NODE_SIZE, 512, \
105 "size", "Btree node size, default 256k") \
107 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
108 OPT_STR(bch2_error_actions), \
109 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \
110 NULL, "Action to take on filesystem error") \
111 x(metadata_replicas, u8, \
112 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
113 OPT_UINT(1, BCH_REPLICAS_MAX), \
114 BCH_SB_META_REPLICAS_WANT, 1, \
115 "#", "Number of metadata replicas") \
116 x(data_replicas, u8, \
117 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
118 OPT_UINT(1, BCH_REPLICAS_MAX), \
119 BCH_SB_DATA_REPLICAS_WANT, 1, \
120 "#", "Number of data replicas") \
121 x(metadata_replicas_required, u8, \
122 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
123 OPT_UINT(1, BCH_REPLICAS_MAX), \
124 BCH_SB_META_REPLICAS_REQ, 1, \
126 x(data_replicas_required, u8, \
127 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
128 OPT_UINT(1, BCH_REPLICAS_MAX), \
129 BCH_SB_DATA_REPLICAS_REQ, 1, \
131 x(encoded_extent_max, u32, \
133 OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\
134 OPT_UINT(4096, 2U << 20), \
135 BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10, \
136 "size", "Maximum size of checksummed/compressed extents")\
137 x(metadata_checksum, u8, \
138 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
139 OPT_STR(bch2_csum_opts), \
140 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
142 x(data_checksum, u8, \
143 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
144 OPT_STR(bch2_csum_opts), \
145 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
148 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
149 OPT_STR(bch2_compression_opts), \
150 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
152 x(background_compression, u8, \
153 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
154 OPT_STR(bch2_compression_opts), \
155 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
158 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
159 OPT_STR(bch2_str_hash_opts), \
160 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
161 NULL, "Hash function for directory entries and xattrs")\
162 x(metadata_target, u16, \
163 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
164 OPT_FN(bch2_opt_target), \
165 BCH_SB_METADATA_TARGET, 0, \
166 "(target)", "Device or disk group for metadata writes") \
167 x(foreground_target, u16, \
168 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
169 OPT_FN(bch2_opt_target), \
170 BCH_SB_FOREGROUND_TARGET, 0, \
171 "(target)", "Device or disk group for foreground writes") \
172 x(background_target, u16, \
173 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
174 OPT_FN(bch2_opt_target), \
175 BCH_SB_BACKGROUND_TARGET, 0, \
176 "(target)", "Device or disk group to move data to in the background")\
177 x(promote_target, u16, \
178 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
179 OPT_FN(bch2_opt_target), \
180 BCH_SB_PROMOTE_TARGET, 0, \
181 "(target)", "Device or disk group to promote data to on read")\
182 x(erasure_code, u16, \
183 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
185 BCH_SB_ERASURE_CODE, false, \
186 NULL, "Enable erasure coding (DO NOT USE YET)") \
187 x(inodes_32bit, u8, \
188 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
190 BCH_SB_INODE_32BIT, true, \
191 NULL, "Constrain inode numbers to 32 bits") \
192 x(shard_inode_numbers, u8, \
193 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
195 BCH_SB_SHARD_INUMS, true, \
196 NULL, "Shard new inode numbers by CPU id") \
197 x(inodes_use_key_cache, u8, \
198 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
200 BCH_SB_INODES_USE_KEY_CACHE, true, \
201 NULL, "Use the btree key cache for the inodes btree") \
202 x(btree_node_mem_ptr_optimization, u8, \
203 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
206 NULL, "Stash pointer to in memory btree node in btree ptr")\
207 x(gc_reserve_percent, u8, \
208 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
210 BCH_SB_GC_RESERVE, 8, \
211 "%", "Percentage of disk space to reserve for copygc")\
212 x(gc_reserve_bytes, u64, \
213 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME| \
214 OPT_HUMAN_READABLE|OPT_SB_FIELD_SECTORS, \
215 OPT_UINT(0, U64_MAX), \
216 BCH_SB_GC_RESERVE_BYTES, 0, \
217 "%", "Amount of disk space to reserve for copygc\n" \
218 "Takes precedence over gc_reserve_percent if set")\
219 x(root_reserve_percent, u8, \
220 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
222 BCH_SB_ROOT_RESERVE, 0, \
223 "%", "Percentage of disk space to reserve for superuser")\
225 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
227 BCH_SB_128_BIT_MACS, false, \
228 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
230 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
233 NULL, "Enable inline data extents") \
235 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
237 BCH_SB_POSIX_ACL, true, \
238 NULL, "Enable POSIX acls") \
240 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
242 BCH_SB_USRQUOTA, false, \
243 NULL, "Enable user quotas") \
245 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
247 BCH_SB_GRPQUOTA, false, \
248 NULL, "Enable group quotas") \
250 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
252 BCH_SB_PRJQUOTA, false, \
253 NULL, "Enable project quotas") \
258 NULL, "Allow mounting in degraded mode") \
259 x(very_degraded, u8, \
263 NULL, "Allow mounting in when data will be missing") \
265 OPT_FS|OPT_MOUNT|OPT_DEVICE, \
268 NULL, "Enable discard/TRIM support") \
273 NULL, "Extra debugging information during mount/recovery")\
274 x(journal_flush_delay, u32, \
275 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
276 OPT_UINT(0, U32_MAX), \
277 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \
278 NULL, "Delay in milliseconds before automatic journal commits")\
279 x(journal_flush_disabled, u8, \
280 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
282 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \
283 NULL, "Disable journal flush on sync/fsync\n" \
284 "If enabled, writes can be lost, but only since the\n"\
285 "last journal write (default 1 second)") \
286 x(journal_reclaim_delay, u32, \
287 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
288 OPT_UINT(0, U32_MAX), \
289 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \
290 NULL, "Delay in milliseconds before automatic journal reclaim")\
295 NULL, "Run fsck on mount") \
300 NULL, "Fix errors during fsck without asking") \
301 x(ratelimit_errors, u8, \
304 NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \
305 NULL, "Ratelimit error messages during fsck") \
310 NULL, "Super read only mode - no writes at all will be issued,\n"\
311 "even if we have to replay the journal") \
316 NULL, "Don't replay the journal") \
317 x(rebuild_replicas, u8, \
321 NULL, "Rebuild the superblock replicas section") \
322 x(keep_journal, u8, \
326 NULL, "Don't free journal entries/keys after startup")\
327 x(read_entire_journal, u8, \
331 NULL, "Read all journal entries, not just dirty ones")\
332 x(journal_transaction_names, u8, \
333 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
335 BCH_SB_JOURNAL_TRANSACTION_NAMES, false, \
336 NULL, "Log transaction function names in journal") \
341 NULL, "Don't open device in exclusive mode") \
344 OPT_UINT(0, S64_MAX), \
345 NO_SB_OPT, BCH_SB_SECTOR, \
346 "offset", "Sector offset of superblock") \
356 NULL, "Don\'t start filesystem, only open devices") \
357 x(reconstruct_alloc, u8, \
361 NULL, "Reconstruct alloc btree") \
362 x(version_upgrade, u8, \
366 NULL, "Set superblock to latest version,\n" \
367 "allowing any new features to be used") \
375 OPT_UINT(0, S64_MAX), \
377 "size", "Size of filesystem on device") \
380 OPT_UINT(0, S64_MAX), \
382 "size", "Size of filesystem on device") \
385 OPT_UINT(0, BCH_REPLICAS_MAX), \
387 "n", "Data written to this device will be considered\n"\
388 "to have already been replicated n times")
391 #define x(_name, _bits, ...) unsigned _name##_defined:1;
395 #define x(_name, _bits, ...) _bits _name;
400 static const struct bch_opts bch2_opts_default = {
401 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
402 ._name##_defined = true, \
409 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
411 #define opt_get(_opts, _name) \
412 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
414 #define opt_set(_opts, _name, _v) \
416 (_opts)._name##_defined = true; \
417 (_opts)._name = _v; \
420 static inline struct bch_opts bch2_opts_empty(void)
422 return (struct bch_opts) { 0 };
425 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
428 #define x(_name, ...) Opt_##_name,
438 struct attribute attr;
439 u64 (*get_sb)(const struct bch_sb *);
440 void (*set_sb)(struct bch_sb *, u64);
442 enum opt_flags flags;
449 const char * const *choices;
452 int (*parse)(struct bch_fs *, const char *, u64 *);
453 void (*to_text)(struct printbuf *, struct bch_fs *, u64);
462 extern const struct bch_option bch2_opt_table[];
464 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
465 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
466 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
468 int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
469 void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64);
470 void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64);
472 int bch2_opt_lookup(const char *);
473 int bch2_opt_parse(struct bch_fs *, const char *, const struct bch_option *,
474 const char *, u64 *);
476 #define OPT_SHOW_FULL_LIST (1 << 0)
477 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
479 void bch2_opt_to_text(struct printbuf *, struct bch_fs *,
480 const struct bch_option *, u64, unsigned);
482 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
483 int bch2_opts_check_may_set(struct bch_fs *);
484 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
489 #define x(_name, _bits) unsigned _name##_defined:1;
493 #define x(_name, _bits) u##_bits _name;
498 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
499 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
500 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
501 bool bch2_opt_is_inode_opt(enum bch_opt_id);
503 #endif /* _BCACHEFS_OPTS_H */