public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Jan Tulak <jtulak@redhat.com>
Cc: linux-xfs@vger.kernel.org, sandeen@sandeen.net
Subject: Re: [PATCH 1/2] mkfs: discard only after all validations
Date: Wed, 19 Sep 2018 07:44:05 -0700	[thread overview]
Message-ID: <20180919144405.GH20086@magnolia> (raw)
In-Reply-To: <20180919125617.28048-1-jtulak@redhat.com>

On Wed, Sep 19, 2018 at 02:56:16PM +0200, Jan Tulak wrote:
> Discard should happen only when everything has been validated, just
> before we start writing to the device. If it happens earlier, it is
> possible that mkfs will abort, but managed to already wipe data. This
> patch moves the discard to the latest possible moment.
> 
> Signed-off-by: Jan Tulak <jtulak@redhat.com>
> ---
>  mkfs/xfs_mkfs.c | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index 2e53c1e8..81d9859a 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -2389,8 +2389,7 @@ _("log stripe unit (%d bytes) is too large (maximum is 256KiB)\n"
>  static void
>  open_devices(
>  	struct mkfs_params	*cfg,
> -	struct libxfs_xinit	*xi,
> -	bool			discard)
> +	struct libxfs_xinit	*xi)
>  {
>  	uint64_t		sector_mask;
>  
> @@ -2419,8 +2418,16 @@ open_devices(
>  	xi->dsize &= sector_mask;
>  	xi->rtsize &= sector_mask;
>  	xi->logBBsize &= (uint64_t)-1 << (max(cfg->lsectorlog, 10) - BBSHIFT);
> +}
>  
> -
> +static void
> +discard_data(

Perhaps discard_devices(), since this function can DISCARD more than
just the data device.

> +	struct libxfs_xinit	*xi,
> +	bool			discard)
> +{
> +	/*
> +	 * This function has to be called after libxfs has been initialized.
> +	 */
>  	if (!discard)
>  		return;
>  

While we're on the topic, I notice that we skip discard for any device
that's actually a file.  Seeing as fallocate(PUNCH_HOLE) works on files
(and block devices), is there a reason why we avoid punching out fs
image files?

> @@ -3901,7 +3908,7 @@ main(
>  	/*
>  	 * Open and validate the device configurations
>  	 */
> -	open_devices(&cfg, &xi, (discard && !dry_run));
> +	open_devices(&cfg, &xi);
>  	validate_datadev(&cfg, &cli);
>  	validate_logdev(&cfg, &cli, &logfile);
>  	validate_rtdev(&cfg, &cli, &rtfile);
> @@ -3952,6 +3959,11 @@ main(
>  			exit(0);
>  	}
>  
> +	/*
> +	 * All values have been validated, discard the old device layout.
> +	 */
> +	discard_data(&xi, (discard && !dry_run));

if (discard && !dry_run)
	discard_devices(&xi);

?

--D

> +
>  	/*
>  	 * we need the libxfs buffer cache from here on in.
>  	 */
> -- 
> 2.18.0
> 

  parent reply	other threads:[~2018-09-19 20:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-19 12:56 [PATCH 1/2] mkfs: discard only after all validations Jan Tulak
2018-09-19 12:56 ` [PATCH 2/2] mkfs: move 'mounted' check before 'existing fs' check Jan Tulak
2018-09-19 14:48   ` Darrick J. Wong
2018-09-19 15:05     ` Jan Tulak
2018-09-20 20:03       ` Darrick J. Wong
2018-09-19 14:44 ` Darrick J. Wong [this message]
2018-09-19 15:11   ` [PATCH 1/2] mkfs: discard only after all validations Jan Tulak
2018-09-20  3:16   ` Dave Chinner
2018-09-20  9:20 ` [PATCH 1/2 v2] " Jan Tulak
2018-09-20 20:03   ` 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=20180919144405.GH20086@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=jtulak@redhat.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