All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: tree-log: Check btrfs_lookup_data_extent return value
@ 2021-08-02 12:34 Marcos Paulo de Souza
  2021-08-02 12:47 ` Filipe Manana
  2021-08-16 13:08 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Marcos Paulo de Souza @ 2021-08-02 12:34 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba, fdmanana, Marcos Paulo de Souza

Function btrfs_lookup_data_extent calls btrfs_search_slot to verify if
the EXTENT_ITEM exists in the extent tree. btrfs_search_slot can return
values bellow zero if an error happened.

Function replay_one_extent currently check if the search found something
(0 returned) and increments the reference, and if not, it seems to evaluate as
'not found'.

Fix the condition by checking if the value was bellow zero and return early.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---

 Found while inspecting some btrfs_search_slot call sites.

 fs/btrfs/tree-log.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 567adc3de11a..867ea0be0665 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -753,7 +753,9 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
 			 */
 			ret = btrfs_lookup_data_extent(fs_info, ins.objectid,
 						ins.offset);
-			if (ret == 0) {
+			if (ret < 0) {
+				goto out;
+			} else if (ret == 0) {
 				btrfs_init_generic_ref(&ref,
 						BTRFS_ADD_DELAYED_REF,
 						ins.objectid, ins.offset, 0);
-- 
2.26.2


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

* Re: [PATCH] btrfs: tree-log: Check btrfs_lookup_data_extent return value
  2021-08-02 12:34 [PATCH] btrfs: tree-log: Check btrfs_lookup_data_extent return value Marcos Paulo de Souza
@ 2021-08-02 12:47 ` Filipe Manana
  2021-08-16 13:08 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Filipe Manana @ 2021-08-02 12:47 UTC (permalink / raw)
  To: Marcos Paulo de Souza; +Cc: linux-btrfs, David Sterba

On Mon, Aug 2, 2021 at 1:35 PM Marcos Paulo de Souza <mpdesouza@suse.com> wrote:
>
> Function btrfs_lookup_data_extent calls btrfs_search_slot to verify if
> the EXTENT_ITEM exists in the extent tree. btrfs_search_slot can return
> values bellow zero if an error happened.
>
> Function replay_one_extent currently check if the search found something
> (0 returned) and increments the reference, and if not, it seems to evaluate as
> 'not found'.
>
> Fix the condition by checking if the value was bellow zero and return early.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>

Reviewed-by: Filipe Manana <fdmanana@suse.com>

That's fine, thanks.

> ---
>
>  Found while inspecting some btrfs_search_slot call sites.
>
>  fs/btrfs/tree-log.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
> index 567adc3de11a..867ea0be0665 100644
> --- a/fs/btrfs/tree-log.c
> +++ b/fs/btrfs/tree-log.c
> @@ -753,7 +753,9 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
>                          */
>                         ret = btrfs_lookup_data_extent(fs_info, ins.objectid,
>                                                 ins.offset);
> -                       if (ret == 0) {
> +                       if (ret < 0) {
> +                               goto out;
> +                       } else if (ret == 0) {
>                                 btrfs_init_generic_ref(&ref,
>                                                 BTRFS_ADD_DELAYED_REF,
>                                                 ins.objectid, ins.offset, 0);
> --
> 2.26.2
>


-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

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

* Re: [PATCH] btrfs: tree-log: Check btrfs_lookup_data_extent return value
  2021-08-02 12:34 [PATCH] btrfs: tree-log: Check btrfs_lookup_data_extent return value Marcos Paulo de Souza
  2021-08-02 12:47 ` Filipe Manana
@ 2021-08-16 13:08 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2021-08-16 13:08 UTC (permalink / raw)
  To: Marcos Paulo de Souza; +Cc: linux-btrfs, dsterba, fdmanana

On Mon, Aug 02, 2021 at 09:34:00AM -0300, Marcos Paulo de Souza wrote:
> Function btrfs_lookup_data_extent calls btrfs_search_slot to verify if
> the EXTENT_ITEM exists in the extent tree. btrfs_search_slot can return
> values bellow zero if an error happened.
> 
> Function replay_one_extent currently check if the search found something
> (0 returned) and increments the reference, and if not, it seems to evaluate as
> 'not found'.
> 
> Fix the condition by checking if the value was bellow zero and return early.
> 
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>

Added to misc-next, thanks.

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

end of thread, other threads:[~2021-08-16 13:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02 12:34 [PATCH] btrfs: tree-log: Check btrfs_lookup_data_extent return value Marcos Paulo de Souza
2021-08-02 12:47 ` Filipe Manana
2021-08-16 13:08 ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.