xref: /openbmc/linux/drivers/md/bcache/features.h (revision 09a4f6f5)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _BCACHE_FEATURES_H
3 #define _BCACHE_FEATURES_H
4 
5 #include <linux/bcache.h>
6 #include <linux/kernel.h>
7 #include <linux/types.h>
8 
9 #define BCH_FEATURE_COMPAT		0
10 #define BCH_FEATURE_RO_COMPAT		1
11 #define BCH_FEATURE_INCOMPAT		2
12 #define BCH_FEATURE_TYPE_MASK		0x03
13 
14 /* Feature set definition */
15 /* Incompat feature set */
16 /* 32bit bucket size, obsoleted */
17 #define BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET		0x0001
18 /* real bucket size is (1 << bucket_size) */
19 #define BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE	0x0002
20 
21 #define BCH_FEATURE_COMPAT_SUPP		0
22 #define BCH_FEATURE_RO_COMPAT_SUPP	0
23 #define BCH_FEATURE_INCOMPAT_SUPP	(BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET| \
24 					 BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE)
25 
26 #define BCH_HAS_COMPAT_FEATURE(sb, mask) \
27 		((sb)->feature_compat & (mask))
28 #define BCH_HAS_RO_COMPAT_FEATURE(sb, mask) \
29 		((sb)->feature_ro_compat & (mask))
30 #define BCH_HAS_INCOMPAT_FEATURE(sb, mask) \
31 		((sb)->feature_incompat & (mask))
32 
33 #define BCH_FEATURE_COMPAT_FUNCS(name, flagname) \
34 static inline int bch_has_feature_##name(struct cache_sb *sb) \
35 { \
36 	return (((sb)->feature_compat & \
37 		BCH##_FEATURE_COMPAT_##flagname) != 0); \
38 } \
39 static inline void bch_set_feature_##name(struct cache_sb *sb) \
40 { \
41 	(sb)->feature_compat |= \
42 		BCH##_FEATURE_COMPAT_##flagname; \
43 } \
44 static inline void bch_clear_feature_##name(struct cache_sb *sb) \
45 { \
46 	(sb)->feature_compat &= \
47 		~BCH##_FEATURE_COMPAT_##flagname; \
48 }
49 
50 #define BCH_FEATURE_RO_COMPAT_FUNCS(name, flagname) \
51 static inline int bch_has_feature_##name(struct cache_sb *sb) \
52 { \
53 	return (((sb)->feature_ro_compat & \
54 		BCH##_FEATURE_RO_COMPAT_##flagname) != 0); \
55 } \
56 static inline void bch_set_feature_##name(struct cache_sb *sb) \
57 { \
58 	(sb)->feature_ro_compat |= \
59 		BCH##_FEATURE_RO_COMPAT_##flagname; \
60 } \
61 static inline void bch_clear_feature_##name(struct cache_sb *sb) \
62 { \
63 	(sb)->feature_ro_compat &= \
64 		~BCH##_FEATURE_RO_COMPAT_##flagname; \
65 }
66 
67 #define BCH_FEATURE_INCOMPAT_FUNCS(name, flagname) \
68 static inline int bch_has_feature_##name(struct cache_sb *sb) \
69 { \
70 	return (((sb)->feature_incompat & \
71 		BCH##_FEATURE_INCOMPAT_##flagname) != 0); \
72 } \
73 static inline void bch_set_feature_##name(struct cache_sb *sb) \
74 { \
75 	(sb)->feature_incompat |= \
76 		BCH##_FEATURE_INCOMPAT_##flagname; \
77 } \
78 static inline void bch_clear_feature_##name(struct cache_sb *sb) \
79 { \
80 	(sb)->feature_incompat &= \
81 		~BCH##_FEATURE_INCOMPAT_##flagname; \
82 }
83 
84 BCH_FEATURE_INCOMPAT_FUNCS(obso_large_bucket, OBSO_LARGE_BUCKET);
85 BCH_FEATURE_INCOMPAT_FUNCS(large_bucket, LOG_LARGE_BUCKET_SIZE);
86 
87 static inline bool bch_has_unknown_compat_features(struct cache_sb *sb)
88 {
89 	return ((sb->feature_compat & ~BCH_FEATURE_COMPAT_SUPP) != 0);
90 }
91 
92 static inline bool bch_has_unknown_ro_compat_features(struct cache_sb *sb)
93 {
94 	return ((sb->feature_ro_compat & ~BCH_FEATURE_RO_COMPAT_SUPP) != 0);
95 }
96 
97 static inline bool bch_has_unknown_incompat_features(struct cache_sb *sb)
98 {
99 	return ((sb->feature_incompat & ~BCH_FEATURE_INCOMPAT_SUPP) != 0);
100 }
101 
102 int bch_print_cache_set_feature_compat(struct cache_set *c, char *buf, int size);
103 int bch_print_cache_set_feature_ro_compat(struct cache_set *c, char *buf, int size);
104 int bch_print_cache_set_feature_incompat(struct cache_set *c, char *buf, int size);
105 
106 #endif
107