linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: Correct try_lock_extent() usage in read_extent_buffer_subpage()
@ 2021-04-08 12:40 Goldwyn Rodrigues
  2021-04-08 12:45 ` Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Goldwyn Rodrigues @ 2021-04-08 12:40 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Qu Wenruo

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.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
 fs/btrfs/extent_io.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 7ad2169e7487..3536feedd6c5 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -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)
-- 
2.30.2

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

* Re: [PATCH] btrfs: Correct try_lock_extent() usage in read_extent_buffer_subpage()
  2021-04-08 12:40 [PATCH] btrfs: Correct try_lock_extent() usage in read_extent_buffer_subpage() Goldwyn Rodrigues
@ 2021-04-08 12:45 ` Qu Wenruo
  2021-04-08 18:05 ` Josef Bacik
  2021-04-23 10:43 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2021-04-08 12:45 UTC (permalink / raw)
  To: Goldwyn Rodrigues, linux-btrfs; +Cc: Qu Wenruo



On 2021/4/8 下午8:40, Goldwyn Rodrigues wrote:
> 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.
>
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>

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

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

But still a nice fix!

Thanks,
Qu
> ---
>   fs/btrfs/extent_io.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index 7ad2169e7487..3536feedd6c5 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -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)
>

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

* Re: [PATCH] btrfs: Correct try_lock_extent() usage in read_extent_buffer_subpage()
  2021-04-08 12:40 [PATCH] btrfs: Correct try_lock_extent() usage in read_extent_buffer_subpage() Goldwyn Rodrigues
  2021-04-08 12:45 ` Qu Wenruo
@ 2021-04-08 18:05 ` Josef Bacik
  2021-04-23 10:43 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Josef Bacik @ 2021-04-08 18:05 UTC (permalink / raw)
  To: Goldwyn Rodrigues, linux-btrfs; +Cc: Qu Wenruo

On 4/8/21 8:40 AM, Goldwyn Rodrigues wrote:
> 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.
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef

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

* Re: [PATCH] btrfs: Correct try_lock_extent() usage in read_extent_buffer_subpage()
  2021-04-08 12:40 [PATCH] btrfs: Correct try_lock_extent() usage in read_extent_buffer_subpage() Goldwyn Rodrigues
  2021-04-08 12:45 ` Qu Wenruo
  2021-04-08 18:05 ` Josef Bacik
@ 2021-04-23 10:43 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2021-04-23 10:43 UTC (permalink / raw)
  To: Goldwyn Rodrigues; +Cc: linux-btrfs, Qu Wenruo

On Thu, Apr 08, 2021 at 07:40:25AM -0500, Goldwyn Rodrigues wrote:
> 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.
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>

Added to misc-next, thanks.

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08 12:40 [PATCH] btrfs: Correct try_lock_extent() usage in read_extent_buffer_subpage() Goldwyn Rodrigues
2021-04-08 12:45 ` Qu Wenruo
2021-04-08 18:05 ` Josef Bacik
2021-04-23 10:43 ` 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).