1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (C) 2008 Oracle. All rights reserved.
4*4882a593Smuzhiyun */
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun #ifndef BTRFS_DELAYED_REF_H
7*4882a593Smuzhiyun #define BTRFS_DELAYED_REF_H
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <linux/refcount.h>
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun /* these are the possible values of struct btrfs_delayed_ref_node->action */
12*4882a593Smuzhiyun #define BTRFS_ADD_DELAYED_REF 1 /* add one backref to the tree */
13*4882a593Smuzhiyun #define BTRFS_DROP_DELAYED_REF 2 /* delete one backref from the tree */
14*4882a593Smuzhiyun #define BTRFS_ADD_DELAYED_EXTENT 3 /* record a full extent allocation */
15*4882a593Smuzhiyun #define BTRFS_UPDATE_DELAYED_HEAD 4 /* not changing ref count on head ref */
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun struct btrfs_delayed_ref_node {
18*4882a593Smuzhiyun struct rb_node ref_node;
19*4882a593Smuzhiyun /*
20*4882a593Smuzhiyun * If action is BTRFS_ADD_DELAYED_REF, also link this node to
21*4882a593Smuzhiyun * ref_head->ref_add_list, then we do not need to iterate the
22*4882a593Smuzhiyun * whole ref_head->ref_list to find BTRFS_ADD_DELAYED_REF nodes.
23*4882a593Smuzhiyun */
24*4882a593Smuzhiyun struct list_head add_list;
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun /* the starting bytenr of the extent */
27*4882a593Smuzhiyun u64 bytenr;
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /* the size of the extent */
30*4882a593Smuzhiyun u64 num_bytes;
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun /* seq number to keep track of insertion order */
33*4882a593Smuzhiyun u64 seq;
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun /* ref count on this data structure */
36*4882a593Smuzhiyun refcount_t refs;
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /*
39*4882a593Smuzhiyun * how many refs is this entry adding or deleting. For
40*4882a593Smuzhiyun * head refs, this may be a negative number because it is keeping
41*4882a593Smuzhiyun * track of the total mods done to the reference count.
42*4882a593Smuzhiyun * For individual refs, this will always be a positive number
43*4882a593Smuzhiyun *
44*4882a593Smuzhiyun * It may be more than one, since it is possible for a single
45*4882a593Smuzhiyun * parent to have more than one ref on an extent
46*4882a593Smuzhiyun */
47*4882a593Smuzhiyun int ref_mod;
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun unsigned int action:8;
50*4882a593Smuzhiyun unsigned int type:8;
51*4882a593Smuzhiyun /* is this node still in the rbtree? */
52*4882a593Smuzhiyun unsigned int is_head:1;
53*4882a593Smuzhiyun unsigned int in_tree:1;
54*4882a593Smuzhiyun };
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun struct btrfs_delayed_extent_op {
57*4882a593Smuzhiyun struct btrfs_disk_key key;
58*4882a593Smuzhiyun u8 level;
59*4882a593Smuzhiyun bool update_key;
60*4882a593Smuzhiyun bool update_flags;
61*4882a593Smuzhiyun bool is_data;
62*4882a593Smuzhiyun u64 flags_to_set;
63*4882a593Smuzhiyun };
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun /*
66*4882a593Smuzhiyun * the head refs are used to hold a lock on a given extent, which allows us
67*4882a593Smuzhiyun * to make sure that only one process is running the delayed refs
68*4882a593Smuzhiyun * at a time for a single extent. They also store the sum of all the
69*4882a593Smuzhiyun * reference count modifications we've queued up.
70*4882a593Smuzhiyun */
71*4882a593Smuzhiyun struct btrfs_delayed_ref_head {
72*4882a593Smuzhiyun u64 bytenr;
73*4882a593Smuzhiyun u64 num_bytes;
74*4882a593Smuzhiyun refcount_t refs;
75*4882a593Smuzhiyun /*
76*4882a593Smuzhiyun * the mutex is held while running the refs, and it is also
77*4882a593Smuzhiyun * held when checking the sum of reference modifications.
78*4882a593Smuzhiyun */
79*4882a593Smuzhiyun struct mutex mutex;
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun spinlock_t lock;
82*4882a593Smuzhiyun struct rb_root_cached ref_tree;
83*4882a593Smuzhiyun /* accumulate add BTRFS_ADD_DELAYED_REF nodes to this ref_add_list. */
84*4882a593Smuzhiyun struct list_head ref_add_list;
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun struct rb_node href_node;
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun struct btrfs_delayed_extent_op *extent_op;
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun /*
91*4882a593Smuzhiyun * This is used to track the final ref_mod from all the refs associated
92*4882a593Smuzhiyun * with this head ref, this is not adjusted as delayed refs are run,
93*4882a593Smuzhiyun * this is meant to track if we need to do the csum accounting or not.
94*4882a593Smuzhiyun */
95*4882a593Smuzhiyun int total_ref_mod;
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun /*
98*4882a593Smuzhiyun * This is the current outstanding mod references for this bytenr. This
99*4882a593Smuzhiyun * is used with lookup_extent_info to get an accurate reference count
100*4882a593Smuzhiyun * for a bytenr, so it is adjusted as delayed refs are run so that any
101*4882a593Smuzhiyun * on disk reference count + ref_mod is accurate.
102*4882a593Smuzhiyun */
103*4882a593Smuzhiyun int ref_mod;
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun /*
106*4882a593Smuzhiyun * when a new extent is allocated, it is just reserved in memory
107*4882a593Smuzhiyun * The actual extent isn't inserted into the extent allocation tree
108*4882a593Smuzhiyun * until the delayed ref is processed. must_insert_reserved is
109*4882a593Smuzhiyun * used to flag a delayed ref so the accounting can be updated
110*4882a593Smuzhiyun * when a full insert is done.
111*4882a593Smuzhiyun *
112*4882a593Smuzhiyun * It is possible the extent will be freed before it is ever
113*4882a593Smuzhiyun * inserted into the extent allocation tree. In this case
114*4882a593Smuzhiyun * we need to update the in ram accounting to properly reflect
115*4882a593Smuzhiyun * the free has happened.
116*4882a593Smuzhiyun */
117*4882a593Smuzhiyun unsigned int must_insert_reserved:1;
118*4882a593Smuzhiyun unsigned int is_data:1;
119*4882a593Smuzhiyun unsigned int is_system:1;
120*4882a593Smuzhiyun unsigned int processing:1;
121*4882a593Smuzhiyun };
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun struct btrfs_delayed_tree_ref {
124*4882a593Smuzhiyun struct btrfs_delayed_ref_node node;
125*4882a593Smuzhiyun u64 root;
126*4882a593Smuzhiyun u64 parent;
127*4882a593Smuzhiyun int level;
128*4882a593Smuzhiyun };
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun struct btrfs_delayed_data_ref {
131*4882a593Smuzhiyun struct btrfs_delayed_ref_node node;
132*4882a593Smuzhiyun u64 root;
133*4882a593Smuzhiyun u64 parent;
134*4882a593Smuzhiyun u64 objectid;
135*4882a593Smuzhiyun u64 offset;
136*4882a593Smuzhiyun };
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun struct btrfs_delayed_ref_root {
139*4882a593Smuzhiyun /* head ref rbtree */
140*4882a593Smuzhiyun struct rb_root_cached href_root;
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun /* dirty extent records */
143*4882a593Smuzhiyun struct rb_root dirty_extent_root;
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun /* this spin lock protects the rbtree and the entries inside */
146*4882a593Smuzhiyun spinlock_t lock;
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun /* how many delayed ref updates we've queued, used by the
149*4882a593Smuzhiyun * throttling code
150*4882a593Smuzhiyun */
151*4882a593Smuzhiyun atomic_t num_entries;
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun /* total number of head nodes in tree */
154*4882a593Smuzhiyun unsigned long num_heads;
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun /* total number of head nodes ready for processing */
157*4882a593Smuzhiyun unsigned long num_heads_ready;
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun u64 pending_csums;
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun /*
162*4882a593Smuzhiyun * set when the tree is flushing before a transaction commit,
163*4882a593Smuzhiyun * used by the throttling code to decide if new updates need
164*4882a593Smuzhiyun * to be run right away
165*4882a593Smuzhiyun */
166*4882a593Smuzhiyun int flushing;
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun u64 run_delayed_start;
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun /*
171*4882a593Smuzhiyun * To make qgroup to skip given root.
172*4882a593Smuzhiyun * This is for snapshot, as btrfs_qgroup_inherit() will manually
173*4882a593Smuzhiyun * modify counters for snapshot and its source, so we should skip
174*4882a593Smuzhiyun * the snapshot in new_root/old_roots or it will get calculated twice
175*4882a593Smuzhiyun */
176*4882a593Smuzhiyun u64 qgroup_to_skip;
177*4882a593Smuzhiyun };
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun enum btrfs_ref_type {
180*4882a593Smuzhiyun BTRFS_REF_NOT_SET,
181*4882a593Smuzhiyun BTRFS_REF_DATA,
182*4882a593Smuzhiyun BTRFS_REF_METADATA,
183*4882a593Smuzhiyun BTRFS_REF_LAST,
184*4882a593Smuzhiyun };
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun struct btrfs_data_ref {
187*4882a593Smuzhiyun /* For EXTENT_DATA_REF */
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun /* Root which refers to this data extent */
190*4882a593Smuzhiyun u64 ref_root;
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun /* Inode which refers to this data extent */
193*4882a593Smuzhiyun u64 ino;
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun /*
196*4882a593Smuzhiyun * file_offset - extent_offset
197*4882a593Smuzhiyun *
198*4882a593Smuzhiyun * file_offset is the key.offset of the EXTENT_DATA key.
199*4882a593Smuzhiyun * extent_offset is btrfs_file_extent_offset() of the EXTENT_DATA data.
200*4882a593Smuzhiyun */
201*4882a593Smuzhiyun u64 offset;
202*4882a593Smuzhiyun };
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun struct btrfs_tree_ref {
205*4882a593Smuzhiyun /*
206*4882a593Smuzhiyun * Level of this tree block
207*4882a593Smuzhiyun *
208*4882a593Smuzhiyun * Shared for skinny (TREE_BLOCK_REF) and normal tree ref.
209*4882a593Smuzhiyun */
210*4882a593Smuzhiyun int level;
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun /*
213*4882a593Smuzhiyun * Root which refers to this tree block.
214*4882a593Smuzhiyun *
215*4882a593Smuzhiyun * For TREE_BLOCK_REF (skinny metadata, either inline or keyed)
216*4882a593Smuzhiyun */
217*4882a593Smuzhiyun u64 root;
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun /* For non-skinny metadata, no special member needed */
220*4882a593Smuzhiyun };
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun struct btrfs_ref {
223*4882a593Smuzhiyun enum btrfs_ref_type type;
224*4882a593Smuzhiyun int action;
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun /*
227*4882a593Smuzhiyun * Whether this extent should go through qgroup record.
228*4882a593Smuzhiyun *
229*4882a593Smuzhiyun * Normally false, but for certain cases like delayed subtree scan,
230*4882a593Smuzhiyun * setting this flag can hugely reduce qgroup overhead.
231*4882a593Smuzhiyun */
232*4882a593Smuzhiyun bool skip_qgroup;
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun /*
235*4882a593Smuzhiyun * Optional. For which root is this modification.
236*4882a593Smuzhiyun * Mostly used for qgroup optimization.
237*4882a593Smuzhiyun *
238*4882a593Smuzhiyun * When unset, data/tree ref init code will populate it.
239*4882a593Smuzhiyun * In certain cases, we're modifying reference for a different root.
240*4882a593Smuzhiyun * E.g. COW fs tree blocks for balance.
241*4882a593Smuzhiyun * In that case, tree_ref::root will be fs tree, but we're doing this
242*4882a593Smuzhiyun * for reloc tree, then we should set @real_root to reloc tree.
243*4882a593Smuzhiyun */
244*4882a593Smuzhiyun u64 real_root;
245*4882a593Smuzhiyun u64 bytenr;
246*4882a593Smuzhiyun u64 len;
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun /* Bytenr of the parent tree block */
249*4882a593Smuzhiyun u64 parent;
250*4882a593Smuzhiyun union {
251*4882a593Smuzhiyun struct btrfs_data_ref data_ref;
252*4882a593Smuzhiyun struct btrfs_tree_ref tree_ref;
253*4882a593Smuzhiyun };
254*4882a593Smuzhiyun };
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun extern struct kmem_cache *btrfs_delayed_ref_head_cachep;
257*4882a593Smuzhiyun extern struct kmem_cache *btrfs_delayed_tree_ref_cachep;
258*4882a593Smuzhiyun extern struct kmem_cache *btrfs_delayed_data_ref_cachep;
259*4882a593Smuzhiyun extern struct kmem_cache *btrfs_delayed_extent_op_cachep;
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun int __init btrfs_delayed_ref_init(void);
262*4882a593Smuzhiyun void __cold btrfs_delayed_ref_exit(void);
263*4882a593Smuzhiyun
btrfs_init_generic_ref(struct btrfs_ref * generic_ref,int action,u64 bytenr,u64 len,u64 parent)264*4882a593Smuzhiyun static inline void btrfs_init_generic_ref(struct btrfs_ref *generic_ref,
265*4882a593Smuzhiyun int action, u64 bytenr, u64 len, u64 parent)
266*4882a593Smuzhiyun {
267*4882a593Smuzhiyun generic_ref->action = action;
268*4882a593Smuzhiyun generic_ref->bytenr = bytenr;
269*4882a593Smuzhiyun generic_ref->len = len;
270*4882a593Smuzhiyun generic_ref->parent = parent;
271*4882a593Smuzhiyun }
272*4882a593Smuzhiyun
btrfs_init_tree_ref(struct btrfs_ref * generic_ref,int level,u64 root)273*4882a593Smuzhiyun static inline void btrfs_init_tree_ref(struct btrfs_ref *generic_ref,
274*4882a593Smuzhiyun int level, u64 root)
275*4882a593Smuzhiyun {
276*4882a593Smuzhiyun /* If @real_root not set, use @root as fallback */
277*4882a593Smuzhiyun if (!generic_ref->real_root)
278*4882a593Smuzhiyun generic_ref->real_root = root;
279*4882a593Smuzhiyun generic_ref->tree_ref.level = level;
280*4882a593Smuzhiyun generic_ref->tree_ref.root = root;
281*4882a593Smuzhiyun generic_ref->type = BTRFS_REF_METADATA;
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun
btrfs_init_data_ref(struct btrfs_ref * generic_ref,u64 ref_root,u64 ino,u64 offset)284*4882a593Smuzhiyun static inline void btrfs_init_data_ref(struct btrfs_ref *generic_ref,
285*4882a593Smuzhiyun u64 ref_root, u64 ino, u64 offset)
286*4882a593Smuzhiyun {
287*4882a593Smuzhiyun /* If @real_root not set, use @root as fallback */
288*4882a593Smuzhiyun if (!generic_ref->real_root)
289*4882a593Smuzhiyun generic_ref->real_root = ref_root;
290*4882a593Smuzhiyun generic_ref->data_ref.ref_root = ref_root;
291*4882a593Smuzhiyun generic_ref->data_ref.ino = ino;
292*4882a593Smuzhiyun generic_ref->data_ref.offset = offset;
293*4882a593Smuzhiyun generic_ref->type = BTRFS_REF_DATA;
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun static inline struct btrfs_delayed_extent_op *
btrfs_alloc_delayed_extent_op(void)297*4882a593Smuzhiyun btrfs_alloc_delayed_extent_op(void)
298*4882a593Smuzhiyun {
299*4882a593Smuzhiyun return kmem_cache_alloc(btrfs_delayed_extent_op_cachep, GFP_NOFS);
300*4882a593Smuzhiyun }
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun static inline void
btrfs_free_delayed_extent_op(struct btrfs_delayed_extent_op * op)303*4882a593Smuzhiyun btrfs_free_delayed_extent_op(struct btrfs_delayed_extent_op *op)
304*4882a593Smuzhiyun {
305*4882a593Smuzhiyun if (op)
306*4882a593Smuzhiyun kmem_cache_free(btrfs_delayed_extent_op_cachep, op);
307*4882a593Smuzhiyun }
308*4882a593Smuzhiyun
btrfs_put_delayed_ref(struct btrfs_delayed_ref_node * ref)309*4882a593Smuzhiyun static inline void btrfs_put_delayed_ref(struct btrfs_delayed_ref_node *ref)
310*4882a593Smuzhiyun {
311*4882a593Smuzhiyun WARN_ON(refcount_read(&ref->refs) == 0);
312*4882a593Smuzhiyun if (refcount_dec_and_test(&ref->refs)) {
313*4882a593Smuzhiyun WARN_ON(ref->in_tree);
314*4882a593Smuzhiyun switch (ref->type) {
315*4882a593Smuzhiyun case BTRFS_TREE_BLOCK_REF_KEY:
316*4882a593Smuzhiyun case BTRFS_SHARED_BLOCK_REF_KEY:
317*4882a593Smuzhiyun kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref);
318*4882a593Smuzhiyun break;
319*4882a593Smuzhiyun case BTRFS_EXTENT_DATA_REF_KEY:
320*4882a593Smuzhiyun case BTRFS_SHARED_DATA_REF_KEY:
321*4882a593Smuzhiyun kmem_cache_free(btrfs_delayed_data_ref_cachep, ref);
322*4882a593Smuzhiyun break;
323*4882a593Smuzhiyun default:
324*4882a593Smuzhiyun BUG();
325*4882a593Smuzhiyun }
326*4882a593Smuzhiyun }
327*4882a593Smuzhiyun }
328*4882a593Smuzhiyun
btrfs_ref_head_to_space_flags(struct btrfs_delayed_ref_head * head_ref)329*4882a593Smuzhiyun static inline u64 btrfs_ref_head_to_space_flags(
330*4882a593Smuzhiyun struct btrfs_delayed_ref_head *head_ref)
331*4882a593Smuzhiyun {
332*4882a593Smuzhiyun if (head_ref->is_data)
333*4882a593Smuzhiyun return BTRFS_BLOCK_GROUP_DATA;
334*4882a593Smuzhiyun else if (head_ref->is_system)
335*4882a593Smuzhiyun return BTRFS_BLOCK_GROUP_SYSTEM;
336*4882a593Smuzhiyun return BTRFS_BLOCK_GROUP_METADATA;
337*4882a593Smuzhiyun }
338*4882a593Smuzhiyun
btrfs_put_delayed_ref_head(struct btrfs_delayed_ref_head * head)339*4882a593Smuzhiyun static inline void btrfs_put_delayed_ref_head(struct btrfs_delayed_ref_head *head)
340*4882a593Smuzhiyun {
341*4882a593Smuzhiyun if (refcount_dec_and_test(&head->refs))
342*4882a593Smuzhiyun kmem_cache_free(btrfs_delayed_ref_head_cachep, head);
343*4882a593Smuzhiyun }
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
346*4882a593Smuzhiyun struct btrfs_ref *generic_ref,
347*4882a593Smuzhiyun struct btrfs_delayed_extent_op *extent_op);
348*4882a593Smuzhiyun int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans,
349*4882a593Smuzhiyun struct btrfs_ref *generic_ref,
350*4882a593Smuzhiyun u64 reserved);
351*4882a593Smuzhiyun int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans,
352*4882a593Smuzhiyun u64 bytenr, u64 num_bytes,
353*4882a593Smuzhiyun struct btrfs_delayed_extent_op *extent_op);
354*4882a593Smuzhiyun void btrfs_merge_delayed_refs(struct btrfs_trans_handle *trans,
355*4882a593Smuzhiyun struct btrfs_delayed_ref_root *delayed_refs,
356*4882a593Smuzhiyun struct btrfs_delayed_ref_head *head);
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun struct btrfs_delayed_ref_head *
359*4882a593Smuzhiyun btrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs,
360*4882a593Smuzhiyun u64 bytenr);
361*4882a593Smuzhiyun int btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs,
362*4882a593Smuzhiyun struct btrfs_delayed_ref_head *head);
btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head * head)363*4882a593Smuzhiyun static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head)
364*4882a593Smuzhiyun {
365*4882a593Smuzhiyun mutex_unlock(&head->mutex);
366*4882a593Smuzhiyun }
367*4882a593Smuzhiyun void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs,
368*4882a593Smuzhiyun struct btrfs_delayed_ref_head *head);
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun struct btrfs_delayed_ref_head *btrfs_select_ref_head(
371*4882a593Smuzhiyun struct btrfs_delayed_ref_root *delayed_refs);
372*4882a593Smuzhiyun
373*4882a593Smuzhiyun int btrfs_check_delayed_seq(struct btrfs_fs_info *fs_info, u64 seq);
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun void btrfs_delayed_refs_rsv_release(struct btrfs_fs_info *fs_info, int nr);
376*4882a593Smuzhiyun void btrfs_update_delayed_refs_rsv(struct btrfs_trans_handle *trans);
377*4882a593Smuzhiyun int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info,
378*4882a593Smuzhiyun enum btrfs_reserve_flush_enum flush);
379*4882a593Smuzhiyun void btrfs_migrate_to_delayed_refs_rsv(struct btrfs_fs_info *fs_info,
380*4882a593Smuzhiyun struct btrfs_block_rsv *src,
381*4882a593Smuzhiyun u64 num_bytes);
382*4882a593Smuzhiyun int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans);
383*4882a593Smuzhiyun bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info);
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun /*
386*4882a593Smuzhiyun * helper functions to cast a node into its container
387*4882a593Smuzhiyun */
388*4882a593Smuzhiyun static inline struct btrfs_delayed_tree_ref *
btrfs_delayed_node_to_tree_ref(struct btrfs_delayed_ref_node * node)389*4882a593Smuzhiyun btrfs_delayed_node_to_tree_ref(struct btrfs_delayed_ref_node *node)
390*4882a593Smuzhiyun {
391*4882a593Smuzhiyun return container_of(node, struct btrfs_delayed_tree_ref, node);
392*4882a593Smuzhiyun }
393*4882a593Smuzhiyun
394*4882a593Smuzhiyun static inline struct btrfs_delayed_data_ref *
btrfs_delayed_node_to_data_ref(struct btrfs_delayed_ref_node * node)395*4882a593Smuzhiyun btrfs_delayed_node_to_data_ref(struct btrfs_delayed_ref_node *node)
396*4882a593Smuzhiyun {
397*4882a593Smuzhiyun return container_of(node, struct btrfs_delayed_data_ref, node);
398*4882a593Smuzhiyun }
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun #endif
401