1 #ifndef _BCACHEFS_OPTS_H
2 #define _BCACHEFS_OPTS_H
5 #include <linux/log2.h>
6 #include <linux/string.h>
7 #include <linux/sysfs.h>
8 #include "bcachefs_format.h"
10 extern const char * const bch2_error_actions[];
11 extern const char * const bch2_csum_types[];
12 extern const char * const bch2_compression_types[];
13 extern const char * const bch2_str_hash_types[];
14 extern const char * const bch2_data_types[];
15 extern const char * const bch2_cache_replacement_policies[];
16 extern const char * const bch2_cache_modes[];
17 extern const char * const bch2_dev_state[];
20 * Mount options; we also store defaults in the superblock.
22 * Also exposed via sysfs: if an option is writeable, and it's also stored in
23 * the superblock, changing it via sysfs (currently? might change this) also
24 * updates the superblock.
26 * We store options as signed integers, where -1 means undefined. This means we
27 * can pass the mount options to bch2_fs_alloc() as a whole struct, and then only
28 * apply the options from that struct that are defined.
31 /* dummy option, for options that aren't stored in the superblock */
32 LE64_BITMASK(NO_SB_OPT, struct bch_sb, flags[0], 0, 0);
34 /* When can be set: */
36 OPT_FORMAT = (1 << 0),
38 OPT_RUNTIME = (1 << 2),
40 OPT_DEVICE = (1 << 4),
52 * x(name, shortopt, type, in mem type, mode, sb_opt)
54 * @name - name of mount option, sysfs attribute, and struct bch_opts
57 * @mode - when opt may be set
59 * @sb_option - name of corresponding superblock option
61 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
73 OPT_SECTORS(1, 128), \
74 BCH_SB_BLOCK_SIZE, 8, \
76 x(btree_node_size, u16, \
78 OPT_SECTORS(1, 128), \
79 BCH_SB_BTREE_NODE_SIZE, 512, \
80 "size", "Btree node size, default 256k") \
82 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
83 OPT_STR(bch2_error_actions), \
84 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_RO, \
85 NULL, "Action to take on filesystem error") \
86 x(metadata_replicas, u8, \
87 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
88 OPT_UINT(1, BCH_REPLICAS_MAX), \
89 BCH_SB_META_REPLICAS_WANT, 1, \
90 "#", "Number of metadata replicas") \
91 x(data_replicas, u8, \
92 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
93 OPT_UINT(1, BCH_REPLICAS_MAX), \
94 BCH_SB_DATA_REPLICAS_WANT, 1, \
95 "#", "Number of data replicas") \
96 x(metadata_replicas_required, u8, \
97 OPT_FORMAT|OPT_MOUNT, \
98 OPT_UINT(1, BCH_REPLICAS_MAX), \
99 BCH_SB_META_REPLICAS_REQ, 1, \
101 x(data_replicas_required, u8, \
102 OPT_FORMAT|OPT_MOUNT, \
103 OPT_UINT(1, BCH_REPLICAS_MAX), \
104 BCH_SB_DATA_REPLICAS_REQ, 1, \
106 x(metadata_checksum, u8, \
107 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
108 OPT_STR(bch2_csum_types), \
109 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \
111 x(data_checksum, u8, \
112 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
113 OPT_STR(bch2_csum_types), \
114 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \
117 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
118 OPT_STR(bch2_compression_types), \
119 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_NONE, \
121 x(background_compression, u8, \
122 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
123 OPT_STR(bch2_compression_types), \
124 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_NONE, \
127 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
128 OPT_STR(bch2_str_hash_types), \
129 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_SIPHASH, \
130 NULL, "Hash function for directory entries and xattrs")\
131 x(foreground_target, u16, \
132 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
133 OPT_FN(bch2_opt_target), \
134 BCH_SB_FOREGROUND_TARGET, 0, \
135 "(target)", "Device or disk group for foreground writes") \
136 x(background_target, u16, \
137 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
138 OPT_FN(bch2_opt_target), \
139 BCH_SB_BACKGROUND_TARGET, 0, \
140 "(target)", "Device or disk group to move data to in the background")\
141 x(promote_target, u16, \
142 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
143 OPT_FN(bch2_opt_target), \
144 BCH_SB_PROMOTE_TARGET, 0, \
145 "(target)", "Device or disk group to promote data to on read")\
146 x(erasure_code, u16, \
147 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
149 BCH_SB_ERASURE_CODE, false, \
150 NULL, "Enable erasure coding (DO NOT USE YET)") \
151 x(inodes_32bit, u8, \
152 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
154 BCH_SB_INODE_32BIT, false, \
155 NULL, "Constrain inode numbers to 32 bits") \
156 x(gc_reserve_percent, u8, \
157 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
159 BCH_SB_GC_RESERVE, 8, \
160 "%", "Percentage of disk space to reserve for copygc")\
161 x(gc_reserve_bytes, u64, \
162 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
163 OPT_SECTORS(0, U64_MAX), \
164 BCH_SB_GC_RESERVE_BYTES, 0, \
165 "%", "Amount of disk space to reserve for copygc\n" \
166 "Takes precedence over gc_reserve_percent if set")\
167 x(root_reserve_percent, u8, \
168 OPT_FORMAT|OPT_MOUNT, \
170 BCH_SB_ROOT_RESERVE, 0, \
171 "%", "Percentage of disk space to reserve for superuser")\
173 OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
175 BCH_SB_128_BIT_MACS, false, \
176 NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
178 OPT_FORMAT|OPT_MOUNT, \
180 BCH_SB_POSIX_ACL, true, \
181 NULL, "Enable POSIX acls") \
183 OPT_FORMAT|OPT_MOUNT, \
185 BCH_SB_USRQUOTA, false, \
186 NULL, "Enable user quotas") \
188 OPT_FORMAT|OPT_MOUNT, \
190 BCH_SB_GRPQUOTA, false, \
191 NULL, "Enable group quotas") \
193 OPT_FORMAT|OPT_MOUNT, \
195 BCH_SB_PRJQUOTA, false, \
196 NULL, "Enable project quotas") \
201 NULL, "Allow mounting in degraded mode") \
203 OPT_MOUNT|OPT_DEVICE, \
206 NULL, "Enable discard/TRIM support") \
211 NULL, "Extra debugging information during mount/recovery")\
212 x(journal_flush_disabled, u8, \
213 OPT_MOUNT|OPT_RUNTIME, \
216 NULL, "Disable journal flush on sync/fsync\n" \
217 "If enabled, writes can be lost, but only since the\n"\
218 "last journal write (default 1 second)") \
223 NULL, "Run fsck on mount") \
228 NULL, "Fix errors during fsck without asking") \
233 NULL, "Super read only mode - no writes at all will be issued,\n"\
234 "even if we have to replay the journal") \
239 NULL, "Don't replay the journal (only for internal tools)")\
249 NULL, "Don't open device in exclusive mode") \
252 OPT_UINT(0, S64_MAX), \
253 NO_SB_OPT, BCH_SB_SECTOR, \
254 "offset", "Sector offset of superblock") \
264 NULL, "Don\'t start filesystem, only open devices") \
265 x(version_upgrade, u8, \
269 NULL, "Set superblock to latest version,\n" \
270 "allowing any new features to be used") \
278 OPT_SECTORS(0, S64_MAX), \
280 "size", "Size of filesystem on device") \
283 OPT_SECTORS(0, S64_MAX), \
285 "size", "Size of filesystem on device") \
288 OPT_UINT(0, BCH_REPLICAS_MAX), \
290 "n", "Data written to this device will be considered\n"\
291 "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 */