19888c340SDavid Sterba /* SPDX-License-Identifier: GPL-2.0 */ 256bec294SChris Mason /* 356bec294SChris Mason * Copyright (C) 2008 Oracle. All rights reserved. 456bec294SChris Mason */ 59888c340SDavid Sterba 69888c340SDavid Sterba #ifndef BTRFS_DELAYED_REF_H 79888c340SDavid Sterba #define BTRFS_DELAYED_REF_H 856bec294SChris Mason 96df8cdf5SElena Reshetova #include <linux/refcount.h> 106df8cdf5SElena Reshetova 1144a075bdSWang Sheng-Hui /* these are the possible values of struct btrfs_delayed_ref_node->action */ 1256bec294SChris Mason #define BTRFS_ADD_DELAYED_REF 1 /* add one backref to the tree */ 1356bec294SChris Mason #define BTRFS_DROP_DELAYED_REF 2 /* delete one backref from the tree */ 1456bec294SChris Mason #define BTRFS_ADD_DELAYED_EXTENT 3 /* record a full extent allocation */ 151a81af4dSChris Mason #define BTRFS_UPDATE_DELAYED_HEAD 4 /* not changing ref count on head ref */ 1656bec294SChris Mason 1756bec294SChris Mason struct btrfs_delayed_ref_node { 180e0adbcfSJosef Bacik struct rb_node ref_node; 191d57ee94SWang Xiaoguang /* 201d57ee94SWang Xiaoguang * If action is BTRFS_ADD_DELAYED_REF, also link this node to 211d57ee94SWang Xiaoguang * ref_head->ref_add_list, then we do not need to iterate the 221d57ee94SWang Xiaoguang * whole ref_head->ref_list to find BTRFS_ADD_DELAYED_REF nodes. 231d57ee94SWang Xiaoguang */ 241d57ee94SWang Xiaoguang struct list_head add_list; 25c6fc2454SQu Wenruo 2656bec294SChris Mason /* the starting bytenr of the extent */ 2756bec294SChris Mason u64 bytenr; 2856bec294SChris Mason 2956bec294SChris Mason /* the size of the extent */ 3056bec294SChris Mason u64 num_bytes; 3156bec294SChris Mason 3200f04b88SArne Jansen /* seq number to keep track of insertion order */ 3300f04b88SArne Jansen u64 seq; 3400f04b88SArne Jansen 3556bec294SChris Mason /* ref count on this data structure */ 366df8cdf5SElena Reshetova refcount_t refs; 3756bec294SChris Mason 3856bec294SChris Mason /* 3956bec294SChris Mason * how many refs is this entry adding or deleting. For 4056bec294SChris Mason * head refs, this may be a negative number because it is keeping 4156bec294SChris Mason * track of the total mods done to the reference count. 4256bec294SChris Mason * For individual refs, this will always be a positive number 4356bec294SChris Mason * 4456bec294SChris Mason * It may be more than one, since it is possible for a single 4556bec294SChris Mason * parent to have more than one ref on an extent 4656bec294SChris Mason */ 4756bec294SChris Mason int ref_mod; 4856bec294SChris Mason 495d4f98a2SYan Zheng unsigned int action:8; 505d4f98a2SYan Zheng unsigned int type:8; 5156bec294SChris Mason /* is this node still in the rbtree? */ 525d4f98a2SYan Zheng unsigned int is_head:1; 5356bec294SChris Mason unsigned int in_tree:1; 5456bec294SChris Mason }; 5556bec294SChris Mason 565d4f98a2SYan Zheng struct btrfs_delayed_extent_op { 575d4f98a2SYan Zheng struct btrfs_disk_key key; 5835b3ad50SDavid Sterba u8 level; 5935b3ad50SDavid Sterba bool update_key; 6035b3ad50SDavid Sterba bool update_flags; 6135b3ad50SDavid Sterba bool is_data; 625d4f98a2SYan Zheng u64 flags_to_set; 635d4f98a2SYan Zheng }; 645d4f98a2SYan Zheng 6556bec294SChris Mason /* 6656bec294SChris Mason * the head refs are used to hold a lock on a given extent, which allows us 6756bec294SChris Mason * to make sure that only one process is running the delayed refs 6856bec294SChris Mason * at a time for a single extent. They also store the sum of all the 6956bec294SChris Mason * reference count modifications we've queued up. 7056bec294SChris Mason */ 7156bec294SChris Mason struct btrfs_delayed_ref_head { 72d278850eSJosef Bacik u64 bytenr; 73d278850eSJosef Bacik u64 num_bytes; 74d278850eSJosef Bacik refcount_t refs; 7556bec294SChris Mason /* 7656bec294SChris Mason * the mutex is held while running the refs, and it is also 7756bec294SChris Mason * held when checking the sum of reference modifications. 7856bec294SChris Mason */ 7956bec294SChris Mason struct mutex mutex; 8056bec294SChris Mason 81d7df2c79SJosef Bacik spinlock_t lock; 82e3d03965SLiu Bo struct rb_root_cached ref_tree; 831d57ee94SWang Xiaoguang /* accumulate add BTRFS_ADD_DELAYED_REF nodes to this ref_add_list. */ 841d57ee94SWang Xiaoguang struct list_head ref_add_list; 85c3e69d58SChris Mason 86c46effa6SLiu Bo struct rb_node href_node; 87c46effa6SLiu Bo 885d4f98a2SYan Zheng struct btrfs_delayed_extent_op *extent_op; 891262133bSJosef Bacik 901262133bSJosef Bacik /* 911262133bSJosef Bacik * This is used to track the final ref_mod from all the refs associated 921262133bSJosef Bacik * with this head ref, this is not adjusted as delayed refs are run, 931262133bSJosef Bacik * this is meant to track if we need to do the csum accounting or not. 941262133bSJosef Bacik */ 951262133bSJosef Bacik int total_ref_mod; 961262133bSJosef Bacik 9756bec294SChris Mason /* 98d278850eSJosef Bacik * This is the current outstanding mod references for this bytenr. This 99d278850eSJosef Bacik * is used with lookup_extent_info to get an accurate reference count 100d278850eSJosef Bacik * for a bytenr, so it is adjusted as delayed refs are run so that any 101d278850eSJosef Bacik * on disk reference count + ref_mod is accurate. 102d278850eSJosef Bacik */ 103d278850eSJosef Bacik int ref_mod; 104d278850eSJosef Bacik 105d278850eSJosef Bacik /* 10656bec294SChris Mason * when a new extent is allocated, it is just reserved in memory 10756bec294SChris Mason * The actual extent isn't inserted into the extent allocation tree 10856bec294SChris Mason * until the delayed ref is processed. must_insert_reserved is 10956bec294SChris Mason * used to flag a delayed ref so the accounting can be updated 11056bec294SChris Mason * when a full insert is done. 11156bec294SChris Mason * 11256bec294SChris Mason * It is possible the extent will be freed before it is ever 11356bec294SChris Mason * inserted into the extent allocation tree. In this case 11456bec294SChris Mason * we need to update the in ram accounting to properly reflect 11556bec294SChris Mason * the free has happened. 11656bec294SChris Mason */ 11756bec294SChris Mason unsigned int must_insert_reserved:1; 1185d4f98a2SYan Zheng unsigned int is_data:1; 1195e388e95SNikolay Borisov unsigned int is_system:1; 120d7df2c79SJosef Bacik unsigned int processing:1; 12156bec294SChris Mason }; 12256bec294SChris Mason 1235d4f98a2SYan Zheng struct btrfs_delayed_tree_ref { 12456bec294SChris Mason struct btrfs_delayed_ref_node node; 12556bec294SChris Mason u64 root; 1265d4f98a2SYan Zheng u64 parent; 1275d4f98a2SYan Zheng int level; 1285d4f98a2SYan Zheng }; 12956bec294SChris Mason 1305d4f98a2SYan Zheng struct btrfs_delayed_data_ref { 1315d4f98a2SYan Zheng struct btrfs_delayed_ref_node node; 1325d4f98a2SYan Zheng u64 root; 1335d4f98a2SYan Zheng u64 parent; 1345d4f98a2SYan Zheng u64 objectid; 1355d4f98a2SYan Zheng u64 offset; 13656bec294SChris Mason }; 13756bec294SChris Mason 138e19eb11fSJosef Bacik enum btrfs_delayed_ref_flags { 139e19eb11fSJosef Bacik /* Indicate that we are flushing delayed refs for the commit */ 140e19eb11fSJosef Bacik BTRFS_DELAYED_REFS_FLUSHING, 141e19eb11fSJosef Bacik }; 142e19eb11fSJosef Bacik 14356bec294SChris Mason struct btrfs_delayed_ref_root { 144c46effa6SLiu Bo /* head ref rbtree */ 1455c9d028bSLiu Bo struct rb_root_cached href_root; 146c46effa6SLiu Bo 1473368d001SQu Wenruo /* dirty extent records */ 1483368d001SQu Wenruo struct rb_root dirty_extent_root; 1493368d001SQu Wenruo 15056bec294SChris Mason /* this spin lock protects the rbtree and the entries inside */ 15156bec294SChris Mason spinlock_t lock; 15256bec294SChris Mason 15356bec294SChris Mason /* how many delayed ref updates we've queued, used by the 15456bec294SChris Mason * throttling code 15556bec294SChris Mason */ 156d7df2c79SJosef Bacik atomic_t num_entries; 15756bec294SChris Mason 158c3e69d58SChris Mason /* total number of head nodes in tree */ 159c3e69d58SChris Mason unsigned long num_heads; 160c3e69d58SChris Mason 161c3e69d58SChris Mason /* total number of head nodes ready for processing */ 162c3e69d58SChris Mason unsigned long num_heads_ready; 163c3e69d58SChris Mason 1641262133bSJosef Bacik u64 pending_csums; 1651262133bSJosef Bacik 166e19eb11fSJosef Bacik unsigned long flags; 167c3e69d58SChris Mason 168c3e69d58SChris Mason u64 run_delayed_start; 1699086db86SQu Wenruo 1709086db86SQu Wenruo /* 1719086db86SQu Wenruo * To make qgroup to skip given root. 17201327610SNicholas D Steeves * This is for snapshot, as btrfs_qgroup_inherit() will manually 1739086db86SQu Wenruo * modify counters for snapshot and its source, so we should skip 1749086db86SQu Wenruo * the snapshot in new_root/old_roots or it will get calculated twice 1759086db86SQu Wenruo */ 1769086db86SQu Wenruo u64 qgroup_to_skip; 17756bec294SChris Mason }; 17856bec294SChris Mason 179b28b1f0cSQu Wenruo enum btrfs_ref_type { 180b28b1f0cSQu Wenruo BTRFS_REF_NOT_SET, 181b28b1f0cSQu Wenruo BTRFS_REF_DATA, 182b28b1f0cSQu Wenruo BTRFS_REF_METADATA, 183b28b1f0cSQu Wenruo BTRFS_REF_LAST, 184b28b1f0cSQu Wenruo }; 185b28b1f0cSQu Wenruo 186b28b1f0cSQu Wenruo struct btrfs_data_ref { 187b28b1f0cSQu Wenruo /* For EXTENT_DATA_REF */ 188b28b1f0cSQu Wenruo 189113479d5SNikolay Borisov /* Original root this data extent belongs to */ 190113479d5SNikolay Borisov u64 owning_root; 191b28b1f0cSQu Wenruo 192b28b1f0cSQu Wenruo /* Inode which refers to this data extent */ 193b28b1f0cSQu Wenruo u64 ino; 194b28b1f0cSQu Wenruo 195b28b1f0cSQu Wenruo /* 196b28b1f0cSQu Wenruo * file_offset - extent_offset 197b28b1f0cSQu Wenruo * 198b28b1f0cSQu Wenruo * file_offset is the key.offset of the EXTENT_DATA key. 199b28b1f0cSQu Wenruo * extent_offset is btrfs_file_extent_offset() of the EXTENT_DATA data. 200b28b1f0cSQu Wenruo */ 201b28b1f0cSQu Wenruo u64 offset; 202b28b1f0cSQu Wenruo }; 203b28b1f0cSQu Wenruo 204b28b1f0cSQu Wenruo struct btrfs_tree_ref { 205b28b1f0cSQu Wenruo /* 206b28b1f0cSQu Wenruo * Level of this tree block 207b28b1f0cSQu Wenruo * 208b28b1f0cSQu Wenruo * Shared for skinny (TREE_BLOCK_REF) and normal tree ref. 209b28b1f0cSQu Wenruo */ 210b28b1f0cSQu Wenruo int level; 211b28b1f0cSQu Wenruo 212b28b1f0cSQu Wenruo /* 213113479d5SNikolay Borisov * Root which owns this tree block. 214b28b1f0cSQu Wenruo * 215b28b1f0cSQu Wenruo * For TREE_BLOCK_REF (skinny metadata, either inline or keyed) 216b28b1f0cSQu Wenruo */ 217113479d5SNikolay Borisov u64 owning_root; 218b28b1f0cSQu Wenruo 219b28b1f0cSQu Wenruo /* For non-skinny metadata, no special member needed */ 220b28b1f0cSQu Wenruo }; 221b28b1f0cSQu Wenruo 222b28b1f0cSQu Wenruo struct btrfs_ref { 223b28b1f0cSQu Wenruo enum btrfs_ref_type type; 224b28b1f0cSQu Wenruo int action; 225b28b1f0cSQu Wenruo 226b28b1f0cSQu Wenruo /* 227b28b1f0cSQu Wenruo * Whether this extent should go through qgroup record. 228b28b1f0cSQu Wenruo * 229b28b1f0cSQu Wenruo * Normally false, but for certain cases like delayed subtree scan, 230b28b1f0cSQu Wenruo * setting this flag can hugely reduce qgroup overhead. 231b28b1f0cSQu Wenruo */ 232b28b1f0cSQu Wenruo bool skip_qgroup; 233b28b1f0cSQu Wenruo 234*eed2037fSNikolay Borisov #ifdef CONFIG_BTRFS_FS_REF_VERIFY 235*eed2037fSNikolay Borisov /* Through which root is this modification. */ 236b28b1f0cSQu Wenruo u64 real_root; 237*eed2037fSNikolay Borisov #endif 238b28b1f0cSQu Wenruo u64 bytenr; 239b28b1f0cSQu Wenruo u64 len; 240b28b1f0cSQu Wenruo 241b28b1f0cSQu Wenruo /* Bytenr of the parent tree block */ 242b28b1f0cSQu Wenruo u64 parent; 243b28b1f0cSQu Wenruo union { 244b28b1f0cSQu Wenruo struct btrfs_data_ref data_ref; 245b28b1f0cSQu Wenruo struct btrfs_tree_ref tree_ref; 246b28b1f0cSQu Wenruo }; 247b28b1f0cSQu Wenruo }; 248b28b1f0cSQu Wenruo 24978a6184aSMiao Xie extern struct kmem_cache *btrfs_delayed_ref_head_cachep; 25078a6184aSMiao Xie extern struct kmem_cache *btrfs_delayed_tree_ref_cachep; 25178a6184aSMiao Xie extern struct kmem_cache *btrfs_delayed_data_ref_cachep; 25278a6184aSMiao Xie extern struct kmem_cache *btrfs_delayed_extent_op_cachep; 25378a6184aSMiao Xie 254f5c29bd9SLiu Bo int __init btrfs_delayed_ref_init(void); 255e67c718bSDavid Sterba void __cold btrfs_delayed_ref_exit(void); 25678a6184aSMiao Xie 257b28b1f0cSQu Wenruo static inline void btrfs_init_generic_ref(struct btrfs_ref *generic_ref, 258b28b1f0cSQu Wenruo int action, u64 bytenr, u64 len, u64 parent) 259b28b1f0cSQu Wenruo { 260b28b1f0cSQu Wenruo generic_ref->action = action; 261b28b1f0cSQu Wenruo generic_ref->bytenr = bytenr; 262b28b1f0cSQu Wenruo generic_ref->len = len; 263b28b1f0cSQu Wenruo generic_ref->parent = parent; 264b28b1f0cSQu Wenruo } 265b28b1f0cSQu Wenruo 266b28b1f0cSQu Wenruo static inline void btrfs_init_tree_ref(struct btrfs_ref *generic_ref, 267f42c5da6SNikolay Borisov int level, u64 root, u64 mod_root, bool skip_qgroup) 268b28b1f0cSQu Wenruo { 269*eed2037fSNikolay Borisov #ifdef CONFIG_BTRFS_FS_REF_VERIFY 270b28b1f0cSQu Wenruo /* If @real_root not set, use @root as fallback */ 271*eed2037fSNikolay Borisov generic_ref->real_root = mod_root ?: root; 272*eed2037fSNikolay Borisov #endif 273b28b1f0cSQu Wenruo generic_ref->tree_ref.level = level; 274113479d5SNikolay Borisov generic_ref->tree_ref.owning_root = root; 275b28b1f0cSQu Wenruo generic_ref->type = BTRFS_REF_METADATA; 276681145d4SNikolay Borisov if (skip_qgroup || !(is_fstree(root) && 277681145d4SNikolay Borisov (!mod_root || is_fstree(mod_root)))) 278681145d4SNikolay Borisov generic_ref->skip_qgroup = true; 279681145d4SNikolay Borisov else 280681145d4SNikolay Borisov generic_ref->skip_qgroup = false; 281681145d4SNikolay Borisov 282b28b1f0cSQu Wenruo } 283b28b1f0cSQu Wenruo 284b28b1f0cSQu Wenruo static inline void btrfs_init_data_ref(struct btrfs_ref *generic_ref, 285f42c5da6SNikolay Borisov u64 ref_root, u64 ino, u64 offset, u64 mod_root, 286f42c5da6SNikolay Borisov bool skip_qgroup) 287b28b1f0cSQu Wenruo { 288*eed2037fSNikolay Borisov #ifdef CONFIG_BTRFS_FS_REF_VERIFY 289b28b1f0cSQu Wenruo /* If @real_root not set, use @root as fallback */ 290*eed2037fSNikolay Borisov generic_ref->real_root = mod_root ?: ref_root; 291*eed2037fSNikolay Borisov #endif 292113479d5SNikolay Borisov generic_ref->data_ref.owning_root = ref_root; 293b28b1f0cSQu Wenruo generic_ref->data_ref.ino = ino; 294b28b1f0cSQu Wenruo generic_ref->data_ref.offset = offset; 295b28b1f0cSQu Wenruo generic_ref->type = BTRFS_REF_DATA; 296681145d4SNikolay Borisov if (skip_qgroup || !(is_fstree(ref_root) && 297681145d4SNikolay Borisov (!mod_root || is_fstree(mod_root)))) 298681145d4SNikolay Borisov generic_ref->skip_qgroup = true; 299681145d4SNikolay Borisov else 300681145d4SNikolay Borisov generic_ref->skip_qgroup = false; 301b28b1f0cSQu Wenruo } 302b28b1f0cSQu Wenruo 30378a6184aSMiao Xie static inline struct btrfs_delayed_extent_op * 30478a6184aSMiao Xie btrfs_alloc_delayed_extent_op(void) 30578a6184aSMiao Xie { 30678a6184aSMiao Xie return kmem_cache_alloc(btrfs_delayed_extent_op_cachep, GFP_NOFS); 30778a6184aSMiao Xie } 30878a6184aSMiao Xie 30978a6184aSMiao Xie static inline void 31078a6184aSMiao Xie btrfs_free_delayed_extent_op(struct btrfs_delayed_extent_op *op) 31178a6184aSMiao Xie { 31278a6184aSMiao Xie if (op) 31378a6184aSMiao Xie kmem_cache_free(btrfs_delayed_extent_op_cachep, op); 31478a6184aSMiao Xie } 31578a6184aSMiao Xie 31656bec294SChris Mason static inline void btrfs_put_delayed_ref(struct btrfs_delayed_ref_node *ref) 31756bec294SChris Mason { 3186df8cdf5SElena Reshetova WARN_ON(refcount_read(&ref->refs) == 0); 3196df8cdf5SElena Reshetova if (refcount_dec_and_test(&ref->refs)) { 32056bec294SChris Mason WARN_ON(ref->in_tree); 32178a6184aSMiao Xie switch (ref->type) { 32278a6184aSMiao Xie case BTRFS_TREE_BLOCK_REF_KEY: 32378a6184aSMiao Xie case BTRFS_SHARED_BLOCK_REF_KEY: 32478a6184aSMiao Xie kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref); 32578a6184aSMiao Xie break; 32678a6184aSMiao Xie case BTRFS_EXTENT_DATA_REF_KEY: 32778a6184aSMiao Xie case BTRFS_SHARED_DATA_REF_KEY: 32878a6184aSMiao Xie kmem_cache_free(btrfs_delayed_data_ref_cachep, ref); 32978a6184aSMiao Xie break; 33078a6184aSMiao Xie default: 33178a6184aSMiao Xie BUG(); 33278a6184aSMiao Xie } 33356bec294SChris Mason } 33456bec294SChris Mason } 33556bec294SChris Mason 3362187374fSJosef Bacik static inline u64 btrfs_ref_head_to_space_flags( 3372187374fSJosef Bacik struct btrfs_delayed_ref_head *head_ref) 3382187374fSJosef Bacik { 3392187374fSJosef Bacik if (head_ref->is_data) 3402187374fSJosef Bacik return BTRFS_BLOCK_GROUP_DATA; 3412187374fSJosef Bacik else if (head_ref->is_system) 3422187374fSJosef Bacik return BTRFS_BLOCK_GROUP_SYSTEM; 3432187374fSJosef Bacik return BTRFS_BLOCK_GROUP_METADATA; 3442187374fSJosef Bacik } 3452187374fSJosef Bacik 346d278850eSJosef Bacik static inline void btrfs_put_delayed_ref_head(struct btrfs_delayed_ref_head *head) 347d278850eSJosef Bacik { 348d278850eSJosef Bacik if (refcount_dec_and_test(&head->refs)) 349d278850eSJosef Bacik kmem_cache_free(btrfs_delayed_ref_head_cachep, head); 350d278850eSJosef Bacik } 351d278850eSJosef Bacik 35244e1c47dSNikolay Borisov int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, 353ed4f255bSQu Wenruo struct btrfs_ref *generic_ref, 3542187374fSJosef Bacik struct btrfs_delayed_extent_op *extent_op); 35588a979c6SNikolay Borisov int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, 35676675593SQu Wenruo struct btrfs_ref *generic_ref, 3572187374fSJosef Bacik u64 reserved); 358c6e340bcSDavid Sterba int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans, 3595d4f98a2SYan Zheng u64 bytenr, u64 num_bytes, 3605d4f98a2SYan Zheng struct btrfs_delayed_extent_op *extent_op); 361ae1e206bSJosef Bacik void btrfs_merge_delayed_refs(struct btrfs_trans_handle *trans, 362ae1e206bSJosef Bacik struct btrfs_delayed_ref_root *delayed_refs, 363ae1e206bSJosef Bacik struct btrfs_delayed_ref_head *head); 36456bec294SChris Mason 3651887be66SChris Mason struct btrfs_delayed_ref_head * 366f72ad18eSLiu Bo btrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, 367f72ad18eSLiu Bo u64 bytenr); 3689e920a6fSLu Fengqi int btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, 369c3e69d58SChris Mason struct btrfs_delayed_ref_head *head); 370093486c4SMiao Xie static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head) 371093486c4SMiao Xie { 372093486c4SMiao Xie mutex_unlock(&head->mutex); 373093486c4SMiao Xie } 374d7baffdaSJosef Bacik void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, 375d7baffdaSJosef Bacik struct btrfs_delayed_ref_head *head); 376d7df2c79SJosef Bacik 3775637c74bSLu Fengqi struct btrfs_delayed_ref_head *btrfs_select_ref_head( 3785637c74bSLu Fengqi struct btrfs_delayed_ref_root *delayed_refs); 37900f04b88SArne Jansen 38041d0bd3bSNikolay Borisov int btrfs_check_delayed_seq(struct btrfs_fs_info *fs_info, u64 seq); 38100f04b88SArne Jansen 3826ef03debSJosef Bacik void btrfs_delayed_refs_rsv_release(struct btrfs_fs_info *fs_info, int nr); 3836ef03debSJosef Bacik void btrfs_update_delayed_refs_rsv(struct btrfs_trans_handle *trans); 3846ef03debSJosef Bacik int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, 3856ef03debSJosef Bacik enum btrfs_reserve_flush_enum flush); 3866ef03debSJosef Bacik void btrfs_migrate_to_delayed_refs_rsv(struct btrfs_fs_info *fs_info, 3876ef03debSJosef Bacik struct btrfs_block_rsv *src, 3886ef03debSJosef Bacik u64 num_bytes); 3896ef03debSJosef Bacik int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans); 3906ef03debSJosef Bacik bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info); 3916ef03debSJosef Bacik 39200f04b88SArne Jansen /* 39356bec294SChris Mason * helper functions to cast a node into its container 39456bec294SChris Mason */ 3955d4f98a2SYan Zheng static inline struct btrfs_delayed_tree_ref * 3965d4f98a2SYan Zheng btrfs_delayed_node_to_tree_ref(struct btrfs_delayed_ref_node *node) 39756bec294SChris Mason { 3985d4f98a2SYan Zheng return container_of(node, struct btrfs_delayed_tree_ref, node); 3995d4f98a2SYan Zheng } 40056bec294SChris Mason 4015d4f98a2SYan Zheng static inline struct btrfs_delayed_data_ref * 4025d4f98a2SYan Zheng btrfs_delayed_node_to_data_ref(struct btrfs_delayed_ref_node *node) 4035d4f98a2SYan Zheng { 4045d4f98a2SYan Zheng return container_of(node, struct btrfs_delayed_data_ref, node); 40556bec294SChris Mason } 4069888c340SDavid Sterba 40756bec294SChris Mason #endif 408