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);
49 * BCH_OPT(name, type, in mem type, mode, sb_opt)
51 * @name - name of mount option, sysfs attribute, and struct bch_opts
54 * @mode - when opt may be set
56 * @sb_option - name of corresponding superblock option
58 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
68 BCH_OPT(block_size, u16, OPT_FORMAT, \
70 BCH_SB_BLOCK_SIZE, 8) \
71 BCH_OPT(btree_node_size, u16, OPT_FORMAT, \
73 BCH_SB_BTREE_NODE_SIZE, 512) \
74 BCH_OPT(errors, u8, OPT_RUNTIME, \
75 OPT_STR(bch2_error_actions), \
76 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_RO) \
77 BCH_OPT(metadata_replicas, u8, OPT_RUNTIME, \
78 OPT_UINT(1, BCH_REPLICAS_MAX), \
79 BCH_SB_META_REPLICAS_WANT, 1) \
80 BCH_OPT(data_replicas, u8, OPT_RUNTIME, \
81 OPT_UINT(1, BCH_REPLICAS_MAX), \
82 BCH_SB_DATA_REPLICAS_WANT, 1) \
83 BCH_OPT(metadata_replicas_required, u8, OPT_MOUNT, \
84 OPT_UINT(1, BCH_REPLICAS_MAX), \
85 BCH_SB_META_REPLICAS_REQ, 1) \
86 BCH_OPT(data_replicas_required, u8, OPT_MOUNT, \
87 OPT_UINT(1, BCH_REPLICAS_MAX), \
88 BCH_SB_DATA_REPLICAS_REQ, 1) \
89 BCH_OPT(metadata_checksum, u8, OPT_RUNTIME, \
90 OPT_STR(bch2_csum_types), \
91 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_CRC32C) \
92 BCH_OPT(data_checksum, u8, OPT_RUNTIME, \
93 OPT_STR(bch2_csum_types), \
94 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_CRC32C) \
95 BCH_OPT(compression, u8, OPT_RUNTIME, \
96 OPT_STR(bch2_compression_types), \
97 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_NONE)\
98 BCH_OPT(background_compression, u8, OPT_RUNTIME, \
99 OPT_STR(bch2_compression_types), \
100 BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_NONE)\
101 BCH_OPT(str_hash, u8, OPT_RUNTIME, \
102 OPT_STR(bch2_str_hash_types), \
103 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_SIPHASH) \
104 BCH_OPT(foreground_target, u16, OPT_RUNTIME, \
105 OPT_FN(bch2_opt_target), \
106 BCH_SB_FOREGROUND_TARGET, 0) \
107 BCH_OPT(background_target, u16, OPT_RUNTIME, \
108 OPT_FN(bch2_opt_target), \
109 BCH_SB_BACKGROUND_TARGET, 0) \
110 BCH_OPT(promote_target, u16, OPT_RUNTIME, \
111 OPT_FN(bch2_opt_target), \
112 BCH_SB_PROMOTE_TARGET, 0) \
113 BCH_OPT(erasure_code, u16, OPT_RUNTIME, \
115 BCH_SB_ERASURE_CODE, false) \
116 BCH_OPT(inodes_32bit, u8, OPT_RUNTIME, \
118 BCH_SB_INODE_32BIT, false) \
119 BCH_OPT(gc_reserve_percent, u8, OPT_RUNTIME, \
121 BCH_SB_GC_RESERVE, 8) \
122 BCH_OPT(gc_reserve_bytes, u64, OPT_RUNTIME, \
123 OPT_UINT(0, U64_MAX), \
124 BCH_SB_GC_RESERVE_BYTES, 0) \
125 BCH_OPT(root_reserve_percent, u8, OPT_MOUNT, \
127 BCH_SB_ROOT_RESERVE, 0) \
128 BCH_OPT(wide_macs, u8, OPT_RUNTIME, \
130 BCH_SB_128_BIT_MACS, false) \
131 BCH_OPT(acl, u8, OPT_MOUNT, \
133 BCH_SB_POSIX_ACL, true) \
134 BCH_OPT(usrquota, u8, OPT_MOUNT, \
136 BCH_SB_USRQUOTA, false) \
137 BCH_OPT(grpquota, u8, OPT_MOUNT, \
139 BCH_SB_GRPQUOTA, false) \
140 BCH_OPT(prjquota, u8, OPT_MOUNT, \
142 BCH_SB_PRJQUOTA, false) \
143 BCH_OPT(degraded, u8, OPT_MOUNT, \
146 BCH_OPT(discard, u8, OPT_MOUNT, \
149 BCH_OPT(verbose_recovery, u8, OPT_MOUNT, \
152 BCH_OPT(verbose_init, u8, OPT_MOUNT, \
155 BCH_OPT(journal_flush_disabled, u8, OPT_RUNTIME, \
158 BCH_OPT(fsck, u8, OPT_MOUNT, \
161 BCH_OPT(fix_errors, u8, OPT_MOUNT, \
164 BCH_OPT(nochanges, u8, OPT_MOUNT, \
167 BCH_OPT(noreplay, u8, OPT_MOUNT, \
170 BCH_OPT(norecovery, u8, OPT_MOUNT, \
173 BCH_OPT(noexcl, u8, OPT_MOUNT, \
176 BCH_OPT(sb, u64, OPT_MOUNT, \
177 OPT_UINT(0, S64_MAX), \
178 NO_SB_OPT, BCH_SB_SECTOR) \
179 BCH_OPT(read_only, u8, OPT_INTERNAL, \
182 BCH_OPT(nostart, u8, OPT_INTERNAL, \
185 BCH_OPT(version_upgrade, u8, OPT_MOUNT, \
188 BCH_OPT(project, u8, OPT_INTERNAL, \
193 #define BCH_OPT(_name, _bits, ...) unsigned _name##_defined:1;
197 #define BCH_OPT(_name, _bits, ...) _bits _name;
202 static const struct bch_opts bch2_opts_default = {
203 #define BCH_OPT(_name, _bits, _mode, _type, _sb_opt, _default) \
204 ._name##_defined = true, \
211 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
213 #define opt_get(_opts, _name) \
214 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
216 #define opt_set(_opts, _name, _v) \
218 (_opts)._name##_defined = true; \
219 (_opts)._name = _v; \
222 static inline struct bch_opts bch2_opts_empty(void)
224 return (struct bch_opts) { 0 };
227 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
230 #define BCH_OPT(_name, ...) Opt_##_name,
240 struct attribute attr;
241 void (*set_sb)(struct bch_sb *, u64);
250 const char * const *choices;
253 int (*parse)(struct bch_fs *, const char *, u64 *);
254 void (*to_text)(struct printbuf *, struct bch_fs *, u64);
260 extern const struct bch_option bch2_opt_table[];
262 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
263 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
264 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
266 struct bch_opts bch2_opts_from_sb(struct bch_sb *);
268 int bch2_opt_lookup(const char *);
269 int bch2_opt_parse(struct bch_fs *, const struct bch_option *, const char *, u64 *);
271 #define OPT_SHOW_FULL_LIST (1 << 0)
272 #define OPT_SHOW_MOUNT_STYLE (1 << 1)
274 void bch2_opt_to_text(struct printbuf *, struct bch_fs *,
275 const struct bch_option *, u64, unsigned);
277 int bch2_opt_check_may_set(struct bch_fs *, int, u64);
278 int bch2_opts_check_may_set(struct bch_fs *);
279 int bch2_parse_mount_opts(struct bch_opts *, char *);
284 #define x(_name, _bits) unsigned _name##_defined:1;
288 #define x(_name, _bits) u##_bits _name;
293 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
294 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
295 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
296 bool bch2_opt_is_inode_opt(enum bch_opt_id);
298 #endif /* _BCACHEFS_OPTS_H */