summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2009-05-11 15:17:33 +1000
committerNeilBrown <neilb@suse.de>2009-05-11 15:17:33 +1000
commit31015d5798c214ff416ff6ef6e10351944661362 (patch)
tree12cf88aac12757c0ae282b8613cc10be8f86de19 /config.c
parent112cace627b02a7bc918e857cce03b2cc5fc3d52 (diff)
conf/assemble: new config line "auto".
The line 'auto' in mdadm.conf can be used to disable assembly of specific metadata types, or of all arrays. This does not affect assembly of arrays listed in mdadm.conf or on command line. auto -all will disable all auto-assembly. auto -ddf will cause mdadm to ignore ddf arrays that are not explicitly mentioned, and auto assemble anything else it finds. Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'config.c')
-rw-r--r--config.c65
1 files changed, 63 insertions, 2 deletions
diff --git a/config.c b/config.c
index 66c3964f..0d5b3f9a 100644
--- a/config.c
+++ b/config.c
@@ -56,7 +56,7 @@
* with a key word, and not be indented, or must start with a
* non-key-word and must be indented.
*
- * Keywords are DEVICE and ARRAY
+ * Keywords are DEVICE and ARRAY ... and several others.
* DEV{ICE} introduces some devices that might contain raid components.
* e.g.
* DEV style=0 /dev/sda* /dev/hd*
@@ -79,7 +79,8 @@
char DefaultConfFile[] = CONFFILE;
char DefaultAltConfFile[] = CONFFILE2;
-enum linetype { Devices, Array, Mailaddr, Mailfrom, Program, CreateDev, Homehost, LTEnd };
+enum linetype { Devices, Array, Mailaddr, Mailfrom, Program, CreateDev,
+ Homehost, AutoMode, LTEnd };
char *keywords[] = {
[Devices] = "devices",
[Array] = "array",
@@ -88,6 +89,7 @@ char *keywords[] = {
[Program] = "program",
[CreateDev]= "create",
[Homehost] = "homehost",
+ [AutoMode] = "auto",
[LTEnd] = NULL
};
@@ -639,6 +641,16 @@ void homehostline(char *line)
}
}
+static char *auto_options = NULL;
+void autoline(char *line)
+{
+ if (auto_options) {
+ fprintf(stderr, Name ": AUTO line may only be give once."
+ " Subsequent lines ignored\n");
+ return;
+ }
+ auto_options = line;
+}
int loaded = 0;
@@ -709,6 +721,9 @@ void load_conffile(void)
case Homehost:
homehostline(line);
break;
+ case AutoMode:
+ autoline(line);
+ break;
default:
fprintf(stderr, Name ": Unknown keyword %s\n", line);
}
@@ -832,6 +847,52 @@ int conf_test_dev(char *devname)
return 0;
}
+int conf_test_metadata(const char *version)
+{
+ /* Check if the given metadata version is allowed
+ * to be auto-assembled.
+ * The default is 'yes' but the 'auto' line might over-ride that.
+ * Word in auto_options are processed in order with the first
+ * match winning.
+ * word can be:
+ * +version - that version can be assembled
+ * -version - that version cannot be auto-assembled
+ * yes or +all - any other version can be assembled
+ * no or -all - no other version can be assembled.
+ */
+ char *w;
+ load_conffile();
+ if (!auto_options)
+ return 1;
+ for (w = dl_next(auto_options); w != auto_options; w = dl_next(w)) {
+ int rv;
+ if (strcasecmp(w, "yes") == 0)
+ return 1;
+ if (strcasecmp(w, "no") == 0)
+ return 0;
+ if (w[0] == '+')
+ rv = 1;
+ else if (w[0] == '-')
+ rv = 0;
+ else continue;
+
+ if (strcasecmp(w+1, "all") == 0)
+ return rv;
+ if (strcasecmp(w+1, version) == 0)
+ return rv;
+ /* allow '0' to match version '0.90'
+ * and 1 or 1.whatever to match version '1.x'
+ */
+ if (version[1] == '.' &&
+ strlen(w+1) == 1 &&
+ w[1] == version[0])
+ return rv;
+ if (version[1] == '.' && version[2] == 'x' &&
+ strncmp(w+1, version, 2) == 0)
+ return rv;
+ }
+ return 1;
+}
int match_oneof(char *devices, char *devname)
{