]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/reflink.h
3745873fd88d90947f610de256931cecec4d9181
[bcachefs-tools-debian] / libbcachefs / reflink.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_REFLINK_H
3 #define _BCACHEFS_REFLINK_H
4
5 const char *bch2_reflink_p_invalid(const struct bch_fs *, struct bkey_s_c);
6 void bch2_reflink_p_to_text(struct printbuf *, struct bch_fs *,
7                             struct bkey_s_c);
8 bool bch2_reflink_p_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
9
10 #define bch2_bkey_ops_reflink_p (struct bkey_ops) {             \
11         .key_invalid    = bch2_reflink_p_invalid,               \
12         .val_to_text    = bch2_reflink_p_to_text,               \
13         .key_merge      = bch2_reflink_p_merge,         \
14 }
15
16 const char *bch2_reflink_v_invalid(const struct bch_fs *, struct bkey_s_c);
17 void bch2_reflink_v_to_text(struct printbuf *, struct bch_fs *,
18                             struct bkey_s_c);
19
20 #define bch2_bkey_ops_reflink_v (struct bkey_ops) {             \
21         .key_invalid    = bch2_reflink_v_invalid,               \
22         .val_to_text    = bch2_reflink_v_to_text,               \
23         .swab           = bch2_ptr_swab,                        \
24 }
25
26 const char *bch2_indirect_inline_data_invalid(const struct bch_fs *,
27                                               struct bkey_s_c);
28 void bch2_indirect_inline_data_to_text(struct printbuf *,
29                                 struct bch_fs *, struct bkey_s_c);
30
31 #define bch2_bkey_ops_indirect_inline_data (struct bkey_ops) {  \
32         .key_invalid    = bch2_indirect_inline_data_invalid,    \
33         .val_to_text    = bch2_indirect_inline_data_to_text,    \
34 }
35
36 static inline const __le64 *bkey_refcount_c(struct bkey_s_c k)
37 {
38         switch (k.k->type) {
39         case KEY_TYPE_reflink_v:
40                 return &bkey_s_c_to_reflink_v(k).v->refcount;
41         case KEY_TYPE_indirect_inline_data:
42                 return &bkey_s_c_to_indirect_inline_data(k).v->refcount;
43         default:
44                 return NULL;
45         }
46 }
47
48 static inline __le64 *bkey_refcount(struct bkey_i *k)
49 {
50         switch (k->k.type) {
51         case KEY_TYPE_reflink_v:
52                 return &bkey_i_to_reflink_v(k)->v.refcount;
53         case KEY_TYPE_indirect_inline_data:
54                 return &bkey_i_to_indirect_inline_data(k)->v.refcount;
55         default:
56                 return NULL;
57         }
58 }
59
60 s64 bch2_remap_range(struct bch_fs *, subvol_inum, u64,
61                      subvol_inum, u64, u64, u64, s64 *);
62
63 #endif /* _BCACHEFS_REFLINK_H */