public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: kaixuxia <xiakaixu1987@gmail.com>
Cc: Eric Sandeen <sandeen@sandeen.net>,
	Chaitanya Kulkarni <Chaitanya.Kulkarni@wdc.com>,
	"linux-xfs@vger.kernel.org" <linux-xfs@vger.kernel.org>,
	Kaixu Xia <kaixuxia@tencent.com>
Subject: Re: [PATCH] mkfs: simplify the configured sector sizes setting in validate_sectorsize
Date: Wed, 20 May 2020 07:15:49 +1000	[thread overview]
Message-ID: <20200519211549.GQ2040@dread.disaster.area> (raw)
In-Reply-To: <64a8d225-1d55-e6f1-eed3-b9a04eb426d6@gmail.com>

On Tue, May 19, 2020 at 10:56:01PM +0800, kaixuxia wrote:
> On 2020/5/19 21:03, Eric Sandeen wrote:
> > On 5/19/20 3:38 AM, Chaitanya Kulkarni wrote:
> >> On 5/18/20 11:39 PM, xiakaixu1987@gmail.com wrote:
> >>> From: Kaixu Xia <kaixuxia@tencent.com>
> >>>
> >>> 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 ?
> >>> Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
> >>> ---
> >>>   mkfs/xfs_mkfs.c | 14 ++++----------
> >>>   1 file changed, 4 insertions(+), 10 deletions(-)
> >>>
> >>> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> >>> index 039b1dcc..e1904d57 100644
> >>> --- a/mkfs/xfs_mkfs.c
> >>> +++ b/mkfs/xfs_mkfs.c
> >>> @@ -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);
> >>> -
> >>
> >> 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.
> 
> 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). 

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.
-- 
Dave Chinner
david@fromorbit.com

      reply	other threads:[~2020-05-19 21:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19  6:38 [PATCH] mkfs: simplify the configured sector sizes setting in validate_sectorsize xiakaixu1987
2020-05-19  8:38 ` Chaitanya Kulkarni
2020-05-19 13:03   ` Eric Sandeen
2020-05-19 14:56     ` kaixuxia
2020-05-19 21:15       ` Dave Chinner [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=20200519211549.GQ2040@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=Chaitanya.Kulkarni@wdc.com \
    --cc=kaixuxia@tencent.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    --cc=xiakaixu1987@gmail.com \
    /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