Skip to content

Commit c920f3f

Browse files
boryaskdave
authored andcommitted
btrfs: fix squota compressed stats leak
The following workload on a squota enabled fs: btrfs subvol create mnt/subvol # ensure subvol extents get accounted sync btrfs qgroup create 1/1 mnt btrfs qgroup assign mnt/subvol 1/1 mnt btrfs qgroup delete mnt/subvol # make the cleaner thread run btrfs filesystem sync mnt sleep 1 btrfs filesystem sync mnt btrfs qgroup destroy 1/1 mnt will fail with EBUSY. The reason is that 1/1 does the quick accounting when we assign subvol to it, gaining its exclusive usage as excl and excl_cmpr. But then when we delete subvol, the decrement happens via record_squota_delta() which does not update excl_cmpr, as squotas does not make any distinction between compressed and normal extents. Thus, we increment excl_cmpr but never decrement it, and are unable to delete 1/1. The two possible fixes are to make squota always mirror excl and excl_cmpr or to make the fast accounting separately track the plain and cmpr numbers. The latter felt cleaner to me so that is what I opted for. Fixes: 1e0e9d5 ("btrfs: add helper for recording simple quota deltas") CC: [email protected] # 6.12+ Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Boris Burkov <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent b710b34 commit c920f3f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/btrfs/qgroup.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,7 @@ static int __qgroup_excl_accounting(struct btrfs_fs_info *fs_info, u64 ref_root,
14551455
struct btrfs_qgroup *qgroup;
14561456
LIST_HEAD(qgroup_list);
14571457
u64 num_bytes = src->excl;
1458+
u64 num_bytes_cmpr = src->excl_cmpr;
14581459
int ret = 0;
14591460

14601461
qgroup = find_qgroup_rb(fs_info, ref_root);
@@ -1466,11 +1467,12 @@ static int __qgroup_excl_accounting(struct btrfs_fs_info *fs_info, u64 ref_root,
14661467
struct btrfs_qgroup_list *glist;
14671468

14681469
qgroup->rfer += sign * num_bytes;
1469-
qgroup->rfer_cmpr += sign * num_bytes;
1470+
qgroup->rfer_cmpr += sign * num_bytes_cmpr;
14701471

14711472
WARN_ON(sign < 0 && qgroup->excl < num_bytes);
1473+
WARN_ON(sign < 0 && qgroup->excl_cmpr < num_bytes_cmpr);
14721474
qgroup->excl += sign * num_bytes;
1473-
qgroup->excl_cmpr += sign * num_bytes;
1475+
qgroup->excl_cmpr += sign * num_bytes_cmpr;
14741476

14751477
if (sign > 0)
14761478
qgroup_rsv_add_by_qgroup(fs_info, qgroup, src);

0 commit comments

Comments
 (0)