Skip to contentSkip to conversation

btrfs: Unlock extents in btrfs_zero_range in case of errors

PATCH In review Nikolay Borisov 3 participants 3 messages Feb 23, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: Unlock extents in btrfs_zero_range in case of errors

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")
---
 fs/btrfs/file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/file.c +4 -1
index 1e68349c3884..af0253473508 100644
@@ -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),
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · 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")

Thanks,
Qu

Quoted 22 lines
---
  fs/btrfs/file.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/file.c +4 -1
index 1e68349c3884..af0253473508 100644
@@ -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 lore raw
In reply to Nikolay Borisov
Quoted 7 lines · 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")

Added to misc-next, thanks.