1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _BCACHE_FEATURES_H
3 #define _BCACHE_FEATURES_H
5 #include <linux/kernel.h>
6 #include <linux/types.h>
8 #include "bcache_ondisk.h"
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
15 /* Feature set definition */
16 /* Incompat feature set */
17 /* 32bit bucket size, obsoleted */
18 #define BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET 0x0001
19 /* real bucket size is (1 << bucket_size) */
20 #define BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE 0x0002
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)
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))
34 #define BCH_FEATURE_COMPAT_FUNCS(name, flagname) \
35 static inline int bch_has_feature_##name(struct cache_sb *sb) \
37 if (sb->version < BCACHE_SB_VERSION_CDEV_WITH_FEATURES) \
39 return (((sb)->feature_compat & \
40 BCH##_FEATURE_COMPAT_##flagname) != 0); \
42 static inline void bch_set_feature_##name(struct cache_sb *sb) \
44 (sb)->feature_compat |= \
45 BCH##_FEATURE_COMPAT_##flagname; \
47 static inline void bch_clear_feature_##name(struct cache_sb *sb) \
49 (sb)->feature_compat &= \
50 ~BCH##_FEATURE_COMPAT_##flagname; \
53 #define BCH_FEATURE_RO_COMPAT_FUNCS(name, flagname) \
54 static inline int bch_has_feature_##name(struct cache_sb *sb) \
56 if (sb->version < BCACHE_SB_VERSION_CDEV_WITH_FEATURES) \
58 return (((sb)->feature_ro_compat & \
59 BCH##_FEATURE_RO_COMPAT_##flagname) != 0); \
61 static inline void bch_set_feature_##name(struct cache_sb *sb) \
63 (sb)->feature_ro_compat |= \
64 BCH##_FEATURE_RO_COMPAT_##flagname; \
66 static inline void bch_clear_feature_##name(struct cache_sb *sb) \
68 (sb)->feature_ro_compat &= \
69 ~BCH##_FEATURE_RO_COMPAT_##flagname; \
72 #define BCH_FEATURE_INCOMPAT_FUNCS(name, flagname) \
73 static inline int bch_has_feature_##name(struct cache_sb *sb) \
75 if (sb->version < BCACHE_SB_VERSION_CDEV_WITH_FEATURES) \
77 return (((sb)->feature_incompat & \
78 BCH##_FEATURE_INCOMPAT_##flagname) != 0); \
80 static inline void bch_set_feature_##name(struct cache_sb *sb) \
82 (sb)->feature_incompat |= \
83 BCH##_FEATURE_INCOMPAT_##flagname; \
85 static inline void bch_clear_feature_##name(struct cache_sb *sb) \
87 (sb)->feature_incompat &= \
88 ~BCH##_FEATURE_INCOMPAT_##flagname; \
91 BCH_FEATURE_INCOMPAT_FUNCS(obso_large_bucket
, OBSO_LARGE_BUCKET
);
92 BCH_FEATURE_INCOMPAT_FUNCS(large_bucket
, LOG_LARGE_BUCKET_SIZE
);
94 static inline bool bch_has_unknown_compat_features(struct cache_sb
*sb
)
96 return ((sb
->feature_compat
& ~BCH_FEATURE_COMPAT_SUPP
) != 0);
99 static inline bool bch_has_unknown_ro_compat_features(struct cache_sb
*sb
)
101 return ((sb
->feature_ro_compat
& ~BCH_FEATURE_RO_COMPAT_SUPP
) != 0);
104 static inline bool bch_has_unknown_incompat_features(struct cache_sb
*sb
)
106 return ((sb
->feature_incompat
& ~BCH_FEATURE_INCOMPAT_SUPP
) != 0);
109 int bch_print_cache_set_feature_compat(struct cache_set
*c
, char *buf
, int size
);
110 int bch_print_cache_set_feature_ro_compat(struct cache_set
*c
, char *buf
, int size
);
111 int bch_print_cache_set_feature_incompat(struct cache_set
*c
, char *buf
, int size
);