* [PATCH 1/2] mkfs: discard only after all validations
@ 2018-09-19 12:56 Jan Tulak
2018-09-19 12:56 ` [PATCH 2/2] mkfs: move 'mounted' check before 'existing fs' check Jan Tulak
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Jan Tulak @ 2018-09-19 12:56 UTC (permalink / raw)
To: linux-xfs; +Cc: sandeen, Jan Tulak
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(
+ struct libxfs_xinit *xi,
+ bool discard)
+{
+ /*
+ * This function has to be called after libxfs has been initialized.
+ */
if (!discard)
return;
@@ -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));
+
/*
* we need the libxfs buffer cache from here on in.
*/
--
2.18.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/2] mkfs: move 'mounted' check before 'existing fs' check
2018-09-19 12:56 [PATCH 1/2] mkfs: discard only after all validations Jan Tulak
@ 2018-09-19 12:56 ` Jan Tulak
2018-09-19 14:48 ` Darrick J. Wong
2018-09-19 14:44 ` [PATCH 1/2] mkfs: discard only after all validations Darrick J. Wong
2018-09-20 9:20 ` [PATCH 1/2 v2] " Jan Tulak
2 siblings, 1 reply; 10+ messages in thread
From: Jan Tulak @ 2018-09-19 12:56 UTC (permalink / raw)
To: linux-xfs; +Cc: sandeen, Jan Tulak
Check if a device is mounted (and issue an error about that) before
asking for -f flag.
Example of the old behaviour I'm changing:
$ mkfs.xfs /dev/sda1
mkfs.xfs: /dev/sda1 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
$ mkfs.xfs -f /dev/sda1
mkfs.xfs: /dev/sda1 contains a mounted filesystem
Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
mkfs/xfs_mkfs.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 81d9859a..97e78647 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -1012,7 +1012,6 @@ check_device_type(
bool no_size,
bool no_name,
int *create,
- bool force_overwrite,
const char *optname)
{
struct stat statbuf;
@@ -1043,13 +1042,6 @@ check_device_type(
return;
}
- if (!force_overwrite && check_overwrite(name)) {
- fprintf(stderr,
- _("%s: Use the -f option to force overwrite.\n"),
- progname);
- exit(1);
- }
-
/*
* We only want to completely truncate and recreate an existing file if
* we were specifically told it was a file. Set the create flag only in
@@ -1079,6 +1071,20 @@ check_device_type(
usage();
}
+static void
+validate_overwrite(
+ const char *name,
+ bool force_overwrite)
+{
+ if (!force_overwrite && check_overwrite(name)) {
+ fprintf(stderr,
+ _("%s: Use the -f option to force overwrite.\n"),
+ progname);
+ exit(1);
+ }
+
+}
+
static void
validate_ag_geometry(
int blocklog,
@@ -1731,18 +1737,15 @@ validate_sectorsize(
* files or block devices and set the control parameters correctly.
*/
check_device_type(dfile, &cli->xi->disfile, !cli->dsize, !dfile,
- dry_run ? NULL : &cli->xi->dcreat,
- force_overwrite, "d");
+ dry_run ? NULL : &cli->xi->dcreat, "d");
if (!cli->loginternal)
check_device_type(cli->xi->logname, &cli->xi->lisfile,
!cli->logsize, !cli->xi->logname,
- dry_run ? NULL : &cli->xi->lcreat,
- force_overwrite, "l");
+ dry_run ? NULL : &cli->xi->lcreat, "l");
if (cli->xi->rtname)
check_device_type(cli->xi->rtname, &cli->xi->risfile,
!cli->rtsize, !cli->xi->rtname,
- dry_run ? NULL : &cli->xi->rcreat,
- force_overwrite, "r");
+ dry_run ? NULL : &cli->xi->rcreat, "r");
/*
* Explicitly disable direct IO for image files so we don't error out on
@@ -3909,6 +3912,7 @@ main(
* Open and validate the device configurations
*/
open_devices(&cfg, &xi);
+ validate_overwrite(dfile, force_overwrite);
validate_datadev(&cfg, &cli);
validate_logdev(&cfg, &cli, &logfile);
validate_rtdev(&cfg, &cli, &rtfile);
--
2.18.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] mkfs: discard only after all validations
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:44 ` Darrick J. Wong
2018-09-19 15:11 ` Jan Tulak
2018-09-20 3:16 ` Dave Chinner
2018-09-20 9:20 ` [PATCH 1/2 v2] " Jan Tulak
2 siblings, 2 replies; 10+ messages in thread
From: Darrick J. Wong @ 2018-09-19 14:44 UTC (permalink / raw)
To: Jan Tulak; +Cc: linux-xfs, sandeen
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
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] mkfs: move 'mounted' check before 'existing fs' check
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
0 siblings, 1 reply; 10+ messages in thread
From: Darrick J. Wong @ 2018-09-19 14:48 UTC (permalink / raw)
To: Jan Tulak; +Cc: linux-xfs, sandeen
On Wed, Sep 19, 2018 at 02:56:17PM +0200, Jan Tulak wrote:
> Check if a device is mounted (and issue an error about that) before
> asking for -f flag.
>
> Example of the old behaviour I'm changing:
> $ mkfs.xfs /dev/sda1
> mkfs.xfs: /dev/sda1 appears to contain an existing filesystem (xfs).
> mkfs.xfs: Use the -f option to force overwrite.
>
> $ mkfs.xfs -f /dev/sda1
> mkfs.xfs: /dev/sda1 contains a mounted filesystem
I'm confused by the commit message -- what is the new behavior?
Is it this?
$ mkfs.xfs /dev/sda1
mkfs.xfs: /dev/sda1 contains a mounted filesystem
$ mkfs.xfs -f /dev/sda1
mkfs.xfs: /dev/sda1 contains a mounted filesystem
--D
> Signed-off-by: Jan Tulak <jtulak@redhat.com>
> ---
> mkfs/xfs_mkfs.c | 32 ++++++++++++++++++--------------
> 1 file changed, 18 insertions(+), 14 deletions(-)
>
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index 81d9859a..97e78647 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -1012,7 +1012,6 @@ check_device_type(
> bool no_size,
> bool no_name,
> int *create,
> - bool force_overwrite,
> const char *optname)
> {
> struct stat statbuf;
> @@ -1043,13 +1042,6 @@ check_device_type(
> return;
> }
>
> - if (!force_overwrite && check_overwrite(name)) {
> - fprintf(stderr,
> - _("%s: Use the -f option to force overwrite.\n"),
> - progname);
> - exit(1);
> - }
> -
> /*
> * We only want to completely truncate and recreate an existing file if
> * we were specifically told it was a file. Set the create flag only in
> @@ -1079,6 +1071,20 @@ check_device_type(
> usage();
> }
>
> +static void
> +validate_overwrite(
> + const char *name,
> + bool force_overwrite)
> +{
> + if (!force_overwrite && check_overwrite(name)) {
> + fprintf(stderr,
> + _("%s: Use the -f option to force overwrite.\n"),
> + progname);
> + exit(1);
> + }
> +
> +}
> +
> static void
> validate_ag_geometry(
> int blocklog,
> @@ -1731,18 +1737,15 @@ validate_sectorsize(
> * files or block devices and set the control parameters correctly.
> */
> check_device_type(dfile, &cli->xi->disfile, !cli->dsize, !dfile,
> - dry_run ? NULL : &cli->xi->dcreat,
> - force_overwrite, "d");
> + dry_run ? NULL : &cli->xi->dcreat, "d");
> if (!cli->loginternal)
> check_device_type(cli->xi->logname, &cli->xi->lisfile,
> !cli->logsize, !cli->xi->logname,
> - dry_run ? NULL : &cli->xi->lcreat,
> - force_overwrite, "l");
> + dry_run ? NULL : &cli->xi->lcreat, "l");
> if (cli->xi->rtname)
> check_device_type(cli->xi->rtname, &cli->xi->risfile,
> !cli->rtsize, !cli->xi->rtname,
> - dry_run ? NULL : &cli->xi->rcreat,
> - force_overwrite, "r");
> + dry_run ? NULL : &cli->xi->rcreat, "r");
>
> /*
> * Explicitly disable direct IO for image files so we don't error out on
> @@ -3909,6 +3912,7 @@ main(
> * Open and validate the device configurations
> */
> open_devices(&cfg, &xi);
> + validate_overwrite(dfile, force_overwrite);
> validate_datadev(&cfg, &cli);
> validate_logdev(&cfg, &cli, &logfile);
> validate_rtdev(&cfg, &cli, &rtfile);
> --
> 2.18.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] mkfs: move 'mounted' check before 'existing fs' check
2018-09-19 14:48 ` Darrick J. Wong
@ 2018-09-19 15:05 ` Jan Tulak
2018-09-20 20:03 ` Darrick J. Wong
0 siblings, 1 reply; 10+ messages in thread
From: Jan Tulak @ 2018-09-19 15:05 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-xfs, Eric Sandeen
On Wed, Sep 19, 2018 at 4:49 PM Darrick J. Wong <darrick.wong@oracle.com> wrote:
>
> On Wed, Sep 19, 2018 at 02:56:17PM +0200, Jan Tulak wrote:
> > Check if a device is mounted (and issue an error about that) before
> > asking for -f flag.
> >
> > Example of the old behaviour I'm changing:
> > $ mkfs.xfs /dev/sda1
> > mkfs.xfs: /dev/sda1 appears to contain an existing filesystem (xfs).
> > mkfs.xfs: Use the -f option to force overwrite.
> >
> > $ mkfs.xfs -f /dev/sda1
> > mkfs.xfs: /dev/sda1 contains a mounted filesystem
>
> I'm confused by the commit message -- what is the new behavior?
>
> Is it this?
>
> $ mkfs.xfs /dev/sda1
> mkfs.xfs: /dev/sda1 contains a mounted filesystem
>
> $ mkfs.xfs -f /dev/sda1
> mkfs.xfs: /dev/sda1 contains a mounted filesystem
Yes. I should put it right into the commit message.
Jan
--
Jan Tulak
jtulak@redhat.com / jan@tulak.me
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] mkfs: discard only after all validations
2018-09-19 14:44 ` [PATCH 1/2] mkfs: discard only after all validations Darrick J. Wong
@ 2018-09-19 15:11 ` Jan Tulak
2018-09-20 3:16 ` Dave Chinner
1 sibling, 0 replies; 10+ messages in thread
From: Jan Tulak @ 2018-09-19 15:11 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-xfs, Eric Sandeen
On Wed, Sep 19, 2018 at 4:44 PM Darrick J. Wong <darrick.wong@oracle.com> wrote:
snip
> > @@ -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.
Agreed.
>
> > + 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?
>
>From what I remember, it went along this: If the user is trying to
mkfs an existing file, we don't want to destroy anything they did with
the file before (sparse file, allocations...).
> > @@ -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);
>
> ?
Yes, this makes more sense.
Jan
--
Jan Tulak
jtulak@redhat.com / jan@tulak.me
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] mkfs: discard only after all validations
2018-09-19 14:44 ` [PATCH 1/2] mkfs: discard only after all validations Darrick J. Wong
2018-09-19 15:11 ` Jan Tulak
@ 2018-09-20 3:16 ` Dave Chinner
1 sibling, 0 replies; 10+ messages in thread
From: Dave Chinner @ 2018-09-20 3:16 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Jan Tulak, linux-xfs, sandeen
On Wed, Sep 19, 2018 at 07:44:05AM -0700, Darrick J. Wong wrote:
> 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?
Yeah - preallocated image files shouldn't be punched, because it
defeats the whole purpose of setting up preallocated image files.
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/2 v2] mkfs: discard only after all validations
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:44 ` [PATCH 1/2] mkfs: discard only after all validations Darrick J. Wong
@ 2018-09-20 9:20 ` Jan Tulak
2018-09-20 20:03 ` Darrick J. Wong
2 siblings, 1 reply; 10+ messages in thread
From: Jan Tulak @ 2018-09-20 9:20 UTC (permalink / raw)
To: linux-xfs; +Cc: Jan Tulak
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>
---
CHANGES:
v2
* discard_data -> discard_devices
* move the discard condition outside of the function
---
mkfs/xfs_mkfs.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 2e53c1e8..c97c69e8 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,10 +2418,15 @@ open_devices(
xi->dsize &= sector_mask;
xi->rtsize &= sector_mask;
xi->logBBsize &= (uint64_t)-1 << (max(cfg->lsectorlog, 10) - BBSHIFT);
+}
-
- if (!discard)
- return;
+static void
+discard_devices(
+ struct libxfs_xinit *xi)
+{
+ /*
+ * This function has to be called after libxfs has been initialized.
+ */
if (!xi->disfile)
discard_blocks(xi->ddev, xi->dsize);
@@ -3901,7 +3905,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 +3956,12 @@ main(
exit(0);
}
+ /*
+ * All values have been validated, discard the old device layout.
+ */
+ if (discard && !dry_run)
+ discard_devices(&xi);
+
/*
* we need the libxfs buffer cache from here on in.
*/
--
2.18.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] mkfs: move 'mounted' check before 'existing fs' check
2018-09-19 15:05 ` Jan Tulak
@ 2018-09-20 20:03 ` Darrick J. Wong
0 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2018-09-20 20:03 UTC (permalink / raw)
To: Jan Tulak; +Cc: linux-xfs, Eric Sandeen
On Wed, Sep 19, 2018 at 05:05:38PM +0200, Jan Tulak wrote:
> On Wed, Sep 19, 2018 at 4:49 PM Darrick J. Wong <darrick.wong@oracle.com> wrote:
> >
> > On Wed, Sep 19, 2018 at 02:56:17PM +0200, Jan Tulak wrote:
> > > Check if a device is mounted (and issue an error about that) before
> > > asking for -f flag.
> > >
> > > Example of the old behaviour I'm changing:
> > > $ mkfs.xfs /dev/sda1
> > > mkfs.xfs: /dev/sda1 appears to contain an existing filesystem (xfs).
> > > mkfs.xfs: Use the -f option to force overwrite.
> > >
> > > $ mkfs.xfs -f /dev/sda1
> > > mkfs.xfs: /dev/sda1 contains a mounted filesystem
> >
> > I'm confused by the commit message -- what is the new behavior?
> >
> > Is it this?
> >
> > $ mkfs.xfs /dev/sda1
> > mkfs.xfs: /dev/sda1 contains a mounted filesystem
> >
> > $ mkfs.xfs -f /dev/sda1
> > mkfs.xfs: /dev/sda1 contains a mounted filesystem
>
> Yes. I should put it right into the commit message.
With that added,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
--D
>
> Jan
>
> --
> Jan Tulak
> jtulak@redhat.com / jan@tulak.me
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2 v2] mkfs: discard only after all validations
2018-09-20 9:20 ` [PATCH 1/2 v2] " Jan Tulak
@ 2018-09-20 20:03 ` Darrick J. Wong
0 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2018-09-20 20:03 UTC (permalink / raw)
To: Jan Tulak; +Cc: linux-xfs
On Thu, Sep 20, 2018 at 11:20:06AM +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>
Looks ok to me,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
--D
> ---
> CHANGES:
> v2
> * discard_data -> discard_devices
> * move the discard condition outside of the function
>
> ---
> mkfs/xfs_mkfs.c | 22 ++++++++++++++++------
> 1 file changed, 16 insertions(+), 6 deletions(-)
>
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index 2e53c1e8..c97c69e8 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,10 +2418,15 @@ open_devices(
> xi->dsize &= sector_mask;
> xi->rtsize &= sector_mask;
> xi->logBBsize &= (uint64_t)-1 << (max(cfg->lsectorlog, 10) - BBSHIFT);
> +}
>
> -
> - if (!discard)
> - return;
> +static void
> +discard_devices(
> + struct libxfs_xinit *xi)
> +{
> + /*
> + * This function has to be called after libxfs has been initialized.
> + */
>
> if (!xi->disfile)
> discard_blocks(xi->ddev, xi->dsize);
> @@ -3901,7 +3905,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 +3956,12 @@ main(
> exit(0);
> }
>
> + /*
> + * All values have been validated, discard the old device layout.
> + */
> + if (discard && !dry_run)
> + discard_devices(&xi);
> +
> /*
> * we need the libxfs buffer cache from here on in.
> */
> --
> 2.18.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2018-09-21 1:48 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 1/2] mkfs: discard only after all validations Darrick J. Wong
2018-09-19 15:11 ` 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
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).