All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: david@fromorbit.com, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/2] xfs: xrep_findroot_block should reject root blocks with siblings
Date: Tue, 2 Oct 2018 08:34:30 -0400	[thread overview]
Message-ID: <20181002123429.GA55077@bfoster> (raw)
In-Reply-To: <153843410206.24414.16640243145941466296.stgit@magnolia>

On Mon, Oct 01, 2018 at 03:48:22PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> In xrep_findroot_block, if we find a candidate root block with sibling
> pointers or sibling blocks on the same tree level, we should not return
> that block as a tree root because root blocks cannot have siblings.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  fs/xfs/scrub/repair.c |   61 +++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 48 insertions(+), 13 deletions(-)
> 
> 
> diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c
> index 9f08dd9bf1d5..6eb66b3543ff 100644
> --- a/fs/xfs/scrub/repair.c
> +++ b/fs/xfs/scrub/repair.c
...
> @@ -735,18 +736,52 @@ xrep_findroot_block(
>  		goto out;
>  	bp->b_ops = fab->buf_ops;
>  
> -	/* Ignore this block if it's lower in the tree than we've seen. */
> -	if (fab->root != NULLAGBLOCK &&
> -	    xfs_btree_get_level(btblock) < fab->height)
> -		goto out;
> -
>  	/* Make sure we pass the verifiers. */
>  	bp->b_ops->verify_read(bp);
>  	if (bp->b_error)
>  		goto out;
> -	fab->root = agbno;
> -	fab->height = xfs_btree_get_level(btblock) + 1;
> -	*found_it = true;
> +
> +	/*
> +	 * This block passes the magic/uuid and verifier tests for this btree
> +	 * type.  We don't need the caller to try the other tree types.
> +	 */
> +	*done_with_block = true;
> +
> +	block_level = xfs_btree_get_level(btblock);
> +	if (block_level + 1 == fab->height) {
> +		/*
> +		 * This block claims to be at the same level as the root we
> +		 * found previously.  There can't be two candidate roots, so
> +		 * we'll throw away both of them and hope we later find a block
> +		 * even higher in the tree.
> +		 */
> +		fab->root = NULLAGBLOCK;
> +		goto out;
> +	} else if (block_level < fab->height) {
> +		/*
> +		 * This block is lower in the tree than the root we found
> +		 * previously, so just ignore it.
> +		 */

Nit: can we combine these two comments into one above the whole if/else
statement? It makes the code slightly more readable than multi-line
comments in each branch, IMO. E.g.:

        /*
         * Compare the current block level with the height of the current
         * candidate root block. If the level matches the current candidate,
         * we know the current candidate can't be a root so we must invalidate
         * it. If the level is lower than the current candidate, just ignore
         * this block.
         */
        block_level = xfs_btree_get_level(btblock);
        if (block_level + 1 == fab->height) {
                fab->root = NULLAGBLOCK;
                goto out;
        } else if (block_level < fab->height) {
                goto out;
        }

With that:

Reviewed-by: Brian Foster <bfoster@redhat.com>

> +		goto out;
> +	}
> +
> +	/*
> +	 * This is the highest block in the tree that we've found so far.
> +	 * Update the btree height to reflect what we've learned from this
> +	 * block.
> +	 */
> +	fab->height = block_level + 1;
> +
> +	/*
> +	 * If this block doesn't have sibling pointers, then it's the new root
> +	 * block candidate.  Otherwise, the root will be found farther up the
> +	 * tree.
> +	 */
> +	if (btblock->bb_u.s.bb_leftsib == cpu_to_be32(NULLAGBLOCK) &&
> +	    btblock->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK))
> +		fab->root = agbno;
> +	else
> +		fab->root = NULLAGBLOCK;
>  
>  	trace_xrep_findroot_block(mp, ri->sc->sa.agno, agbno,
>  			be32_to_cpu(btblock->bb_magic), fab->height - 1);
> @@ -768,7 +803,7 @@ xrep_findroot_rmap(
>  	struct xrep_findroot		*ri = priv;
>  	struct xrep_find_ag_btree	*fab;
>  	xfs_agblock_t			b;
> -	bool				found_it;
> +	bool				done;
>  	int				error = 0;
>  
>  	/* Ignore anything that isn't AG metadata. */
> @@ -777,16 +812,16 @@ xrep_findroot_rmap(
>  
>  	/* Otherwise scan each block + btree type. */
>  	for (b = 0; b < rec->rm_blockcount; b++) {
> -		found_it = false;
> +		done = false;
>  		for (fab = ri->btree_info; fab->buf_ops; fab++) {
>  			if (rec->rm_owner != fab->rmap_owner)
>  				continue;
>  			error = xrep_findroot_block(ri, fab,
>  					rec->rm_owner, rec->rm_startblock + b,
> -					&found_it);
> +					&done);
>  			if (error)
>  				return error;
> -			if (found_it)
> +			if (done)
>  				break;
>  		}
>  	}
> 

  reply	other threads:[~2018-10-02 19:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 22:48 [PATCH v2 0/2] xfs-4.20: scrub fixes Darrick J. Wong
2018-10-01 22:48 ` [PATCH 1/2] xfs: xrep_findroot_block should reject root blocks with siblings Darrick J. Wong
2018-10-02 12:34   ` Brian Foster [this message]
2018-10-02 15:39     ` Darrick J. Wong
2018-10-03  2:01   ` [PATCH v2 " Darrick J. Wong
2018-10-01 22:48 ` [PATCH 2/2] xfs: fix buffer state management in xrep_findroot_block Darrick J. Wong
2018-10-02 12:36   ` Brian Foster
2018-10-02 19:56     ` Darrick J. Wong
2018-10-03 11:03       ` Brian Foster
2018-10-03  2:02   ` [PATCH v2 " Darrick J. Wong
2018-10-03 11:05     ` Brian Foster
2018-10-04 22:15       ` Darrick J. Wong
2018-10-05 10:27         ` Brian Foster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181002123429.GA55077@bfoster \
    --to=bfoster@redhat.com \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.