Btrfs: add missing extents release on file extent cluster relocation error
PATCH 1/1 Btrfs: add missing extents release on file extent cluster relocation error
From: Filipe Manana <[email protected]>
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.
--- fs/btrfs/relocation.c | 2 ++ 1 file changed, 2 insertions(+)
fs/btrfs/relocation.c +2 -0
@@ -3277,6 +3277,8 @@ static int relocate_file_extent_cluster(struct inode *inode,if (!page) {btrfs_delalloc_release_metadata (BTRFS_I (inode),PAGE_SIZE , true); +btrfs_delalloc_release_extents (BTRFS_I (inode), +PAGE_SIZE , true); ret = -ENOMEM ; goto out; }
Signature · 1 line
2.11.0
Quoted 20 lines · On 09/10/2019 18:43, [email protected] wrote:
From: Filipe Manana <[email protected]>
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 tobtrfs_delalloc_reserve_metadata(), otherwise the inode's block reserve size can never decrease to zero and metadata space is leaked. Therefore add a call tobtrfs_delalloc_release_extents()in case we can't find the target page.Fixes 8b62f87bad9cf0 ("Btrfs: rework outstanding_extents")Signed-off-by Filipe Manana <[email protected]>--- fs/btrfs/relocation.c | 2 ++ 1 file changed, 2 insertions(+)fs/btrfs/relocation.c +0
-0
fs/btrfs/relocation.c static int relocate_file_extent_cluster(struct inode *inode, · line 3281
Quoted 5 lines
fs/btrfs/relocation.c +2
-0@@ -3277,6 +3277,8 @@ static int relocate_file_extent_cluster(struct inode *inode,if (!page) {btrfs_delalloc_release_metadata (BTRFS_I (inode),PAGE_SIZE , true); +btrfs_delalloc_release_extents (BTRFS_I (inode), +PAGE_SIZE , true);
Hmm how about adding a wrapper to combine these two calls similar to what btrfs_delalloc_release_space() is doing for btrfs_delalloc_release_metadata() and btrfs_free_reserved_data_space()?
I count at least 3 other occurences of this pattern with a simple git grep -C 4 btrfs_delalloc_release_metadata fs/btrfs/ | \
grep btrfs_delalloc_release_extents
One of them being in the same function.
Otherwise
Signature · 8 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 247165, AG München) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Quoted 31 lines · Johannes Thumshirn
Quoted 20 lines · On 09/10/2019 18:43, [email protected] wrote:
From: Filipe Manana <[email protected]>
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 tobtrfs_delalloc_reserve_metadata(), otherwise the inode's block reserve size can never decrease to zero and metadata space is leaked. Therefore add a call tobtrfs_delalloc_release_extents()in case we can't find the target page.Fixes 8b62f87bad9cf0 ("Btrfs: rework outstanding_extents")Signed-off-by Filipe Manana <[email protected]>--- fs/btrfs/relocation.c | 2 ++ 1 file changed, 2 insertions(+)fs/btrfs/relocation.c +0
-0fs/btrfs/relocation.c static int relocate_file_extent_cluster(struct inode *inode, · line 3281
Quoted 5 lines
fs/btrfs/relocation.c +2
-0@@ -3277,6 +3277,8 @@ static int relocate_file_extent_cluster(struct inode *inode,if (!page) {btrfs_delalloc_release_metadata (BTRFS_I (inode),PAGE_SIZE , true); +btrfs_delalloc_release_extents (BTRFS_I (inode), +PAGE_SIZE , true);Hmm how about adding a wrapper to combine these two calls similar to what
btrfs_delalloc_release_space()is doing forbtrfs_delalloc_release_metadata()andbtrfs_free_reserved_data_space()?
Quoted 5 lines
I count at least 3 other occurences of this pattern with a simple git grep -C 4
btrfs_delalloc_release_metadatafs/btrfs/| \
grepbtrfs_delalloc_release_extentsOne of them being in the same function.
I'm not sure another wrapper would be a significant improvement. The two functions are called separatelly in many places so it has to be decided case by case anyway.
Reading relocate_file_extent_cluster, there are places that call only one of the functions (due to partial initialization) and that need both, so that it's explicitly visible can be matched agains the context. Eg. hilighting the function in the editor is a visual clue that I'm using often so the extra wrapper would slightly obscure that.
Quoted 11 lines · On Wed, Oct 09, 2019 at 05:43:45PM +0100, [email protected] wrote:
From: Filipe Manana <[email protected]>
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 tobtrfs_delalloc_reserve_metadata(), otherwise the inode's block reserve size can never decrease to zero and metadata space is leaked. Therefore add a call tobtrfs_delalloc_release_extents()in case we can't find the target page.Fixes 8b62f87bad9cf0 ("Btrfs: rework outstanding_extents")Signed-off-by Filipe Manana <[email protected]>
Added to misc-next, thanks.