]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/bkey_methods.h
Update bcachefs sources to f026e4e024
[bcachefs-tools-debian] / libbcachefs / bkey_methods.h
1 #ifndef _BCACHE_BKEY_METHODS_H
2 #define _BCACHE_BKEY_METHODS_H
3
4 #include "bkey.h"
5
6 #define DEF_BTREE_ID(kwd, val, name) BKEY_TYPE_##kwd = val,
7
8 enum bkey_type {
9         DEFINE_BCH_BTREE_IDS()
10         BKEY_TYPE_BTREE,
11 };
12
13 /* Type of a key in btree @id at level @level: */
14 static inline enum bkey_type bkey_type(unsigned level, enum btree_id id)
15 {
16         return level ? BKEY_TYPE_BTREE : (enum bkey_type) id;
17 }
18
19 static inline bool btree_type_has_ptrs(enum bkey_type type)
20 {
21         switch (type) {
22         case BKEY_TYPE_BTREE:
23         case BKEY_TYPE_EXTENTS:
24                 return true;
25         default:
26                 return false;
27         }
28 }
29
30 struct bch_fs;
31 struct btree;
32 struct bkey;
33
34 enum merge_result {
35         BCH_MERGE_NOMERGE,
36
37         /*
38          * The keys were mergeable, but would have overflowed size - so instead
39          * l was changed to the maximum size, and both keys were modified:
40          */
41         BCH_MERGE_PARTIAL,
42         BCH_MERGE_MERGE,
43 };
44
45 typedef bool (*key_filter_fn)(struct bch_fs *, struct btree *,
46                               struct bkey_s);
47 typedef enum merge_result (*key_merge_fn)(struct bch_fs *,
48                                           struct btree *,
49                                           struct bkey_i *, struct bkey_i *);
50
51 struct bkey_ops {
52         /* Returns reason for being invalid if invalid, else NULL: */
53         const char *    (*key_invalid)(const struct bch_fs *,
54                                        struct bkey_s_c);
55         void            (*key_debugcheck)(struct bch_fs *, struct btree *,
56                                           struct bkey_s_c);
57         void            (*val_to_text)(struct bch_fs *, char *,
58                                        size_t, struct bkey_s_c);
59         void            (*swab)(const struct bkey_format *, struct bkey_packed *);
60         key_filter_fn   key_normalize;
61         key_merge_fn    key_merge;
62         bool            is_extents;
63 };
64
65 const char *bch2_bkey_invalid(struct bch_fs *, enum bkey_type, struct bkey_s_c);
66 const char *bch2_btree_bkey_invalid(struct bch_fs *, struct btree *,
67                                     struct bkey_s_c);
68
69 void bch2_bkey_debugcheck(struct bch_fs *, struct btree *, struct bkey_s_c);
70 char *bch2_val_to_text(struct bch_fs *, enum bkey_type,
71                        char *, size_t, struct bkey_s_c);
72 char *bch2_bkey_val_to_text(struct bch_fs *, enum bkey_type,
73                             char *, size_t, struct bkey_s_c);
74
75 void bch2_bkey_swab(enum bkey_type, const struct bkey_format *,
76                     struct bkey_packed *);
77
78 extern const struct bkey_ops *bch2_bkey_ops[];
79
80 #undef DEF_BTREE_ID
81
82 #endif /* _BCACHE_BKEY_METHODS_H */