From: "Luis R. Rodriguez" <mcgrof@kernel.org>
To: Jan Tulak <jtulak@redhat.com>
Cc: "Luis R. Rodriguez" <mcgrof@kernel.org>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/7] mkfs: Save raw user input field to the opts struct
Date: Mon, 7 Aug 2017 19:26:49 +0200 [thread overview]
Message-ID: <20170807172649.GL27873@wotan.suse.de> (raw)
In-Reply-To: <932c46d4-0304-9e6a-35fe-f12c8f8dc7f3@redhat.com>
On Fri, Aug 04, 2017 at 03:50:19PM +0200, Jan Tulak wrote:
>
>
> On 04/08/2017 00:25, Luis R. Rodriguez wrote:
> > On Thu, Aug 03, 2017 at 03:07:20PM +0200, Jan Tulak wrote:
> > > OK, I'm willing to return errors for the _raw functions. These are used only
> > > on few places, so it is not a big issue. Especially if I add a wrapper for
> > > the get_conf_raw function - right now, these are used only as fprintf()
> > > arguments to print an error. So the wrapper makes it easy to use in this
> > > case (with the old die-on-error behavior), but if you want to use it for
> > > something else, you can use it directly and get an error as a return code.
> > > Does this looks good?
> > >
> > > +/*
> > > + * Return 0 on success, -ENOMEM if it could not allocate enough memory for
> > > + * the string to be saved into the out pointer.
> > > + */
> > > +static int
> > > +get_conf_raw(const struct opt_params *opt, const int subopt, char **out)
> > > +{
> > > + if (subopt < 0 || subopt >= MAX_SUBOPTS) {
> > > + fprintf(stderr,
> > > + "This is a bug: get_conf_raw called with invalid opt/subopt:
> > > %c/%d\n",
> > > + opt->name, subopt);
> > > + exit(1);
> > Why not return -EINVAL?
>
> If we know we hit a bug, we should terminate as soon as possible. We are in
> an indeterminable state and we shouldn't risk that we will write anything. C
> does not have exceptions, so I think that here we really should just exit.
> The memory issue can have a solution, but a bug? Time to end ASAP.
>
> And set/get_conf_val is yet another issue. I really don't want to return
> errors there, because then we can't do things like:
>
> if (get_conf_val(OPT_D, D_AGCOUNT) > XFS_MAX_AGNUMBER + 1)
>
> There is over 350 uses of get_conf_val similar to this and if every usage
> should be changed to something like:
>
> test_error(get_conf_val(OPT_D, D_AGCOUNT, &tmp_x));
> if(tmp_x > XFS_MAX_AGNUMBER + 1)
>
> Then this whole thing with temporary variables would make the situation
> worse than it is now.
Then one can keep the behaviour for get_conf_val() and it would use __get_conf_val()
which in turn *does* do the return. This way if I need to capture and handle the return
differently later this can be done and the code for existing callers does not need
to change, and the same paranoid behaviour can be kept?
Luis
next prev parent reply other threads:[~2017-08-07 17:26 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-20 9:29 [PATCH 0/7] mkfs: save user input into opts table Jan Tulak
2017-07-20 9:29 ` [PATCH 1/7] mkfs: Save raw user input field to the opts struct Jan Tulak
2017-07-27 16:27 ` Luis R. Rodriguez
2017-07-28 14:45 ` Jan Tulak
2017-07-29 17:12 ` Luis R. Rodriguez
2017-08-02 14:30 ` Jan Tulak
2017-08-02 15:51 ` Jan Tulak
2017-08-02 19:41 ` Luis R. Rodriguez
2017-08-02 19:19 ` Luis R. Rodriguez
2017-08-03 13:07 ` Jan Tulak
2017-08-03 22:25 ` Luis R. Rodriguez
2017-08-04 13:50 ` Jan Tulak
2017-08-07 17:26 ` Luis R. Rodriguez [this message]
2017-08-07 17:36 ` Jan Tulak
2017-07-20 9:29 ` [PATCH 2/7] mkfs: rename defaultval to flagval in opts Jan Tulak
2017-07-20 9:29 ` [PATCH 3/7] mkfs: remove intermediate getstr followed by getnum Jan Tulak
2017-07-20 15:54 ` Darrick J. Wong
2017-07-21 8:56 ` Jan Tulak
2017-07-26 20:49 ` Eric Sandeen
2017-07-27 7:50 ` Jan Tulak
2017-07-27 13:35 ` Eric Sandeen
2017-07-21 12:24 ` [PATCH 3/7 v2] " Jan Tulak
2017-07-26 23:23 ` Eric Sandeen
2017-07-20 9:29 ` [PATCH 4/7] mkfs: merge tables for opts parsing into one table Jan Tulak
2017-07-20 9:29 ` [PATCH 5/7] mkfs: move getnum within the file Jan Tulak
2017-07-26 23:27 ` Eric Sandeen
2017-07-20 9:29 ` [PATCH 6/7] mkfs: extend opt_params with a value field Jan Tulak
2017-07-27 16:18 ` Luis R. Rodriguez
2017-07-28 14:44 ` Jan Tulak
2017-07-29 17:02 ` Luis R. Rodriguez
2017-08-02 14:43 ` Jan Tulak
2017-08-02 16:57 ` Luis R. Rodriguez
2017-08-02 18:11 ` Jan Tulak
2017-08-02 19:48 ` Luis R. Rodriguez
2017-08-03 13:23 ` Jan Tulak
2017-08-03 20:47 ` Luis R. Rodriguez
2017-07-20 9:29 ` [PATCH 7/7] mkfs: save user input values into opts Jan Tulak
2017-07-26 23:53 ` Eric Sandeen
2017-07-27 14:21 ` 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=20170807172649.GL27873@wotan.suse.de \
--to=mcgrof@kernel.org \
--cc=jtulak@redhat.com \
--cc=linux-xfs@vger.kernel.org \
/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