Skip to content

Commit a8df356

Browse files
boryaskdave
authored andcommitted
btrfs: forbid deleting live subvol qgroup
If a subvolume still exists, forbid deleting its qgroup 0/subvolid. This behavior generally leads to incorrect behavior in squotas and doesn't have a legitimate purpose. Fixes: cecbb53 ("btrfs: record simple quota deltas in delayed refs") CC: [email protected] # 5.4+ Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Boris Burkov <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 0c309d6 commit a8df356

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fs/btrfs/qgroup.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,15 @@ int btrfs_create_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid)
17361736
return ret;
17371737
}
17381738

1739+
static bool qgroup_has_usage(struct btrfs_qgroup *qgroup)
1740+
{
1741+
return (qgroup->rfer > 0 || qgroup->rfer_cmpr > 0 ||
1742+
qgroup->excl > 0 || qgroup->excl_cmpr > 0 ||
1743+
qgroup->rsv.values[BTRFS_QGROUP_RSV_DATA] > 0 ||
1744+
qgroup->rsv.values[BTRFS_QGROUP_RSV_META_PREALLOC] > 0 ||
1745+
qgroup->rsv.values[BTRFS_QGROUP_RSV_META_PERTRANS] > 0);
1746+
}
1747+
17391748
int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid)
17401749
{
17411750
struct btrfs_fs_info *fs_info = trans->fs_info;
@@ -1755,6 +1764,11 @@ int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid)
17551764
goto out;
17561765
}
17571766

1767+
if (is_fstree(qgroupid) && qgroup_has_usage(qgroup)) {
1768+
ret = -EBUSY;
1769+
goto out;
1770+
}
1771+
17581772
/* Check if there are no children of this qgroup */
17591773
if (!list_empty(&qgroup->members)) {
17601774
ret = -EBUSY;

0 commit comments

Comments
 (0)