linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: linux-xfs <linux-xfs@vger.kernel.org>
Subject: Re: [PATCH 2/5] xfs: factor out secondary superblock updates
Date: Wed, 2 May 2018 07:29:18 -0700	[thread overview]
Message-ID: <20180502142918.GM4127@magnolia> (raw)
In-Reply-To: <aecfedfa-6216-80d8-bbac-3dfad639f9c8@sandeen.net>

On Mon, Apr 30, 2018 at 10:43:55AM -0500, Eric Sandeen wrote:
> growfs rewrites all secondary supers, and relabel should do so as well;
> factor out the code which does this for use by both operations.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  fs/xfs/xfs_fsops.c | 130 +++++++++++++++++++++++++++++++----------------------
>  fs/xfs/xfs_fsops.h |   2 +
>  2 files changed, 79 insertions(+), 53 deletions(-)
> 
> diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
> index 5237927..8f2a73a 100644
> --- a/fs/xfs/xfs_fsops.c
> +++ b/fs/xfs/xfs_fsops.c
> @@ -71,6 +71,79 @@
>  	return bp;
>  }
>  
> +/*
> + * Copy the contents of the primary super to all backup supers.
> + * %agcount is currently existing AGs
> + * %new_ags is the number of new AGs to write out if we're growing the
> + * filesystem.
> + * We can't use mp->m_sb.sb_agcount here because growfs already updated it.
> + */
> +int
> +xfs_update_secondary_supers(
> +	xfs_mount_t		*mp,
> +	xfs_agnumber_t		agcount,
> +	xfs_agnumber_t		new_ags)
> +{
> +	int			error, saved_error;
> +	xfs_agnumber_t		agno;
> +	xfs_buf_t		*bp;
> +
> +	error = saved_error = 0;
> +
> +	/* update secondary superblocks. */
> +	for (agno = 1; agno < agcount + new_ags; agno++) {
> +		error = 0;
> +		/*
> +		 * new secondary superblocks need to be zeroed, not read from
> +		 * disk as the contents of the new area we are growing into is
> +		 * completely unknown.
> +		 */
> +		if (agno < agcount) {
> +			error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp,
> +				  XFS_AGB_TO_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
> +				  XFS_FSS_TO_BB(mp, 1), 0, &bp,
> +				  &xfs_sb_buf_ops);
> +		} else {
> +			bp = xfs_trans_get_buf(NULL, mp->m_ddev_targp,
> +				  XFS_AGB_TO_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
> +				  XFS_FSS_TO_BB(mp, 1), 0);
> +			if (bp) {
> +				bp->b_ops = &xfs_sb_buf_ops;
> +				xfs_buf_zero(bp, 0, BBTOB(bp->b_length));
> +			} else
> +				error = -ENOMEM;
> +		}
> +
> +		/*
> +		 * If we get an error reading or writing alternate superblocks,
> +		 * continue.  xfs_repair chooses the "best" superblock based
> +		 * on most matches; if we break early, we'll leave more
> +		 * superblocks un-updated than updated, and xfs_repair may
> +		 * pick them over the properly-updated primary.
> +		 */
> +		if (error) {
> +			xfs_warn(mp,
> +		"error %d reading secondary superblock for ag %d",
> +				error, agno);
> +			saved_error = error;
> +			continue;
> +		}
> +		xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb);
> +
> +		error = xfs_bwrite(bp);
> +		xfs_buf_relse(bp);
> +		if (error) {
> +			xfs_warn(mp,
> +		"write error %d updating secondary superblock for ag %d",
> +				error, agno);
> +			saved_error = error;
> +			continue;
> +		}
> +	}
> +
> +	return saved_error ? saved_error : error;
> +}
> +
>  static int
>  xfs_growfs_data_private(
>  	xfs_mount_t		*mp,		/* mount point for filesystem */
> @@ -86,7 +159,7 @@
>  	xfs_buf_t		*bp;
>  	int			bucket;
>  	int			dpct;
> -	int			error, saved_error = 0;
> +	int			error;
>  	xfs_agnumber_t		nagcount;
>  	xfs_agnumber_t		nagimax = 0;
>  	xfs_rfsblock_t		nb, nb_mod;
> @@ -557,59 +630,10 @@
>  	if (error && error != -ENOSPC)
>  		goto out;
>  
> -	/* update secondary superblocks. */
> -	for (agno = 1; agno < nagcount; agno++) {
> -		error = 0;
> -		/*
> -		 * new secondary superblocks need to be zeroed, not read from
> -		 * disk as the contents of the new area we are growing into is
> -		 * completely unknown.
> -		 */
> -		if (agno < oagcount) {
> -			error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp,
> -				  XFS_AGB_TO_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
> -				  XFS_FSS_TO_BB(mp, 1), 0, &bp,
> -				  &xfs_sb_buf_ops);
> -		} else {
> -			bp = xfs_trans_get_buf(NULL, mp->m_ddev_targp,
> -				  XFS_AGB_TO_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
> -				  XFS_FSS_TO_BB(mp, 1), 0);
> -			if (bp) {
> -				bp->b_ops = &xfs_sb_buf_ops;
> -				xfs_buf_zero(bp, 0, BBTOB(bp->b_length));
> -			} else
> -				error = -ENOMEM;
> -		}
> -
> -		/*
> -		 * If we get an error reading or writing alternate superblocks,
> -		 * continue.  xfs_repair chooses the "best" superblock based
> -		 * on most matches; if we break early, we'll leave more
> -		 * superblocks un-updated than updated, and xfs_repair may
> -		 * pick them over the properly-updated primary.
> -		 */
> -		if (error) {
> -			xfs_warn(mp,
> -		"error %d reading secondary superblock for ag %d",
> -				error, agno);
> -			saved_error = error;
> -			continue;
> -		}
> -		xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb);
> -
> -		error = xfs_bwrite(bp);
> -		xfs_buf_relse(bp);
> -		if (error) {
> -			xfs_warn(mp,
> -		"write error %d updating secondary superblock for ag %d",
> -				error, agno);
> -			saved_error = error;
> -			continue;
> -		}
> -	}
> -
> +	/* Copy new geometry to all backup superblocks, old & new */
> +	error = xfs_update_secondary_supers(mp, oagcount, nagcount - oagcount);
>   out:
> -	return saved_error ? saved_error : error;
> +	return error;
>  
>   error0:
>  	xfs_trans_cancel(tp);
> diff --git a/fs/xfs/xfs_fsops.h b/fs/xfs/xfs_fsops.h
> index 20484ed..ffc5377 100644
> --- a/fs/xfs/xfs_fsops.h
> +++ b/fs/xfs/xfs_fsops.h
> @@ -18,6 +18,8 @@
>  #ifndef __XFS_FSOPS_H__
>  #define	__XFS_FSOPS_H__
>  
> +extern int xfs_update_secondary_supers(xfs_mount_t *mp, xfs_agnumber_t agcount,
> +				xfs_agnumber_t new_ags);
>  extern int xfs_growfs_data(xfs_mount_t *mp, xfs_growfs_data_t *in);
>  extern int xfs_growfs_log(xfs_mount_t *mp, xfs_growfs_log_t *in);
>  extern int xfs_fs_counts(xfs_mount_t *mp, xfs_fsop_counts_t *cnt);
> -- 
> 1.8.3.1
> 
> --
> 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

  parent reply	other threads:[~2018-05-02 14:29 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-30 15:40 [PATCH 0/5] xfs: add online relabel capabilities Eric Sandeen
2018-04-30 15:42 ` [PATCH 1/5] fs: hoist BTRFS_IOC_[SG]ET_FSLABEL to vfs Eric Sandeen
2018-05-02 14:30   ` Darrick J. Wong
2018-04-30 15:43 ` [PATCH 2/5] xfs: factor out secondary superblock updates Eric Sandeen
2018-05-01 14:17   ` Brian Foster
2018-05-01 14:19     ` Eric Sandeen
2018-05-02 14:29   ` Darrick J. Wong [this message]
2018-04-30 15:45 ` [PATCH 3/5] xfs: move xfs_scrub_checkpoint_log to xfs_log_checkpoint for general use Eric Sandeen
2018-05-01 23:04   ` Eric Sandeen
2018-04-30 15:46 ` [PATCH 4/5] xfs: implement online get/set fs label Eric Sandeen
2018-05-01 14:18   ` Brian Foster
2018-05-01 14:27     ` Eric Sandeen
2018-05-01 14:42       ` Brian Foster
2018-05-01 14:49         ` Darrick J. Wong
2018-05-01 15:01         ` Eric Sandeen
2018-05-01 22:11   ` Dave Chinner
2018-05-01 22:20     ` Eric Sandeen
2018-05-01 23:04   ` [PATCH 4/5 V2] " Eric Sandeen
2018-05-02 10:48     ` Brian Foster
2018-05-02 14:24     ` Darrick J. Wong
2018-05-02 14:28       ` Eric Sandeen
2018-05-02 14:38         ` Darrick J. Wong
2018-05-02 21:57         ` Dave Chinner
2018-04-30 15:48 ` [PATCH 5/5] xfs_io: add label command Eric Sandeen
2018-05-02 14:37   ` Darrick J. Wong

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=20180502142918.GM4127@magnolia \
    --to=darrick.wong@oracle.com \
    --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).