btrfs: qgroup: Free per-trans reserved space when a subvolume get dropped
diff mbox series

Message ID
State New
Headers show
  • btrfs: qgroup: Free per-trans reserved space when a subvolume get dropped
Related show

Commit Message

Qu Wenruo July 14, 2020, 1:12 a.m. UTC
Sometime fsstress could lead to qgroup warning for case like
  BTRFS warning (device dm-3): qgroup 0/259 has unreleased space, type 1 rsv 81920
  ------------[ cut here ]------------
  WARNING: CPU: 9 PID: 24535 at fs/btrfs/disk-io.c:4142 close_ctree+0x1dc/0x323 [btrfs]
  Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015
  RIP: 0010:close_ctree+0x1dc/0x323 [btrfs]
  Call Trace:
   btrfs_put_super+0x15/0x17 [btrfs]
   btrfs_kill_super+0x17/0x30 [btrfs]
  ---[ end trace 6c341cdf9b6cc3c1 ]---
  BTRFS error (device dm-3): qgroup reserved space leaked

While that subvolume 259 is no longer in that filesystem.

Normally per-trans qgroup reserved space is freed when a transaction is
committed, in commit_fs_roots().

However for completely dropped subvolume, that subvolume is completely
gone, thus is no longer in the fs_roots_radix, and its per-trans
reserved qgroup will never be freed.

The only good news is, since the subvolume is already gone, leaked
per-trans space won't cause any thing wrong for end users.

Just call btrfs_qgroup_free_meta_all_pertrans() before a subvolume is
completely dropped.

Signed-off-by: Qu Wenruo <>
 fs/btrfs/extent-tree.c | 9 +++++++++
 1 file changed, 9 insertions(+)


David Sterba July 14, 2020, 2:22 p.m. UTC | #1
On Tue, Jul 14, 2020 at 09:12:20AM +0800, Qu Wenruo wrote:
> Signed-off-by: Qu Wenruo <>

Added to misc-next, thanks.

diff mbox series

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index c0bc35f932bf..122a0884a3a7 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5466,6 +5466,15 @@  int btrfs_drop_snapshot(struct btrfs_root *root, int update_ref, int for_reloc)
+	/*
+	 * This subvolume is going to be completely dropped, and won't be
+	 * recorded as dirty roots, thus pertrans meta rsv will not be freed
+	 * at commit transaction time.
+	 * So free it here manually.
+	 */
+	btrfs_qgroup_convert_reserved_meta(root, INT_MAX);
+	btrfs_qgroup_free_meta_all_pertrans(root);
 	if (test_bit(BTRFS_ROOT_IN_RADIX, &root->state))
 		btrfs_add_dropped_root(trans, root);