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