Skip to contentSkip to conversation

btrfs: Correct try_lock_extent() usage in read_extent_buffer_subpage()

PATCH In review Goldwyn Rodrigues 4 participants 4 messages Apr 8, 2021 – Apr 23, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: Correct try_lock_extent() usage in read_extent_buffer_subpage()

try_lock_extent() returns 1 on success or 0 for failure and not an error code. If try_lock_extent() fails, read_extent_buffer_subpage() returns zero indicating subpage extent read success.

Return EAGAIN/EWOULDBLOCK if try_lock_extent() fails in locking the extent.

---
 fs/btrfs/extent_io.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/extent_io.c +2 -4
index 7ad2169e7487..3536feedd6c5 100644
@@ -5914,10 +5914,8 @@ static int read_extent_buffer_subpage(struct extent_buffer *eb, int wait,
 	io_tree = &BTRFS_I(fs_info->btree_inode)->io_tree;
 
 	if (wait == WAIT_NONE) {
-		ret = try_lock_extent(io_tree, eb->start,
-				      eb->start + eb->len - 1);
-		if (ret <= 0)
-			return ret;
+		if (!try_lock_extent(io_tree, eb->start, eb->start + eb->len - 1))
+			return -EAGAIN;
 	} else {
 		ret = lock_extent(io_tree, eb->start, eb->start + eb->len - 1);
 		if (ret < 0)
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Goldwyn Rodrigues

try_lock_extent() returns 1 on success or 0 for failure and not an error code. If try_lock_extent() fails, read_extent_buffer_subpage() returns zero indicating subpage extent read success.

Return EAGAIN/EWOULDBLOCK if try_lock_extent() fails in locking the extent.

Thankfully the only metadata reader who will pass wait == WAIT_NONE is readahead, so no real damage.

But still a nice fix!

Thanks,
Qu

Quoted 22 lines
---
  fs/btrfs/extent_io.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/extent_io.c +2 -4
index 7ad2169e7487..3536feedd6c5 100644
@@ -5914,10 +5914,8 @@ static int read_extent_buffer_subpage(struct extent_buffer *eb, int wait,
  	io_tree = &BTRFS_I(fs_info->btree_inode)->io_tree;
 
  	if (wait == WAIT_NONE) {
-		ret = try_lock_extent(io_tree, eb->start,
-				      eb->start + eb->len - 1);
-		if (ret <= 0)
-			return ret;
+		if (!try_lock_extent(io_tree, eb->start, eb->start + eb->len - 1))
+			return -EAGAIN;
  	} else {
  		ret = lock_extent(io_tree, eb->start, eb->start + eb->len - 1);
  		if (ret < 0)
Reviewed-by on v1 1/1
#2 lore raw
In reply to Goldwyn Rodrigues
Quoted 8 lines · Goldwyn Rodrigues

try_lock_extent() returns 1 on success or 0 for failure and not an error code. If try_lock_extent() fails, read_extent_buffer_subpage() returns zero indicating subpage extent read success.

Return EAGAIN/EWOULDBLOCK if try_lock_extent() fails in locking the extent.

Thanks,

Josef

#3 lore raw
In reply to Goldwyn Rodrigues
Quoted 8 lines · Goldwyn Rodrigues

try_lock_extent() returns 1 on success or 0 for failure and not an error code. If try_lock_extent() fails, read_extent_buffer_subpage() returns zero indicating subpage extent read success.

Return EAGAIN/EWOULDBLOCK if try_lock_extent() fails in locking the extent.

Added to misc-next, thanks.