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_csum_opts[];
14 extern const char * const bch2_compression_opts[];
15 extern const char * const bch2_str_hash_types[];
16 extern const char * const bch2_data_types[];
17 extern const char * const bch2_cache_replacement_policies[];
18 extern const char * const bch2_cache_modes[];
19 extern const char * const bch2_dev_state[];
22 * Mount options; we also store defaults in the superblock.
24 * Also exposed via sysfs: if an option is writeable, and it's also stored in
25 * the superblock, changing it via sysfs (currently? might change this) also
26 * updates the superblock.
28 * We store options as signed integers, where -1 means undefined. This means we
29 * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only
30 * apply the options from that struct that are defined.
33 /* dummy option, for options that aren't stored in the superblock */
34 LE64_BITMASK(NO_SB_OPT, struct bch_sb, flags[0], 0, 0);
36 /* When can be set: */
38 OPT_FORMAT = (1 << 0),
40 OPT_RUNTIME = (1 << 2),
42 OPT_DEVICE = (1 << 4),
54 * x(name, shortopt, type, in mem type, mode, sb_opt)
56 * @name - name of mount option, sysfs attribute, and struct bch_opts
59 * @mode - when opt may be set
61 * @sb_option - name of corresponding superblock option
63 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
73 #define RATELIMIT_ERRORS true
75 #define RATELIMIT_ERRORS false
81 OPT_SECTORS(1, 128), \
82 BCH_SB_BLOCK_SIZE, 8, \
84 x(btree_node_size, u16, \
86 OPT_SECTORS(1, 512), \
87 BCH_SB_BTREE_NODE_SIZE, 512, \
88 "size", "Btree node size, default 256k") \
90 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
91 OPT_STR(bch2_error_actions), \
92 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_RO, \
93 NULL, "Action to take on filesystem error") \
94 x(metadata_replicas, u8, \
95 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
96 OPT_UINT(1, BCH_REPLICAS_MAX), \
97 BCH_SB_META_REPLICAS_WANT, 1, \
98 "#", "Number of metadata replicas") \
99 x(data_replicas, u8, \
100 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
101 OPT_UINT(1, BCH_REPLICAS_MAX), \
102 BCH_SB_DATA_REPLICAS_WANT, 1, \
103 "#", "Number of data replicas") \
104 x(metadata_replicas_required, u8, \
105 OPT_FORMAT|OPT_MOUNT, \
106 OPT_UINT(1, BCH_REPLICAS_MAX), \
107 BCH_SB_META_REPLICAS_REQ, 1, \
109 x(data_replicas_required, u8, \
110 OPT_FORMAT|OPT_MOUNT, \
111 OPT_UINT(1, BCH_REPLICAS_MAX), \
112 BCH_SB_DATA_REPLICAS_REQ, 1, \
114 x(metadata_checksum, u8, \
115 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
116 OPT_STR(bch2_csum_opts), \
117 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \
119 x(data_checksum, u8, \
120 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
121 OPT_STR(bch2_csum_opts), \
122 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \
125 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
126 OPT_STR(bch2_compression_opts), \
127 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_none, \
129 x(background_compression, u8, \
130 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
131 OPT_STR(bch2_compression_opts), \
132 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_none, \
135 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
136 OPT_STR(bch2_str_hash_types), \
137 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_SIPHASH, \
138 NULL, "Hash function for directory entries and xattrs")\
139 x(metadata_target, u16, \
140 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
141 OPT_FN(bch2_opt_target), \
142 BCH_SB_METADATA_TARGET, 0, \
143 "(target)", "Device or disk group for metadata writes") \
144 x(foreground_target, u16, \
145 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
146 OPT_FN(bch2_opt_target), \
147 BCH_SB_FOREGROUND_TARGET, 0, \
148 "(target)", "Device or disk group for foreground writes") \
149 x(background_target, u16, \
150 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
151 OPT_FN(bch2_opt_target), \
152 BCH_SB_BACKGROUND_TARGET, 0, \
153 "(target)", "Device or disk group to move data to in the background")\
154 x(promote_target, u16, \
155 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
156 OPT_FN(bch2_opt_target), \
157 BCH_SB_PROMOTE_TARGET, 0, \
158 "(target)", "Device or disk group to promote data to on read")\
159 x(erasure_code, u16, \
160 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
162 BCH_SB_ERASURE_CODE, false, \
163 NULL, "Enable erasure coding (DO NOT USE YET)") \
164 x(inodes_32bit, u8, \
165 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
167 BCH_SB_INODE_32BIT, false, \
168 NULL, "Constrain inode numbers to 32 bits") \
169 x(gc_reserve_percent, u8, \
170 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
172 BCH_SB_GC_RESERVE, 8, \
173 "%", "Percentage of disk space to reserve for copygc")\
174 x(gc_reserve_bytes, u64, \
175 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
176 OPT_SECTORS(0, U64_MAX), \
177 BCH_SB_GC_RESERVE_BYTES, 0, \
178 "%", "Amount of disk space to reserve for copygc\n" \
179 "Takes precedence over gc_reserve_percent if set")\
180 x(root_reserve_percent, u8, \
181 OPT_FORMAT|OPT_MOUNT, \
183 BCH_SB_ROOT_RESERVE, 0, \
184 "%", "Percentage of disk space to reserve for superuser")\
186 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
188 BCH_SB_128_BIT_MACS, false, \
189 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
191 OPT_MOUNT|OPT_RUNTIME, \
194 NULL, "Enable inline data extents") \
196 OPT_FORMAT|OPT_MOUNT, \
198 BCH_SB_POSIX_ACL, true, \
199 NULL, "Enable POSIX acls") \
201 OPT_FORMAT|OPT_MOUNT, \
203 BCH_SB_USRQUOTA, false, \
204 NULL, "Enable user quotas") \
206 OPT_FORMAT|OPT_MOUNT, \
208 BCH_SB_GRPQUOTA, false, \
209 NULL, "Enable group quotas") \
211 OPT_FORMAT|OPT_MOUNT, \
213 BCH_SB_PRJQUOTA, false, \
214 NULL, "Enable project quotas") \
216 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
218 BCH_SB_REFLINK, true, \
219 NULL, "Enable reflink support") \
224 NULL, "Allow mounting in degraded mode") \
226 OPT_MOUNT|OPT_DEVICE, \
229 NULL, "Enable discard/TRIM support") \
234 NULL, "Extra debugging information during mount/recovery")\
235 x(journal_flush_disabled, u8, \
236 OPT_MOUNT|OPT_RUNTIME, \
239 NULL, "Disable journal flush on sync/fsync\n" \
240 "If enabled, writes can be lost, but only since the\n"\
241 "last journal write (default 1 second)") \
246 NULL, "Run fsck on mount") \
251 NULL, "Fix errors during fsck without asking") \
252 x(ratelimit_errors, u8, \
255 NO_SB_OPT, RATELIMIT_ERRORS, \
256 NULL, "Ratelimit error messages during fsck") \
261 NULL, "Super read only mode - no writes at all will be issued,\n"\
262 "even if we have to replay the journal") \
267 NULL, "Don't replay the journal") \
268 x(rebuild_replicas, u8, \
272 NULL, "Rebuild the superblock replicas section") \
273 x(keep_journal, u8, \
277 NULL, "Don't free journal entries/keys after startup")\
278 x(read_entire_journal, u8, \
282 NULL, "Read all journal entries, not just dirty ones")\
287 NULL, "Don't open device in exclusive mode") \
290 OPT_UINT(0, S64_MAX), \
291 NO_SB_OPT, BCH_SB_SECTOR, \
292 "offset", "Sector offset of superblock") \
302 NULL, "Don\'t start filesystem, only open devices") \
303 x(reconstruct_alloc, u8, \
307 NULL, "Reconstruct alloc btree") \
308 x(version_upgrade, u8, \
312 NULL, "Set superblock to latest version,\n" \
313 "allowing any new features to be used") \
321 OPT_SECTORS(0, S64_MAX), \
323 "size", "Size of filesystem on device") \
326 OPT_SECTORS(0, S64_MAX), \
328 "size", "Size of filesystem on device") \
331 OPT_UINT(0, BCH_REPLICAS_MAX), \
333 "n", "Data written to this device will be considered\n"\
334 "to have already been replicated n times")
337 #define x(_name, _bits, ...) unsigned _name##_defined:1;
341 #define x(_name, _bits, ...) _bits _name;
346 static const struct bch_opts bch2_opts_default = {
347 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
348 ._name##_defined = true, \
355 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
357 #define opt_get(_opts, _name) \
358 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
360 #define opt_set(_opts, _name, _v) \
362 (_opts)._name##_defined = true; \
363 (_opts)._name = _v; \
366 static inline struct bch_opts bch2_opts_empty(void)
368 return (struct bch_opts) { 0 };
371 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
374 #define x(_name, ...) Opt_##_name,
384 struct attribute attr;
385 void (*set_sb)(struct bch_sb *, u64);
394 const char * const *choices;
397 int (*parse)(struct bch_fs *, const char *, u64 *);
398 void (*to_text)(struct printbuf *, struct bch_fs *, u64);
407 extern const struct bch_option bch2_opt_table[];
409 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
410 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
411 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
413 struct bch_opts bch2_opts_from_sb(struct bch_sb *);
415 int bch2_opt_lookup(const char *);
416 int bch2_opt_parse(struct bch_fs *, const struct bch_option *, const char *, u64 *);
418 #define OPT_SHOW_FULL_LIST (1 << 0)
419 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
421 void bch2_opt_to_text(struct printbuf *, struct bch_fs *,
422 const struct bch_option *, u64, unsigned);
424 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
425 int bch2_opts_check_may_set(struct bch_fs *);
426 int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
431 #define x(_name, _bits) unsigned _name##_defined:1;
435 #define x(_name, _bits) u##_bits _name;
440 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
441 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
442 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
443 bool bch2_opt_is_inode_opt(enum bch_opt_id);
445 #endif /* _BCACHEFS_OPTS_H */