Commit 76675593 authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: delayed-ref: Use btrfs_ref to refactor btrfs_add_delayed_data_ref()

Just like btrfs_add_delayed_tree_ref(), use btrfs_ref to refactor
btrfs_add_delayed_data_ref().
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent ed4f255b
...@@ -832,10 +832,9 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, ...@@ -832,10 +832,9 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
* add a delayed data ref. it's similar to btrfs_add_delayed_tree_ref. * add a delayed data ref. it's similar to btrfs_add_delayed_tree_ref.
*/ */
int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, struct btrfs_ref *generic_ref,
u64 parent, u64 ref_root, u64 reserved, int *old_ref_mod,
u64 owner, u64 offset, u64 reserved, int action, int *new_ref_mod)
int *old_ref_mod, int *new_ref_mod)
{ {
struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_delayed_data_ref *ref; struct btrfs_delayed_data_ref *ref;
...@@ -843,9 +842,17 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, ...@@ -843,9 +842,17 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans,
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 action = generic_ref->action;
int ret; int ret;
u64 bytenr = generic_ref->bytenr;
u64 num_bytes = generic_ref->len;
u64 parent = generic_ref->parent;
u64 ref_root = generic_ref->data_ref.ref_root;
u64 owner = generic_ref->data_ref.ino;
u64 offset = generic_ref->data_ref.offset;
u8 ref_type; u8 ref_type;
ASSERT(generic_ref->type == BTRFS_REF_DATA && action);
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;
...@@ -869,7 +876,9 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, ...@@ -869,7 +876,9 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans,
} }
if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags) && if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags) &&
is_fstree(ref_root)) { is_fstree(ref_root) &&
is_fstree(generic_ref->real_root) &&
!generic_ref->skip_qgroup) {
record = kzalloc(sizeof(*record), GFP_NOFS); record = kzalloc(sizeof(*record), GFP_NOFS);
if (!record) { if (!record) {
kmem_cache_free(btrfs_delayed_data_ref_cachep, ref); kmem_cache_free(btrfs_delayed_data_ref_cachep, ref);
......
...@@ -337,10 +337,9 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, ...@@ -337,10 +337,9 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
struct btrfs_delayed_extent_op *extent_op, struct btrfs_delayed_extent_op *extent_op,
int *old_ref_mod, int *new_ref_mod); int *old_ref_mod, int *new_ref_mod);
int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, struct btrfs_ref *generic_ref,
u64 parent, u64 ref_root, u64 reserved, int *old_ref_mod,
u64 owner, u64 offset, u64 reserved, int action, int *new_ref_mod);
int *old_ref_mod, int *new_ref_mod);
int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info,
struct btrfs_trans_handle *trans, struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, u64 bytenr, u64 num_bytes,
......
...@@ -2065,10 +2065,8 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, ...@@ -2065,10 +2065,8 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
ret = btrfs_add_delayed_tree_ref(trans, &generic_ref, ret = btrfs_add_delayed_tree_ref(trans, &generic_ref,
NULL, &old_ref_mod, &new_ref_mod); NULL, &old_ref_mod, &new_ref_mod);
} else { } else {
ret = btrfs_add_delayed_data_ref(trans, bytenr, btrfs_init_data_ref(&generic_ref, root_objectid, owner, offset);
num_bytes, parent, ret = btrfs_add_delayed_data_ref(trans, &generic_ref, 0,
root_objectid, owner, offset,
0, BTRFS_ADD_DELAYED_REF,
&old_ref_mod, &new_ref_mod); &old_ref_mod, &new_ref_mod);
} }
...@@ -7276,10 +7274,8 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans, ...@@ -7276,10 +7274,8 @@ int btrfs_free_extent(struct btrfs_trans_handle *trans,
ret = btrfs_add_delayed_tree_ref(trans, &generic_ref, NULL, ret = btrfs_add_delayed_tree_ref(trans, &generic_ref, NULL,
&old_ref_mod, &new_ref_mod); &old_ref_mod, &new_ref_mod);
} else { } else {
ret = btrfs_add_delayed_data_ref(trans, bytenr, btrfs_init_data_ref(&generic_ref, root_objectid, owner, offset);
num_bytes, parent, ret = btrfs_add_delayed_data_ref(trans, &generic_ref, 0,
root_objectid, owner, offset,
0, BTRFS_DROP_DELAYED_REF,
&old_ref_mod, &new_ref_mod); &old_ref_mod, &new_ref_mod);
} }
...@@ -8385,6 +8381,7 @@ int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, ...@@ -8385,6 +8381,7 @@ int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
u64 offset, u64 ram_bytes, u64 offset, u64 ram_bytes,
struct btrfs_key *ins) struct btrfs_key *ins)
{ {
struct btrfs_ref generic_ref = { 0 };
int ret; int ret;
BUG_ON(root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID); BUG_ON(root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID);
...@@ -8393,11 +8390,11 @@ int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans, ...@@ -8393,11 +8390,11 @@ int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
root->root_key.objectid, owner, offset, root->root_key.objectid, owner, offset,
BTRFS_ADD_DELAYED_EXTENT); BTRFS_ADD_DELAYED_EXTENT);
ret = btrfs_add_delayed_data_ref(trans, ins->objectid, btrfs_init_generic_ref(&generic_ref, BTRFS_ADD_DELAYED_EXTENT,
ins->offset, 0, ins->objectid, ins->offset, 0);
root->root_key.objectid, owner, btrfs_init_data_ref(&generic_ref, root->root_key.objectid, owner, offset);
offset, ram_bytes, ret = btrfs_add_delayed_data_ref(trans, &generic_ref,
BTRFS_ADD_DELAYED_EXTENT, NULL, NULL); ram_bytes, NULL, NULL);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment