linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: linux-xfs@vger.kernel.org
Cc: david@fromorbit.com
Subject: Re: [PATCH v2 1/5] xfs: check the uniqueness of the AGFL entries
Date: Thu, 9 Nov 2017 14:12:36 -0800	[thread overview]
Message-ID: <20171109221236.GN26910@magnolia> (raw)
In-Reply-To: <20171109050235.GJ26910@magnolia>

On Wed, Nov 08, 2017 at 09:02:35PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Make sure we don't list a block twice in the agfl.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> v2: various review cleanups
> ---
>  fs/xfs/scrub/agheader.c |   56 +++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 54 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c
> index 5495aa5..489f985 100644
> --- a/fs/xfs/scrub/agheader.c
> +++ b/fs/xfs/scrub/agheader.c
> @@ -476,6 +476,11 @@ xfs_scrub_agf(
>  
>  /* AGFL */
>  
> +struct xfs_scrub_agfl_info {
> +	unsigned int			nr_entries;
> +	xfs_agblock_t			*entries;
> +};
> +
>  /* Scrub an AGFL block. */
>  STATIC int
>  xfs_scrub_agfl_block(
> @@ -484,20 +489,38 @@ xfs_scrub_agfl_block(
>  	void				*priv)
>  {
>  	struct xfs_mount		*mp = sc->mp;
> +	struct xfs_scrub_agfl_info	*sai = priv;
>  	xfs_agnumber_t			agno = sc->sa.agno;
>  
> -	if (!xfs_verify_agbno(mp, agno, agbno))
> +	if (xfs_verify_agbno(mp, agno, agbno))
> +		sai->entries[sai->nr_entries++] = agbno;

self-NAK on this second version, because we need to ensure that we don't
overflow or underflow the entries array -- in other words, that flfirst
and fllast exactly match flcount.

--D

> +	else
>  		xfs_scrub_block_set_corrupt(sc, sc->sa.agfl_bp);
>  
>  	return 0;
>  }
>  
> +static int
> +xfs_scrub_agblock_cmp(
> +	const void		*pa,
> +	const void		*pb)
> +{
> +	const xfs_agblock_t	*a = pa;
> +	const xfs_agblock_t	*b = pb;
> +
> +	return (int)*a - (int)*b;
> +}
> +
>  /* Scrub the AGFL. */
>  int
>  xfs_scrub_agfl(
>  	struct xfs_scrub_context	*sc)
>  {
> +	struct xfs_scrub_agfl_info	sai = { 0 };
> +	struct xfs_agf			*agf;
>  	xfs_agnumber_t			agno;
> +	unsigned int			agflcount;
> +	unsigned int			i;
>  	int				error;
>  
>  	agno = sc->sa.agno = sc->sm->sm_agno;
> @@ -508,8 +531,37 @@ xfs_scrub_agfl(
>  	if (!sc->sa.agf_bp)
>  		return -EFSCORRUPTED;
>  
> +	/* Allocate buffer to ensure uniqueness of AGFL entries. */
> +	agf = XFS_BUF_TO_AGF(sc->sa.agf_bp);
> +	agflcount = be32_to_cpu(agf->agf_flcount);
> +	if (agflcount > XFS_AGFL_SIZE(sc->mp)) {
> +		xfs_scrub_block_set_corrupt(sc, sc->sa.agf_bp);
> +		goto out;
> +	}
> +	sai.entries = kmem_zalloc(sizeof(xfs_agblock_t) * agflcount,
> +			KM_SLEEP | KM_NOFS);
> +	if (!sai.entries) {
> +		error = -ENOMEM;
> +		goto out;
> +	}
> +
>  	/* Check the blocks in the AGFL. */
> -	return xfs_scrub_walk_agfl(sc, xfs_scrub_agfl_block, NULL);
> +	error = xfs_scrub_walk_agfl(sc, xfs_scrub_agfl_block, &sai);
> +	if (error)
> +		goto out_free;
> +
> +	/* Sort entries, check for duplicates. */
> +	sort(sai.entries, sai.nr_entries, sizeof(sai.entries[0]),
> +			xfs_scrub_agblock_cmp, NULL);
> +	for (i = 1; i < sai.nr_entries; i++) {
> +		if (sai.entries[i] == sai.entries[i - 1]) {
> +			xfs_scrub_block_set_corrupt(sc, sc->sa.agf_bp);
> +			break;
> +		}
> +	}
> +
> +out_free:
> +	kmem_free(sai.entries);
>  out:
>  	return error;
>  }
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2017-11-09 22:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-07  1:03 [PATCH 0/5] xfs: various 4.15 scrub fixes Darrick J. Wong
2017-11-07  1:03 ` [PATCH 1/5] xfs: check the uniqueness of the AGFL entries Darrick J. Wong
2017-11-09  2:08   ` Dave Chinner
2017-11-09  2:48     ` Darrick J. Wong
2017-11-09  5:02   ` [PATCH v2 " Darrick J. Wong
2017-11-09 22:12     ` Darrick J. Wong [this message]
2017-11-09 23:39   ` [PATCH v3 " Darrick J. Wong
2017-11-10  1:23     ` Dave Chinner
2017-11-07  1:03 ` [PATCH 2/5] xfs: refactor the directory data block bestfree checks Darrick J. Wong
2017-11-09  2:11   ` Dave Chinner
2017-11-07  1:03 ` [PATCH 3/5] xfs: pass inode number to xfs_scrub_ino_set_{preen, warning} Darrick J. Wong
2017-11-09  2:13   ` Dave Chinner
2017-11-07  1:03 ` [PATCH 4/5] xfs: fix uninitialized return values in scrub code Darrick J. Wong
2017-11-09  2:13   ` Dave Chinner
2017-11-07  1:03 ` [PATCH 5/5] xfs: fix btree scrub deref check Darrick J. Wong
2017-11-09  2:16   ` Dave Chinner
2017-11-08 20:56 ` [PATCH 6/5] xfs: only check da node header padding on v5 filesystems Darrick J. Wong
2017-11-09  2:17   ` Dave Chinner
2017-11-09  6:00 ` [PATCH 7/5] xfs: on failed mount, force-reclaim inodes after unmounting quota controls Darrick J. Wong
2017-11-09 23:24   ` Dave Chinner
2017-11-09 23:49     ` Darrick J. Wong
2017-11-09 23:57   ` [PATCH v2 " Darrick J. Wong
2017-11-10  1:19     ` Dave Chinner
2017-11-09 17:35 ` [PATCH 8/5] xfs: remove u_int* type usage Darrick J. Wong
2017-11-09 23:25   ` Dave Chinner

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=20171109221236.GN26910@magnolia \
    --to=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 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).