linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: Unlock extents in btrfs_zero_range in case of errors
@ 2021-02-23 13:20 Nikolay Borisov
  2021-02-23 13:24 ` Qu Wenruo
  2021-02-23 14:01 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Nikolay Borisov @ 2021-02-23 13:20 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

If btrfs_qgroup_reserve_data returns an error (i.e quota limit reached)
the handling logic directly goes to the 'out' label without first
unlocking the extent range between lockstart, lockend. This results in
deadlocks as processes try to lock the same extent.

Fixes: a7f8b1c2ac21 ("btrfs: file: reserve qgroup space after the hole punch range is locked")
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 1e68349c3884..af0253473508 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -3259,8 +3259,11 @@ static int btrfs_zero_range(struct inode *inode,
 			goto out;
 		ret = btrfs_qgroup_reserve_data(BTRFS_I(inode), &data_reserved,
 						alloc_start, bytes_to_reserve);
-		if (ret)
+		if (ret) {
+			unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart,
+					     lockend, &cached_state);
 			goto out;
+		}
 		ret = btrfs_prealloc_file_range(inode, mode, alloc_start,
 						alloc_end - alloc_start,
 						i_blocksize(inode),
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: Unlock extents in btrfs_zero_range in case of errors
  2021-02-23 13:20 [PATCH] btrfs: Unlock extents in btrfs_zero_range in case of errors Nikolay Borisov
@ 2021-02-23 13:24 ` Qu Wenruo
  2021-02-23 14:01 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2021-02-23 13:24 UTC (permalink / raw)
  To: Nikolay Borisov, linux-btrfs



On 2021/2/23 下午9:20, Nikolay Borisov wrote:
> If btrfs_qgroup_reserve_data returns an error (i.e quota limit reached)
> the handling logic directly goes to the 'out' label without first
> unlocking the extent range between lockstart, lockend. This results in
> deadlocks as processes try to lock the same extent.
>
> Fixes: a7f8b1c2ac21 ("btrfs: file: reserve qgroup space after the hole punch range is locked")
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/file.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 1e68349c3884..af0253473508 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -3259,8 +3259,11 @@ static int btrfs_zero_range(struct inode *inode,
>   			goto out;
>   		ret = btrfs_qgroup_reserve_data(BTRFS_I(inode), &data_reserved,
>   						alloc_start, bytes_to_reserve);
> -		if (ret)
> +		if (ret) {
> +			unlock_extent_cached(&BTRFS_I(inode)->io_tree, lockstart,
> +					     lockend, &cached_state);
>   			goto out;
> +		}
>   		ret = btrfs_prealloc_file_range(inode, mode, alloc_start,
>   						alloc_end - alloc_start,
>   						i_blocksize(inode),
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: Unlock extents in btrfs_zero_range in case of errors
  2021-02-23 13:20 [PATCH] btrfs: Unlock extents in btrfs_zero_range in case of errors Nikolay Borisov
  2021-02-23 13:24 ` Qu Wenruo
@ 2021-02-23 14:01 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2021-02-23 14:01 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-btrfs

On Tue, Feb 23, 2021 at 03:20:42PM +0200, Nikolay Borisov wrote:
> If btrfs_qgroup_reserve_data returns an error (i.e quota limit reached)
> the handling logic directly goes to the 'out' label without first
> unlocking the extent range between lockstart, lockend. This results in
> deadlocks as processes try to lock the same extent.
> 
> Fixes: a7f8b1c2ac21 ("btrfs: file: reserve qgroup space after the hole punch range is locked")
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Added to misc-next, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-23 14:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-23 13:20 [PATCH] btrfs: Unlock extents in btrfs_zero_range in case of errors Nikolay Borisov
2021-02-23 13:24 ` Qu Wenruo
2021-02-23 14:01 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).