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_opts[];
16 extern const char * const bch2_compression_opts[];
17 extern const char * const bch2_str_hash_types[];
18 extern const char * const bch2_data_types[];
19 extern const char * const bch2_cache_replacement_policies[];
20 extern const char * const bch2_member_states[];
21 extern const char * const bch2_d_types[];
24 * Mount options; we also store defaults in the superblock.
26 * Also exposed via sysfs: if an option is writeable, and it's also stored in
27 * the superblock, changing it via sysfs (currently? might change this) also
28 * updates the superblock.
30 * We store options as signed integers, where -1 means undefined. This means we
31 * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only
32 * apply the options from that struct that are defined.
35 /* dummy option, for options that aren't stored in the superblock */
36 LE64_BITMASK(NO_SB_OPT, struct bch_sb, flags[0], 0, 0);
38 /* When can be set: */
40 OPT_FORMAT = (1 << 0),
42 OPT_RUNTIME = (1 << 2),
44 OPT_DEVICE = (1 << 4),
56 * x(name, shortopt, type, in mem type, mode, sb_opt)
58 * @name - name of mount option, sysfs attribute, and struct bch_opts
61 * @mode - when opt may be set
63 * @sb_option - name of corresponding superblock option
65 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
75 #define RATELIMIT_ERRORS true
77 #define RATELIMIT_ERRORS false
83 OPT_SECTORS(1, 128), \
84 BCH_SB_BLOCK_SIZE, 8, \
86 x(btree_node_size, u16, \
88 OPT_SECTORS(1, 512), \
89 BCH_SB_BTREE_NODE_SIZE, 512, \
90 "size", "Btree node size, default 256k") \
92 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
93 OPT_STR(bch2_error_actions), \
94 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \
95 NULL, "Action to take on filesystem error") \
96 x(metadata_replicas, u8, \
97 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
98 OPT_UINT(1, BCH_REPLICAS_MAX), \
99 BCH_SB_META_REPLICAS_WANT, 1, \
100 "#", "Number of metadata replicas") \
101 x(data_replicas, u8, \
102 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
103 OPT_UINT(1, BCH_REPLICAS_MAX), \
104 BCH_SB_DATA_REPLICAS_WANT, 1, \
105 "#", "Number of data replicas") \
106 x(metadata_replicas_required, u8, \
107 OPT_FORMAT|OPT_MOUNT, \
108 OPT_UINT(1, BCH_REPLICAS_MAX), \
109 BCH_SB_META_REPLICAS_REQ, 1, \
111 x(data_replicas_required, u8, \
112 OPT_FORMAT|OPT_MOUNT, \
113 OPT_UINT(1, BCH_REPLICAS_MAX), \
114 BCH_SB_DATA_REPLICAS_REQ, 1, \
116 x(metadata_checksum, u8, \
117 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
118 OPT_STR(bch2_csum_opts), \
119 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
121 x(data_checksum, u8, \
122 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
123 OPT_STR(bch2_csum_opts), \
124 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
127 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
128 OPT_STR(bch2_compression_opts), \
129 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
131 x(background_compression, u8, \
132 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
133 OPT_STR(bch2_compression_opts), \
134 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
137 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
138 OPT_STR(bch2_str_hash_types), \
139 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
140 NULL, "Hash function for directory entries and xattrs")\
141 x(metadata_target, u16, \
142 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
143 OPT_FN(bch2_opt_target), \
144 BCH_SB_METADATA_TARGET, 0, \
145 "(target)", "Device or disk group for metadata writes") \
146 x(foreground_target, u16, \
147 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
148 OPT_FN(bch2_opt_target), \
149 BCH_SB_FOREGROUND_TARGET, 0, \
150 "(target)", "Device or disk group for foreground writes") \
151 x(background_target, u16, \
152 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
153 OPT_FN(bch2_opt_target), \
154 BCH_SB_BACKGROUND_TARGET, 0, \
155 "(target)", "Device or disk group to move data to in the background")\
156 x(promote_target, u16, \
157 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
158 OPT_FN(bch2_opt_target), \
159 BCH_SB_PROMOTE_TARGET, 0, \
160 "(target)", "Device or disk group to promote data to on read")\
161 x(erasure_code, u16, \
162 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
164 BCH_SB_ERASURE_CODE, false, \
165 NULL, "Enable erasure coding (DO NOT USE YET)") \
166 x(inodes_32bit, u8, \
167 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
169 BCH_SB_INODE_32BIT, true, \
170 NULL, "Constrain inode numbers to 32 bits") \
171 x(shard_inode_numbers, u8, \
172 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
174 BCH_SB_SHARD_INUMS, true, \
175 NULL, "Shard new inode numbers by CPU id") \
176 x(inodes_use_key_cache, u8, \
177 OPT_FORMAT|OPT_MOUNT, \
179 BCH_SB_INODES_USE_KEY_CACHE, true, \
180 NULL, "Use the btree key cache for the inodes btree") \
181 x(btree_node_mem_ptr_optimization, u8, \
182 OPT_MOUNT|OPT_RUNTIME, \
185 NULL, "Stash pointer to in memory btree node in btree ptr")\
186 x(gc_reserve_percent, u8, \
187 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
189 BCH_SB_GC_RESERVE, 8, \
190 "%", "Percentage of disk space to reserve for copygc")\
191 x(gc_reserve_bytes, u64, \
192 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
193 OPT_SECTORS(0, U64_MAX), \
194 BCH_SB_GC_RESERVE_BYTES, 0, \
195 "%", "Amount of disk space to reserve for copygc\n" \
196 "Takes precedence over gc_reserve_percent if set")\
197 x(root_reserve_percent, u8, \
198 OPT_FORMAT|OPT_MOUNT, \
200 BCH_SB_ROOT_RESERVE, 0, \
201 "%", "Percentage of disk space to reserve for superuser")\
203 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
205 BCH_SB_128_BIT_MACS, false, \
206 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
208 OPT_MOUNT|OPT_RUNTIME, \
211 NULL, "Enable inline data extents") \
213 OPT_FORMAT|OPT_MOUNT, \
215 BCH_SB_POSIX_ACL, true, \
216 NULL, "Enable POSIX acls") \
218 OPT_FORMAT|OPT_MOUNT, \
220 BCH_SB_USRQUOTA, false, \
221 NULL, "Enable user quotas") \
223 OPT_FORMAT|OPT_MOUNT, \
225 BCH_SB_GRPQUOTA, false, \
226 NULL, "Enable group quotas") \
228 OPT_FORMAT|OPT_MOUNT, \
230 BCH_SB_PRJQUOTA, false, \
231 NULL, "Enable project quotas") \
236 NULL, "Allow mounting in degraded mode") \
237 x(very_degraded, u8, \
241 NULL, "Allow mounting in when data will be missing") \
243 OPT_MOUNT|OPT_DEVICE, \
246 NULL, "Enable discard/TRIM support") \
251 NULL, "Extra debugging information during mount/recovery")\
252 x(journal_flush_disabled, u8, \
253 OPT_MOUNT|OPT_RUNTIME, \
256 NULL, "Disable journal flush on sync/fsync\n" \
257 "If enabled, writes can be lost, but only since the\n"\
258 "last journal write (default 1 second)") \
263 NULL, "Run fsck on mount") \
268 NULL, "Fix errors during fsck without asking") \
269 x(ratelimit_errors, u8, \
272 NO_SB_OPT, RATELIMIT_ERRORS, \
273 NULL, "Ratelimit error messages during fsck") \
278 NULL, "Super read only mode - no writes at all will be issued,\n"\
279 "even if we have to replay the journal") \
284 NULL, "Don't replay the journal") \
285 x(rebuild_replicas, u8, \
289 NULL, "Rebuild the superblock replicas section") \
290 x(keep_journal, u8, \
294 NULL, "Don't free journal entries/keys after startup")\
295 x(read_entire_journal, u8, \
299 NULL, "Read all journal entries, not just dirty ones")\
304 NULL, "Don't open device in exclusive mode") \
307 OPT_UINT(0, S64_MAX), \
308 NO_SB_OPT, BCH_SB_SECTOR, \
309 "offset", "Sector offset of superblock") \
319 NULL, "Don\'t start filesystem, only open devices") \
320 x(reconstruct_alloc, u8, \
324 NULL, "Reconstruct alloc btree") \
325 x(version_upgrade, u8, \
329 NULL, "Set superblock to latest version,\n" \
330 "allowing any new features to be used") \
338 OPT_SECTORS(0, S64_MAX), \
340 "size", "Size of filesystem on device") \
343 OPT_SECTORS(0, S64_MAX), \
345 "size", "Size of filesystem on device") \
348 OPT_UINT(0, BCH_REPLICAS_MAX), \
350 "n", "Data written to this device will be considered\n"\
351 "to have already been replicated n times")
354 #define x(_name, _bits, ...) unsigned _name##_defined:1;
358 #define x(_name, _bits, ...) _bits _name;
363 static const struct bch_opts bch2_opts_default = {
364 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
365 ._name##_defined = true, \
372 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
374 #define opt_get(_opts, _name) \
375 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
377 #define opt_set(_opts, _name, _v) \
379 (_opts)._name##_defined = true; \
380 (_opts)._name = _v; \
383 static inline struct bch_opts bch2_opts_empty(void)
385 return (struct bch_opts) { 0 };
388 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
391 #define x(_name, ...) Opt_##_name,
401 struct attribute attr;
402 void (*set_sb)(struct bch_sb *, u64);
411 const char * const *choices;
414 int (*parse)(struct bch_fs *, const char *, u64 *);
415 void (*to_text)(struct printbuf *, struct bch_fs *, u64);
424 extern const struct bch_option bch2_opt_table[];
426 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
427 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
428 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
430 struct bch_opts bch2_opts_from_sb(struct bch_sb *);
432 int bch2_opt_lookup(const char *);
433 int bch2_opt_parse(struct bch_fs *, const struct bch_option *, const char *, u64 *);
435 #define OPT_SHOW_FULL_LIST (1 << 0)
436 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
438 void bch2_opt_to_text(struct printbuf *, struct bch_fs *,
439 const struct bch_option *, u64, unsigned);
441 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
442 int bch2_opts_check_may_set(struct bch_fs *);
443 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
448 #define x(_name, _bits) unsigned _name##_defined:1;
452 #define x(_name, _bits) u##_bits _name;
457 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
458 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
459 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
460 bool bch2_opt_is_inode_opt(enum bch_opt_id);
462 #endif /* _BCACHEFS_OPTS_H */