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_cache_replacement_policies[];
23 extern const char * const bch2_member_states[];
24 extern const char * const bch2_d_types[];
26 static inline const char *bch2_d_type_str(unsigned d_type)
28 return (d_type < BCH_DT_MAX ? bch2_d_types[d_type] : NULL) ?: "(bad d_type)";
32 * Mount options; we also store defaults in the superblock.
34 * Also exposed via sysfs: if an option is writeable, and it's also stored in
35 * the superblock, changing it via sysfs (currently? might change this) also
36 * updates the superblock.
38 * We store options as signed integers, where -1 means undefined. This means we
39 * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only
40 * apply the options from that struct that are defined.
43 /* dummy option, for options that aren't stored in the superblock */
44 LE64_BITMASK(NO_SB_OPT, struct bch_sb, flags[0], 0, 0);
46 /* When can be set: */
48 OPT_FS = (1 << 0), /* Filesystem option */
49 OPT_DEVICE = (1 << 1), /* Device option */
50 OPT_INODE = (1 << 2), /* Inode option */
51 OPT_FORMAT = (1 << 3), /* May be specified at format time */
52 OPT_MOUNT = (1 << 4), /* May be specified at mount time */
53 OPT_RUNTIME = (1 << 5), /* May be specified at runtime */
65 * x(name, shortopt, type, in mem type, mode, sb_opt)
67 * @name - name of mount option, sysfs attribute, and struct bch_opts
70 * @mode - when opt may be set
72 * @sb_option - name of corresponding superblock option
74 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
84 #define RATELIMIT_ERRORS true
86 #define RATELIMIT_ERRORS false
92 OPT_SECTORS(1, 128), \
93 BCH_SB_BLOCK_SIZE, 8, \
95 x(btree_node_size, u16, \
97 OPT_SECTORS(1, 512), \
98 BCH_SB_BTREE_NODE_SIZE, 512, \
99 "size", "Btree node size, default 256k") \
101 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
102 OPT_STR(bch2_error_actions), \
103 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \
104 NULL, "Action to take on filesystem error") \
105 x(metadata_replicas, u8, \
106 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
107 OPT_UINT(1, BCH_REPLICAS_MAX), \
108 BCH_SB_META_REPLICAS_WANT, 1, \
109 "#", "Number of metadata replicas") \
110 x(data_replicas, u8, \
111 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
112 OPT_UINT(1, BCH_REPLICAS_MAX), \
113 BCH_SB_DATA_REPLICAS_WANT, 1, \
114 "#", "Number of data replicas") \
115 x(metadata_replicas_required, u8, \
116 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
117 OPT_UINT(1, BCH_REPLICAS_MAX), \
118 BCH_SB_META_REPLICAS_REQ, 1, \
120 x(data_replicas_required, u8, \
121 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
122 OPT_UINT(1, BCH_REPLICAS_MAX), \
123 BCH_SB_DATA_REPLICAS_REQ, 1, \
125 x(metadata_checksum, u8, \
126 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
127 OPT_STR(bch2_csum_opts), \
128 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
130 x(data_checksum, u8, \
131 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
132 OPT_STR(bch2_csum_opts), \
133 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
136 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
137 OPT_STR(bch2_compression_opts), \
138 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
140 x(background_compression, u8, \
141 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
142 OPT_STR(bch2_compression_opts), \
143 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
146 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
147 OPT_STR(bch2_str_hash_opts), \
148 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
149 NULL, "Hash function for directory entries and xattrs")\
150 x(metadata_target, u16, \
151 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
152 OPT_FN(bch2_opt_target), \
153 BCH_SB_METADATA_TARGET, 0, \
154 "(target)", "Device or disk group for metadata writes") \
155 x(foreground_target, u16, \
156 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
157 OPT_FN(bch2_opt_target), \
158 BCH_SB_FOREGROUND_TARGET, 0, \
159 "(target)", "Device or disk group for foreground writes") \
160 x(background_target, u16, \
161 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
162 OPT_FN(bch2_opt_target), \
163 BCH_SB_BACKGROUND_TARGET, 0, \
164 "(target)", "Device or disk group to move data to in the background")\
165 x(promote_target, u16, \
166 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
167 OPT_FN(bch2_opt_target), \
168 BCH_SB_PROMOTE_TARGET, 0, \
169 "(target)", "Device or disk group to promote data to on read")\
170 x(erasure_code, u16, \
171 OPT_FS|OPT_INODE|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
173 BCH_SB_ERASURE_CODE, false, \
174 NULL, "Enable erasure coding (DO NOT USE YET)") \
175 x(inodes_32bit, u8, \
176 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
178 BCH_SB_INODE_32BIT, true, \
179 NULL, "Constrain inode numbers to 32 bits") \
180 x(shard_inode_numbers, u8, \
181 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
183 BCH_SB_SHARD_INUMS, true, \
184 NULL, "Shard new inode numbers by CPU id") \
185 x(inodes_use_key_cache, u8, \
186 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
188 BCH_SB_INODES_USE_KEY_CACHE, true, \
189 NULL, "Use the btree key cache for the inodes btree") \
190 x(btree_node_mem_ptr_optimization, u8, \
191 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
194 NULL, "Stash pointer to in memory btree node in btree ptr")\
195 x(gc_reserve_percent, u8, \
196 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
198 BCH_SB_GC_RESERVE, 8, \
199 "%", "Percentage of disk space to reserve for copygc")\
200 x(gc_reserve_bytes, u64, \
201 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
202 OPT_SECTORS(0, U64_MAX), \
203 BCH_SB_GC_RESERVE_BYTES, 0, \
204 "%", "Amount of disk space to reserve for copygc\n" \
205 "Takes precedence over gc_reserve_percent if set")\
206 x(root_reserve_percent, u8, \
207 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
209 BCH_SB_ROOT_RESERVE, 0, \
210 "%", "Percentage of disk space to reserve for superuser")\
212 OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
214 BCH_SB_128_BIT_MACS, false, \
215 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
217 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
220 NULL, "Enable inline data extents") \
222 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
224 BCH_SB_POSIX_ACL, true, \
225 NULL, "Enable POSIX acls") \
227 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
229 BCH_SB_USRQUOTA, false, \
230 NULL, "Enable user quotas") \
232 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
234 BCH_SB_GRPQUOTA, false, \
235 NULL, "Enable group quotas") \
237 OPT_FS|OPT_FORMAT|OPT_MOUNT, \
239 BCH_SB_PRJQUOTA, false, \
240 NULL, "Enable project quotas") \
245 NULL, "Allow mounting in degraded mode") \
246 x(very_degraded, u8, \
250 NULL, "Allow mounting in when data will be missing") \
252 OPT_FS|OPT_MOUNT|OPT_DEVICE, \
255 NULL, "Enable discard/TRIM support") \
260 NULL, "Extra debugging information during mount/recovery")\
261 x(journal_flush_delay, u32, \
262 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
263 OPT_UINT(0, U32_MAX), \
264 BCH_SB_JOURNAL_FLUSH_DELAY, 1000, \
265 NULL, "Delay in milliseconds before automatic journal commits")\
266 x(journal_flush_disabled, u8, \
267 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
269 BCH_SB_JOURNAL_FLUSH_DISABLED,false, \
270 NULL, "Disable journal flush on sync/fsync\n" \
271 "If enabled, writes can be lost, but only since the\n"\
272 "last journal write (default 1 second)") \
273 x(journal_reclaim_delay, u32, \
274 OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
275 OPT_UINT(0, U32_MAX), \
276 BCH_SB_JOURNAL_RECLAIM_DELAY, 100, \
277 NULL, "Delay in milliseconds before automatic journal reclaim")\
282 NULL, "Run fsck on mount") \
287 NULL, "Fix errors during fsck without asking") \
288 x(ratelimit_errors, u8, \
291 NO_SB_OPT, RATELIMIT_ERRORS, \
292 NULL, "Ratelimit error messages during fsck") \
297 NULL, "Super read only mode - no writes at all will be issued,\n"\
298 "even if we have to replay the journal") \
303 NULL, "Don't replay the journal") \
304 x(rebuild_replicas, u8, \
308 NULL, "Rebuild the superblock replicas section") \
309 x(keep_journal, u8, \
313 NULL, "Don't free journal entries/keys after startup")\
314 x(read_entire_journal, u8, \
318 NULL, "Read all journal entries, not just dirty ones")\
323 NULL, "Don't open device in exclusive mode") \
326 OPT_UINT(0, S64_MAX), \
327 NO_SB_OPT, BCH_SB_SECTOR, \
328 "offset", "Sector offset of superblock") \
338 NULL, "Don\'t start filesystem, only open devices") \
339 x(reconstruct_alloc, u8, \
343 NULL, "Reconstruct alloc btree") \
344 x(version_upgrade, u8, \
348 NULL, "Set superblock to latest version,\n" \
349 "allowing any new features to be used") \
357 OPT_SECTORS(0, S64_MAX), \
359 "size", "Size of filesystem on device") \
362 OPT_SECTORS(0, S64_MAX), \
364 "size", "Size of filesystem on device") \
367 OPT_UINT(0, BCH_REPLICAS_MAX), \
369 "n", "Data written to this device will be considered\n"\
370 "to have already been replicated n times")
373 #define x(_name, _bits, ...) unsigned _name##_defined:1;
377 #define x(_name, _bits, ...) _bits _name;
382 static const struct bch_opts bch2_opts_default = {
383 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
384 ._name##_defined = true, \
391 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
393 #define opt_get(_opts, _name) \
394 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
396 #define opt_set(_opts, _name, _v) \
398 (_opts)._name##_defined = true; \
399 (_opts)._name = _v; \
402 static inline struct bch_opts bch2_opts_empty(void)
404 return (struct bch_opts) { 0 };
407 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
410 #define x(_name, ...) Opt_##_name,
420 struct attribute attr;
421 void (*set_sb)(struct bch_sb *, u64);
430 const char * const *choices;
433 int (*parse)(struct bch_fs *, const char *, u64 *);
434 void (*to_text)(struct printbuf *, struct bch_fs *, u64);
443 extern const struct bch_option bch2_opt_table[];
445 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
446 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
447 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
449 struct bch_opts bch2_opts_from_sb(struct bch_sb *);
451 int bch2_opt_lookup(const char *);
452 int bch2_opt_parse(struct bch_fs *, const struct bch_option *, const char *, u64 *);
454 #define OPT_SHOW_FULL_LIST (1 << 0)
455 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
457 void bch2_opt_to_text(struct printbuf *, struct bch_fs *,
458 const struct bch_option *, u64, unsigned);
460 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
461 int bch2_opts_check_may_set(struct bch_fs *);
462 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
467 #define x(_name, _bits) unsigned _name##_defined:1;
471 #define x(_name, _bits) u##_bits _name;
476 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
477 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
478 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
479 bool bch2_opt_is_inode_opt(enum bch_opt_id);
481 #endif /* _BCACHEFS_OPTS_H */