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