mkfs: add mkfs config version specifier for the config file
PATCH v2 1/1 mkfs: add mkfs config version specifier for the config file
We may opt later to bump this and add new features which we don't want a v1 parser to use. So peg a version number. We add a new [global] section dedicated for special configuration file option specifiers, with the only subtopt supported being 'version'.
The only we support for now is version 1.
---
As suggested by Sandeed, added a [global] section which makes the code easier to read and maintain.
man/man8/mkfs.xfs.8.in | 9 ++++- mkfs/config.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-)
man/man8/mkfs.xfs.8.in +8 -1
@@ -965,12 +965,19 @@ option follow a simple ini-style format as shown below. Available options consist of a small subset of the parameters available via the .BR mkfs.xfs (8) -command line. +command line. All configuration files must start with an annotation of +the configuration file format, specified in the global section with the keyword +.B version +and the only supported version format is 1. Currently all default parameters can only be either enabled or disabled, with a value of 1 to enable or 0 to disable. See below for a list of all supported configuration parameters and their current built-in default settings. .PP +.BI [global] +.br +.BI version=1 +.PP .BI [data] .br .BI noalign=0
mkfs/config.c +91 -0
145 lines not on this page · raw message
Signature · 1 line
2.16.3
Quoted 5 lines · Luis R. Rodriguez
We may opt later to bump this and add new features which we don't want a v1 parser to use. So peg a version number. We add a new [global] section dedicated for special configuration file option specifiers, with the only subtopt supported being 'version'.
Quoted 8 lines
The only we support for now is version 1.
Suggested-by Dave Chinner <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>---
As suggested by Sandeed, added a [global] section which makes the code easier to read and maintain.
Soo....
I'm really on the fence about versioning at all, because we have yet to identify any concrete scenario in which we'd need to bump the version; we haven't even defined what exactly the "version" implies.
Here's my high-level view.
1) The config file is a 1:1 mapping from [section] to option ([metadata]::"-m") and from token to suboption (crc=0::crc=0). So it's really just an alternate representation of a command line.
2) We have no "version" on the command line - new options come, and rarely old options sometimes go, and invalid command lines will issue informative errors. The same should be expected from the config file as it gains or loses the ability to parse any given section or token. Directives coming or going won't require a new version.
3) The config file is in INI format, which is trivial and well-established, and exceedingly unlikely to change, so I can't foresee any situation where we'd need to know the version in order to parse the file.
3a) If the config file format /did/ change, we have a chicken and egg problem where we have to parse a potentially unsupported format in order to get the version out.
So unless anyone has a concrete example of how a version would be needed, functional, reliably-parsed, and well-defined I'm inclined to leave this out.
Thanks,
-Eric
Quoted 188 lines
man/man8/mkfs.xfs.8.in | 9 ++++- mkfs/config.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-)man/man8/mkfs.xfs.8.in +8
-1@@ -965,12 +965,19 @@ option follow a simple ini-style format as shown below. Available options consist of a small subset of the parameters available via the .BR mkfs.xfs (8) -command line. +command line. All configuration files must start with an annotation of +the configuration file format, specified in the global section with the keyword +.B version +and the only supported version format is 1. Currently all default parameters can only be either enabled or disabled, with a value of 1 to enable or 0 to disable. See below for a list of all supported configuration parameters and their current built-in default settings. .PP +.BI [global] +.br +.BI version=1 +.PP .BI [data] .br .BI noalign=0mkfs/config.c +91
-0@@ -32,6 +32,8 @@* We only provide definitions for what we currently support parsing. */ +static uint64_t mkfs_config_version; +enum data_subopts {D_NOALIGN =0 , };@@ -42,6 +44,14 @@ enum inode_subopts { I_SPINODES, }; +/* +* These are not part of the defaults but rather global generic configuration +* file options. +*/ +enum global_subopts { +G_VERSION =0 , +}; +enum log_subopts {L_LAZYSBCNTR =0 , };@@ -122,6 +132,24 @@ inode_config_parser(return -1 ; } +static int +global_config_parser ( +struct mkfs_default_params *dft, +int psubopt, +uint64_t value) +{ +enum global_subopts subopt = psubopt; + +switch (subopt) { +case G_VERSION : +if (value !=1 ) +return -1 ; + mkfs_config_version = value; +return 0 ; + } +return -1 ; +} + static int log_config_parser( struct mkfs_default_params *dft,@@ -234,6 +262,14 @@ struct confopts { }, .parser = inode_config_parser, }, + { + .name = "global", + .subopts = { + [G_VERSION ] ="version" , +NULL + }, + .parser = global_config_parser, + }, { .name ="log" , .subopts = {@@ -287,6 +323,24 @@ get_confopts(return NULL ; } +static bool config_version_set (void ) +{ +/* cannot fail */ +struct confopts *opts =get_confopts ("global" ); + +return opts->seen; +} + +static uint64_t config_version (void ) +{ +/* cannot fail */ +struct confopts *opts =get_confopts ("global" ); + +if (!opts->seen) +return 0 ; +return mkfs_config_version; +} +enum parse_line_type {PARSE_COMMENT =0 ,PARSE_EMPTY ,@@ -379,6 +433,32 @@ parse_get_line_type(return PARSE_INVALID ; } +static bool +check_version_supported ( +void ) +{ +uint64_t version =config_version (); + +if (!version) { +fprintf (stderr, +_ ("Version for configuration file not specified\n" )); + goto out; + } + +if (version !=1 ) { + errno =EOPNOTSUPP ; +fprintf (stderr, +_ ("Only version 1 supported, you specified version %lu\n" ), version); + goto out; + } + +return true; + +out: + errno =EOPNOTSUPP ; +return false; +} + static int parse_config_stream( struct mkfs_default_params *dft,@@ -420,6 +500,7 @@ parse_config_stream( config_file, lineno, line); goto out;case PARSE_SECTION : + confopt =get_confopts (tag);if (!confopt) { fprintf(stderr,@@ -451,6 +532,13 @@ _("No section specified yet on line %s:%zu : %s\n"), goto out_free_tag; } +if (!config_version_set () && +strcmp (confopt->name,"global" ) !=0 ) { +fprintf (stderr, +_ ("A global section with a version set was not detected and must be set first\n" )); + goto out_free_tag; + } +/* * We re-use the line buffer allocated by getline(), * however line must be kept pointing to its original @@ -486,6 +574,9 @@ _("Error parsing line %s:%zu : %s\n"), goto out; } +if (!check_version_supported ()) + goto out; +break ; }free (line);
Quoted 5 lines · Eric Sandeen
Soo....
I'm really on the fence about versioning at all, because we have yet to identify any concrete scenario in which we'd need to bump the version; we haven't even defined what exactly the "version" implies.
Right.
Quoted 2 lines
So unless anyone has a concrete example of how a version would be needed, functional, reliably-parsed, and well-defined I'm inclined to leave this out.
Dave asked for it, so I would imagine he could make a better case for it.
But from a generic file format point of view, a version typically does make sense for a slew of reasons, but it is typically the not known, the unexpected, for which it can be a life saver.
Things that I can mention other than what you mentioned (whether or not they are good, this is just a list of crazy things):
1) We move from using our own parser to e2fsprogs profile parser (recall that my studies revealed it was the smallest) or lib_iniconfig (more robust, and widely used, however a kitchen sink compared to e2fsprogs profile parser)
Both however support the INI format we are using.
The version however may help to make the old parser not barf if say we added some magic in the future which would make the old parser barf.
2) Data type change for an existing token. Say crc=2 was invented (again just an example), it would barf on the old parser, but with the version check it would immediately tell you a more meaningful message.
Perhaps the biggest advantage I can think of then then is a better error message for a set of supported features, starting with what we have today reflected as parsed as version 1. This does differ from what we do with the CLI, however as with the respecification simplifcation done on config.c in contrast to the CLI respecification checks, I would see this as a win for users, and yet keeps things simple.
If this seems acceptable and reasonable, then version would be a reflection of supporting the format and layout of the file, as well was indicative of supporting only a specific feature set.
Thoughts?
Luis
Quoted 7 lines · Luis R. Rodriguez
Quoted 5 lines · Eric Sandeen
Soo....
I'm really on the fence about versioning at all, because we have yet to identify any concrete scenario in which we'd need to bump the version; we haven't even defined what exactly the "version" implies.
Quoted 6 lines
Right.
Quoted 2 lines
So unless anyone has a concrete example of how a version would be needed, functional, reliably-parsed, and well-defined I'm inclined to leave this out.
Dave asked for it, so I would imagine he could make a better case for it.
Yup; well, I spoke with Dave and he was kind of leaving it as an exercise for the reader, an exercise in which we are now engaged. :)
Quoted 12 lines
But from a generic file format point of view, a version typically does make sense for a slew of reasons, but it is typically the not known, the unexpected, for which it can be a life saver.
Things that I can mention other than what you mentioned (whether or not they are good, this is just a list of crazy things):
1) We move from using our own parser to e2fsprogs profile parser (recall that my studies revealed it was the smallest) or
lib_iniconfig(more robust, and widely used, however a kitchen sink compared to e2fsprogs profile parser)
Quoted 5 lines
Both however support the INI format we are using.
The version however may help to make the old parser not barf if say we added some magic in the future which would make the old parser barf.
... if the file format does not change, a parser change doesn't matter, and a version change would be pointless.
Quoted 4 lines
2) Data type change for an existing token. Say crc=2 was invented (again just an example), it would barf on the old parser, but with the version check it would immediately tell you a more meaningful message.
But how is that any different from what it would do on the command line for a similar change?
"Invalid value 2 for token crc=2 on line XYZ" is completely reasonable, and does not require any version information.
In fact, what you are suggesting here means we'd bump the version if and only if the config file contained "crc=2" which makes little sense.
Quoted 6 lines
Perhaps the biggest advantage I can think of then then is a better error message for a set of supported features, starting with what we have today reflected as parsed as version 1. This does differ from what we do with the CLI, however as with the respecification simplifcation done on
config.cin contrast to the CLI respecification checks, I would see this as a win for users, and yet keeps things simple.
See my earlier email for why versioning cannot depend on the presence or absence of any parseable tokens ... stating "token XYZ not supported" should suffice IMHO.
(now, it's true that today we don't distinguish between unknown vs. unsupported tokens, I don't know if I should try to fix that before 4.17 or not; again, though, that is on the parser side, not the config file side.)
Quoted 3 lines
If this seems acceptable and reasonable, then version would be a reflection of supporting the format and layout of the file, as well was indicative of supporting only a specific feature set.
What is or is not a supported token is wholly a function of the mkfs/parser version, not the config file version, right?
So, not to be argumentative ... but I remain unconvinced of the need for config file versioning.
Thanks,
-Eric
Quoted 4 lines
Thoughts?
Luis
Quoted 13 lines · Eric Sandeen
Quoted 12 lines · Luis R. Rodriguez
But from a generic file format point of view, a version typically does make sense for a slew of reasons, but it is typically the not known, the unexpected, for which it can be a life saver.
Things that I can mention other than what you mentioned (whether or not they are good, this is just a list of crazy things):
1) We move from using our own parser to e2fsprogs profile parser (recall that my studies revealed it was the smallest) or
lib_iniconfig(more robust, and widely used, however a kitchen sink compared to e2fsprogs profile parser)
Quoted 8 lines
Quoted 5 lines
Both however support the INI format we are using.
The version however may help to make the old parser not barf if say we added some magic in the future which would make the old parser barf.
... if the file format does not change, a parser change doesn't matter, and a version change would be pointless.
It can. Consider support for different comment styles.
Quoted 7 lines
Quoted 4 lines
2) Data type change for an existing token. Say crc=2 was invented (again just an example), it would barf on the old parser, but with the version check it would immediately tell you a more meaningful message.
But how is that any different from what it would do on the command line for a similar change?
So long as we remain forward compatible its a non-issue. If we say decide to make a unit not compatible with old values then surely that's a format change which would break old configs.
We should keep the config file parser ompatible with old config files produced. That means anything and everything we allow today should keep working in the future, and one way to sanely break that compatibility would be a version bump.
Quoted 5 lines
"Invalid value 2 for token crc=2 on line XYZ" is completely reasonable, and does not require any version information.
In fact, what you are suggesting here means we'd bump the version if and only if the config file contained "crc=2" which makes little sense.
For example, a config file in the future with format 2 with crc=2 would not work with and older xfsprog which only supports format version 1. Saying that your xfsprogs does not support version 2 is IMHO clearer what the issue may be.
Quoted 9 lines
Quoted 5 lines
message for a set of supported features, starting with what we have today reflected as parsed as version 1. This does differ from what we do with the CLI, however as with the respecification simplifcation done on
config.cin contrast to the CLI respecification checks, I would see this as a win for users, and yet keeps things simple.See my earlier email for why versioning cannot depend on the presence or absence of any parseable tokens ... stating "token XYZ not supported" should suffice IMHO.
It can. And ultimately its up to you to pick and choose.
Quoted 3 lines
(now, it's true that today we don't distinguish between unknown vs. unsupported tokens, I don't know if I should try to fix that before 4.17 or not; again, though,
I don't think its worth to say something is unsupported vs unknown given we don't know what options will be supported, as some config file entries are expected to differ from CLI.
Quoted 8 lines
that is on the parser side, not the config file side.)
Quoted 3 lines
If this seems acceptable and reasonable, then version would be a reflection of supporting the format and layout of the file, as well was indicative of supporting only a specific feature set.
What is or is not a supported token is wholly a function of the mkfs/parser version, not the config file version, right?
Yes.
Quoted 2 lines
So, not to be argumentative ... but I remain unconvinced of the need for config file versioning.
Your call :)
Luis
Quoted 16 lines · Luis R. Rodriguez
Quoted 15 lines · Eric Sandeen
Quoted 14 lines · Luis R. Rodriguez
But from a generic file format point of view, a version typically does make sense for a slew of reasons, but it is typically the not known, the unexpected, for which it can be a life saver.
Things that I can mention other than what you mentioned (whether or not they are good, this is just a list of crazy things):
1) We move from using our own parser to e2fsprogs profile parser (recall that my studies revealed it was the smallest) or
lib_iniconfig(more robust, and widely used, however a kitchen sink compared to e2fsprogs profile parser)Both however support the INI format we are using.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
The version however may help to make the old parser not barf if say we added some magic in the future which would make the old parser barf.
... if the file format does not change, a parser change doesn't matter, and a version change would be pointless.
It can. Consider support for different comment styles.
IMO comments are part of the format and if they change, then the format itself was changed too. So I find it difficult to see any practical use for a config version, but all arguments about it were already said. Still, if we end up with something like this, let's make the section to be optional.
If we ever happen to find ourselves in such situation and we need the version check as an emergency brake, then we can specify that the v2 format has to begin with version=2. The old parser will understand it and abort, but if it is not present, it is equal to version=1 and we will not pollute the configs in the meantime.
Cheers,
Jan
Quoted 7 lines · Luis R. Rodriguez
Quoted 5 lines · Eric Sandeen
Soo....
I'm really on the fence about versioning at all, because we have yet to identify any concrete scenario in which we'd need to bump the version; we haven't even defined what exactly the "version" implies.
Quoted 6 lines
Right.
Quoted 2 lines
So unless anyone has a concrete example of how a version would be needed, functional, reliably-parsed, and well-defined I'm inclined to leave this out.
Dave asked for it, so I would imagine he could make a better case for it.
I ask for things so that people think about the problem, not necessarily because I want something to be done. Please don't conflate "Dave says X" with "we must implement X" because I am often wrong and/or playing the Devil's Advocate role.
I try to look outside the box for potential issues, so if I see a potential issue I'll say /something/ just to get people to discuss that aspect of the problem and come up with a reasonable solution. I don't have the time to solve every problem we have, I don't /want/ to solve every problem, but I want to make sure we solve the problems we have in the right way the first time.
In reality, I don't care either way if we have a version symbol in the config file, and if it is decided that it is a good thing how it will be implemented. What I care about is that we've thought about supporting config files over their entire lifetime, not just considered what is needed in the near term to solve the immediate problem.
IOWs, my comments about treating a config file like any other long term persistent structure were intended to shift the focus of the discussion from implementation minutae to the bigger, long term picture details that needed to be thrashed out. Work out the big picture first, the small details will fall naturally from that...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]