]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/opts.h
Delete more unused shim code, update bcache code
[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_dev_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 bch_fs_alloc() as a whole struct, and then only
26  * apply the options from that struct that are defined.
27  */
28
29 /* dummy option, for options that aren't stored in the superblock */
30 LE64_BITMASK(NO_SB_OPT,         struct bch_sb, flags[0], 0, 0);
31
32 /**
33  * BCH_OPT(name, mode, sb_opt, type, ...)
34  *
35  * @name        - name of mount option, sysfs attribute, and struct bch_opts
36  *                member
37  *
38  * @mode        - sysfs attr permissions
39  *
40  * @sb_option   - name of corresponding superblock option
41  *
42  * @type        - one of OPT_BOOL, OPT_UINT, OPT_STR
43  */
44
45 enum opt_type {
46         BCH_OPT_BOOL,
47         BCH_OPT_UINT,
48         BCH_OPT_STR,
49 };
50
51 #define BCH_VISIBLE_OPTS()                                              \
52         BCH_OPT(errors,                 0644,   BCH_SB_ERROR_ACTION,    \
53                 s8,  OPT_STR(bch_error_actions))                        \
54         BCH_OPT(metadata_replicas,      0444,   BCH_SB_META_REPLICAS_WANT,\
55                 s8,  OPT_UINT(0, BCH_REPLICAS_MAX))                     \
56         BCH_OPT(data_replicas,          0444,   BCH_SB_DATA_REPLICAS_WANT,\
57                 s8,  OPT_UINT(0, BCH_REPLICAS_MAX))                     \
58         BCH_OPT(metadata_checksum,      0644,   BCH_SB_META_CSUM_TYPE,  \
59                 s8,  OPT_STR(bch_csum_types))                           \
60         BCH_OPT(data_checksum,          0644,   BCH_SB_DATA_CSUM_TYPE,  \
61                 s8,  OPT_STR(bch_csum_types))                           \
62         BCH_OPT(compression,            0644,   BCH_SB_COMPRESSION_TYPE,\
63                 s8,  OPT_STR(bch_compression_types))                    \
64         BCH_OPT(str_hash,               0644,   BCH_SB_STR_HASH_TYPE,   \
65                 s8,  OPT_STR(bch_str_hash_types))                       \
66         BCH_OPT(inodes_32bit,           0644,   BCH_SB_INODE_32BIT,     \
67                 s8,  OPT_BOOL())                                        \
68         BCH_OPT(gc_reserve_percent,     0444,   BCH_SB_GC_RESERVE,      \
69                 s8,  OPT_UINT(5, 21))                                   \
70         BCH_OPT(root_reserve_percent,   0444,   BCH_SB_ROOT_RESERVE,    \
71                 s8,  OPT_UINT(0, 100))                                  \
72         BCH_OPT(wide_macs,              0644,   BCH_SB_128_BIT_MACS,    \
73                 s8,  OPT_BOOL())                                        \
74         BCH_OPT(verbose_recovery,       0444,   NO_SB_OPT,              \
75                 s8,  OPT_BOOL())                                        \
76         BCH_OPT(posix_acl,              0444,   NO_SB_OPT,              \
77                 s8,  OPT_BOOL())                                        \
78         BCH_OPT(journal_flush_disabled, 0644,   NO_SB_OPT,              \
79                 s8,  OPT_BOOL())                                        \
80         BCH_OPT(nofsck,                 0444,   NO_SB_OPT,              \
81                 s8,  OPT_BOOL())                                        \
82         BCH_OPT(fix_errors,             0444,   NO_SB_OPT,              \
83                 s8,  OPT_BOOL())                                        \
84         BCH_OPT(nochanges,              0444,   NO_SB_OPT,              \
85                 s8,  OPT_BOOL())                                        \
86         BCH_OPT(noreplay,               0444,   NO_SB_OPT,              \
87                 s8,  OPT_BOOL())                                        \
88         BCH_OPT(norecovery,             0444,   NO_SB_OPT,              \
89                 s8,  OPT_BOOL())
90
91 #define BCH_OPTS()                                                      \
92         BCH_OPT(read_only,              0444,   NO_SB_OPT,              \
93                 s8,  OPT_BOOL())                                        \
94         BCH_VISIBLE_OPTS()
95
96 struct bch_opts {
97 #define BCH_OPT(_name, _mode, _sb_opt, _bits, ...)                      \
98         _bits   _name;
99
100         BCH_OPTS()
101 #undef BCH_OPT
102 };
103
104 enum bch_opt_id {
105 #define BCH_OPT(_name, ...)                     \
106         Opt_##_name,
107
108         BCH_VISIBLE_OPTS()
109 #undef BCH_OPT
110 };
111
112 struct bch_option {
113         const char              *name;
114         void                    (*set_sb)(struct bch_sb *, u64);
115         enum opt_type           type;
116
117         union {
118         struct {
119                 u64             min, max;
120         };
121         struct {
122                 const char * const *choices;
123         };
124         };
125
126 };
127
128 extern const struct bch_option bch_opt_table[];
129
130 static inline struct bch_opts bch_opts_empty(void)
131 {
132         struct bch_opts ret;
133
134         memset(&ret, 255, sizeof(ret));
135         return ret;
136 }
137
138 static inline void bch_opts_apply(struct bch_opts *dst, struct bch_opts src)
139 {
140 #define BCH_OPT(_name, ...)                     \
141         if (src._name >= 0)                                             \
142                 dst->_name = src._name;
143
144         BCH_OPTS()
145 #undef BCH_OPT
146 }
147
148 void bch_opt_set(struct bch_opts *, enum bch_opt_id, u64);
149 struct bch_opts bch_sb_opts(struct bch_sb *);
150
151 int bch_parse_mount_opts(struct bch_opts *, char *);
152 enum bch_opt_id bch_parse_sysfs_opt(const char *, const char *, u64 *);
153
154 ssize_t bch_opt_show(struct bch_opts *, const char *, char *, size_t);
155
156 #endif /* _BCACHE_OPTS_H */