Skip to contentSkip to conversation

btrfs: qgroup: Always remove all qgroup relation in btrfs_remove_qgroup()

PATCH In review Misono Tomohiro 2 participants 2 messages Aug 9, 2018 1 message not in the archive Btrfs file system

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 btrfs: qgroup: Always remove all qgroup relation in btrfs_remove_qgroup()

In btrfs_remove_qgroup(), each qgroup relation is removed by calling __del_qgroup_relation(). However, __del_qgroup_relation() returns 1 if deletion of qgroup relation causes inconsistency and current code exits immediately in that case.

Therefore if there are several qgroup relations and removing first relation causes inconsistency, remaining items will not be removed.

Fix this by continuing to remove items if return value of __del_qgroup_relation() is 1.

---
 fs/btrfs/qgroup.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +12 -3
index 2ba29f0609d9..f18284253e77 100644
@@ -1428,12 +1428,21 @@ int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid)
 		goto out;
 
 	while (!list_empty(&qgroup->groups)) {
+		int ret2;
+
 		list = list_first_entry(&qgroup->groups,
 					struct btrfs_qgroup_list, next_group);
-		ret = __del_qgroup_relation(trans, qgroupid,
+		ret2 = __del_qgroup_relation(trans, qgroupid,
 					    list->group->qgroupid);
-		if (ret)
-			goto out;
+		if (ret2) {
+			ret = ret2;
+			/*
+			 * __del_qgroup_relation() returns 1 if qgroup becomes
+			 * inconsistent. Continue to remove items in that case.
+			 */
+			if (ret != 1)
+				goto out;
+		}
 	}
 
 	spin_lock(&fs_info->qgroup_lock);
Signature · 1 line
2.14.4
Reviewed-by on v1 1/1
#2 lore raw
Quoted 5 lines · Misono Tomohiro

In btrfs_remove_qgroup(), each qgroup relation is removed by calling __del_qgroup_relation(). However, __del_qgroup_relation() returns 1 if deletion of qgroup relation causes inconsistency and current code exits immediately in that case.

Quoted 7 lines

Therefore if there are several qgroup relations and removing first relation causes inconsistency, remaining items will not be removed.

Fix this by continuing to remove items if return value of __del_qgroup_relation() is 1.

Indeed we still need to remove all qgroup relationship even we will make qgroup inconsistent.

Thanks,
Qu

Quoted 34 lines
---
 fs/btrfs/qgroup.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
fs/btrfs/qgroup.c +12 -3
index 2ba29f0609d9..f18284253e77 100644
@@ -1428,12 +1428,21 @@ int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid)
 		goto out;
 
 	while (!list_empty(&qgroup->groups)) {
+		int ret2;
+
 		list = list_first_entry(&qgroup->groups,
 					struct btrfs_qgroup_list, next_group);
-		ret = __del_qgroup_relation(trans, qgroupid,
+		ret2 = __del_qgroup_relation(trans, qgroupid,
 					    list->group->qgroupid);
-		if (ret)
-			goto out;
+		if (ret2) {
+			ret = ret2;
+			/*
+			 * __del_qgroup_relation() returns 1 if qgroup becomes
+			 * inconsistent. Continue to remove items in that case.
+			 */
+			if (ret != 1)
+				goto out;
+		}
 	}
 
 	spin_lock(&fs_info->qgroup_lock);