From: Dave Chinner <david@fromorbit.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 2/5] mkfs: add initial ini format config file parsing support
Date: Thu, 15 Oct 2020 17:09:03 +1100 [thread overview]
Message-ID: <20201015060903.GF7391@dread.disaster.area> (raw)
In-Reply-To: <20201015054633.GS9832@magnolia>
On Wed, Oct 14, 2020 at 10:46:33PM -0700, Darrick J. Wong wrote:
> On Thu, Oct 15, 2020 at 02:29:22PM +1100, Dave Chinner wrote:
> > From: Dave Chinner <dchinner@redhat.com>
> >
> > Add the framework that will allow the config file to be supplied on
> > the CLI and passed to the library that will parse it. This does not
> > yet do any option parsing from the config file.
> >
> > Signed-off-by: Dave Chinner <dchinner@redhat.com>
> > ---
> > mkfs/Makefile | 2 +-
> > mkfs/xfs_mkfs.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++-
> > 2 files changed, 115 insertions(+), 2 deletions(-)
> >
> > diff --git a/mkfs/Makefile b/mkfs/Makefile
> > index 31482b08d559..b8805f7e1ea1 100644
> > --- a/mkfs/Makefile
> > +++ b/mkfs/Makefile
> > @@ -11,7 +11,7 @@ HFILES =
> > CFILES = proto.c xfs_mkfs.c
> >
> > LLDLIBS += $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBRT) $(LIBPTHREAD) $(LIBBLKID) \
> > - $(LIBUUID)
> > + $(LIBUUID) $(LIBINIH)
> > LTDEPENDENCIES += $(LIBXFS) $(LIBXCMD) $(LIBFROG)
> > LLDFLAGS = -static-libtool-libs
> >
> > diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> > index 8fe149d74b0a..e84be74fb100 100644
> > --- a/mkfs/xfs_mkfs.c
> > +++ b/mkfs/xfs_mkfs.c
> > @@ -11,6 +11,7 @@
> > #include "libfrog/fsgeom.h"
> > #include "libfrog/topology.h"
> > #include "libfrog/convert.h"
> > +#include <ini.h>
> >
> > #define TERABYTES(count, blog) ((uint64_t)(count) << (40 - (blog)))
> > #define GIGABYTES(count, blog) ((uint64_t)(count) << (30 - (blog)))
> > @@ -44,6 +45,11 @@ enum {
> > B_MAX_OPTS,
> > };
> >
> > +enum {
> > + C_OPTFILE = 0,
> > + C_MAX_OPTS,
> > +};
> > +
> > enum {
> > D_AGCOUNT = 0,
> > D_FILE,
> > @@ -237,6 +243,28 @@ static struct opt_params bopts = {
> > },
> > };
> >
> > +/*
> > + * Config file specification. Usage is:
> > + *
> > + * mkfs.xfs -c file=<name>
>
> I thought it was -c options=/dev/random ?
I fixed that, refreshed the patch and updated the change log! How
the hell did I lose that change?
> > { 'd', &dopts, data_opts_parser },
> > { 'i', &iopts, inode_opts_parser },
> > { 'l', &lopts, log_opts_parser },
> > @@ -3562,6 +3611,61 @@ check_root_ino(
> > }
> > }
> >
> > +/*
> > + * INI file format option parser.
> > + *
> > + * This is called by the file parser library for every valid option it finds in
> > + * the config file. The option is already broken down into a
> > + * {section,name,value} tuple, so all we need to do is feed it to the correct
>
> XFS, SAX style.
>
> > + * suboption parser function and translate the return value.
> > + *
> > + * Returns 0 on failure, 1 for success.
> > + */
> > +static int
> > +cfgfile_parse_ini(
> > + void *user,
> > + const char *section,
> > + const char *name,
> > + const char *value)
> > +{
> > + struct cli_params *cli = user;
> > +
> > + fprintf(stderr, "Ini debug: file %s, section %s, name %s, value %s\n",
> > + cli->cfgfile, section, name, value);
> > +
> > + return 1;
> > +}
> > +
> > +void
> > +cfgfile_parse(
> > + struct cli_params *cli)
> > +{
> > + int error;
> > +
> > + if (!cli->cfgfile)
> > + return;
> > +
> > + error = ini_parse(cli->cfgfile, cfgfile_parse_ini, cli);
> > + if (error) {
> > + if (error > 0) {
> > + fprintf(stderr,
> > + _("%s: Unrecognised input on line %d. Aborting.\n"),
> > + cli->cfgfile, error);
> > + } else if (error == -2) {
> > + fprintf(stderr,
> > + _("Memory allocation failure parsing %s. Aborting.\n"),
> > + cli->cfgfile);
> > + } else {
> > + fprintf(stderr,
> > + _("Unable to open config file %s. Aborting.\n"),
> > + cli->cfgfile);
>
> I worry about libinih someday defining more negative error codes. -1 is
> "open failed", -2 is OOM, and positive is the line number of a parsing
> error, at least according to the documentation.
>
> Maybe we should handle -1 specifically and use the else as a catchall
> for unrecognized error codes?
Makes sense.
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2020-10-15 6:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-15 3:29 [PATCH 0/5] mkfs: Configuration file defined options Dave Chinner
2020-10-15 3:29 ` [PATCH 1/5] build: add support for libinih for mkfs Dave Chinner
2020-10-15 5:40 ` Darrick J. Wong
2020-10-15 3:29 ` [PATCH 2/5] mkfs: add initial ini format config file parsing support Dave Chinner
2020-10-15 5:46 ` Darrick J. Wong
2020-10-15 6:09 ` Dave Chinner [this message]
2020-10-15 3:29 ` [PATCH 3/5] mkfs: constify various strings Dave Chinner
2020-10-15 5:31 ` Darrick J. Wong
2020-10-15 3:29 ` [PATCH 4/5] mkfs: hook up suboption parsing to ini files Dave Chinner
2020-10-15 5:24 ` Darrick J. Wong
2020-10-15 3:29 ` [PATCH 5/5] mkfs: document config files in mkfs.xfs(8) Dave Chinner
2020-10-15 5:36 ` Darrick J. Wong
2020-10-15 5:13 ` [PATCH 0/5] mkfs: Configuration file defined options Darrick J. Wong
2020-10-15 5:32 ` Dave Chinner
2020-10-15 5:39 ` Darrick J. Wong
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=20201015060903.GF7391@dread.disaster.area \
--to=david@fromorbit.com \
--cc=darrick.wong@oracle.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;
as well as URLs for NNTP newsgroup(s).