btrfs: qgroup: reuse btrfs_qgroup* in add_qgroup_relation
PATCH 1/1 btrfs: qgroup: reuse btrfs_qgroup* in add_qgroup_relation
In btrfs_add_qgroup_relation(), this function gets btrfs_qgroup with calling find_qgroup_rb() and checks its validity. if it's valid, it executes opeartion that add qgroup relation. But in this logic, it calls add_relation_rb() and it finds btrfs_qgroup again from id. This process can be skipped if we reuse the pointer get before. This patch adds add_relation_rb_qgroup() that receive btrfs_qgroup pointer but id. and replace add_relation_rb() to new helper function.
Signed-off-by Sidong Yang <[email protected]>
--- fs/btrfs/qgroup.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
fs/btrfs/qgroup.c +22 -1
@@ -259,6 +259,27 @@ static int del_qgroup_rb(struct btrfs_fs_info *fs_info, u64 qgroupid)return 0 ; } +/* must be called with qgroup_lock held */ +static int add_relation_rb_qgroup (struct btrfs_fs_info *fs_info, +struct btrfs_qgroup * member,struct btrfs_qgroup * parent) +{ +struct btrfs_qgroup_list *list; + +if (!member || !parent) +return -EINVAL ; + + list =kzalloc (sizeof (*list),GFP_ATOMIC ); +if (!list) +return -ENOMEM ; + + list->group = parent; + list->member = member; +list_add_tail (&list->next_group, &member->groups); +list_add_tail (&list->next_member, &parent->members); + +return 0 ; +} +/* must be called with qgroup_lock held */ static int add_relation_rb (struct btrfs_fs_info *fs_info,u64 memberid,u64 parentid)
@@ -1409,7 +1430,7 @@ int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans, u64 src, }spin_lock (&fs_info->qgroup_lock); - ret =add_relation_rb (fs_info, src, dst); + ret =add_relation_rb_qgroup (fs_info, member, parent);if (ret <0 ) {spin_unlock (&fs_info->qgroup_lock); goto out;
Signature · 1 line
2.25.1