[PATCH] mkfs: add mkfs_config_version specifier for the config file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 use
mkfs_config_version as special token as other sections may use
'version' already, such is the case for log.

Suggested-by: Dave Chinner <david@xxxxxxxxxxxxx>
Signed-off-by: Luis R. Rodriguez <mcgrof@xxxxxxxxxx>
---
 man/man8/mkfs.xfs.8.in |  7 ++++++-
 mkfs/config.c          | 55 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/man/man8/mkfs.xfs.8.in b/man/man8/mkfs.xfs.8.in
index cf4bdf827d9c..71573daec718 100644
--- a/man/man8/mkfs.xfs.8.in
+++ b/man/man8/mkfs.xfs.8.in
@@ -965,12 +965,17 @@ 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 with the keyword
+.B mkfs_config_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 mkfs_config_version=1
+.br
 .BI [data]
 .br
 .BI noalign=0
diff --git a/mkfs/config.c b/mkfs/config.c
index 835adc45f02d..072ac16ab796 100644
--- a/mkfs/config.c
+++ b/mkfs/config.c
@@ -379,6 +379,31 @@ parse_get_line_type(
 	return PARSE_INVALID;
 }
 
+static bool
+check_version_supported(
+		uint64_t		version,
+		bool			version_set)
+{
+	if (!version_set) {
+		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,
@@ -389,7 +414,8 @@ parse_config_stream(
 	char				*line = NULL;
 	ssize_t				linelen;
 	size_t				len = 0, lineno = 0;
-	uint64_t			value;
+	uint64_t			value, version = 0;
+	bool				version_set = false;
 	enum parse_line_type		parse_type;
 	struct confopts			*confopt = NULL;
 	int				subopt;
@@ -400,6 +426,7 @@ parse_config_stream(
 		char	*p;
 
 		lineno++;
+		value = 0;
 
 		/*
 		 * tag is allocated for us by scanf(), it must freed only on
@@ -420,6 +447,9 @@ parse_config_stream(
 					  config_file, lineno, line);
 			goto out;
 		case PARSE_SECTION:
+			if (!check_version_supported(version, version_set))
+				goto out_free_tag;
+
 			confopt = get_confopts(tag);
 			if (!confopt) {
 				fprintf(stderr,
@@ -445,12 +475,35 @@ _("Section '%s' respecified\n"),
 			break;
 		case PARSE_TAG_VALUE:
 			if (!confopt) {
+				if (strcmp("mkfs_config_version", tag) == 0) {
+					if (!version_set) {
+						free(tag);
+						version = value;
+						version_set = true;
+					} else {
+						fprintf(stderr,
+_("Version respecified on line %s:%zu : %s\n"),
+							config_file, lineno,
+							line);
+						goto out_free_tag;
+					}
+
+					break;
+				}
+
+				if (!check_version_supported(version,
+							     version_set))
+					goto out_free_tag;
+
 				fprintf(stderr,
 _("No section specified yet on line %s:%zu : %s\n"),
 					config_file, lineno, line);
 				goto out_free_tag;
 			}
 
+			if (!check_version_supported(version, version_set))
+				goto out_free_tag;
+
 			/*
 			 * We re-use the line buffer allocated by getline(),
 			 * however line must be kept pointing to its original
-- 
2.16.3

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux