18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2008 Oracle. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef BTRFS_DELAYED_REF_H 78c2ecf20Sopenharmony_ci#define BTRFS_DELAYED_REF_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/refcount.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/* these are the possible values of struct btrfs_delayed_ref_node->action */ 128c2ecf20Sopenharmony_ci#define BTRFS_ADD_DELAYED_REF 1 /* add one backref to the tree */ 138c2ecf20Sopenharmony_ci#define BTRFS_DROP_DELAYED_REF 2 /* delete one backref from the tree */ 148c2ecf20Sopenharmony_ci#define BTRFS_ADD_DELAYED_EXTENT 3 /* record a full extent allocation */ 158c2ecf20Sopenharmony_ci#define BTRFS_UPDATE_DELAYED_HEAD 4 /* not changing ref count on head ref */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistruct btrfs_delayed_ref_node { 188c2ecf20Sopenharmony_ci struct rb_node ref_node; 198c2ecf20Sopenharmony_ci /* 208c2ecf20Sopenharmony_ci * If action is BTRFS_ADD_DELAYED_REF, also link this node to 218c2ecf20Sopenharmony_ci * ref_head->ref_add_list, then we do not need to iterate the 228c2ecf20Sopenharmony_ci * whole ref_head->ref_list to find BTRFS_ADD_DELAYED_REF nodes. 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci struct list_head add_list; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci /* the starting bytenr of the extent */ 278c2ecf20Sopenharmony_ci u64 bytenr; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci /* the size of the extent */ 308c2ecf20Sopenharmony_ci u64 num_bytes; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci /* seq number to keep track of insertion order */ 338c2ecf20Sopenharmony_ci u64 seq; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci /* ref count on this data structure */ 368c2ecf20Sopenharmony_ci refcount_t refs; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci /* 398c2ecf20Sopenharmony_ci * how many refs is this entry adding or deleting. For 408c2ecf20Sopenharmony_ci * head refs, this may be a negative number because it is keeping 418c2ecf20Sopenharmony_ci * track of the total mods done to the reference count. 428c2ecf20Sopenharmony_ci * For individual refs, this will always be a positive number 438c2ecf20Sopenharmony_ci * 448c2ecf20Sopenharmony_ci * It may be more than one, since it is possible for a single 458c2ecf20Sopenharmony_ci * parent to have more than one ref on an extent 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_ci int ref_mod; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci unsigned int action:8; 508c2ecf20Sopenharmony_ci unsigned int type:8; 518c2ecf20Sopenharmony_ci /* is this node still in the rbtree? */ 528c2ecf20Sopenharmony_ci unsigned int is_head:1; 538c2ecf20Sopenharmony_ci unsigned int in_tree:1; 548c2ecf20Sopenharmony_ci}; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistruct btrfs_delayed_extent_op { 578c2ecf20Sopenharmony_ci struct btrfs_disk_key key; 588c2ecf20Sopenharmony_ci u8 level; 598c2ecf20Sopenharmony_ci bool update_key; 608c2ecf20Sopenharmony_ci bool update_flags; 618c2ecf20Sopenharmony_ci bool is_data; 628c2ecf20Sopenharmony_ci u64 flags_to_set; 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/* 668c2ecf20Sopenharmony_ci * the head refs are used to hold a lock on a given extent, which allows us 678c2ecf20Sopenharmony_ci * to make sure that only one process is running the delayed refs 688c2ecf20Sopenharmony_ci * at a time for a single extent. They also store the sum of all the 698c2ecf20Sopenharmony_ci * reference count modifications we've queued up. 708c2ecf20Sopenharmony_ci */ 718c2ecf20Sopenharmony_cistruct btrfs_delayed_ref_head { 728c2ecf20Sopenharmony_ci u64 bytenr; 738c2ecf20Sopenharmony_ci u64 num_bytes; 748c2ecf20Sopenharmony_ci refcount_t refs; 758c2ecf20Sopenharmony_ci /* 768c2ecf20Sopenharmony_ci * the mutex is held while running the refs, and it is also 778c2ecf20Sopenharmony_ci * held when checking the sum of reference modifications. 788c2ecf20Sopenharmony_ci */ 798c2ecf20Sopenharmony_ci struct mutex mutex; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci spinlock_t lock; 828c2ecf20Sopenharmony_ci struct rb_root_cached ref_tree; 838c2ecf20Sopenharmony_ci /* accumulate add BTRFS_ADD_DELAYED_REF nodes to this ref_add_list. */ 848c2ecf20Sopenharmony_ci struct list_head ref_add_list; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci struct rb_node href_node; 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci struct btrfs_delayed_extent_op *extent_op; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci /* 918c2ecf20Sopenharmony_ci * This is used to track the final ref_mod from all the refs associated 928c2ecf20Sopenharmony_ci * with this head ref, this is not adjusted as delayed refs are run, 938c2ecf20Sopenharmony_ci * this is meant to track if we need to do the csum accounting or not. 948c2ecf20Sopenharmony_ci */ 958c2ecf20Sopenharmony_ci int total_ref_mod; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci /* 988c2ecf20Sopenharmony_ci * This is the current outstanding mod references for this bytenr. This 998c2ecf20Sopenharmony_ci * is used with lookup_extent_info to get an accurate reference count 1008c2ecf20Sopenharmony_ci * for a bytenr, so it is adjusted as delayed refs are run so that any 1018c2ecf20Sopenharmony_ci * on disk reference count + ref_mod is accurate. 1028c2ecf20Sopenharmony_ci */ 1038c2ecf20Sopenharmony_ci int ref_mod; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci /* 1068c2ecf20Sopenharmony_ci * when a new extent is allocated, it is just reserved in memory 1078c2ecf20Sopenharmony_ci * The actual extent isn't inserted into the extent allocation tree 1088c2ecf20Sopenharmony_ci * until the delayed ref is processed. must_insert_reserved is 1098c2ecf20Sopenharmony_ci * used to flag a delayed ref so the accounting can be updated 1108c2ecf20Sopenharmony_ci * when a full insert is done. 1118c2ecf20Sopenharmony_ci * 1128c2ecf20Sopenharmony_ci * It is possible the extent will be freed before it is ever 1138c2ecf20Sopenharmony_ci * inserted into the extent allocation tree. In this case 1148c2ecf20Sopenharmony_ci * we need to update the in ram accounting to properly reflect 1158c2ecf20Sopenharmony_ci * the free has happened. 1168c2ecf20Sopenharmony_ci */ 1178c2ecf20Sopenharmony_ci unsigned int must_insert_reserved:1; 1188c2ecf20Sopenharmony_ci unsigned int is_data:1; 1198c2ecf20Sopenharmony_ci unsigned int is_system:1; 1208c2ecf20Sopenharmony_ci unsigned int processing:1; 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistruct btrfs_delayed_tree_ref { 1248c2ecf20Sopenharmony_ci struct btrfs_delayed_ref_node node; 1258c2ecf20Sopenharmony_ci u64 root; 1268c2ecf20Sopenharmony_ci u64 parent; 1278c2ecf20Sopenharmony_ci int level; 1288c2ecf20Sopenharmony_ci}; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistruct btrfs_delayed_data_ref { 1318c2ecf20Sopenharmony_ci struct btrfs_delayed_ref_node node; 1328c2ecf20Sopenharmony_ci u64 root; 1338c2ecf20Sopenharmony_ci u64 parent; 1348c2ecf20Sopenharmony_ci u64 objectid; 1358c2ecf20Sopenharmony_ci u64 offset; 1368c2ecf20Sopenharmony_ci}; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cistruct btrfs_delayed_ref_root { 1398c2ecf20Sopenharmony_ci /* head ref rbtree */ 1408c2ecf20Sopenharmony_ci struct rb_root_cached href_root; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci /* dirty extent records */ 1438c2ecf20Sopenharmony_ci struct rb_root dirty_extent_root; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci /* this spin lock protects the rbtree and the entries inside */ 1468c2ecf20Sopenharmony_ci spinlock_t lock; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci /* how many delayed ref updates we've queued, used by the 1498c2ecf20Sopenharmony_ci * throttling code 1508c2ecf20Sopenharmony_ci */ 1518c2ecf20Sopenharmony_ci atomic_t num_entries; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci /* total number of head nodes in tree */ 1548c2ecf20Sopenharmony_ci unsigned long num_heads; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci /* total number of head nodes ready for processing */ 1578c2ecf20Sopenharmony_ci unsigned long num_heads_ready; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci u64 pending_csums; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci /* 1628c2ecf20Sopenharmony_ci * set when the tree is flushing before a transaction commit, 1638c2ecf20Sopenharmony_ci * used by the throttling code to decide if new updates need 1648c2ecf20Sopenharmony_ci * to be run right away 1658c2ecf20Sopenharmony_ci */ 1668c2ecf20Sopenharmony_ci int flushing; 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci u64 run_delayed_start; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci /* 1718c2ecf20Sopenharmony_ci * To make qgroup to skip given root. 1728c2ecf20Sopenharmony_ci * This is for snapshot, as btrfs_qgroup_inherit() will manually 1738c2ecf20Sopenharmony_ci * modify counters for snapshot and its source, so we should skip 1748c2ecf20Sopenharmony_ci * the snapshot in new_root/old_roots or it will get calculated twice 1758c2ecf20Sopenharmony_ci */ 1768c2ecf20Sopenharmony_ci u64 qgroup_to_skip; 1778c2ecf20Sopenharmony_ci}; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cienum btrfs_ref_type { 1808c2ecf20Sopenharmony_ci BTRFS_REF_NOT_SET, 1818c2ecf20Sopenharmony_ci BTRFS_REF_DATA, 1828c2ecf20Sopenharmony_ci BTRFS_REF_METADATA, 1838c2ecf20Sopenharmony_ci BTRFS_REF_LAST, 1848c2ecf20Sopenharmony_ci}; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cistruct btrfs_data_ref { 1878c2ecf20Sopenharmony_ci /* For EXTENT_DATA_REF */ 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci /* Root which refers to this data extent */ 1908c2ecf20Sopenharmony_ci u64 ref_root; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci /* Inode which refers to this data extent */ 1938c2ecf20Sopenharmony_ci u64 ino; 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci /* 1968c2ecf20Sopenharmony_ci * file_offset - extent_offset 1978c2ecf20Sopenharmony_ci * 1988c2ecf20Sopenharmony_ci * file_offset is the key.offset of the EXTENT_DATA key. 1998c2ecf20Sopenharmony_ci * extent_offset is btrfs_file_extent_offset() of the EXTENT_DATA data. 2008c2ecf20Sopenharmony_ci */ 2018c2ecf20Sopenharmony_ci u64 offset; 2028c2ecf20Sopenharmony_ci}; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cistruct btrfs_tree_ref { 2058c2ecf20Sopenharmony_ci /* 2068c2ecf20Sopenharmony_ci * Level of this tree block 2078c2ecf20Sopenharmony_ci * 2088c2ecf20Sopenharmony_ci * Shared for skinny (TREE_BLOCK_REF) and normal tree ref. 2098c2ecf20Sopenharmony_ci */ 2108c2ecf20Sopenharmony_ci int level; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci /* 2138c2ecf20Sopenharmony_ci * Root which refers to this tree block. 2148c2ecf20Sopenharmony_ci * 2158c2ecf20Sopenharmony_ci * For TREE_BLOCK_REF (skinny metadata, either inline or keyed) 2168c2ecf20Sopenharmony_ci */ 2178c2ecf20Sopenharmony_ci u64 root; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci /* For non-skinny metadata, no special member needed */ 2208c2ecf20Sopenharmony_ci}; 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_cistruct btrfs_ref { 2238c2ecf20Sopenharmony_ci enum btrfs_ref_type type; 2248c2ecf20Sopenharmony_ci int action; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci /* 2278c2ecf20Sopenharmony_ci * Whether this extent should go through qgroup record. 2288c2ecf20Sopenharmony_ci * 2298c2ecf20Sopenharmony_ci * Normally false, but for certain cases like delayed subtree scan, 2308c2ecf20Sopenharmony_ci * setting this flag can hugely reduce qgroup overhead. 2318c2ecf20Sopenharmony_ci */ 2328c2ecf20Sopenharmony_ci bool skip_qgroup; 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci /* 2358c2ecf20Sopenharmony_ci * Optional. For which root is this modification. 2368c2ecf20Sopenharmony_ci * Mostly used for qgroup optimization. 2378c2ecf20Sopenharmony_ci * 2388c2ecf20Sopenharmony_ci * When unset, data/tree ref init code will populate it. 2398c2ecf20Sopenharmony_ci * In certain cases, we're modifying reference for a different root. 2408c2ecf20Sopenharmony_ci * E.g. COW fs tree blocks for balance. 2418c2ecf20Sopenharmony_ci * In that case, tree_ref::root will be fs tree, but we're doing this 2428c2ecf20Sopenharmony_ci * for reloc tree, then we should set @real_root to reloc tree. 2438c2ecf20Sopenharmony_ci */ 2448c2ecf20Sopenharmony_ci u64 real_root; 2458c2ecf20Sopenharmony_ci u64 bytenr; 2468c2ecf20Sopenharmony_ci u64 len; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci /* Bytenr of the parent tree block */ 2498c2ecf20Sopenharmony_ci u64 parent; 2508c2ecf20Sopenharmony_ci union { 2518c2ecf20Sopenharmony_ci struct btrfs_data_ref data_ref; 2528c2ecf20Sopenharmony_ci struct btrfs_tree_ref tree_ref; 2538c2ecf20Sopenharmony_ci }; 2548c2ecf20Sopenharmony_ci}; 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ciextern struct kmem_cache *btrfs_delayed_ref_head_cachep; 2578c2ecf20Sopenharmony_ciextern struct kmem_cache *btrfs_delayed_tree_ref_cachep; 2588c2ecf20Sopenharmony_ciextern struct kmem_cache *btrfs_delayed_data_ref_cachep; 2598c2ecf20Sopenharmony_ciextern struct kmem_cache *btrfs_delayed_extent_op_cachep; 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ciint __init btrfs_delayed_ref_init(void); 2628c2ecf20Sopenharmony_civoid __cold btrfs_delayed_ref_exit(void); 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cistatic inline void btrfs_init_generic_ref(struct btrfs_ref *generic_ref, 2658c2ecf20Sopenharmony_ci int action, u64 bytenr, u64 len, u64 parent) 2668c2ecf20Sopenharmony_ci{ 2678c2ecf20Sopenharmony_ci generic_ref->action = action; 2688c2ecf20Sopenharmony_ci generic_ref->bytenr = bytenr; 2698c2ecf20Sopenharmony_ci generic_ref->len = len; 2708c2ecf20Sopenharmony_ci generic_ref->parent = parent; 2718c2ecf20Sopenharmony_ci} 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_cistatic inline void btrfs_init_tree_ref(struct btrfs_ref *generic_ref, 2748c2ecf20Sopenharmony_ci int level, u64 root) 2758c2ecf20Sopenharmony_ci{ 2768c2ecf20Sopenharmony_ci /* If @real_root not set, use @root as fallback */ 2778c2ecf20Sopenharmony_ci if (!generic_ref->real_root) 2788c2ecf20Sopenharmony_ci generic_ref->real_root = root; 2798c2ecf20Sopenharmony_ci generic_ref->tree_ref.level = level; 2808c2ecf20Sopenharmony_ci generic_ref->tree_ref.root = root; 2818c2ecf20Sopenharmony_ci generic_ref->type = BTRFS_REF_METADATA; 2828c2ecf20Sopenharmony_ci} 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_cistatic inline void btrfs_init_data_ref(struct btrfs_ref *generic_ref, 2858c2ecf20Sopenharmony_ci u64 ref_root, u64 ino, u64 offset) 2868c2ecf20Sopenharmony_ci{ 2878c2ecf20Sopenharmony_ci /* If @real_root not set, use @root as fallback */ 2888c2ecf20Sopenharmony_ci if (!generic_ref->real_root) 2898c2ecf20Sopenharmony_ci generic_ref->real_root = ref_root; 2908c2ecf20Sopenharmony_ci generic_ref->data_ref.ref_root = ref_root; 2918c2ecf20Sopenharmony_ci generic_ref->data_ref.ino = ino; 2928c2ecf20Sopenharmony_ci generic_ref->data_ref.offset = offset; 2938c2ecf20Sopenharmony_ci generic_ref->type = BTRFS_REF_DATA; 2948c2ecf20Sopenharmony_ci} 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_cistatic inline struct btrfs_delayed_extent_op * 2978c2ecf20Sopenharmony_cibtrfs_alloc_delayed_extent_op(void) 2988c2ecf20Sopenharmony_ci{ 2998c2ecf20Sopenharmony_ci return kmem_cache_alloc(btrfs_delayed_extent_op_cachep, GFP_NOFS); 3008c2ecf20Sopenharmony_ci} 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_cistatic inline void 3038c2ecf20Sopenharmony_cibtrfs_free_delayed_extent_op(struct btrfs_delayed_extent_op *op) 3048c2ecf20Sopenharmony_ci{ 3058c2ecf20Sopenharmony_ci if (op) 3068c2ecf20Sopenharmony_ci kmem_cache_free(btrfs_delayed_extent_op_cachep, op); 3078c2ecf20Sopenharmony_ci} 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_cistatic inline void btrfs_put_delayed_ref(struct btrfs_delayed_ref_node *ref) 3108c2ecf20Sopenharmony_ci{ 3118c2ecf20Sopenharmony_ci WARN_ON(refcount_read(&ref->refs) == 0); 3128c2ecf20Sopenharmony_ci if (refcount_dec_and_test(&ref->refs)) { 3138c2ecf20Sopenharmony_ci WARN_ON(ref->in_tree); 3148c2ecf20Sopenharmony_ci switch (ref->type) { 3158c2ecf20Sopenharmony_ci case BTRFS_TREE_BLOCK_REF_KEY: 3168c2ecf20Sopenharmony_ci case BTRFS_SHARED_BLOCK_REF_KEY: 3178c2ecf20Sopenharmony_ci kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref); 3188c2ecf20Sopenharmony_ci break; 3198c2ecf20Sopenharmony_ci case BTRFS_EXTENT_DATA_REF_KEY: 3208c2ecf20Sopenharmony_ci case BTRFS_SHARED_DATA_REF_KEY: 3218c2ecf20Sopenharmony_ci kmem_cache_free(btrfs_delayed_data_ref_cachep, ref); 3228c2ecf20Sopenharmony_ci break; 3238c2ecf20Sopenharmony_ci default: 3248c2ecf20Sopenharmony_ci BUG(); 3258c2ecf20Sopenharmony_ci } 3268c2ecf20Sopenharmony_ci } 3278c2ecf20Sopenharmony_ci} 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_cistatic inline u64 btrfs_ref_head_to_space_flags( 3308c2ecf20Sopenharmony_ci struct btrfs_delayed_ref_head *head_ref) 3318c2ecf20Sopenharmony_ci{ 3328c2ecf20Sopenharmony_ci if (head_ref->is_data) 3338c2ecf20Sopenharmony_ci return BTRFS_BLOCK_GROUP_DATA; 3348c2ecf20Sopenharmony_ci else if (head_ref->is_system) 3358c2ecf20Sopenharmony_ci return BTRFS_BLOCK_GROUP_SYSTEM; 3368c2ecf20Sopenharmony_ci return BTRFS_BLOCK_GROUP_METADATA; 3378c2ecf20Sopenharmony_ci} 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_cistatic inline void btrfs_put_delayed_ref_head(struct btrfs_delayed_ref_head *head) 3408c2ecf20Sopenharmony_ci{ 3418c2ecf20Sopenharmony_ci if (refcount_dec_and_test(&head->refs)) 3428c2ecf20Sopenharmony_ci kmem_cache_free(btrfs_delayed_ref_head_cachep, head); 3438c2ecf20Sopenharmony_ci} 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ciint btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, 3468c2ecf20Sopenharmony_ci struct btrfs_ref *generic_ref, 3478c2ecf20Sopenharmony_ci struct btrfs_delayed_extent_op *extent_op); 3488c2ecf20Sopenharmony_ciint btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, 3498c2ecf20Sopenharmony_ci struct btrfs_ref *generic_ref, 3508c2ecf20Sopenharmony_ci u64 reserved); 3518c2ecf20Sopenharmony_ciint btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans, 3528c2ecf20Sopenharmony_ci u64 bytenr, u64 num_bytes, 3538c2ecf20Sopenharmony_ci struct btrfs_delayed_extent_op *extent_op); 3548c2ecf20Sopenharmony_civoid btrfs_merge_delayed_refs(struct btrfs_trans_handle *trans, 3558c2ecf20Sopenharmony_ci struct btrfs_delayed_ref_root *delayed_refs, 3568c2ecf20Sopenharmony_ci struct btrfs_delayed_ref_head *head); 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_cistruct btrfs_delayed_ref_head * 3598c2ecf20Sopenharmony_cibtrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, 3608c2ecf20Sopenharmony_ci u64 bytenr); 3618c2ecf20Sopenharmony_ciint btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, 3628c2ecf20Sopenharmony_ci struct btrfs_delayed_ref_head *head); 3638c2ecf20Sopenharmony_cistatic inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head) 3648c2ecf20Sopenharmony_ci{ 3658c2ecf20Sopenharmony_ci mutex_unlock(&head->mutex); 3668c2ecf20Sopenharmony_ci} 3678c2ecf20Sopenharmony_civoid btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, 3688c2ecf20Sopenharmony_ci struct btrfs_delayed_ref_head *head); 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_cistruct btrfs_delayed_ref_head *btrfs_select_ref_head( 3718c2ecf20Sopenharmony_ci struct btrfs_delayed_ref_root *delayed_refs); 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ciint btrfs_check_delayed_seq(struct btrfs_fs_info *fs_info, u64 seq); 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_civoid btrfs_delayed_refs_rsv_release(struct btrfs_fs_info *fs_info, int nr); 3768c2ecf20Sopenharmony_civoid btrfs_update_delayed_refs_rsv(struct btrfs_trans_handle *trans); 3778c2ecf20Sopenharmony_ciint btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, 3788c2ecf20Sopenharmony_ci enum btrfs_reserve_flush_enum flush); 3798c2ecf20Sopenharmony_civoid btrfs_migrate_to_delayed_refs_rsv(struct btrfs_fs_info *fs_info, 3808c2ecf20Sopenharmony_ci struct btrfs_block_rsv *src, 3818c2ecf20Sopenharmony_ci u64 num_bytes); 3828c2ecf20Sopenharmony_ciint btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans); 3838c2ecf20Sopenharmony_cibool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info); 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci/* 3868c2ecf20Sopenharmony_ci * helper functions to cast a node into its container 3878c2ecf20Sopenharmony_ci */ 3888c2ecf20Sopenharmony_cistatic inline struct btrfs_delayed_tree_ref * 3898c2ecf20Sopenharmony_cibtrfs_delayed_node_to_tree_ref(struct btrfs_delayed_ref_node *node) 3908c2ecf20Sopenharmony_ci{ 3918c2ecf20Sopenharmony_ci return container_of(node, struct btrfs_delayed_tree_ref, node); 3928c2ecf20Sopenharmony_ci} 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_cistatic inline struct btrfs_delayed_data_ref * 3958c2ecf20Sopenharmony_cibtrfs_delayed_node_to_data_ref(struct btrfs_delayed_ref_node *node) 3968c2ecf20Sopenharmony_ci{ 3978c2ecf20Sopenharmony_ci return container_of(node, struct btrfs_delayed_data_ref, node); 3988c2ecf20Sopenharmony_ci} 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci#endif 401