|
@@ -695,44 +695,6 @@ static void init_delayed_ref_common(struct btrfs_fs_info *fs_info,
|
|
INIT_LIST_HEAD(&ref->add_list);
|
|
INIT_LIST_HEAD(&ref->add_list);
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
- * helper to insert a delayed data ref into the rbtree.
|
|
|
|
- */
|
|
|
|
-static noinline void
|
|
|
|
-add_delayed_data_ref(struct btrfs_trans_handle *trans,
|
|
|
|
- struct btrfs_delayed_ref_head *head_ref,
|
|
|
|
- struct btrfs_delayed_ref_node *ref, u64 bytenr,
|
|
|
|
- u64 num_bytes, u64 parent, u64 ref_root, u64 owner,
|
|
|
|
- u64 offset, int action)
|
|
|
|
-{
|
|
|
|
- struct btrfs_delayed_data_ref *full_ref;
|
|
|
|
- struct btrfs_delayed_ref_root *delayed_refs;
|
|
|
|
- u8 ref_type;
|
|
|
|
- int ret;
|
|
|
|
-
|
|
|
|
- delayed_refs = &trans->transaction->delayed_refs;
|
|
|
|
- full_ref = btrfs_delayed_node_to_data_ref(ref);
|
|
|
|
- if (parent)
|
|
|
|
- ref_type = BTRFS_SHARED_DATA_REF_KEY;
|
|
|
|
- else
|
|
|
|
- ref_type = BTRFS_EXTENT_DATA_REF_KEY;
|
|
|
|
-
|
|
|
|
- init_delayed_ref_common(trans->fs_info, ref, bytenr, num_bytes,
|
|
|
|
- ref_root, action, ref_type);
|
|
|
|
- full_ref->root = ref_root;
|
|
|
|
- full_ref->parent = parent;
|
|
|
|
- full_ref->objectid = owner;
|
|
|
|
- full_ref->offset = offset;
|
|
|
|
-
|
|
|
|
- trace_add_delayed_data_ref(trans->fs_info, ref, full_ref,
|
|
|
|
- action == BTRFS_ADD_DELAYED_EXTENT ?
|
|
|
|
- BTRFS_ADD_DELAYED_REF : action);
|
|
|
|
-
|
|
|
|
- ret = insert_delayed_ref(trans, delayed_refs, head_ref, ref);
|
|
|
|
- if (ret > 0)
|
|
|
|
- kmem_cache_free(btrfs_delayed_data_ref_cachep, full_ref);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/*
|
|
/*
|
|
* add a delayed tree ref. This does all of the accounting required
|
|
* add a delayed tree ref. This does all of the accounting required
|
|
* to make sure the delayed ref is eventually processed before this
|
|
* to make sure the delayed ref is eventually processed before this
|
|
@@ -832,11 +794,25 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
|
|
struct btrfs_delayed_ref_root *delayed_refs;
|
|
struct btrfs_delayed_ref_root *delayed_refs;
|
|
struct btrfs_qgroup_extent_record *record = NULL;
|
|
struct btrfs_qgroup_extent_record *record = NULL;
|
|
int qrecord_inserted;
|
|
int qrecord_inserted;
|
|
|
|
+ int ret;
|
|
|
|
+ u8 ref_type;
|
|
|
|
|
|
ref = kmem_cache_alloc(btrfs_delayed_data_ref_cachep, GFP_NOFS);
|
|
ref = kmem_cache_alloc(btrfs_delayed_data_ref_cachep, GFP_NOFS);
|
|
if (!ref)
|
|
if (!ref)
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
+ if (parent)
|
|
|
|
+ ref_type = BTRFS_SHARED_DATA_REF_KEY;
|
|
|
|
+ else
|
|
|
|
+ ref_type = BTRFS_EXTENT_DATA_REF_KEY;
|
|
|
|
+ init_delayed_ref_common(fs_info, &ref->node, bytenr, num_bytes,
|
|
|
|
+ ref_root, action, ref_type);
|
|
|
|
+ ref->root = ref_root;
|
|
|
|
+ ref->parent = parent;
|
|
|
|
+ ref->objectid = owner;
|
|
|
|
+ ref->offset = offset;
|
|
|
|
+
|
|
|
|
+
|
|
head_ref = kmem_cache_alloc(btrfs_delayed_ref_head_cachep, GFP_NOFS);
|
|
head_ref = kmem_cache_alloc(btrfs_delayed_ref_head_cachep, GFP_NOFS);
|
|
if (!head_ref) {
|
|
if (!head_ref) {
|
|
kmem_cache_free(btrfs_delayed_data_ref_cachep, ref);
|
|
kmem_cache_free(btrfs_delayed_data_ref_cachep, ref);
|
|
@@ -868,10 +844,16 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
|
|
action, 1, 0, &qrecord_inserted,
|
|
action, 1, 0, &qrecord_inserted,
|
|
old_ref_mod, new_ref_mod);
|
|
old_ref_mod, new_ref_mod);
|
|
|
|
|
|
- add_delayed_data_ref(trans, head_ref, &ref->node, bytenr, num_bytes,
|
|
|
|
- parent, ref_root, owner, offset, action);
|
|
|
|
|
|
+ ret = insert_delayed_ref(trans, delayed_refs, head_ref, &ref->node);
|
|
spin_unlock(&delayed_refs->lock);
|
|
spin_unlock(&delayed_refs->lock);
|
|
|
|
|
|
|
|
+ trace_add_delayed_data_ref(trans->fs_info, &ref->node, ref,
|
|
|
|
+ action == BTRFS_ADD_DELAYED_EXTENT ?
|
|
|
|
+ BTRFS_ADD_DELAYED_REF : action);
|
|
|
|
+ if (ret > 0)
|
|
|
|
+ kmem_cache_free(btrfs_delayed_data_ref_cachep, ref);
|
|
|
|
+
|
|
|
|
+
|
|
if (qrecord_inserted)
|
|
if (qrecord_inserted)
|
|
return btrfs_qgroup_trace_extent_post(fs_info, record);
|
|
return btrfs_qgroup_trace_extent_post(fs_info, record);
|
|
return 0;
|
|
return 0;
|