* [PATCH 0/3] btrfs: fixes for inline extent fallback and error handling
@ 2025-12-15 9:38 fdmanana
2025-12-15 9:38 ` [PATCH 1/3] btrfs: do not free data reservation in fallback from inline due to -ENOSPC fdmanana
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: fdmanana @ 2025-12-15 9:38 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
A couple fixes and a cleanup in the inline extent creation path.
Details in the changelogs.
Filipe Manana (3):
btrfs: do not free data reservation in fallback from inline due to -ENOSPC
btrfs: fix reservation leak in some error paths when inserting inline extent
btrfs: update stale comment in __cow_file_range_inline()
fs/btrfs/inode.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
--
2.47.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] btrfs: do not free data reservation in fallback from inline due to -ENOSPC
2025-12-15 9:38 [PATCH 0/3] btrfs: fixes for inline extent fallback and error handling fdmanana
@ 2025-12-15 9:38 ` fdmanana
2025-12-15 9:45 ` Qu Wenruo
2025-12-15 9:38 ` [PATCH 2/3] btrfs: fix reservation leak in some error paths when inserting inline extent fdmanana
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: fdmanana @ 2025-12-15 9:38 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
If we fail to create an inline extent due to -ENOSPC, we will attempt to
go through the normal COW path, reserve an extent, create an ordered
extent, etc. However we were always freeing the reserved qgroup data,
which is wrong since we will use data. Fix this by freeing the reserved
qgroup data in __cow_file_range_inline() only if we are not doing the
fallback (ret is <= 0).
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/inode.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 566780eb80ff..605589f29da7 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -675,8 +675,12 @@ static noinline int __cow_file_range_inline(struct btrfs_inode *inode,
* it won't count as data extent, free them directly here.
* And at reserve time, it's always aligned to page size, so
* just free one page here.
+ *
+ * If we fallback to non-inline (ret == 1) due to -ENOSPC, then we need
+ * to keep the data reservation.
*/
- btrfs_qgroup_free_data(inode, NULL, 0, fs_info->sectorsize, NULL);
+ if (ret <= 0)
+ btrfs_qgroup_free_data(inode, NULL, 0, fs_info->sectorsize, NULL);
btrfs_free_path(path);
btrfs_end_transaction(trans);
return ret;
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] btrfs: fix reservation leak in some error paths when inserting inline extent
2025-12-15 9:38 [PATCH 0/3] btrfs: fixes for inline extent fallback and error handling fdmanana
2025-12-15 9:38 ` [PATCH 1/3] btrfs: do not free data reservation in fallback from inline due to -ENOSPC fdmanana
@ 2025-12-15 9:38 ` fdmanana
2025-12-15 9:38 ` [PATCH 3/3] btrfs: update stale comment in __cow_file_range_inline() fdmanana
2025-12-15 18:43 ` [PATCH 0/3] btrfs: fixes for inline extent fallback and error handling David Sterba
3 siblings, 0 replies; 9+ messages in thread
From: fdmanana @ 2025-12-15 9:38 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
If we fail to allocate a path or join a transaction, we return from
__cow_file_range_inline() without freeing the reserved qgroup data,
resulting in a leak. Fix this by ensuring we call btrfs_qgroup_free_data()
in such cases.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/inode.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 605589f29da7..f1ead789146b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -619,19 +619,22 @@ static noinline int __cow_file_range_inline(struct btrfs_inode *inode,
struct btrfs_drop_extents_args drop_args = { 0 };
struct btrfs_root *root = inode->root;
struct btrfs_fs_info *fs_info = root->fs_info;
- struct btrfs_trans_handle *trans;
+ struct btrfs_trans_handle *trans = NULL;
u64 data_len = (compressed_size ?: size);
int ret;
struct btrfs_path *path;
path = btrfs_alloc_path();
- if (!path)
- return -ENOMEM;
+ if (!path) {
+ ret = -ENOMEM;
+ goto out;
+ }
trans = btrfs_join_transaction(root);
if (IS_ERR(trans)) {
- btrfs_free_path(path);
- return PTR_ERR(trans);
+ ret = PTR_ERR(trans);
+ trans = NULL;
+ goto out;
}
trans->block_rsv = &inode->block_rsv;
@@ -682,7 +685,8 @@ static noinline int __cow_file_range_inline(struct btrfs_inode *inode,
if (ret <= 0)
btrfs_qgroup_free_data(inode, NULL, 0, fs_info->sectorsize, NULL);
btrfs_free_path(path);
- btrfs_end_transaction(trans);
+ if (trans)
+ btrfs_end_transaction(trans);
return ret;
}
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] btrfs: update stale comment in __cow_file_range_inline()
2025-12-15 9:38 [PATCH 0/3] btrfs: fixes for inline extent fallback and error handling fdmanana
2025-12-15 9:38 ` [PATCH 1/3] btrfs: do not free data reservation in fallback from inline due to -ENOSPC fdmanana
2025-12-15 9:38 ` [PATCH 2/3] btrfs: fix reservation leak in some error paths when inserting inline extent fdmanana
@ 2025-12-15 9:38 ` fdmanana
2025-12-15 9:47 ` Qu Wenruo
2025-12-15 18:43 ` [PATCH 0/3] btrfs: fixes for inline extent fallback and error handling David Sterba
3 siblings, 1 reply; 9+ messages in thread
From: fdmanana @ 2025-12-15 9:38 UTC (permalink / raw)
To: linux-btrfs
From: Filipe Manana <fdmanana@suse.com>
We mention that the reserved data space is page size aligned but that's
not true anymore, as it's sector size aligned instead.
In commit 0bb067ca64e3 ("btrfs: fix the qgroup data free range for inline
data extents") we updated the amount passed to btrfs_qgroup_free_data()
from page size to sector size, but forgot to update the comment.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
fs/btrfs/inode.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index f1ead789146b..6ae36cc5bcda 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -676,7 +676,7 @@ static noinline int __cow_file_range_inline(struct btrfs_inode *inode,
/*
* Don't forget to free the reserved space, as for inlined extent
* it won't count as data extent, free them directly here.
- * And at reserve time, it's always aligned to page size, so
+ * And at reserve time, it's always aligned to sector size, so
* just free one page here.
*
* If we fallback to non-inline (ret == 1) due to -ENOSPC, then we need
--
2.47.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] btrfs: do not free data reservation in fallback from inline due to -ENOSPC
2025-12-15 9:38 ` [PATCH 1/3] btrfs: do not free data reservation in fallback from inline due to -ENOSPC fdmanana
@ 2025-12-15 9:45 ` Qu Wenruo
0 siblings, 0 replies; 9+ messages in thread
From: Qu Wenruo @ 2025-12-15 9:45 UTC (permalink / raw)
To: fdmanana, linux-btrfs
在 2025/12/15 20:08, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> If we fail to create an inline extent due to -ENOSPC, we will attempt to
> go through the normal COW path, reserve an extent, create an ordered
> extent, etc. However we were always freeing the reserved qgroup data,
> which is wrong since we will use data. Fix this by freeing the reserved
> qgroup data in __cow_file_range_inline() only if we are not doing the
> fallback (ret is <= 0).
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/inode.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 566780eb80ff..605589f29da7 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -675,8 +675,12 @@ static noinline int __cow_file_range_inline(struct btrfs_inode *inode,
> * it won't count as data extent, free them directly here.
> * And at reserve time, it's always aligned to page size, so
> * just free one page here.
> + *
> + * If we fallback to non-inline (ret == 1) due to -ENOSPC, then we need
> + * to keep the data reservation.
> */
> - btrfs_qgroup_free_data(inode, NULL, 0, fs_info->sectorsize, NULL);
> + if (ret <= 0)
> + btrfs_qgroup_free_data(inode, NULL, 0, fs_info->sectorsize, NULL);
> btrfs_free_path(path);
> btrfs_end_transaction(trans);
> return ret;
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] btrfs: update stale comment in __cow_file_range_inline()
2025-12-15 9:38 ` [PATCH 3/3] btrfs: update stale comment in __cow_file_range_inline() fdmanana
@ 2025-12-15 9:47 ` Qu Wenruo
2025-12-15 9:49 ` Filipe Manana
0 siblings, 1 reply; 9+ messages in thread
From: Qu Wenruo @ 2025-12-15 9:47 UTC (permalink / raw)
To: fdmanana, linux-btrfs
在 2025/12/15 20:08, fdmanana@kernel.org 写道:
> From: Filipe Manana <fdmanana@suse.com>
>
> We mention that the reserved data space is page size aligned but that's
> not true anymore, as it's sector size aligned instead.
> In commit 0bb067ca64e3 ("btrfs: fix the qgroup data free range for inline
> data extents") we updated the amount passed to btrfs_qgroup_free_data()
> from page size to sector size, but forgot to update the comment.
>
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---
> fs/btrfs/inode.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index f1ead789146b..6ae36cc5bcda 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -676,7 +676,7 @@ static noinline int __cow_file_range_inline(struct btrfs_inode *inode,
> /*
> * Don't forget to free the reserved space, as for inlined extent
> * it won't count as data extent, free them directly here.
> - * And at reserve time, it's always aligned to page size, so
> + * And at reserve time, it's always aligned to sector size, so
> * just free one page here.
There is still a "page" reference here.
Other than that it looks good to me.
Thanks,
Qu
> *
> * If we fallback to non-inline (ret == 1) due to -ENOSPC, then we need
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] btrfs: update stale comment in __cow_file_range_inline()
2025-12-15 9:47 ` Qu Wenruo
@ 2025-12-15 9:49 ` Filipe Manana
2025-12-15 9:50 ` Qu Wenruo
0 siblings, 1 reply; 9+ messages in thread
From: Filipe Manana @ 2025-12-15 9:49 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Mon, Dec 15, 2025 at 9:47 AM Qu Wenruo <quwenruo.btrfs@gmx.com> wrote:
>
>
>
> 在 2025/12/15 20:08, fdmanana@kernel.org 写道:
> > From: Filipe Manana <fdmanana@suse.com>
> >
> > We mention that the reserved data space is page size aligned but that's
> > not true anymore, as it's sector size aligned instead.
> > In commit 0bb067ca64e3 ("btrfs: fix the qgroup data free range for inline
> > data extents") we updated the amount passed to btrfs_qgroup_free_data()
> > from page size to sector size, but forgot to update the comment.
> >
> > Signed-off-by: Filipe Manana <fdmanana@suse.com>
> > ---
> > fs/btrfs/inode.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> > index f1ead789146b..6ae36cc5bcda 100644
> > --- a/fs/btrfs/inode.c
> > +++ b/fs/btrfs/inode.c
> > @@ -676,7 +676,7 @@ static noinline int __cow_file_range_inline(struct btrfs_inode *inode,
> > /*
> > * Don't forget to free the reserved space, as for inlined extent
> > * it won't count as data extent, free them directly here.
> > - * And at reserve time, it's always aligned to page size, so
> > + * And at reserve time, it's always aligned to sector size, so
> > * just free one page here.
>
> There is still a "page" reference here.
Ah yes, I will update it before pushing to for-next, thanks.
>
> Other than that it looks good to me.
>
> Thanks,
> Qu
>
> > *
> > * If we fallback to non-inline (ret == 1) due to -ENOSPC, then we need
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] btrfs: update stale comment in __cow_file_range_inline()
2025-12-15 9:49 ` Filipe Manana
@ 2025-12-15 9:50 ` Qu Wenruo
0 siblings, 0 replies; 9+ messages in thread
From: Qu Wenruo @ 2025-12-15 9:50 UTC (permalink / raw)
To: Filipe Manana; +Cc: linux-btrfs
在 2025/12/15 20:19, Filipe Manana 写道:
> On Mon, Dec 15, 2025 at 9:47 AM Qu Wenruo <quwenruo.btrfs@gmx.com> wrote:
>>
>>
>>
>> 在 2025/12/15 20:08, fdmanana@kernel.org 写道:
>>> From: Filipe Manana <fdmanana@suse.com>
>>>
>>> We mention that the reserved data space is page size aligned but that's
>>> not true anymore, as it's sector size aligned instead.
>>> In commit 0bb067ca64e3 ("btrfs: fix the qgroup data free range for inline
>>> data extents") we updated the amount passed to btrfs_qgroup_free_data()
>>> from page size to sector size, but forgot to update the comment.
>>>
>>> Signed-off-by: Filipe Manana <fdmanana@suse.com>
>>> ---
>>> fs/btrfs/inode.c | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
>>> index f1ead789146b..6ae36cc5bcda 100644
>>> --- a/fs/btrfs/inode.c
>>> +++ b/fs/btrfs/inode.c
>>> @@ -676,7 +676,7 @@ static noinline int __cow_file_range_inline(struct btrfs_inode *inode,
>>> /*
>>> * Don't forget to free the reserved space, as for inlined extent
>>> * it won't count as data extent, free them directly here.
>>> - * And at reserve time, it's always aligned to page size, so
>>> + * And at reserve time, it's always aligned to sector size, so
>>> * just free one page here.
>>
>> There is still a "page" reference here.
>
> Ah yes, I will update it before pushing to for-next, thanks.
Oh, forgot my tag.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
>
>>
>> Other than that it looks good to me.
>>
>> Thanks,
>> Qu
>>
>>> *
>>> * If we fallback to non-inline (ret == 1) due to -ENOSPC, then we need
>>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] btrfs: fixes for inline extent fallback and error handling
2025-12-15 9:38 [PATCH 0/3] btrfs: fixes for inline extent fallback and error handling fdmanana
` (2 preceding siblings ...)
2025-12-15 9:38 ` [PATCH 3/3] btrfs: update stale comment in __cow_file_range_inline() fdmanana
@ 2025-12-15 18:43 ` David Sterba
3 siblings, 0 replies; 9+ messages in thread
From: David Sterba @ 2025-12-15 18:43 UTC (permalink / raw)
To: fdmanana; +Cc: linux-btrfs
On Mon, Dec 15, 2025 at 09:38:24AM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> A couple fixes and a cleanup in the inline extent creation path.
> Details in the changelogs.
>
> Filipe Manana (3):
> btrfs: do not free data reservation in fallback from inline due to -ENOSPC
> btrfs: fix reservation leak in some error paths when inserting inline extent
> btrfs: update stale comment in __cow_file_range_inline()
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-12-15 18:43 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-15 9:38 [PATCH 0/3] btrfs: fixes for inline extent fallback and error handling fdmanana
2025-12-15 9:38 ` [PATCH 1/3] btrfs: do not free data reservation in fallback from inline due to -ENOSPC fdmanana
2025-12-15 9:45 ` Qu Wenruo
2025-12-15 9:38 ` [PATCH 2/3] btrfs: fix reservation leak in some error paths when inserting inline extent fdmanana
2025-12-15 9:38 ` [PATCH 3/3] btrfs: update stale comment in __cow_file_range_inline() fdmanana
2025-12-15 9:47 ` Qu Wenruo
2025-12-15 9:49 ` Filipe Manana
2025-12-15 9:50 ` Qu Wenruo
2025-12-15 18:43 ` [PATCH 0/3] btrfs: fixes for inline extent fallback and error handling David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox