All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Tulak <jtulak@redhat.com>
To: "Luis R. Rodriguez" <mcgrof@kernel.org>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 08/12] mkfs: replace variables with opts table: -b,d,s options
Date: Tue, 25 Apr 2017 10:37:57 +0200	[thread overview]
Message-ID: <CACj3i73PnrUGRL+1zQtj=vgdih5ne3AZ8rnmNCn-zTmmnrV8EA@mail.gmail.com> (raw)
In-Reply-To: <20170425052721.GL28800@wotan.suse.de>

On Tue, Apr 25, 2017 at 7:27 AM, Luis R. Rodriguez <mcgrof@kernel.org> wrote:
> On Sun, Apr 23, 2017 at 08:54:59PM +0200, Jan Tulak wrote:
>> Remove variables that can be replaced with a direct access to the opts table,
>> so we have it all in a single place, acessible from anywhere.
>>
>> In future, we can remove some passing of values forth and back, but now limit
>> the changes to simple replacement without a change in the logic.
>
> What do you mean passing of values here, as an example with bopts ?

Passing it to a function and then retrieving with pointers, e.g. change this

static void
calc_stripe_factors(
        int             dsu,
        int             dsw,
        int             dsectsz,
        int             lsu,
        int             lsectsz,
        uint64_t        *dsunit,
        uint64_t        *dswidth,
        uint64_t        *lsunit)


to this

static void
calc_stripe_factors(struct opt_params * opts) // or no argument at all...

Which btw needs to be updated anyway because it is still using int...

>
>> This is first of multiple similar patches that do the same, but for other
>> options.
>>
>> Signed-off-by: Jan Tulak <jtulak@redhat.com>
>> ---
>>  mkfs/xfs_mkfs.c | 814 ++++++++++++++++++++++++++++++++++----------------------
>>  1 file changed, 503 insertions(+), 311 deletions(-)
>>
>> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
>> index 362c9b4..6857c30 100644
>> --- a/mkfs/xfs_mkfs.c
>> +++ b/mkfs/xfs_mkfs.c
>> @@ -1485,15 +1480,12 @@ main(
>>       int                     argc,
>>       char                    **argv)
>>  {
>> -     uint64_t                agcount;
>>       xfs_agf_t               *agf;
>>       xfs_agi_t               *agi;
>>       xfs_agnumber_t          agno;
>> -     uint64_t                agsize;
>>       xfs_alloc_rec_t         *arec;
>>       struct xfs_btree_block  *block;
>>       bool                    blflag;
>
> Note: blflag
>
>> -     uint64_t                blocklog;
>>       bool                    bsflag;
>
> Note: bsflag
>
>>       memset(&fsx, 0, sizeof(fsx));
>> @@ -1629,6 +1613,7 @@ main(
>>                       break;
>>               case 'b':
>>                       p = optarg;
>> +                     uint64_t tmp;
>>                       while (*p != '\0') {
>>                               char    **subopts =
>>                                               (char **)opts[OPT_B].subopts;
>> @@ -1636,19 +1621,17 @@ main(
>>
>>                               switch (getsubopt(&p, subopts, &value)) {
>>                               case B_LOG:
>> -                                     blocklog = parse_conf_val(OPT_B, B_LOG,
>> -                                                               value);
>> -                                     blocksize = 1 << blocklog;
>> +                                     tmp = parse_conf_val(OPT_B, B_LOG,
>> +                                                          value);
>> +                                     set_conf_val(OPT_B, B_SIZE, 1 << tmp);
>>                                       blflag = 1;
>
> This is a collateral variable set when blog is set. If we have to parse the
> blog again, it means similar code would be needed.
>
>> -                                     set_conf_val(OPT_B, B_SIZE, blocksize);
>>                                       break;
>>                               case B_SIZE:
>> -                                     blocksize = parse_conf_val(OPT_B,
>> -                                                                B_SIZE,
>> -                                                                value);
>> -                                     blocklog = libxfs_highbit32(blocksize);
>> +                                     tmp = parse_conf_val(OPT_B, B_SIZE,
>> +                                                          value);
>> +                                     set_conf_val(OPT_B, B_LOG,
>> +                                             libxfs_highbit32(tmp));
>>                                       bsflag = 1;
>
> Likewise for bsflag.
>
>> -                                     set_conf_val(OPT_B, B_LOG, blocklog);
>>                                       break;
>>                               default:
>>                                       unknown('b', value);
>
> What I'm questioning is whether or not it makes sense instead for parse_conf_val()
> to return void and do all this meddling for us, this would require stuffing any
> collateral variables into a struct and passing that to parse_conf_val and using
> it on main() as well.

Again, this (both logic and flags) is something I want to do later.
And in fact, I think that perhaps the whole manual loop in main() can
be removed in the future once the case logic is moved elsewhere.
Because then we can extract specific cases from the opts table with
the help of some helper functions...

Jan

>
>   Luis



-- 
Jan Tulak
jtulak@redhat.com / jan@tulak.me

  parent reply	other threads:[~2017-04-25  8: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
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 [this message]
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='CACj3i73PnrUGRL+1zQtj=vgdih5ne3AZ8rnmNCn-zTmmnrV8EA@mail.gmail.com' \
    --to=jtulak@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=mcgrof@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.