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