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);
48 * BCH_OPT(name, type, in mem type, mode, sb_opt)
50 * @name - name of mount option, sysfs attribute, and struct bch_opts
53 * @mode - when opt may be set
55 * @sb_option - name of corresponding superblock option
57 * @type - one of OPT_BOOL, OPT_UINT, OPT_STR
67 BCH_OPT(block_size, u16, OPT_FORMAT, \
69 BCH_SB_BLOCK_SIZE, 8) \
70 BCH_OPT(btree_node_size, u16, OPT_FORMAT, \
72 BCH_SB_BTREE_NODE_SIZE, 512) \
73 BCH_OPT(errors, u8, OPT_RUNTIME, \
74 OPT_STR(bch2_error_actions), \
75 BCH_SB_ERROR_ACTION, BCH_ON_ERROR_RO) \
76 BCH_OPT(metadata_replicas, u8, OPT_RUNTIME, \
77 OPT_UINT(1, BCH_REPLICAS_MAX), \
78 BCH_SB_META_REPLICAS_WANT, 1) \
79 BCH_OPT(data_replicas, u8, OPT_RUNTIME, \
80 OPT_UINT(1, BCH_REPLICAS_MAX), \
81 BCH_SB_DATA_REPLICAS_WANT, 1) \
82 BCH_OPT(metadata_replicas_required, u8, OPT_MOUNT, \
83 OPT_UINT(1, BCH_REPLICAS_MAX), \
84 BCH_SB_META_REPLICAS_REQ, 1) \
85 BCH_OPT(data_replicas_required, u8, OPT_MOUNT, \
86 OPT_UINT(1, BCH_REPLICAS_MAX), \
87 BCH_SB_DATA_REPLICAS_REQ, 1) \
88 BCH_OPT(metadata_checksum, u8, OPT_RUNTIME, \
89 OPT_STR(bch2_csum_types), \
90 BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_CRC32C) \
91 BCH_OPT(data_checksum, u8, OPT_RUNTIME, \
92 OPT_STR(bch2_csum_types), \
93 BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_CRC32C) \
94 BCH_OPT(compression, u8, OPT_RUNTIME, \
95 OPT_STR(bch2_compression_types), \
96 BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_NONE)\
97 BCH_OPT(str_hash, u8, OPT_RUNTIME, \
98 OPT_STR(bch2_str_hash_types), \
99 BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_SIPHASH) \
100 BCH_OPT(inodes_32bit, u8, OPT_RUNTIME, \
102 BCH_SB_INODE_32BIT, false) \
103 BCH_OPT(gc_reserve_percent, u8, OPT_MOUNT, \
105 BCH_SB_GC_RESERVE, 8) \
106 BCH_OPT(root_reserve_percent, u8, OPT_MOUNT, \
108 BCH_SB_ROOT_RESERVE, 0) \
109 BCH_OPT(wide_macs, u8, OPT_RUNTIME, \
111 BCH_SB_128_BIT_MACS, false) \
112 BCH_OPT(acl, u8, OPT_MOUNT, \
114 BCH_SB_POSIX_ACL, true) \
115 BCH_OPT(usrquota, u8, OPT_MOUNT, \
117 BCH_SB_USRQUOTA, false) \
118 BCH_OPT(grpquota, u8, OPT_MOUNT, \
120 BCH_SB_GRPQUOTA, false) \
121 BCH_OPT(prjquota, u8, OPT_MOUNT, \
123 BCH_SB_PRJQUOTA, false) \
124 BCH_OPT(degraded, u8, OPT_MOUNT, \
127 BCH_OPT(verbose_recovery, u8, OPT_MOUNT, \
130 BCH_OPT(verbose_init, u8, OPT_MOUNT, \
133 BCH_OPT(journal_flush_disabled, u8, OPT_RUNTIME, \
136 BCH_OPT(nofsck, u8, OPT_MOUNT, \
139 BCH_OPT(fix_errors, u8, OPT_MOUNT, \
142 BCH_OPT(nochanges, u8, OPT_MOUNT, \
145 BCH_OPT(noreplay, u8, OPT_MOUNT, \
148 BCH_OPT(norecovery, u8, OPT_MOUNT, \
151 BCH_OPT(noexcl, u8, OPT_MOUNT, \
154 BCH_OPT(sb, u64, OPT_MOUNT, \
155 OPT_UINT(0, S64_MAX), \
156 NO_SB_OPT, BCH_SB_SECTOR) \
157 BCH_OPT(read_only, u8, OPT_INTERNAL, \
160 BCH_OPT(nostart, u8, OPT_INTERNAL, \
165 #define BCH_OPT(_name, _bits, ...) unsigned _name##_defined:1;
169 #define BCH_OPT(_name, _bits, ...) _bits _name;
174 static const struct bch_opts bch2_opts_default = {
175 #define BCH_OPT(_name, _bits, _mode, _type, _sb_opt, _default) \
176 ._name##_defined = true, \
183 #define opt_defined(_opts, _name) ((_opts)._name##_defined)
185 #define opt_get(_opts, _name) \
186 (opt_defined(_opts, _name) ? (_opts)._name : bch2_opts_default._name)
188 #define opt_set(_opts, _name, _v) \
190 (_opts)._name##_defined = true; \
191 (_opts)._name = _v; \
194 static inline struct bch_opts bch2_opts_empty(void)
196 return (struct bch_opts) { 0 };
199 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
202 #define BCH_OPT(_name, ...) Opt_##_name,
209 struct attribute attr;
210 void (*set_sb)(struct bch_sb *, u64);
219 const char * const *choices;
225 extern const struct bch_option bch2_opt_table[];
227 bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
228 u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
229 void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
231 struct bch_opts bch2_opts_from_sb(struct bch_sb *);
233 int bch2_opt_lookup(const char *);
234 int bch2_opt_parse(const struct bch_option *, const char *, u64 *);
235 int bch2_parse_mount_opts(struct bch_opts *, char *);
239 #define BCH_INODE_OPTS() \
240 BCH_INODE_OPT(data_checksum, 8) \
241 BCH_INODE_OPT(compression, 8)
244 #define BCH_INODE_OPT(_name, _bits) unsigned _name##_defined:1;
248 #define BCH_INODE_OPT(_name, _bits) u##_bits _name;
253 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
254 struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
255 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
256 bool bch2_opt_is_inode_opt(enum bch_opt_id);
258 #endif /* _BCACHEFS_OPTS_H */