]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/opts.h
1d30848f775a79672fadbbbd6b1fc01aee5aaaa6
[bcachefs-tools-debian] / libbcache / opts.h
1 #ifndef _BCACHE_OPTS_H
2 #define _BCACHE_OPTS_H
3
4 #include <linux/bcache.h>
5 #include <linux/bug.h>
6 #include <linux/log2.h>
7 #include <linux/string.h>
8
9 extern const char * const bch_error_actions[];
10 extern const char * const bch_csum_types[];
11 extern const char * const bch_compression_types[];
12 extern const char * const bch_str_hash_types[];
13 extern const char * const bch_cache_replacement_policies[];
14 extern const char * const bch_cache_modes[];
15 extern const char * const bch_cache_state[];
16
17 /*
18  * Mount options; we also store defaults in the superblock.
19  *
20  * Also exposed via sysfs: if an option is writeable, and it's also stored in
21  * the superblock, changing it via sysfs (currently? might change this) also
22  * updates the superblock.
23  *
24  * We store options as signed integers, where -1 means undefined. This means we
25  * can pass the mount options to cache_set_alloc() as a whole struct, and then
26  * only apply the options from that struct that are defined.
27  */
28
29 extern const char * const bch_bool_opt[];
30 extern const char * const bch_uint_opt[];
31
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);
34
35 #define BCH_VISIBLE_OPTS()                                      \
36         BCH_OPT(verbose_recovery,                               \
37                 bch_bool_opt, 0, 2,                             \
38                 NO_SB_OPT, false)                               \
39         BCH_OPT(posix_acl,                                      \
40                 bch_bool_opt, 0, 2,                             \
41                 NO_SB_OPT, false)                               \
42         BCH_OPT(journal_flush_disabled,                         \
43                 bch_bool_opt, 0, 2,                             \
44                 NO_SB_OPT, true)                                \
45         BCH_OPT(nofsck,                                         \
46                 bch_bool_opt, 0, 2,                             \
47                 NO_SB_OPT, true)                                \
48         BCH_OPT(fix_errors,                                     \
49                 bch_bool_opt, 0, 2,                             \
50                 NO_SB_OPT, true)                                \
51         BCH_OPT(nochanges,                                      \
52                 bch_bool_opt, 0, 2,                             \
53                 NO_SB_OPT, 0)                                   \
54         BCH_OPT(noreplay,                                       \
55                 bch_bool_opt, 0, 2,                             \
56                 NO_SB_OPT, 0)                                   \
57         BCH_OPT(norecovery,                                     \
58                 bch_bool_opt, 0, 2,                             \
59                 NO_SB_OPT, 0)                                   \
60         BCH_SB_OPTS()
61
62 #define BCH_OPTS()                                              \
63         BCH_OPT(read_only,                                      \
64                 bch_bool_opt, 0, 2,                             \
65                 NO_SB_OPT, 0)                                   \
66         BCH_VISIBLE_OPTS()
67
68 struct cache_set_opts {
69 #define BCH_OPT(_name, _choices, _min, _max, _sb_opt, _perm)\
70         s8 _name;
71
72         BCH_OPTS()
73 #undef BCH_OPT
74 };
75
76 static inline struct cache_set_opts cache_set_opts_empty(void)
77 {
78         struct cache_set_opts ret;
79
80         memset(&ret, 255, sizeof(ret));
81         return ret;
82 }
83
84 /*
85  * Initial options from superblock - here we don't want any options undefined,
86  * any options the superblock doesn't specify are set to 0:
87  */
88 static inline struct cache_set_opts cache_superblock_opts(struct bch_sb *sb)
89 {
90         return (struct cache_set_opts) {
91 #define BCH_OPT(_name, _choices, _min, _max, _sb_opt, _perm)\
92                 ._name = _sb_opt##_BITS ? _sb_opt(sb) : 0,
93
94         BCH_SB_OPTS()
95 #undef BCH_OPT
96         };
97 }
98
99 static inline void cache_set_opts_apply(struct cache_set_opts *dst,
100                                         struct cache_set_opts src)
101 {
102 #define BCH_OPT(_name, _choices, _min, _max, _sb_opt, _perm)\
103         BUILD_BUG_ON(_max > S8_MAX);                            \
104         if (src._name >= 0)                                     \
105                 dst->_name = src._name;
106
107         BCH_SB_OPTS()
108 #undef BCH_OPT
109 }
110
111 int bch_parse_options(struct cache_set_opts *, int, char *);
112
113 #endif /* _BCACHE_OPTS_H */