Skip to contentSkip to conversation

btrfs: qgroup: Remove duplicated check in adding qgroup rels

PATCH In review Sidong Yang 2 participants 2 messages Feb 6, 2022 – Feb 10, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: qgroup: Remove duplicated check in adding qgroup rels

This patch removes duplicated check in adding qgroup relations. btrfs_add_qgroup_relations function add relations by calling add_relation_rb(). add_relation_rb() checks that member/parentid exists in current qgroup_tree. But it already checked before calling the function. It seems that we don't need to double check. This patch addes new function __add_relation_rb() that adds relations with btrfs_qgroup* not id and make old function use the new one. And it make btrfs_add_qgroup_relation() function work without double checks by calling the new function.

---
 fs/btrfs/qgroup.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
fs/btrfs/qgroup.c +16 -7
index 8928275823a1..29ffd37d8525 100644
@@ -259,15 +259,11 @@ static int del_qgroup_rb(struct btrfs_fs_info *fs_info, u64 qgroupid)
 }
 
 /* must be called with qgroup_lock held */
-static int add_relation_rb(struct btrfs_fs_info *fs_info,
-			   u64 memberid, u64 parentid)
+static int __add_relation_rb(struct btrfs_qgroup *member,
+							 struct btrfs_qgroup *parent)
 {
-	struct btrfs_qgroup *member;
-	struct btrfs_qgroup *parent;
 	struct btrfs_qgroup_list *list;
 
-	member = find_qgroup_rb(fs_info, memberid);
-	parent = find_qgroup_rb(fs_info, parentid);
 	if (!member || !parent)
 		return -ENOENT;
 
@@ -283,6 +279,19 @@ static int add_relation_rb(struct btrfs_fs_info *fs_info,
 	return 0;
 }
 
+/* must be called with qgroup_lock held */
+static int add_relation_rb(struct btrfs_fs_info *fs_info,
+			   u64 memberid, u64 parentid)
+{
+	struct btrfs_qgroup *member;
+	struct btrfs_qgroup *parent;
+
+	member = find_qgroup_rb(fs_info, memberid);
+	parent = find_qgroup_rb(fs_info, parentid);
+
+	return __add_relation_rb(member, parent);
+}
+
 /* must be called with qgroup_lock held */
 static int del_relation_rb(struct btrfs_fs_info *fs_info,
 			   u64 memberid, u64 parentid)
@@ -1430,7 +1439,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(member, parent);
 	if (ret < 0) {
 		spin_unlock(&fs_info->qgroup_lock);
 		goto out;
Signature · 1 line
2.25.1
#1 lore raw
Quoted 11 lines · Sidong Yang

This patch removes duplicated check in adding qgroup relations. btrfs_add_qgroup_relations function add relations by calling add_relation_rb(). add_relation_rb() checks that member/parentid exists in current qgroup_tree. But it already checked before calling the function. It seems that we don't need to double check. This patch addes new function __add_relation_rb() that adds relations with btrfs_qgroup* not id and make old function use the new one. And it make btrfs_add_qgroup_relation() function work without double checks by calling the new function.

Added to misc-next, thanks. I've written the function comments so it's clear that NULL is accepted for the pointer version.