]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/bkey_methods.h
Update bcachefs sources to d7dbddc450 bcachefs: revamp to_text methods
[bcachefs-tools-debian] / libbcachefs / bkey_methods.h
1 #ifndef _BCACHEFS_BKEY_METHODS_H
2 #define _BCACHEFS_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 #undef DEF_BTREE_ID
14
15 /* Type of a key in btree @id at level @level: */
16 static inline enum bkey_type bkey_type(unsigned level, enum btree_id id)
17 {
18         return level ? BKEY_TYPE_BTREE : (enum bkey_type) id;
19 }
20
21 struct bch_fs;
22 struct btree;
23 struct bkey;
24
25 enum merge_result {
26         BCH_MERGE_NOMERGE,
27
28         /*
29          * The keys were mergeable, but would have overflowed size - so instead
30          * l was changed to the maximum size, and both keys were modified:
31          */
32         BCH_MERGE_PARTIAL,
33         BCH_MERGE_MERGE,
34 };
35
36 typedef bool (*key_filter_fn)(struct bch_fs *, struct btree *,
37                               struct bkey_s);
38 typedef enum merge_result (*key_merge_fn)(struct bch_fs *,
39                                           struct btree *,
40                                           struct bkey_i *, struct bkey_i *);
41
42 struct bkey_ops {
43         /* Returns reason for being invalid if invalid, else NULL: */
44         const char *    (*key_invalid)(const struct bch_fs *,
45                                        struct bkey_s_c);
46         void            (*key_debugcheck)(struct bch_fs *, struct btree *,
47                                           struct bkey_s_c);
48         void            (*val_to_text)(struct printbuf *, struct bch_fs *,
49                                        struct bkey_s_c);
50         void            (*swab)(const struct bkey_format *, struct bkey_packed *);
51         key_filter_fn   key_normalize;
52         key_merge_fn    key_merge;
53         bool            is_extents;
54 };
55
56 const char *bch2_bkey_val_invalid(struct bch_fs *, enum bkey_type,
57                                   struct bkey_s_c);
58 const char *__bch2_bkey_invalid(struct bch_fs *, enum bkey_type, struct bkey_s_c);
59 const char *bch2_bkey_invalid(struct bch_fs *, enum bkey_type, struct bkey_s_c);
60 const char *bch2_bkey_in_btree_node(struct btree *, struct bkey_s_c);
61
62 void bch2_bkey_debugcheck(struct bch_fs *, struct btree *, struct bkey_s_c);
63
64 void bch2_bpos_to_text(struct printbuf *, struct bpos);
65 void bch2_bkey_to_text(struct printbuf *, const struct bkey *);
66 void bch2_val_to_text(struct printbuf *, struct bch_fs *, enum bkey_type,
67                       struct bkey_s_c);
68 void bch2_bkey_val_to_text(struct printbuf *, struct bch_fs *,
69                            enum bkey_type, struct bkey_s_c);
70
71 void bch2_bkey_swab(enum bkey_type, const struct bkey_format *,
72                     struct bkey_packed *);
73
74 extern const struct bkey_ops bch2_bkey_ops[];
75
76 #endif /* _BCACHEFS_BKEY_METHODS_H */