284
* This checks to see if there are any delayed refs in the
285
* btree for a given bytenr. It returns one if it finds any
286
* and zero otherwise.
288
* If it only finds a head node, it returns 0.
290
* The idea is to use this when deciding if you can safely delete an
291
* extent from the extent allocation tree. There may be a pending
292
* ref in the rbtree that adds or removes references, so as long as this
293
* returns one you need to leave the BTRFS_EXTENT_ITEM in the extent
296
int btrfs_delayed_ref_pending(struct btrfs_trans_handle *trans, u64 bytenr)
298
struct btrfs_delayed_ref_node *ref;
299
struct btrfs_delayed_ref_root *delayed_refs;
300
struct rb_node *prev_node;
303
delayed_refs = &trans->transaction->delayed_refs;
304
spin_lock(&delayed_refs->lock);
306
ref = find_ref_head(&delayed_refs->root, bytenr, NULL);
308
prev_node = rb_prev(&ref->rb_node);
311
ref = rb_entry(prev_node, struct btrfs_delayed_ref_node,
313
if (ref->bytenr == bytenr)
317
spin_unlock(&delayed_refs->lock);
322
284
* helper function to update an extent delayed ref in the
323
285
* rbtree. existing and update must both have the same
324
286
* bytenr and parent
741
709
return btrfs_delayed_node_to_head(ref);
746
* add a delayed ref to the tree. This does all of the accounting required
747
* to make sure the delayed ref is eventually processed before this
748
* transaction commits.
750
* The main point of this call is to add and remove a backreference in a single
751
* shot, taking the lock only once, and only searching for the head node once.
753
* It is the same as doing a ref add and delete in two separate calls.
756
int btrfs_update_delayed_ref(struct btrfs_trans_handle *trans,
757
u64 bytenr, u64 num_bytes, u64 orig_parent,
758
u64 parent, u64 orig_ref_root, u64 ref_root,
759
u64 orig_ref_generation, u64 ref_generation,
760
u64 owner_objectid, int pin)
762
struct btrfs_delayed_ref *ref;
763
struct btrfs_delayed_ref *old_ref;
764
struct btrfs_delayed_ref_head *head_ref;
765
struct btrfs_delayed_ref_root *delayed_refs;
768
ref = kmalloc(sizeof(*ref), GFP_NOFS);
772
old_ref = kmalloc(sizeof(*old_ref), GFP_NOFS);
779
* the parent = 0 case comes from cases where we don't actually
780
* know the parent yet. It will get updated later via a add/drop
785
if (orig_parent == 0)
786
orig_parent = bytenr;
788
head_ref = kmalloc(sizeof(*head_ref), GFP_NOFS);
794
delayed_refs = &trans->transaction->delayed_refs;
795
spin_lock(&delayed_refs->lock);
798
* insert both the head node and the new ref without dropping
801
ret = __btrfs_add_delayed_ref(trans, &head_ref->node, bytenr, num_bytes,
803
BTRFS_UPDATE_DELAYED_HEAD, 0);
806
ret = __btrfs_add_delayed_ref(trans, &ref->node, bytenr, num_bytes,
807
parent, ref_root, ref_generation,
808
owner_objectid, BTRFS_ADD_DELAYED_REF, 0);
811
ret = __btrfs_add_delayed_ref(trans, &old_ref->node, bytenr, num_bytes,
812
orig_parent, orig_ref_root,
813
orig_ref_generation, owner_objectid,
814
BTRFS_DROP_DELAYED_REF, pin);
816
spin_unlock(&delayed_refs->lock);