bcachefs: Make bkey types globally unique
[linux-block.git] / fs / bcachefs / bkey_methods.h
CommitLineData
1c6fdbd8
KO
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _BCACHEFS_BKEY_METHODS_H
3#define _BCACHEFS_BKEY_METHODS_H
4
5#include "bkey.h"
6
1c6fdbd8
KO
7struct bch_fs;
8struct btree;
9struct bkey;
26609b61
KO
10enum btree_node_type;
11
12extern const char * const bch_bkey_types[];
1c6fdbd8
KO
13
14enum merge_result {
15 BCH_MERGE_NOMERGE,
16
17 /*
18 * The keys were mergeable, but would have overflowed size - so instead
19 * l was changed to the maximum size, and both keys were modified:
20 */
21 BCH_MERGE_PARTIAL,
22 BCH_MERGE_MERGE,
23};
24
1c6fdbd8
KO
25struct bkey_ops {
26 /* Returns reason for being invalid if invalid, else NULL: */
27 const char * (*key_invalid)(const struct bch_fs *,
28 struct bkey_s_c);
29 void (*key_debugcheck)(struct bch_fs *, struct btree *,
30 struct bkey_s_c);
319f9ac3
KO
31 void (*val_to_text)(struct printbuf *, struct bch_fs *,
32 struct bkey_s_c);
1c6fdbd8 33 void (*swab)(const struct bkey_format *, struct bkey_packed *);
26609b61
KO
34 bool (*key_normalize)(struct bch_fs *, struct bkey_s);
35 enum merge_result (*key_merge)(struct bch_fs *,
36 struct bkey_i *, struct bkey_i *);
1c6fdbd8
KO
37};
38
26609b61
KO
39const char *bch2_bkey_val_invalid(struct bch_fs *, struct bkey_s_c);
40const char *__bch2_bkey_invalid(struct bch_fs *, struct bkey_s_c,
41 enum btree_node_type);
42const char *bch2_bkey_invalid(struct bch_fs *, struct bkey_s_c,
43 enum btree_node_type);
1c6fdbd8
KO
44const char *bch2_bkey_in_btree_node(struct btree *, struct bkey_s_c);
45
46void bch2_bkey_debugcheck(struct bch_fs *, struct btree *, struct bkey_s_c);
47
319f9ac3
KO
48void bch2_bpos_to_text(struct printbuf *, struct bpos);
49void bch2_bkey_to_text(struct printbuf *, const struct bkey *);
26609b61 50void bch2_val_to_text(struct printbuf *, struct bch_fs *,
319f9ac3
KO
51 struct bkey_s_c);
52void bch2_bkey_val_to_text(struct printbuf *, struct bch_fs *,
26609b61
KO
53 struct bkey_s_c);
54
55void bch2_bkey_swab(const struct bkey_format *, struct bkey_packed *);
56
57bool bch2_bkey_normalize(struct bch_fs *, struct bkey_s);
1c6fdbd8 58
26609b61
KO
59enum merge_result bch2_bkey_merge(struct bch_fs *,
60 struct bkey_i *, struct bkey_i *);
1c6fdbd8 61
26609b61 62void bch2_bkey_renumber(enum btree_node_type, struct bkey_packed *, int);
1c6fdbd8
KO
63
64#endif /* _BCACHEFS_BKEY_METHODS_H */