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(foreground_target, u16, \
140 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
141 OPT_FN(bch2_opt_target), \
142 BCH_SB_FOREGROUND_TARGET, 0, \
143 "(target)", "Device or disk group for foreground writes") \
144 x(background_target, u16, \
145 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
146 OPT_FN(bch2_opt_target), \
147 BCH_SB_BACKGROUND_TARGET, 0, \
148 "(target)", "Device or disk group to move data to in the background")\
149 x(promote_target, u16, \
150 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
151 OPT_FN(bch2_opt_target), \
152 BCH_SB_PROMOTE_TARGET, 0, \
153 "(target)", "Device or disk group to promote data to on read")\
154 x(erasure_code, u16, \
155 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
157 BCH_SB_ERASURE_CODE, false, \
158 NULL, "Enable erasure coding (DO NOT USE YET)") \
159 x(inodes_32bit, u8, \
160 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
162 BCH_SB_INODE_32BIT, false, \
163 NULL, "Constrain inode numbers to 32 bits") \
164 x(gc_reserve_percent, u8, \
165 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
167 BCH_SB_GC_RESERVE, 8, \
168 "%", "Percentage of disk space to reserve for copygc")\
169 x(gc_reserve_bytes, u64, \
170 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
171 OPT_SECTORS(0, U64_MAX), \
172 BCH_SB_GC_RESERVE_BYTES, 0, \
173 "%", "Amount of disk space to reserve for copygc\n" \
174 "Takes precedence over gc_reserve_percent if set")\
175 x(root_reserve_percent, u8, \
176 OPT_FORMAT|OPT_MOUNT, \
178 BCH_SB_ROOT_RESERVE, 0, \
179 "%", "Percentage of disk space to reserve for superuser")\
181 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
183 BCH_SB_128_BIT_MACS, false, \
184 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
186 OPT_MOUNT|OPT_RUNTIME, \
189 NULL, "Enable inline data extents") \
191 OPT_FORMAT|OPT_MOUNT, \
193 BCH_SB_POSIX_ACL, true, \
194 NULL, "Enable POSIX acls") \
196 OPT_FORMAT|OPT_MOUNT, \
198 BCH_SB_USRQUOTA, false, \
199 NULL, "Enable user quotas") \
201 OPT_FORMAT|OPT_MOUNT, \
203 BCH_SB_GRPQUOTA, false, \
204 NULL, "Enable group quotas") \
206 OPT_FORMAT|OPT_MOUNT, \
208 BCH_SB_PRJQUOTA, false, \
209 NULL, "Enable project quotas") \
211 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
213 BCH_SB_REFLINK, true, \
214 NULL, "Enable reflink support") \
219 NULL, "Allow mounting in degraded mode") \
221 OPT_MOUNT|OPT_DEVICE, \
224 NULL, "Enable discard/TRIM support") \
229 NULL, "Extra debugging information during mount/recovery")\
230 x(journal_flush_disabled, u8, \
231 OPT_MOUNT|OPT_RUNTIME, \
234 NULL, "Disable journal flush on sync/fsync\n" \
235 "If enabled, writes can be lost, but only since the\n"\
236 "last journal write (default 1 second)") \
241 NULL, "Run fsck on mount") \
246 NULL, "Fix errors during fsck without asking") \
247 x(ratelimit_errors, u8, \
250 NO_SB_OPT, RATELIMIT_ERRORS, \
251 NULL, "Ratelimit error messages during fsck") \
256 NULL, "Super read only mode - no writes at all will be issued,\n"\
257 "even if we have to replay the journal") \
262 NULL, "Don't replay the journal") \
263 x(rebuild_replicas, u8, \
267 NULL, "Rebuild the superblock replicas section") \
268 x(keep_journal, u8, \
272 NULL, "Don't free journal entries/keys after startup")\
273 x(read_entire_journal, u8, \
277 NULL, "Read all journal entries, not just dirty ones")\
282 NULL, "Don't open device in exclusive mode") \
285 OPT_UINT(0, S64_MAX), \
286 NO_SB_OPT, BCH_SB_SECTOR, \
287 "offset", "Sector offset of superblock") \
297 NULL, "Don\'t start filesystem, only open devices") \
298 x(reconstruct_alloc, u8, \
302 NULL, "Reconstruct alloc btree") \
303 x(version_upgrade, u8, \
307 NULL, "Set superblock to latest version,\n" \
308 "allowing any new features to be used") \
316 OPT_SECTORS(0, S64_MAX), \
318 "size", "Size of filesystem on device") \
321 OPT_SECTORS(0, S64_MAX), \
323 "size", "Size of filesystem on device") \
326 OPT_UINT(0, BCH_REPLICAS_MAX), \
328 "n", "Data written to this device will be considered\n"\
329 "to have already been replicated n times")
332 #define x(_name, _bits, ...) unsigned _name##_defined:1;
336 #define x(_name, _bits, ...) _bits _name;
341 static const struct bch_opts bch2_opts_default = {
342 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
343 ._name##_defined = true, \
350 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
352 #define opt_get(_opts, _name) \
353 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
355 #define opt_set(_opts, _name, _v) \
357 (_opts)._name##_defined = true; \
358 (_opts)._name = _v; \
361 static inline struct bch_opts bch2_opts_empty(void)
363 return (struct bch_opts) { 0 };
366 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
369 #define x(_name, ...) Opt_##_name,
379 struct attribute attr;
380 void (*set_sb)(struct bch_sb *, u64);
389 const char * const *choices;
392 int (*parse)(struct bch_fs *, const char *, u64 *);
393 void (*to_text)(struct printbuf *, struct bch_fs *, u64);
402 extern const struct bch_option bch2_opt_table[];
404 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
405 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
406 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
408 struct bch_opts bch2_opts_from_sb(struct bch_sb *);
410 int bch2_opt_lookup(const char *);
411 int bch2_opt_parse(struct bch_fs *, const struct bch_option *, const char *, u64 *);
413 #define OPT_SHOW_FULL_LIST (1 << 0)
414 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
416 void bch2_opt_to_text(struct printbuf *, struct bch_fs *,
417 const struct bch_option *, u64, unsigned);
419 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
420 int bch2_opts_check_may_set(struct bch_fs *);
421 int bch2_parse_mount_opts(struct bch_opts *, char *);
426 #define x(_name, _bits) unsigned _name##_defined:1;
430 #define x(_name, _bits) u##_bits _name;
435 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
436 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
437 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
438 bool bch2_opt_is_inode_opt(enum bch_opt_id);
440 #endif /* _BCACHEFS_OPTS_H */