linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Allison Henderson <allison.henderson@oracle.com>
To: "Darrick J. Wong" <djwong@kernel.org>, sandeen@sandeen.net
Cc: Christoph Hellwig <hch@lst.de>, Brian Foster <bfoster@redhat.com>,
	linux-xfs@vger.kernel.org
Subject: Re: [PATCH 7/7] xfs_repair: clear the needsrepair flag
Date: Tue, 23 Feb 2021 13:18:55 -0700	[thread overview]
Message-ID: <856b5717-6451-4f66-7dd1-0854f810f828@oracle.com> (raw)
In-Reply-To: <161404925861.425352.15560707043185552680.stgit@magnolia>



On 2/22/21 8:00 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Clear the needsrepair flag, since it's used to prevent mounting of an
> inconsistent filesystem.  We only do this if we make it to the end of
> repair with a non-zero error code, and all the rebuilt indices and
> corrected metadata are persisted correctly.
> 
> Note that we cannot combine clearing needsrepair with clearing the quota
> checked flags because we need to clear the quota flags even if
> reformatting the log fails, whereas we can't clear needsrepair if the
> log reformat fails.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: Brian Foster <bfoster@redhat.com>
Ok, makes sense
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>

> ---
>   include/xfs_mount.h |    1 +
>   libxfs/init.c       |   20 +++++++++++++-------
>   repair/agheader.c   |   21 +++++++++++++++++++++
>   repair/xfs_repair.c |   42 ++++++++++++++++++++++++++++++++++++++++++
>   4 files changed, 77 insertions(+), 7 deletions(-)
> 
> 
> diff --git a/include/xfs_mount.h b/include/xfs_mount.h
> index 36594643..75230ca5 100644
> --- a/include/xfs_mount.h
> +++ b/include/xfs_mount.h
> @@ -181,6 +181,7 @@ xfs_perag_resv(
>   
>   extern xfs_mount_t	*libxfs_mount (xfs_mount_t *, xfs_sb_t *,
>   				dev_t, dev_t, dev_t, int);
> +int libxfs_flush_mount(struct xfs_mount *mp);
>   int		libxfs_umount(struct xfs_mount *mp);
>   extern void	libxfs_rtmount_destroy (xfs_mount_t *);
>   
> diff --git a/libxfs/init.c b/libxfs/init.c
> index 9fe13b8d..8a8ce3c4 100644
> --- a/libxfs/init.c
> +++ b/libxfs/init.c
> @@ -870,7 +870,7 @@ _("%s: Flushing the %s failed, err=%d!\n"),
>    * Flush all dirty buffers to stable storage and report on writes that didn't
>    * make it to stable storage.
>    */
> -static int
> +int
>   libxfs_flush_mount(
>   	struct xfs_mount	*mp)
>   {
> @@ -878,13 +878,13 @@ libxfs_flush_mount(
>   	int			err2;
>   
>   	/*
> -	 * Purge the buffer cache to write all dirty buffers to disk and free
> -	 * all incore buffers.  Buffers that fail write verification will cause
> -	 * the CORRUPT_WRITE flag to be set in the buftarg.  Buffers that
> -	 * cannot be written will cause the LOST_WRITE flag to be set in the
> -	 * buftarg.
> +	 * Flush the buffer cache to write all dirty buffers to disk.  Buffers
> +	 * that fail write verification will cause the CORRUPT_WRITE flag to be
> +	 * set in the buftarg.  Buffers that cannot be written will cause the
> +	 * LOST_WRITE flag to be set in the buftarg.  Once that's done,
> +	 * instruct the disks to persist their write caches.
>   	 */
> -	libxfs_bcache_purge();
> +	libxfs_bcache_flush();
>   
>   	/* Flush all kernel and disk write caches, and report failures. */
>   	if (mp->m_ddev_targp) {
> @@ -923,6 +923,12 @@ libxfs_umount(
>   
>   	libxfs_rtmount_destroy(mp);
>   
> +	/*
> +	 * Purge the buffer cache to write all dirty buffers to disk and free
> +	 * all incore buffers, then pick up the outcome when we tell the disks
> +	 * to persist their write caches.
> +	 */
> +	libxfs_bcache_purge();
>   	error = libxfs_flush_mount(mp);
>   
>   	for (agno = 0; agno < mp->m_maxagi; agno++) {
> diff --git a/repair/agheader.c b/repair/agheader.c
> index 8bb99489..2af24106 100644
> --- a/repair/agheader.c
> +++ b/repair/agheader.c
> @@ -452,6 +452,27 @@ secondary_sb_whack(
>   			rval |= XR_AG_SB_SEC;
>   	}
>   
> +	if (xfs_sb_version_needsrepair(sb)) {
> +		if (i == 0) {
> +			if (!no_modify)
> +				do_warn(
> +	_("clearing needsrepair flag and regenerating metadata\n"));
> +			else
> +				do_warn(
> +	_("would clear needsrepair flag and regenerate metadata\n"));
> +		} else {
> +			/*
> +			 * Quietly clear needsrepair on the secondary supers as
> +			 * part of ensuring them.  If needsrepair is set on the
> +			 * primary, it will be cleared at the end of repair
> +			 * once we've flushed all other dirty blocks to disk.
> +			 */
> +			sb->sb_features_incompat &=
> +					~XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR;
> +			rval |= XR_AG_SB_SEC;
> +		}
> +	}
> +
>   	return(rval);
>   }
>   
> diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
> index 40352458..e2e99b21 100644
> --- a/repair/xfs_repair.c
> +++ b/repair/xfs_repair.c
> @@ -712,6 +712,45 @@ check_fs_vs_host_sectsize(
>   	}
>   }
>   
> +/* Clear needsrepair after a successful repair run. */
> +void
> +clear_needsrepair(
> +	struct xfs_mount	*mp)
> +{
> +	struct xfs_buf		*bp;
> +	int			error;
> +
> +	/*
> +	 * If we're going to clear NEEDSREPAIR, we need to make absolutely sure
> +	 * that everything is ok with the ondisk filesystem.  Make sure any
> +	 * dirty buffers are sent to disk and that the disks have persisted
> +	 * writes to stable storage.  If that fails, leave NEEDSREPAIR in
> +	 * place.
> +	 */
> +	error = -libxfs_flush_mount(mp);
> +	if (error) {
> +		do_warn(
> +	_("Cannot clear needsrepair due to flush failure, err=%d.\n"),
> +			error);
> +		return;
> +	}
> +
> +	/* Clear needsrepair from the superblock. */
> +	bp = libxfs_getsb(mp);
> +	if (!bp || bp->b_error) {
> +		do_warn(
> +	_("Cannot clear needsrepair from primary super, err=%d.\n"),
> +			bp ? bp->b_error : ENOMEM);
> +	} else {
> +		mp->m_sb.sb_features_incompat &=
> +				~XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR;
> +		libxfs_sb_to_disk(bp->b_addr, &mp->m_sb);
> +		libxfs_buf_mark_dirty(bp);
> +	}
> +	if (bp)
> +		libxfs_buf_relse(bp);
> +}
> +
>   int
>   main(int argc, char **argv)
>   {
> @@ -1128,6 +1167,9 @@ _("Note - stripe unit (%d) and width (%d) were copied from a backup superblock.\
>   	libxfs_bcache_flush();
>   	format_log_max_lsn(mp);
>   
> +	if (xfs_sb_version_needsrepair(&mp->m_sb))
> +		clear_needsrepair(mp);
> +
>   	/* Report failure if anything failed to get written to our fs. */
>   	error = -libxfs_umount(mp);
>   	if (error)
> 

      reply	other threads:[~2021-02-23 20:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-23  3:00 [PATCHSET v6 0/7] xfsprogs: add the ability to flag a fs for repair Darrick J. Wong
2021-02-23  3:00 ` [PATCH 1/7] xfs_admin: clean up string quoting Darrick J. Wong
2021-02-23 20:18   ` Allison Henderson
2021-02-23  3:00 ` [PATCH 2/7] xfs_admin: support filesystems with realtime devices Darrick J. Wong
2021-02-23 20:18   ` Allison Henderson
2021-02-23  3:00 ` [PATCH 3/7] xfs_db: report the needsrepair flag in check and version commands Darrick J. Wong
2021-02-23 20:18   ` Allison Henderson
2021-02-25  8:11   ` Christoph Hellwig
2021-02-23  3:00 ` [PATCH 4/7] xfs_db: don't allow label/uuid setting if the needsrepair flag is set Darrick J. Wong
2021-02-23 20:18   ` Allison Henderson
2021-02-25  8:13   ` Christoph Hellwig
2021-02-23  3:00 ` [PATCH 5/7] xfs_repair: fix unmount error message to have a newline Darrick J. Wong
2021-02-23 20:18   ` Allison Henderson
2021-02-23  3:00 ` [PATCH 6/7] xfs_repair: clear quota CHKD flags on the incore superblock too Darrick J. Wong
2021-02-23 20:18   ` Allison Henderson
2021-02-23  3:00 ` [PATCH 7/7] xfs_repair: clear the needsrepair flag Darrick J. Wong
2021-02-23 20:18   ` Allison Henderson [this message]

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=856b5717-6451-4f66-7dd1-0854f810f828@oracle.com \
    --to=allison.henderson@oracle.com \
    --cc=bfoster@redhat.com \
    --cc=djwong@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /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).