diff mbox series

[08/25] btrfs: remove BUG_ON() in find_parent_nodes()

Message ID be1a91360aa5e5eaae56cb09a90333f7da07b3a6.1636144971.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs: extent tree v2 prep work for global roots | expand

Commit Message

Josef Bacik Nov. 5, 2021, 8:45 p.m. UTC
We search for an extent entry with .offset = -1, which shouldn't be a
thing, but corruption happens.  Add an ASSERT() for the developers,
return -EUCLEAN for mortals.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/backref.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Nikolay Borisov Nov. 23, 2021, 8:53 p.m. UTC | #1
On 5.11.21 г. 22:45, Josef Bacik wrote:
> We search for an extent entry with .offset = -1, which shouldn't be a
> thing, but corruption happens.  Add an ASSERT() for the developers,
> return -EUCLEAN for mortals.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/backref.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
> index 12276ff08dd4..7d942f5d6443 100644
> --- a/fs/btrfs/backref.c
> +++ b/fs/btrfs/backref.c
> @@ -1210,7 +1210,12 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
>  	ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
>  	if (ret < 0)
>  		goto out;
> -	BUG_ON(ret == 0);
> +	if (ret == 0) {
> +		/* This shouldn't happen, indicates a bug or fs corruption. */
> +		ASSERT(ret != 0);

This can never trigger in this branch, because ret is guaranteed to be 0
o_O?

> +		ret = -EUCLEAN;
> +		goto out;
> +	}
>  
>  	if (trans && likely(trans->type != __TRANS_DUMMY) &&
>  	    time_seq != BTRFS_SEQ_LAST) {
>
Josef Bacik Nov. 23, 2021, 9:35 p.m. UTC | #2
On Tue, Nov 23, 2021 at 10:53:07PM +0200, Nikolay Borisov wrote:
> 
> 
> On 5.11.21 г. 22:45, Josef Bacik wrote:
> > We search for an extent entry with .offset = -1, which shouldn't be a
> > thing, but corruption happens.  Add an ASSERT() for the developers,
> > return -EUCLEAN for mortals.
> > 
> > Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> > ---
> >  fs/btrfs/backref.c | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
> > index 12276ff08dd4..7d942f5d6443 100644
> > --- a/fs/btrfs/backref.c
> > +++ b/fs/btrfs/backref.c
> > @@ -1210,7 +1210,12 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
> >  	ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
> >  	if (ret < 0)
> >  		goto out;
> > -	BUG_ON(ret == 0);
> > +	if (ret == 0) {
> > +		/* This shouldn't happen, indicates a bug or fs corruption. */
> > +		ASSERT(ret != 0);
> 
> This can never trigger in this branch, because ret is guaranteed to be 0
> o_O?
> 

It'll always trigger right?  ASSERT(false) == BUG_ON(true), and in this case ret
== 0, so we'll BUG_ON() in this case because it's wrong.  Thanks,

Jsoef
diff mbox series

Patch

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 12276ff08dd4..7d942f5d6443 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -1210,7 +1210,12 @@  static int find_parent_nodes(struct btrfs_trans_handle *trans,
 	ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
 	if (ret < 0)
 		goto out;
-	BUG_ON(ret == 0);
+	if (ret == 0) {
+		/* This shouldn't happen, indicates a bug or fs corruption. */
+		ASSERT(ret != 0);
+		ret = -EUCLEAN;
+		goto out;
+	}
 
 	if (trans && likely(trans->type != __TRANS_DUMMY) &&
 	    time_seq != BTRFS_SEQ_LAST) {