]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/reflink.h
Update bcachefs sources to 400f275d46 bcachefs: Fix check_overlapping_extents()
[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 int bch2_reflink_p_invalid(const struct bch_fs *, struct bkey_s_c,
6                            unsigned, struct printbuf *);
7 void bch2_reflink_p_to_text(struct printbuf *, struct bch_fs *,
8                             struct bkey_s_c);
9 bool bch2_reflink_p_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
10
11 #define bch2_bkey_ops_reflink_p ((struct bkey_ops) {            \
12         .key_invalid    = bch2_reflink_p_invalid,               \
13         .val_to_text    = bch2_reflink_p_to_text,               \
14         .key_merge      = bch2_reflink_p_merge,                 \
15         .trans_trigger  = bch2_trans_mark_reflink_p,            \
16         .atomic_trigger = bch2_mark_reflink_p,                  \
17         .min_val_size   = 16,                                   \
18 })
19
20 int bch2_reflink_v_invalid(const struct bch_fs *, struct bkey_s_c,
21                            unsigned, struct printbuf *);
22 void bch2_reflink_v_to_text(struct printbuf *, struct bch_fs *,
23                             struct bkey_s_c);
24 int bch2_trans_mark_reflink_v(struct btree_trans *, enum btree_id, unsigned,
25                               struct bkey_s_c, struct bkey_i *, unsigned);
26
27 #define bch2_bkey_ops_reflink_v ((struct bkey_ops) {            \
28         .key_invalid    = bch2_reflink_v_invalid,               \
29         .val_to_text    = bch2_reflink_v_to_text,               \
30         .swab           = bch2_ptr_swab,                        \
31         .trans_trigger  = bch2_trans_mark_reflink_v,            \
32         .atomic_trigger = bch2_mark_extent,                     \
33         .min_val_size   = 8,                                    \
34 })
35
36 int bch2_indirect_inline_data_invalid(const struct bch_fs *, struct bkey_s_c,
37                                       unsigned, struct printbuf *);
38 void bch2_indirect_inline_data_to_text(struct printbuf *,
39                                 struct bch_fs *, struct bkey_s_c);
40 int bch2_trans_mark_indirect_inline_data(struct btree_trans *,
41                                          enum btree_id, unsigned,
42                               struct bkey_s_c, struct bkey_i *,
43                               unsigned);
44
45 #define bch2_bkey_ops_indirect_inline_data ((struct bkey_ops) { \
46         .key_invalid    = bch2_indirect_inline_data_invalid,    \
47         .val_to_text    = bch2_indirect_inline_data_to_text,    \
48         .trans_trigger  = bch2_trans_mark_indirect_inline_data, \
49         .min_val_size   = 8,                                    \
50 })
51
52 static inline const __le64 *bkey_refcount_c(struct bkey_s_c k)
53 {
54         switch (k.k->type) {
55         case KEY_TYPE_reflink_v:
56                 return &bkey_s_c_to_reflink_v(k).v->refcount;
57         case KEY_TYPE_indirect_inline_data:
58                 return &bkey_s_c_to_indirect_inline_data(k).v->refcount;
59         default:
60                 return NULL;
61         }
62 }
63
64 static inline __le64 *bkey_refcount(struct bkey_i *k)
65 {
66         switch (k->k.type) {
67         case KEY_TYPE_reflink_v:
68                 return &bkey_i_to_reflink_v(k)->v.refcount;
69         case KEY_TYPE_indirect_inline_data:
70                 return &bkey_i_to_indirect_inline_data(k)->v.refcount;
71         default:
72                 return NULL;
73         }
74 }
75
76 s64 bch2_remap_range(struct bch_fs *, subvol_inum, u64,
77                      subvol_inum, u64, u64, u64, s64 *);
78
79 #endif /* _BCACHEFS_REFLINK_H */