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
74 OPT_SECTORS(1, 128), \
75 BCH_SB_BLOCK_SIZE, 8, \
77 x(btree_node_size, u16, \
79 OPT_SECTORS(1, 128), \
80 BCH_SB_BTREE_NODE_SIZE, 512, \
81 "size", "Btree node size, default 256k") \
83 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
84 OPT_STR(bch2_error_actions), \
85 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_RO, \
86 NULL, "Action to take on filesystem error") \
87 x(metadata_replicas, u8, \
88 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
89 OPT_UINT(1, BCH_REPLICAS_MAX), \
90 BCH_SB_META_REPLICAS_WANT, 1, \
91 "#", "Number of metadata replicas") \
92 x(data_replicas, u8, \
93 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
94 OPT_UINT(1, BCH_REPLICAS_MAX), \
95 BCH_SB_DATA_REPLICAS_WANT, 1, \
96 "#", "Number of data replicas") \
97 x(metadata_replicas_required, u8, \
98 OPT_FORMAT|OPT_MOUNT, \
99 OPT_UINT(1, BCH_REPLICAS_MAX), \
100 BCH_SB_META_REPLICAS_REQ, 1, \
102 x(data_replicas_required, u8, \
103 OPT_FORMAT|OPT_MOUNT, \
104 OPT_UINT(1, BCH_REPLICAS_MAX), \
105 BCH_SB_DATA_REPLICAS_REQ, 1, \
107 x(metadata_checksum, u8, \
108 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
109 OPT_STR(bch2_csum_types), \
110 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \
112 x(data_checksum, u8, \
113 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
114 OPT_STR(bch2_csum_types), \
115 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \
118 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
119 OPT_STR(bch2_compression_types), \
120 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_NONE, \
122 x(background_compression, u8, \
123 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
124 OPT_STR(bch2_compression_types), \
125 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_NONE, \
128 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
129 OPT_STR(bch2_str_hash_types), \
130 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_SIPHASH, \
131 NULL, "Hash function for directory entries and xattrs")\
132 x(foreground_target, u16, \
133 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
134 OPT_FN(bch2_opt_target), \
135 BCH_SB_FOREGROUND_TARGET, 0, \
136 "(target)", "Device or disk group for foreground writes") \
137 x(background_target, u16, \
138 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
139 OPT_FN(bch2_opt_target), \
140 BCH_SB_BACKGROUND_TARGET, 0, \
141 "(target)", "Device or disk group to move data to in the background")\
142 x(promote_target, u16, \
143 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
144 OPT_FN(bch2_opt_target), \
145 BCH_SB_PROMOTE_TARGET, 0, \
146 "(target)", "Device or disk group to promote data to on read")\
147 x(erasure_code, u16, \
148 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
150 BCH_SB_ERASURE_CODE, false, \
151 NULL, "Enable erasure coding (DO NOT USE YET)") \
152 x(inodes_32bit, u8, \
153 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
155 BCH_SB_INODE_32BIT, false, \
156 NULL, "Constrain inode numbers to 32 bits") \
157 x(gc_reserve_percent, u8, \
158 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
160 BCH_SB_GC_RESERVE, 8, \
161 "%", "Percentage of disk space to reserve for copygc")\
162 x(gc_reserve_bytes, u64, \
163 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
164 OPT_SECTORS(0, U64_MAX), \
165 BCH_SB_GC_RESERVE_BYTES, 0, \
166 "%", "Amount of disk space to reserve for copygc\n" \
167 "Takes precedence over gc_reserve_percent if set")\
168 x(root_reserve_percent, u8, \
169 OPT_FORMAT|OPT_MOUNT, \
171 BCH_SB_ROOT_RESERVE, 0, \
172 "%", "Percentage of disk space to reserve for superuser")\
174 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
176 BCH_SB_128_BIT_MACS, false, \
177 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
179 OPT_FORMAT|OPT_MOUNT, \
181 BCH_SB_POSIX_ACL, true, \
182 NULL, "Enable POSIX acls") \
184 OPT_FORMAT|OPT_MOUNT, \
186 BCH_SB_USRQUOTA, false, \
187 NULL, "Enable user quotas") \
189 OPT_FORMAT|OPT_MOUNT, \
191 BCH_SB_GRPQUOTA, false, \
192 NULL, "Enable group quotas") \
194 OPT_FORMAT|OPT_MOUNT, \
196 BCH_SB_PRJQUOTA, false, \
197 NULL, "Enable project quotas") \
202 NULL, "Allow mounting in degraded mode") \
204 OPT_MOUNT|OPT_DEVICE, \
207 NULL, "Enable discard/TRIM support") \
212 NULL, "Extra debugging information during mount/recovery")\
213 x(journal_flush_disabled, u8, \
214 OPT_MOUNT|OPT_RUNTIME, \
217 NULL, "Disable journal flush on sync/fsync\n" \
218 "If enabled, writes can be lost, but only since the\n"\
219 "last journal write (default 1 second)") \
224 NULL, "Run fsck on mount") \
229 NULL, "Fix errors during fsck without asking") \
234 NULL, "Super read only mode - no writes at all will be issued,\n"\
235 "even if we have to replay the journal") \
240 NULL, "Don't replay the journal") \
245 NULL, "Don't open device in exclusive mode") \
248 OPT_UINT(0, S64_MAX), \
249 NO_SB_OPT, BCH_SB_SECTOR, \
250 "offset", "Sector offset of superblock") \
260 NULL, "Don\'t start filesystem, only open devices") \
261 x(reconstruct_alloc, u8, \
265 NULL, "Reconstruct alloc btree") \
266 x(version_upgrade, u8, \
270 NULL, "Set superblock to latest version,\n" \
271 "allowing any new features to be used") \
279 OPT_SECTORS(0, S64_MAX), \
281 "size", "Size of filesystem on device") \
284 OPT_SECTORS(0, S64_MAX), \
286 "size", "Size of filesystem on device") \
289 OPT_UINT(0, BCH_REPLICAS_MAX), \
291 "n", "Data written to this device will be considered\n"\
292 "to have already been replicated n times")
295 #define x(_name, _bits, ...) unsigned _name##_defined:1;
299 #define x(_name, _bits, ...) _bits _name;
304 static const struct bch_opts bch2_opts_default = {
305 #define x(_name, _bits, _mode, _type, _sb_opt, _default, ...) \
306 ._name##_defined = true, \
313 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
315 #define opt_get(_opts, _name) \
316 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
318 #define opt_set(_opts, _name, _v) \
320 (_opts)._name##_defined = true; \
321 (_opts)._name = _v; \
324 static inline struct bch_opts bch2_opts_empty(void)
326 return (struct bch_opts) { 0 };
329 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
332 #define x(_name, ...) Opt_##_name,
342 struct attribute attr;
343 void (*set_sb)(struct bch_sb *, u64);
352 const char * const *choices;
355 int (*parse)(struct bch_fs *, const char *, u64 *);
356 void (*to_text)(struct printbuf *, struct bch_fs *, u64);
365 extern const struct bch_option bch2_opt_table[];
367 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
368 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
369 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
371 struct bch_opts bch2_opts_from_sb(struct bch_sb *);
373 int bch2_opt_lookup(const char *);
374 int bch2_opt_parse(struct bch_fs *, const struct bch_option *, const char *, u64 *);
376 #define OPT_SHOW_FULL_LIST (1 << 0)
377 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
379 void bch2_opt_to_text(struct printbuf *, struct bch_fs *,
380 const struct bch_option *, u64, unsigned);
382 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
383 int bch2_opts_check_may_set(struct bch_fs *);
384 int bch2_parse_mount_opts(struct bch_opts *, char *);
389 #define x(_name, _bits) unsigned _name##_defined:1;
393 #define x(_name, _bits) u##_bits _name;
398 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
399 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
400 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
401 bool bch2_opt_is_inode_opt(enum bch_opt_id);
403 #endif /* _BCACHEFS_OPTS_H */