linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Allison Henderson <allison.henderson@oracle.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 3/6] xfs: sanity check ag header values in xrep_calc_ag_resblks
Date: Sun, 12 Aug 2018 00:55:07 -0700	[thread overview]
Message-ID: <b4a0adda-8586-f184-6011-82a871baba19@oracle.com> (raw)
In-Reply-To: <153400171586.27471.17428651076544146314.stgit@magnolia>

On 08/11/2018 08:35 AM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Check the values we read in from the AG headers when calculating the
> block reservations for a repair transaction.  If they're obviously
> wrong, substitute worst case assumptions (rather than ENOSPC on a bogus
> reservatoin request).
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>   fs/xfs/scrub/repair.c |   46 +++++++++++++++++++++++++++-------------------
>   1 file changed, 27 insertions(+), 19 deletions(-)
> 
> 
> diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c
> index 42d8c798ce7d..97c3077fb005 100644
> --- a/fs/xfs/scrub/repair.c
> +++ b/fs/xfs/scrub/repair.c
> @@ -195,8 +195,8 @@ xrep_calc_ag_resblks(
>   	struct xfs_scrub_metadata	*sm = sc->sm;
>   	struct xfs_perag		*pag;
>   	struct xfs_buf			*bp;
> -	xfs_agino_t			icount = 0;
> -	xfs_extlen_t			aglen = 0;
> +	xfs_agino_t			icount = NULLAGINO;
> +	xfs_extlen_t			aglen = NULLAGBLOCK;
>   	xfs_extlen_t			usedlen;
>   	xfs_extlen_t			freelen;
>   	xfs_extlen_t			bnobt_sz;
> @@ -208,20 +208,14 @@ xrep_calc_ag_resblks(
>   	if (!(sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR))
>   		return 0;
>   
> -	/* Use in-core counters if possible. */
>   	pag = xfs_perag_get(mp, sm->sm_agno);
> -	if (pag->pagi_init)
> +	if (pag->pagi_init) {
> +		/* Use in-core icount if possible. */
>   		icount = pag->pagi_count;
> -
> -	/*
> -	 * Otherwise try to get the actual counters from disk; if not, make
> -	 * some worst case assumptions.
> -	 */
> -	if (icount == 0) {
> +	} else {
> +		/* Try to get the actual counters from disk. */
>   		error = xfs_ialloc_read_agi(mp, NULL, sm->sm_agno, &bp);
> -		if (error) {
> -			icount = mp->m_sb.sb_agblocks / mp->m_sb.sb_inopblock;
> -		} else {
> +		if (!error) {
>   			icount = pag->pagi_count;
>   			xfs_buf_relse(bp);
>   		}
> @@ -229,18 +223,32 @@ xrep_calc_ag_resblks(
>   
>   	/* Now grab the block counters from the AGF. */
>   	error = xfs_alloc_read_agf(mp, NULL, sm->sm_agno, 0, &bp);
> -	if (error) {
> -		aglen = mp->m_sb.sb_agblocks;
> -		freelen = aglen;
> -		usedlen = aglen;
> -	} else {
> +	if (!error) {
>   		aglen = be32_to_cpu(XFS_BUF_TO_AGF(bp)->agf_length);
> -		freelen = pag->pagf_freeblks;
> +		freelen = be32_to_cpu(XFS_BUF_TO_AGF(bp)->agf_freeblks);
>   		usedlen = aglen - freelen;
>   		xfs_buf_relse(bp);
>   	}
>   	xfs_perag_put(pag);
>   
> +	/* If the icount is impossible, make some worst-case assumptions. */
> +	if (icount == NULLAGINO ||
> +	    !xfs_verify_agino(mp, sm->sm_agno, icount)) {
> +		xfs_agino_t	first, last;
> +
> +		xfs_agino_range(mp, sm->sm_agno, &first, &last);
> +		icount = last - first + 1;
> +	}
> +
> +	/* If the block counts are impossible, make worst-case assumptions. */
> +	if (aglen == NULLAGBLOCK ||
> +	    aglen != xfs_ag_block_count(mp, sm->sm_agno) ||
> +	    freelen >= aglen) {
> +		aglen = xfs_ag_block_count(mp, sm->sm_agno);
> +		freelen = aglen;
> +		usedlen = aglen;
> +	}
> +
>   	trace_xrep_calc_ag_resblks(mp, sm->sm_agno, icount, aglen,
>   			freelen, usedlen);
>   
> 
Ok, makes sense
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>

  reply	other threads:[~2018-08-12 10:32 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-11 15:34 [PATCH v2 0/6] xfs-4.19: various fixes Darrick J. Wong
2018-08-11 15:35 ` [PATCH 1/6] xfs: recalculate summary counters at mount time if icount is bad Darrick J. Wong
2018-08-12  7:53   ` Allison Henderson
2018-08-13  7:46   ` Carlos Maiolino
2018-08-11 15:35 ` [PATCH 2/6] xfs: xrep_findroot_block should reject root blocks with siblings Darrick J. Wong
2018-08-12  7:53   ` Allison Henderson
2018-08-13  7:48   ` Carlos Maiolino
2018-08-13 16:56   ` Brian Foster
2018-09-27 23:20     ` Darrick J. Wong
2018-08-11 15:35 ` [PATCH 3/6] xfs: sanity check ag header values in xrep_calc_ag_resblks Darrick J. Wong
2018-08-12  7:55   ` Allison Henderson [this message]
2018-08-13  7:52   ` Carlos Maiolino
2018-08-11 15:35 ` [PATCH 4/6] xfs: fix buffer state management in xrep_findroot_block Darrick J. Wong
2018-08-12  7:53   ` Allison Henderson
2018-08-13  8:05   ` Carlos Maiolino
2018-08-13 16:56   ` Brian Foster
2018-09-28  0:32     ` Darrick J. Wong
2018-08-13 22:56   ` Dave Chinner
2018-09-28  0:28     ` Darrick J. Wong
2018-08-11 15:35 ` [PATCH 5/6] iomap: fix WARN_ON_ONCE on uninitialized variable Darrick J. Wong
2018-08-12  7:55   ` Allison Henderson
2018-08-13  8:07   ` Carlos Maiolino
2018-08-11 15:35 ` [PATCH 6/6] xfs: don't crash the vfs on a garbage inline symlink Darrick J. Wong
2018-08-12  7:54   ` Allison Henderson
2018-08-13  7:23   ` Christoph Hellwig
2018-09-28  0:31     ` Darrick J. Wong
2018-08-19 21:07   ` Xu, Wen

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=b4a0adda-8586-f184-6011-82a871baba19@oracle.com \
    --to=allison.henderson@oracle.com \
    --cc=darrick.wong@oracle.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).