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_FORMAT = (1 << 0),
50 OPT_RUNTIME = (1 << 2),
52 OPT_DEVICE = (1 << 4),
64 * x(name, shortopt, type, in mem type, mode, sb_opt)
66 * @name - name of mount option, sysfs attribute, and struct bch_opts
69 * @mode - when opt may be set
71 * @sb_option - name of corresponding superblock option
73 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
83 #define RATELIMIT_ERRORS true
85 #define RATELIMIT_ERRORS false
91 OPT_SECTORS(1, 128), \
92 BCH_SB_BLOCK_SIZE, 8, \
94 x(btree_node_size, u16, \
96 OPT_SECTORS(1, 512), \
97 BCH_SB_BTREE_NODE_SIZE, 512, \
98 "size", "Btree node size, default 256k") \
100 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
101 OPT_STR(bch2_error_actions), \
102 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \
103 NULL, "Action to take on filesystem error") \
104 x(metadata_replicas, u8, \
105 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
106 OPT_UINT(1, BCH_REPLICAS_MAX), \
107 BCH_SB_META_REPLICAS_WANT, 1, \
108 "#", "Number of metadata replicas") \
109 x(data_replicas, u8, \
110 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
111 OPT_UINT(1, BCH_REPLICAS_MAX), \
112 BCH_SB_DATA_REPLICAS_WANT, 1, \
113 "#", "Number of data replicas") \
114 x(metadata_replicas_required, u8, \
115 OPT_FORMAT|OPT_MOUNT, \
116 OPT_UINT(1, BCH_REPLICAS_MAX), \
117 BCH_SB_META_REPLICAS_REQ, 1, \
119 x(data_replicas_required, u8, \
120 OPT_FORMAT|OPT_MOUNT, \
121 OPT_UINT(1, BCH_REPLICAS_MAX), \
122 BCH_SB_DATA_REPLICAS_REQ, 1, \
124 x(metadata_checksum, u8, \
125 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
126 OPT_STR(bch2_csum_opts), \
127 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
129 x(data_checksum, u8, \
130 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
131 OPT_STR(bch2_csum_opts), \
132 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
135 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
136 OPT_STR(bch2_compression_opts), \
137 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
139 x(background_compression, u8, \
140 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
141 OPT_STR(bch2_compression_opts), \
142 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
145 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
146 OPT_STR(bch2_str_hash_opts), \
147 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
148 NULL, "Hash function for directory entries and xattrs")\
149 x(metadata_target, u16, \
150 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
151 OPT_FN(bch2_opt_target), \
152 BCH_SB_METADATA_TARGET, 0, \
153 "(target)", "Device or disk group for metadata writes") \
154 x(foreground_target, u16, \
155 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
156 OPT_FN(bch2_opt_target), \
157 BCH_SB_FOREGROUND_TARGET, 0, \
158 "(target)", "Device or disk group for foreground writes") \
159 x(background_target, u16, \
160 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
161 OPT_FN(bch2_opt_target), \
162 BCH_SB_BACKGROUND_TARGET, 0, \
163 "(target)", "Device or disk group to move data to in the background")\
164 x(promote_target, u16, \
165 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
166 OPT_FN(bch2_opt_target), \
167 BCH_SB_PROMOTE_TARGET, 0, \
168 "(target)", "Device or disk group to promote data to on read")\
169 x(erasure_code, u16, \
170 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
172 BCH_SB_ERASURE_CODE, false, \
173 NULL, "Enable erasure coding (DO NOT USE YET)") \
174 x(inodes_32bit, u8, \
175 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
177 BCH_SB_INODE_32BIT, true, \
178 NULL, "Constrain inode numbers to 32 bits") \
179 x(shard_inode_numbers, u8, \
180 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
182 BCH_SB_SHARD_INUMS, true, \
183 NULL, "Shard new inode numbers by CPU id") \
184 x(inodes_use_key_cache, u8, \
185 OPT_FORMAT|OPT_MOUNT, \
187 BCH_SB_INODES_USE_KEY_CACHE, true, \
188 NULL, "Use the btree key cache for the inodes btree") \
189 x(btree_node_mem_ptr_optimization, u8, \
190 OPT_MOUNT|OPT_RUNTIME, \
193 NULL, "Stash pointer to in memory btree node in btree ptr")\
194 x(gc_reserve_percent, u8, \
195 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
197 BCH_SB_GC_RESERVE, 8, \
198 "%", "Percentage of disk space to reserve for copygc")\
199 x(gc_reserve_bytes, u64, \
200 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
201 OPT_SECTORS(0, U64_MAX), \
202 BCH_SB_GC_RESERVE_BYTES, 0, \
203 "%", "Amount of disk space to reserve for copygc\n" \
204 "Takes precedence over gc_reserve_percent if set")\
205 x(root_reserve_percent, u8, \
206 OPT_FORMAT|OPT_MOUNT, \
208 BCH_SB_ROOT_RESERVE, 0, \
209 "%", "Percentage of disk space to reserve for superuser")\
211 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
213 BCH_SB_128_BIT_MACS, false, \
214 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
216 OPT_MOUNT|OPT_RUNTIME, \
219 NULL, "Enable inline data extents") \
221 OPT_FORMAT|OPT_MOUNT, \
223 BCH_SB_POSIX_ACL, true, \
224 NULL, "Enable POSIX acls") \
226 OPT_FORMAT|OPT_MOUNT, \
228 BCH_SB_USRQUOTA, false, \
229 NULL, "Enable user quotas") \
231 OPT_FORMAT|OPT_MOUNT, \
233 BCH_SB_GRPQUOTA, false, \
234 NULL, "Enable group quotas") \
236 OPT_FORMAT|OPT_MOUNT, \
238 BCH_SB_PRJQUOTA, false, \
239 NULL, "Enable project quotas") \
244 NULL, "Allow mounting in degraded mode") \
245 x(very_degraded, u8, \
249 NULL, "Allow mounting in when data will be missing") \
251 OPT_MOUNT|OPT_DEVICE, \
254 NULL, "Enable discard/TRIM support") \
259 NULL, "Extra debugging information during mount/recovery")\
260 x(journal_flush_disabled, u8, \
261 OPT_MOUNT|OPT_RUNTIME, \
264 NULL, "Disable journal flush on sync/fsync\n" \
265 "If enabled, writes can be lost, but only since the\n"\
266 "last journal write (default 1 second)") \
271 NULL, "Run fsck on mount") \
276 NULL, "Fix errors during fsck without asking") \
277 x(ratelimit_errors, u8, \
280 NO_SB_OPT, RATELIMIT_ERRORS, \
281 NULL, "Ratelimit error messages during fsck") \
286 NULL, "Super read only mode - no writes at all will be issued,\n"\
287 "even if we have to replay the journal") \
292 NULL, "Don't replay the journal") \
293 x(rebuild_replicas, u8, \
297 NULL, "Rebuild the superblock replicas section") \
298 x(keep_journal, u8, \
302 NULL, "Don't free journal entries/keys after startup")\
303 x(read_entire_journal, u8, \
307 NULL, "Read all journal entries, not just dirty ones")\
312 NULL, "Don't open device in exclusive mode") \
315 OPT_UINT(0, S64_MAX), \
316 NO_SB_OPT, BCH_SB_SECTOR, \
317 "offset", "Sector offset of superblock") \
327 NULL, "Don\'t start filesystem, only open devices") \
328 x(reconstruct_alloc, u8, \
332 NULL, "Reconstruct alloc btree") \
333 x(version_upgrade, u8, \
337 NULL, "Set superblock to latest version,\n" \
338 "allowing any new features to be used") \
346 OPT_SECTORS(0, S64_MAX), \
348 "size", "Size of filesystem on device") \
351 OPT_SECTORS(0, S64_MAX), \
353 "size", "Size of filesystem on device") \
356 OPT_UINT(0, BCH_REPLICAS_MAX), \
358 "n", "Data written to this device will be considered\n"\
359 "to have already been replicated n times")
362 #define x(_name, _bits, ...) unsigned _name##_defined:1;
366 #define x(_name, _bits, ...) _bits _name;
371 static const struct bch_opts bch2_opts_default = {
372 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
373 ._name##_defined = true, \
380 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
382 #define opt_get(_opts, _name) \
383 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
385 #define opt_set(_opts, _name, _v) \
387 (_opts)._name##_defined = true; \
388 (_opts)._name = _v; \
391 static inline struct bch_opts bch2_opts_empty(void)
393 return (struct bch_opts) { 0 };
396 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
399 #define x(_name, ...) Opt_##_name,
409 struct attribute attr;
410 void (*set_sb)(struct bch_sb *, u64);
419 const char * const *choices;
422 int (*parse)(struct bch_fs *, const char *, u64 *);
423 void (*to_text)(struct printbuf *, struct bch_fs *, u64);
432 extern const struct bch_option bch2_opt_table[];
434 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
435 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
436 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
438 struct bch_opts bch2_opts_from_sb(struct bch_sb *);
440 int bch2_opt_lookup(const char *);
441 int bch2_opt_parse(struct bch_fs *, const struct bch_option *, const char *, u64 *);
443 #define OPT_SHOW_FULL_LIST (1 << 0)
444 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
446 void bch2_opt_to_text(struct printbuf *, struct bch_fs *,
447 const struct bch_option *, u64, unsigned);
449 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
450 int bch2_opts_check_may_set(struct bch_fs *);
451 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
456 #define x(_name, _bits) unsigned _name##_defined:1;
460 #define x(_name, _bits) u##_bits _name;
465 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
466 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
467 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
468 bool bch2_opt_is_inode_opt(enum bch_opt_id);
470 #endif /* _BCACHEFS_OPTS_H */