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_csum_types[];
13 extern const char * const bch2_compression_types[];
14 extern const char * const bch2_str_hash_types[];
15 extern const char * const bch2_data_types[];
16 extern const char * const bch2_cache_replacement_policies[];
17 extern const char * const bch2_cache_modes[];
18 extern const char * const bch2_dev_state[];
21 * Mount options; we also store defaults in the superblock.
23 * Also exposed via sysfs: if an option is writeable, and it's also stored in
24 * the superblock, changing it via sysfs (currently? might change this) also
25 * updates the superblock.
27 * We store options as signed integers, where -1 means undefined. This means we
28 * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only
29 * apply the options from that struct that are defined.
32 /* dummy option, for options that aren't stored in the superblock */
33 LE64_BITMASK(NO_SB_OPT, struct bch_sb, flags[0], 0, 0);
35 /* When can be set: */
37 OPT_FORMAT = (1 << 0),
39 OPT_RUNTIME = (1 << 2),
41 OPT_DEVICE = (1 << 4),
53 * x(name, shortopt, type, in mem type, mode, sb_opt)
55 * @name - name of mount option, sysfs attribute, and struct bch_opts
58 * @mode - when opt may be set
60 * @sb_option - name of corresponding superblock option
62 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
72 #define RATELIMIT_ERRORS true
74 #define RATELIMIT_ERRORS false
80 OPT_SECTORS(1, 128), \
81 BCH_SB_BLOCK_SIZE, 8, \
83 x(btree_node_size, u16, \
85 OPT_SECTORS(1, 128), \
86 BCH_SB_BTREE_NODE_SIZE, 512, \
87 "size", "Btree node size, default 256k") \
89 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
90 OPT_STR(bch2_error_actions), \
91 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_RO, \
92 NULL, "Action to take on filesystem error") \
93 x(metadata_replicas, u8, \
94 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
95 OPT_UINT(1, BCH_REPLICAS_MAX), \
96 BCH_SB_META_REPLICAS_WANT, 1, \
97 "#", "Number of metadata replicas") \
98 x(data_replicas, u8, \
99 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
100 OPT_UINT(1, BCH_REPLICAS_MAX), \
101 BCH_SB_DATA_REPLICAS_WANT, 1, \
102 "#", "Number of data replicas") \
103 x(metadata_replicas_required, u8, \
104 OPT_FORMAT|OPT_MOUNT, \
105 OPT_UINT(1, BCH_REPLICAS_MAX), \
106 BCH_SB_META_REPLICAS_REQ, 1, \
108 x(data_replicas_required, u8, \
109 OPT_FORMAT|OPT_MOUNT, \
110 OPT_UINT(1, BCH_REPLICAS_MAX), \
111 BCH_SB_DATA_REPLICAS_REQ, 1, \
113 x(metadata_checksum, u8, \
114 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
115 OPT_STR(bch2_csum_types), \
116 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \
118 x(data_checksum, u8, \
119 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
120 OPT_STR(bch2_csum_types), \
121 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \
124 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
125 OPT_STR(bch2_compression_types), \
126 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_NONE, \
128 x(background_compression, u8, \
129 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
130 OPT_STR(bch2_compression_types), \
131 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_NONE, \
134 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
135 OPT_STR(bch2_str_hash_types), \
136 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_SIPHASH, \
137 NULL, "Hash function for directory entries and xattrs")\
138 x(foreground_target, u16, \
139 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
140 OPT_FN(bch2_opt_target), \
141 BCH_SB_FOREGROUND_TARGET, 0, \
142 "(target)", "Device or disk group for foreground writes") \
143 x(background_target, u16, \
144 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
145 OPT_FN(bch2_opt_target), \
146 BCH_SB_BACKGROUND_TARGET, 0, \
147 "(target)", "Device or disk group to move data to in the background")\
148 x(promote_target, u16, \
149 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
150 OPT_FN(bch2_opt_target), \
151 BCH_SB_PROMOTE_TARGET, 0, \
152 "(target)", "Device or disk group to promote data to on read")\
153 x(erasure_code, u16, \
154 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
156 BCH_SB_ERASURE_CODE, false, \
157 NULL, "Enable erasure coding (DO NOT USE YET)") \
158 x(inodes_32bit, u8, \
159 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
161 BCH_SB_INODE_32BIT, false, \
162 NULL, "Constrain inode numbers to 32 bits") \
163 x(gc_reserve_percent, u8, \
164 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
166 BCH_SB_GC_RESERVE, 8, \
167 "%", "Percentage of disk space to reserve for copygc")\
168 x(gc_reserve_bytes, u64, \
169 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
170 OPT_SECTORS(0, U64_MAX), \
171 BCH_SB_GC_RESERVE_BYTES, 0, \
172 "%", "Amount of disk space to reserve for copygc\n" \
173 "Takes precedence over gc_reserve_percent if set")\
174 x(root_reserve_percent, u8, \
175 OPT_FORMAT|OPT_MOUNT, \
177 BCH_SB_ROOT_RESERVE, 0, \
178 "%", "Percentage of disk space to reserve for superuser")\
180 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
182 BCH_SB_128_BIT_MACS, false, \
183 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
185 OPT_MOUNT|OPT_RUNTIME, \
188 NULL, "Enable inline data extents") \
190 OPT_FORMAT|OPT_MOUNT, \
192 BCH_SB_POSIX_ACL, true, \
193 NULL, "Enable POSIX acls") \
195 OPT_FORMAT|OPT_MOUNT, \
197 BCH_SB_USRQUOTA, false, \
198 NULL, "Enable user quotas") \
200 OPT_FORMAT|OPT_MOUNT, \
202 BCH_SB_GRPQUOTA, false, \
203 NULL, "Enable group quotas") \
205 OPT_FORMAT|OPT_MOUNT, \
207 BCH_SB_PRJQUOTA, false, \
208 NULL, "Enable project quotas") \
213 NULL, "Allow mounting in degraded mode") \
215 OPT_MOUNT|OPT_DEVICE, \
218 NULL, "Enable discard/TRIM support") \
223 NULL, "Extra debugging information during mount/recovery")\
224 x(journal_flush_disabled, u8, \
225 OPT_MOUNT|OPT_RUNTIME, \
228 NULL, "Disable journal flush on sync/fsync\n" \
229 "If enabled, writes can be lost, but only since the\n"\
230 "last journal write (default 1 second)") \
235 NULL, "Run fsck on mount") \
240 NULL, "Fix errors during fsck without asking") \
241 x(ratelimit_errors, u8, \
244 NO_SB_OPT, RATELIMIT_ERRORS, \
245 NULL, "Ratelimit error messages during fsck") \
250 NULL, "Super read only mode - no writes at all will be issued,\n"\
251 "even if we have to replay the journal") \
256 NULL, "Don't replay the journal") \
261 NULL, "Don't open device in exclusive mode") \
264 OPT_UINT(0, S64_MAX), \
265 NO_SB_OPT, BCH_SB_SECTOR, \
266 "offset", "Sector offset of superblock") \
276 NULL, "Don\'t start filesystem, only open devices") \
277 x(reconstruct_alloc, u8, \
281 NULL, "Reconstruct alloc btree") \
282 x(version_upgrade, u8, \
286 NULL, "Set superblock to latest version,\n" \
287 "allowing any new features to be used") \
295 OPT_SECTORS(0, S64_MAX), \
297 "size", "Size of filesystem on device") \
300 OPT_SECTORS(0, S64_MAX), \
302 "size", "Size of filesystem on device") \
305 OPT_UINT(0, BCH_REPLICAS_MAX), \
307 "n", "Data written to this device will be considered\n"\
308 "to have already been replicated n times")
311 #define x(_name, _bits, ...) unsigned _name##_defined:1;
315 #define x(_name, _bits, ...) _bits _name;
320 static const struct bch_opts bch2_opts_default = {
321 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
322 ._name##_defined = true, \
329 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
331 #define opt_get(_opts, _name) \
332 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
334 #define opt_set(_opts, _name, _v) \
336 (_opts)._name##_defined = true; \
337 (_opts)._name = _v; \
340 static inline struct bch_opts bch2_opts_empty(void)
342 return (struct bch_opts) { 0 };
345 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
348 #define x(_name, ...) Opt_##_name,
358 struct attribute attr;
359 void (*set_sb)(struct bch_sb *, u64);
368 const char * const *choices;
371 int (*parse)(struct bch_fs *, const char *, u64 *);
372 void (*to_text)(struct printbuf *, struct bch_fs *, u64);
381 extern const struct bch_option bch2_opt_table[];
383 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
384 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
385 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
387 struct bch_opts bch2_opts_from_sb(struct bch_sb *);
389 int bch2_opt_lookup(const char *);
390 int bch2_opt_parse(struct bch_fs *, const struct bch_option *, const char *, u64 *);
392 #define OPT_SHOW_FULL_LIST (1 << 0)
393 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
395 void bch2_opt_to_text(struct printbuf *, struct bch_fs *,
396 const struct bch_option *, u64, unsigned);
398 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
399 int bch2_opts_check_may_set(struct bch_fs *);
400 int bch2_parse_mount_opts(struct bch_opts *, char *);
405 #define x(_name, _bits) unsigned _name##_defined:1;
409 #define x(_name, _bits) u##_bits _name;
414 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
415 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
416 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
417 bool bch2_opt_is_inode_opt(enum bch_opt_id);
419 #endif /* _BCACHEFS_OPTS_H */