blob: 46e1a62b4b6f4f94fab78ade95c331631e356cce [file] [log] [blame]
From 95b1249d2901e4343e23db86a038d1d2d9e79fa5 Mon Sep 17 00:00:00 2001
From: Filipe Manana <>
Date: Wed, 9 Oct 2019 17:43:45 +0100
Subject: [PATCH] Btrfs: add missing extents release on file extent cluster
relocation error
commit 44db1216efe37bf670f8d1019cdc41658d84baf5 upstream.
If we error out when finding a page at relocate_file_extent_cluster(), we
need to release the outstanding extents counter on the relocation inode,
set by the previous call to btrfs_delalloc_reserve_metadata(), otherwise
the inode's block reserve size can never decrease to zero and metadata
space is leaked. Therefore add a call to btrfs_delalloc_release_extents()
in case we can't find the target page.
Fixes: 8b62f87bad9c ("Btrfs: rework outstanding_extents")
CC: # 4.19+
Signed-off-by: Filipe Manana <>
Reviewed-by: David Sterba <>
Signed-off-by: David Sterba <>
Signed-off-by: Paul Gortmaker <>
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 87e69df1bc8a..4ac240c18cbd 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3275,6 +3275,8 @@ static int relocate_file_extent_cluster(struct inode *inode,
if (!page) {
PAGE_SIZE, true);
+ btrfs_delalloc_release_extents(BTRFS_I(inode),
+ PAGE_SIZE, true);
ret = -ENOMEM;
goto out;