Skip to contentSkip to conversation

Btrfs: add missing extents release on file extent cluster relocation error

PATCH In review [email protected] 3 participants 4 messages Oct 9, 2019 – Oct 11, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

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.

Fixes 8b62f87bad9cf0 ("Btrfs: rework outstanding_extents")
---
 fs/btrfs/relocation.c | 2 ++
 1 file changed, 2 insertions(+)
fs/btrfs/relocation.c +2 -0
index 00504657b602..88dbc0127793 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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 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 8b62f87bad9cf0 ("Btrfs: rework outstanding_extents")
---
 fs/btrfs/relocation.c | 2 ++
 1 file changed, 2 insertions(+)
fs/btrfs/relocation.c +0 -0
index 00504657b602..88dbc0127793 100644

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
#2 lore raw
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 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 8b62f87bad9cf0 ("Btrfs: rework outstanding_extents")
---
 fs/btrfs/relocation.c | 2 ++
 1 file changed, 2 insertions(+)
fs/btrfs/relocation.c +0 -0
index 00504657b602..88dbc0127793 100644

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()?

Quoted 5 lines

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.

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.

#3 lore raw
In reply to [email protected]
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 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 8b62f87bad9cf0 ("Btrfs: rework outstanding_extents")

Added to misc-next, thanks.