btrfs: qgroup: remove duplicated check in adding qgroup relations
authorSidong Yang <realwakka@gmail.com>
Sun, 6 Feb 2022 12:52:48 +0000 (12:52 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 14 Mar 2022 12:13:50 +0000 (13:13 +0100)
Removes duplicated check when adding qgroup relations.
btrfs_add_qgroup_relations function adds 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.

Add new function __add_relation_rb() that adds relations with
qgroup structures and makes old function use the new one. And it makes
btrfs_add_qgroup_relation() function work without double checks by
calling the new function.

Signed-off-by: Sidong Yang <realwakka@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ add comments ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/qgroup.c

index d437511ed35406f3e359ad6806a60c2ab19a61c3..a22b901ac25a7100ea9b37f5aac56673af94d2d0 100644 (file)
@@ -258,16 +258,19 @@ 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(struct btrfs_fs_info *fs_info,
-                          u64 memberid, u64 parentid)
+/*
+ * Add relation specified by two qgroups.
+ *
+ * Must be called with qgroup_lock held.
+ *
+ * Return: 0        on success
+ *         -ENOENT  if one of the qgroups is NULL
+ *         <0       other errors
+ */
+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,7 +286,27 @@ static int add_relation_rb(struct btrfs_fs_info *fs_info,
        return 0;
 }
 
-/* must be called with qgroup_lock held */
+/*
+ * Add relation specified by two qgoup ids.
+ *
+ * Must be called with qgroup_lock held.
+ *
+ * Return: 0        on success
+ *         -ENOENT  if one of the ids does not exist
+ *         <0       other errors
+ */
+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)
 {
@@ -1457,7 +1480,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;