public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <mcgrof@kernel.org>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: Jan Tulak <jtulak@redhat.com>,
	"Luis R. Rodriguez" <mcgrof@kernel.org>,
	linux-xfs@vger.kernel.org
Subject: Re: [PATCH 04/12] mkfs: merge tables for opts parsing into one table
Date: Wed, 26 Apr 2017 03:38:15 +0200	[thread overview]
Message-ID: <20170426013815.GS28800@wotan.suse.de> (raw)
In-Reply-To: <175c1e19-12df-2993-811d-b5de631ac00f@sandeen.net>

On Tue, Apr 25, 2017 at 08:28:23AM -0500, Eric Sandeen wrote:
> On 4/25/17 2:45 AM, Jan Tulak wrote:
> > On Tue, Apr 25, 2017 at 5:04 AM, Luis R. Rodriguez <mcgrof@kernel.org> wrote:
> >> On Sun, Apr 23, 2017 at 08:54:55PM +0200, Jan Tulak wrote:
> >>> Merge separate instances of opt_params into one indexable table. Git
> >>> makes this patch looks a bit more complicated, but it does not change
> >>> values or structure of anything else. It only moves all the "struct
> >>> opt_params dopts = {...}", changes indentation for these substructures
> >>> and replaces their usage (dopts -> opts[OPT_D]).
> >>>
> >>> Signed-off-by: Jan Tulak <jtulak@redhat.com>
> >>> ---
> >>>  mkfs/xfs_mkfs.c | 1316 +++++++++++++++++++++++++++++--------------------------
> >>>  1 file changed, 683 insertions(+), 633 deletions(-)
> >>>
> >>> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> >>> index 7a72b11..513e106 100644
> >>> --- a/mkfs/xfs_mkfs.c
> >>> +++ b/mkfs/xfs_mkfs.c
> >>> @@ -42,6 +42,7 @@ static int  ispow2(unsigned int i);
> >>>  uint64_t             blocksize;
> >>>  uint64_t             sectorsize;
> >>>
> >>> +#define MAX_OPTS     16
> >>
> >> This is fragile, every time a new opt is added this needs to be updated
> 
> <pedantic>There are only 8 now, so there are still 8 free slots</pedantic>
> 
> >> and so is the index, and we should be pedantic over not going out of bounds.
> >> We could instead use a flexible array and compute the max opts at run time
> >> as a global. This way the max opts is always updated automatically.
> 
> I don't think it's all that fragile;

We can avoid such compilation warnings.

> this is used only for a global structure
> declaration & initialization.

*Currently used*. I'll later use it to bail out early if the mkfs.xfs.conf stat
file size is too big compared to what we max expect prior letting a library
chew on data. This lets us bail out early instead of having the library stall.
Its a rare corner case but can easily be considered and dealt with.

> If you add too many new members to opt_params,
> compilation will issue warnings:
> 
> xfs_mkfs.c:342: warning: excess elements in array initializer
> xfs_mkfs.c:342: warning: (near initialization for ‘opts’)
> xfs_mkfs.c:424: warning: excess elements in array initializer
> xfs_mkfs.c:424: warning: (near initialization for ‘opts’)
> xfs_mkfs.c:543: warning: excess elements in array initializer
> xfs_mkfs.c:543: warning: (near initialization for ‘opts’)
> ...

Warnings are not treated as failures though AFAICT, and if you fly
by through then yes, its fragile and will crash with out of bound
array access / segfault.

> and it will be quite obvious, at which point you can bump it up before
> you send that patch.  ;)

Mater of taste I guess, but then again I tend to only deal with kernel code and
to me the above is just recipe for disaster.

> Anyway, because the the definition is never used at runtime, there's
> no need to be computing it at runtime, either.

Not currently used at run time. I do plan on using it later at run time but its
for a rather odd corner case to avoid stalls on parsing  a large file when we
know its just not possible to be parsing it.

> > Mmm, that is a good idea and I see no issue with it. But I'm not sure
> > if it is worth of rewriting this patch as we already use MAX_SUBOPTS
> > anyway. Rather I see it as a standalone patch in the next set. What do
> > you think?
> 
> I think that given how it's used, there is no real need for any extra
> complexity.

I find it much simpler, but that seems to be subjective.

> In any case, any changes around this behavior would certainly
> be part of a different patch, because you'd want to be consistent with all
> the other structure initializers, and it would be a functionally separate
> change if it is warranted at all.

The opt_params are separate today though, this patch folds them in together,
what I propose is just to use a flexible array to avoid an explicit size
from the start. Not sure how much more functional of a change that is ?

  Luis

  reply	other threads:[~2017-04-26  1:38 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-23 18:54 [PATCH 00/12] mkfs: save user input into opts table Jan Tulak
2017-04-23 18:54 ` [PATCH 01/12] mkfs: Save raw user input field to the opts struct Jan Tulak
2017-04-25 17:38   ` Eric Sandeen
2017-04-23 18:54 ` [PATCH 02/12] mkfs: rename defaultval to flagval in opts Jan Tulak
2017-04-25 16:52   ` Eric Sandeen
2017-04-26  7:30     ` Jan Tulak
2017-04-26 13:02       ` Eric Sandeen
2017-04-26 13:20         ` Jan Tulak
2017-04-23 18:54 ` [PATCH 03/12] mkfs: remove intermediate getstr followed by getnum Jan Tulak
2017-04-25 17:37   ` Eric Sandeen
2017-04-26  7:40     ` Jan Tulak
2017-04-26 13:13       ` Eric Sandeen
2017-04-23 18:54 ` [PATCH 04/12] mkfs: merge tables for opts parsing into one table Jan Tulak
2017-04-25  3:04   ` Luis R. Rodriguez
2017-04-25  7:45     ` Jan Tulak
2017-04-25 13:28       ` Eric Sandeen
2017-04-26  1:38         ` Luis R. Rodriguez [this message]
2017-04-26  1:45           ` Luis R. Rodriguez
2017-04-26  2:00           ` Eric Sandeen
2017-04-26  8:01             ` Luis R. Rodriguez
2017-04-26  8:24               ` Jan Tulak
2017-04-26  8:21       ` Luis R. Rodriguez
2017-04-26  8:38         ` Jan Tulak
2017-04-25 21:45   ` Eric Sandeen
2017-04-26  4:09     ` Eric Sandeen
2017-04-26  8:14     ` Jan Tulak
2017-04-23 18:54 ` [PATCH 05/12] mkfs: extend opt_params with a value field Jan Tulak
2017-04-25  3:13   ` Luis R. Rodriguez
2017-04-25  8:04     ` Jan Tulak
2017-04-25  9:39       ` Jan Tulak
2017-04-26  1:04         ` Luis R. Rodriguez
2017-04-26  8:51           ` Jan Tulak
2017-04-26  1:10       ` Luis R. Rodriguez
2017-04-26  2:50         ` Eric Sandeen
2017-04-26  8:52           ` Jan Tulak
2017-04-23 18:54 ` [PATCH 06/12] mkfs: create get/set functions for opts table Jan Tulak
2017-04-25  3:40   ` Luis R. Rodriguez
2017-04-25  8:11     ` Jan Tulak
2017-04-26  1:43       ` Luis R. Rodriguez
2017-04-23 18:54 ` [PATCH 07/12] mkfs: save user input values into opts Jan Tulak
2017-04-25  5:19   ` Luis R. Rodriguez
2017-04-25  8:16     ` Jan Tulak
2017-04-26  1:47       ` Luis R. Rodriguez
2017-04-23 18:54 ` [PATCH 08/12] mkfs: replace variables with opts table: -b,d,s options Jan Tulak
2017-04-25  5:27   ` Luis R. Rodriguez
2017-04-25  5:30     ` Luis R. Rodriguez
2017-04-25  8:37     ` Jan Tulak
2017-04-26  0:45       ` Luis R. Rodriguez
2017-04-26  9:09         ` Jan Tulak
2017-04-23 18:55 ` [PATCH 09/12] mkfs: replace variables with opts table: -i options Jan Tulak
2017-04-23 18:55 ` [PATCH 10/12] mkfs: replace variables with opts table: -l options Jan Tulak
2017-04-23 18:55 ` [PATCH 11/12] mkfs: replace variables with opts table: -n options Jan Tulak
2017-04-23 18:55 ` [PATCH 12/12] mkfs: replace variables with opts table: -r options Jan Tulak
2017-04-25  2:52 ` [PATCH 00/12] mkfs: save user input into opts table Luis R. Rodriguez
2017-04-25 16:20 ` Eric Sandeen
2017-04-26  2:02   ` Luis R. Rodriguez
2017-04-26  2:17     ` Eric Sandeen
2017-06-28 16:18 ` Luis R. Rodriguez
2017-06-29  7:56   ` Jan Tulak

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=20170426013815.GS28800@wotan.suse.de \
    --to=mcgrof@kernel.org \
    --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