Skip to contentSkip to conversation

mkfs: simplify the configured sector sizes setting in validate_sectorsize

PATCH Superseded [email protected] 4 participants 5 messages May 19, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs: simplify the configured sector sizes setting in validate_sectorsize

From: Kaixu Xia <[email protected]>

There are two places that set the configured sector sizes in validate_sectorsize, actually we can simplify them and combine into one if statement.

---
 mkfs/xfs_mkfs.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
mkfs/xfs_mkfs.c +4 -10
index 039b1dcc..e1904d57 100644
@@ -1696,14 +1696,6 @@ validate_sectorsize(
 	int			dry_run,
 	int			force_overwrite)
 {
-	/* set configured sector sizes in preparation for checks */
-	if (!cli->sectorsize) {
-		cfg->sectorsize = dft->sectorsize;
-	} else {
-		cfg->sectorsize = cli->sectorsize;
-	}
-	cfg->sectorlog = libxfs_highbit32(cfg->sectorsize);
-
 	/*
 	 * Before anything else, verify that we are correctly operating on
 	 * files or block devices and set the control parameters correctly.
@@ -1730,6 +1722,7 @@ validate_sectorsize(
 	memset(ft, 0, sizeof(*ft));
 	get_topology(cli->xi, ft, force_overwrite);
 
+	/* set configured sector sizes in preparation for checks */
 	if (!cli->sectorsize) {
 		/*
 		 * Unless specified manually on the command line use the
@@ -1759,9 +1752,10 @@ _("specified blocksize %d is less than device physical sector size %d\n"
 				ft->lsectorsize);
 			cfg->sectorsize = ft->lsectorsize;
 		}
+	} else
+		cfg->sectorsize = cli->sectorsize;
 
-		cfg->sectorlog = libxfs_highbit32(cfg->sectorsize);
-	}
+	cfg->sectorlog = libxfs_highbit32(cfg->sectorsize);
 
 	/* validate specified/probed sector size */
 	if (cfg->sectorsize < XFS_MIN_SECTORSIZE ||
Signature · 1 line
2.20.0
#1 lore raw
Quoted 5 lines · On 5/18/20 11:39 PM, [email protected] wrote:

From: Kaixu Xia <[email protected]>

There are two places that set the configured sector sizes in validate_sectorsize, actually we can simplify them and combine into one if statement.
Is it me or patch description seems to be longer than what is in the

tree ?

Quoted 11 lines
---
  mkfs/xfs_mkfs.c | 14 ++++----------
  1 file changed, 4 insertions(+), 10 deletions(-)
mkfs/xfs_mkfs.c +0 -0
index 039b1dcc..e1904d57 100644
@@ -1696,14 +1696,6 @@ validate_sectorsize(
  	int			dry_run,

mkfs/xfs_mkfs.c validate_sectorsize( · line 1706

Quoted 10 lines
mkfs/xfs_mkfs.c +0 -8
  	int			force_overwrite)
  {
-	/* set configured sector sizes in preparation for checks */
-	if (!cli->sectorsize) {
-		cfg->sectorsize = dft->sectorsize;
-	} else {
-		cfg->sectorsize = cli->sectorsize;
-	}
-	cfg->sectorlog = libxfs_highbit32(cfg->sectorsize);
-

If above logic is correct which I've not looked into it, then dft is not used in validate_sectorsize(), how about something like this on the top of this this patch (totally untested):-

mkfs/xfs_mkfs.c +1 -3
index 3ed7d844..6cbd5d9d 100644
@@ -1690,7 +1690,6 @@ static void
  validate_sectorsize(
         struct mkfs_params      *cfg,
         struct cli_params       *cli,
-       struct mkfs_default_params *dft,
         struct fs_topology      *ft,
         char                    *dfile,
         int                     dry_run,
@@ -3696,8 +3695,7 @@ main(
          * before opening the libxfs devices.
          */
         validate_blocksize(&cfg, &cli, &dft);
-       validate_sectorsize(&cfg, &cli, &dft, &ft, dfile, dry_run,
-                           force_overwrite);
+       validate_sectorsize(&cfg, &cli, &ft, dfile, dry_run, 

force_overwrite);

/*
* XXX: we still need to set block size and sector size global
variables

Quoted 25 lines
mkfs/xfs_mkfs.c +4 -2
  	/*
  	 * Before anything else, verify that we are correctly operating on
  	 * files or block devices and set the control parameters correctly.
@@ -1730,6 +1722,7 @@ validate_sectorsize(
  	memset(ft, 0, sizeof(*ft));
  	get_topology(cli->xi, ft, force_overwrite);
 
+	/* set configured sector sizes in preparation for checks */
  	if (!cli->sectorsize) {
  		/*
  		 * Unless specified manually on the command line use the
@@ -1759,9 +1752,10 @@ _("specified blocksize %d is less than device physical sector size %d\n"
  				ft->lsectorsize);
  			cfg->sectorsize = ft->lsectorsize;
  		}
+	} else
+		cfg->sectorsize = cli->sectorsize;
 
-		cfg->sectorlog = libxfs_highbit32(cfg->sectorsize);
-	}
+	cfg->sectorlog = libxfs_highbit32(cfg->sectorsize);
 
  	/* validate specified/probed sector size */
  	if (cfg->sectorsize < XFS_MIN_SECTORSIZE ||
#2 lore raw
Quoted 24 lines · Chaitanya Kulkarni
Quoted 5 lines · On 5/18/20 11:39 PM, [email protected] wrote:

From: Kaixu Xia <[email protected]>

There are two places that set the configured sector sizes in validate_sectorsize, actually we can simplify them and combine into one if statement.
Is it me or patch description seems to be longer than what is in the

tree ?

Quoted 17 lines
---
  mkfs/xfs_mkfs.c | 14 ++++----------
  1 file changed, 4 insertions(+), 10 deletions(-)
mkfs/xfs_mkfs.c +0 -4
index 039b1dcc..e1904d57 100644
@@ -1696,14 +1696,6 @@ validate_sectorsize(
  	int			dry_run,
  	int			force_overwrite)
  {
-	/* set configured sector sizes in preparation for checks */
-	if (!cli->sectorsize) {
-		cfg->sectorsize = dft->sectorsize;
-	} else {
Quoted 8 lines

mkfs/xfs_mkfs.c validate_sectorsize( · line 1706

Quoted 4 lines
mkfs/xfs_mkfs.c +0 -4
-		cfg->sectorsize = cli->sectorsize;
-	}
-	cfg->sectorlog = libxfs_highbit32(cfg->sectorsize);
-

If above logic is correct which I've not looked into it, then dft is not used in validate_sectorsize(), how about something like this on the top of this this patch (totally untested):-

Honestly if not set via commandline, and probing fails, we should fall back to dft->sectorsize so that all the defaults are still set in one place, i.e. the defaults structure mkfs_default_params.

-Eric

author
#3 lore raw
Quoted 34 lines · Eric Sandeen
Quoted 24 lines · Chaitanya Kulkarni
Quoted 5 lines · On 5/18/20 11:39 PM, [email protected] wrote:

From: Kaixu Xia <[email protected]>

There are two places that set the configured sector sizes in validate_sectorsize, actually we can simplify them and combine into one if statement.
Is it me or patch description seems to be longer than what is in the

tree ?

Quoted 17 lines
---
  mkfs/xfs_mkfs.c | 14 ++++----------
  1 file changed, 4 insertions(+), 10 deletions(-)
mkfs/xfs_mkfs.c +0 -4
index 039b1dcc..e1904d57 100644
@@ -1696,14 +1696,6 @@ validate_sectorsize(
  	int			dry_run,
  	int			force_overwrite)
  {
-	/* set configured sector sizes in preparation for checks */
-	if (!cli->sectorsize) {
-		cfg->sectorsize = dft->sectorsize;
-	} else {
Quoted 8 lines

mkfs/xfs_mkfs.c validate_sectorsize( · line 1706

Quoted 4 lines
mkfs/xfs_mkfs.c +0 -4
-		cfg->sectorsize = cli->sectorsize;
-	}
-	cfg->sectorlog = libxfs_highbit32(cfg->sectorsize);
-

If above logic is correct which I've not looked into it, then dft is not used in validate_sectorsize(), how about something like this on the top of this this patch (totally untested):-

Quoted 3 lines

Honestly if not set via commandline, and probing fails, we should fall back to dft->sectorsize so that all the defaults are still set in one place, i.e. the defaults structure mkfs_default_params.

The original logic in validate_sectorsize() is:

static void
validate_sectorsize(

    ...
    if (!cli->sectorsize) {
	cfg->sectorsize = dft->sectorsize;
    } else {
	cfg->sectorsize = cli->sectorsize;
    }
    ...
    if (!cli->sectorsize) {
	if (!ft->lsectorsize)
	   ft->lsectorsize = XFS_MIN_SECTORSIZE;
	...
	cfg->sectorsize = ft->psectorsize;
	...
    } 
    ...

}

Firstly, if not set via commandline and probing fails, we will use the XFS_MIN_SECTORSIZE (actually equal to dft->sectorsize).
Secondly, for the !cli->sectorsize case, the first if statement set cfg->sectorsize to dft->sectorsize, but the cfg->sectorsize value would be overwrote and set to ft->psectorsize in the next if statement, so the first if statement is meaningless and the two if statements can be combined.

Quoted 4 lines

-Eric

Signature · 1 line
kaixuxia
#4 lore raw
Quoted 58 lines · kaixuxia
Quoted 34 lines · Eric Sandeen
Quoted 24 lines · Chaitanya Kulkarni
Quoted 5 lines · On 5/18/20 11:39 PM, [email protected] wrote:

From: Kaixu Xia <[email protected]>

There are two places that set the configured sector sizes in validate_sectorsize, actually we can simplify them and combine into one if statement.
Is it me or patch description seems to be longer than what is in the

tree ?

Quoted 17 lines
---
  mkfs/xfs_mkfs.c | 14 ++++----------
  1 file changed, 4 insertions(+), 10 deletions(-)
mkfs/xfs_mkfs.c +0 -4
index 039b1dcc..e1904d57 100644
@@ -1696,14 +1696,6 @@ validate_sectorsize(
  	int			dry_run,
  	int			force_overwrite)
  {
-	/* set configured sector sizes in preparation for checks */
-	if (!cli->sectorsize) {
-		cfg->sectorsize = dft->sectorsize;
-	} else {
Quoted 8 lines

mkfs/xfs_mkfs.c validate_sectorsize( · line 1706

Quoted 4 lines
mkfs/xfs_mkfs.c +0 -4
-		cfg->sectorsize = cli->sectorsize;
-	}
-	cfg->sectorlog = libxfs_highbit32(cfg->sectorsize);
-

If above logic is correct which I've not looked into it, then dft is not used in validate_sectorsize(), how about something like this on the top of this this patch (totally untested):-

Quoted 3 lines

Honestly if not set via commandline, and probing fails, we should fall back to dft->sectorsize so that all the defaults are still set in one place, i.e. the defaults structure mkfs_default_params.

The original logic in validate_sectorsize() is:

static void
validate_sectorsize(

    ...
    if (!cli->sectorsize) {
	cfg->sectorsize = dft->sectorsize;
    } else {
	cfg->sectorsize = cli->sectorsize;
    }
    ...
    if (!cli->sectorsize) {
	if (!ft->lsectorsize)
	   ft->lsectorsize = XFS_MIN_SECTORSIZE;
	...
	cfg->sectorsize = ft->psectorsize;
	...
    } 
    ...
Quoted 4 lines

}

Firstly, if not set via commandline and probing fails, we will use the XFS_MIN_SECTORSIZE (actually equal to dft->sectorsize).

Which is incorrect - this code should be using dft->sectorsize, not hard coding a default value. Defaults are set in the default value structure so they are all configured in one place, not strewn randomly through the code and hence are impossible to find and review.

With the added change to use dft->sectorsize, the rest of the patch is fine.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]