// SPDX-License-Identifier: GPL-2.0/* * Copyright (C) 2009 Oracle. All rights reserved. */#include<linux/sched.h>#include<linux/slab.h>#include<linux/sort.h>#include"messages.h"#include"ctree.h"#include"delayed-ref.h"#include"extent-tree.h"#include"transaction.h"#include"qgroup.h"#include"space-info.h"#include"tree-mod-log.h"#include"fs.h"structkmem_cache*btrfs_delayed_ref_head_cachep;structkmem_cache*btrfs_delayed_ref_node_cachep;structkmem_cache*btrfs_delayed_extent_op_cachep;/* * delayed back reference update tracking. For subvolume trees * we queue up extent allocations and backref maintenance for * delayed processing. This avoids deep call chains where we * add extents in the middle of btrfs_search_slot, and it allows * us to buffer up frequently modified backrefs in an rb tree instead * of hammering updates on the extent allocation tree. */boolbtrfs_check_space_for_delayed_refs(structbtrfs_fs_info*fs_info){structbtrfs_block_rsv*delayed_refs_rsv=&fs_info->delayed_refs_rsv;structbtrfs_block_rsv*global_rsv=&fs_info->global_block_rsv;boolret=false;u64reserved;spin_lock(&global_rsv->lock);reserved=global_rsv->reserved;spin_unlock(&global_rsv->lock);/* * Since the global reserve is just kind of magic we don't really want * to rely on it to save our bacon, so if our size is more than the * delayed_refs_rsv and the global rsv then it's time to think about * bailing. */spin_lock(&delayed_refs_rsv->lock);reserved+=delayed_refs_rsv->reserved;if(delayed_refs_rsv->size>=reserved)ret=true;spin_unlock(&delayed_refs_rsv->lock);returnret;}/* * Release a ref head's reservation. * * @fs_info: the filesystem * @nr_refs: number of delayed refs to drop * @nr_csums: number of csum items to drop * * Drops the delayed ref head's count from the delayed refs rsv and free any * excess reservation we had. */voidbtrfs_delayed_refs_rsv_release(structbtrfs_fs_info*fs_info,intnr_refs,int<