btrfs: free block groups after free'ing fs trees
diff mbox series

Message ID
State New
Headers show
  • btrfs: free block groups after free'ing fs trees
Related show

Commit Message

Josef Bacik Dec. 19, 2019, 8:39 p.m. UTC
Sometimes when running generic/475 we would trip the
WARN_ON(cache->reserved) check when free'ing the block groups on umount.
This is because sometimes we don't commit the transaction because of IO
errors and thus do not cleanup the tree logs until at umount time.
These blocks are still reserved until they are cleaned up, but they
aren't cleaned up until _after_ we do the free block groups work.  Fix
this by moving the free after free'ing the fs roots, that way all of the
tree logs are cleaned up and we have a properly cleaned fs.  A bunch of
loops of generic/475 confirmed this fixes the problem.

Signed-off-by: Josef Bacik <>
 fs/btrfs/disk-io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff mbox series

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index fb60d09d2ac7..ed9f10cd1797 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -4050,12 +4050,12 @@  void __cold close_ctree(struct btrfs_fs_info *fs_info)
-	btrfs_free_block_groups(fs_info);
 	clear_bit(BTRFS_FS_OPEN, &fs_info->flags);
 	free_root_pointers(fs_info, true);
+	btrfs_free_block_groups(fs_info);