]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
config: read /etc/mdadm.conf.d as well as /etc/mdadm.conf
authorNeilBrown <neilb@suse.de>
Mon, 2 Sep 2013 23:29:52 +0000 (09:29 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 2 Sep 2013 23:29:52 +0000 (09:29 +1000)
If a configfile is explicitly given, just that file or directory
is read. Otherwise we now read both a file
  /etc/mdadm.conf
and a directory
  /etc/mdadm.conf.d

This allows a transition to directory based config, which in turn
allows easy control from scripts.

Signed-off-by: NeilBrown <neilb@suse.de>
config.c
mdadm.8.in

index c15102c7b33dee3db8a7c83798c53396870a249d..38ed8a2b5c3ffa534f2ea5a65a94db32f64a5b12 100644 (file)
--- a/config.c
+++ b/config.c
@@ -72,7 +72,9 @@
 #define CONFFILE2 "/etc/mdadm/mdadm.conf"
 #endif
 char DefaultConfFile[] = CONFFILE;
+char DefaultConfDir[] = CONFFILE ".d";
 char DefaultAltConfFile[] = CONFFILE2;
+char DefaultAltConfDir[] = CONFFILE2 ".d";
 
 enum linetype { Devices, Array, Mailaddr, Mailfrom, Program, CreateDev,
                Homehost, AutoMode, Policy, PartPolicy, LTEnd };
@@ -792,10 +794,13 @@ void conf_file_or_dir(FILE *f)
 void load_conffile(void)
 {
        FILE *f;
+       char *confdir = NULL;
 
        if (loaded) return;
-       if (conffile == NULL)
+       if (conffile == NULL) {
                conffile = DefaultConfFile;
+               confdir = DefaultConfDir;
+       }
 
        if (strcmp(conffile, "none") == 0) {
                loaded = 1;
@@ -819,18 +824,24 @@ void load_conffile(void)
        if (f == NULL &&
            conffile == DefaultConfFile) {
                f = fopen(DefaultAltConfFile, "r");
-               if (f)
+               if (f) {
                        conffile = DefaultAltConfFile;
+                       confdir = DefaultAltConfDir;
+               }
+       }
+       if (f) {
+               loaded = 1;
+               conf_file_or_dir(f);
+               fclose(f);
+       }
+       if (confdir) {
+               f = fopen(confdir, "r");
+               if (f) {
+                       loaded = 1;
+                       conf_file_or_dir(f);
+                       fclose(f);
+               }
        }
-       if (f == NULL)
-               return;
-
-       loaded = 1;
-       conf_file_or_dir(f);
-
-       fclose(f);
-
-/*    printf("got file\n"); */
 }
 
 char *conf_get_mailaddr(void)
index 089639e850b0faa1f560468df5f2e0c7a004eda6..fbb37c63e12bf25fce3b579e324bb67b74824176 100644 (file)
@@ -263,16 +263,22 @@ the exact meaning of this option in different contexts.
 
 .TP
 .BR \-c ", " \-\-config=
-Specify the config file.  Default is to use
-.BR /etc/mdadm.conf ,
-or if that is missing then
-.BR /etc/mdadm/mdadm.conf .
+Specify the config file or directory.  Default is to use
+.B /etc/mdadm.conf
+and
+.BR /etc/mdadm.conf.d ,
+or if those are missing then
+.B /etc/mdadm/mdadm.conf
+and
+.BR /etc/mdadm/mdadm.conf.d .
 If the config file given is
 .B "partitions"
 then nothing will be read, but
 .I mdadm
 will act as though the config file contained exactly
-.B "DEVICE partitions containers"
+.br
+.B "    DEVICE partitions containers"
+.br
 and will read
 .B /proc/partitions
 to find a list of devices to scan, and
@@ -284,6 +290,13 @@ is given for the config file, then
 .I mdadm
 will act as though the config file were empty.
 
+If the name given is of a directory, then
+.I mdadm
+will collect all the files contained in the directory with a name ending
+in
+.BR .conf ,
+sort them lexically, and process all of those files as config files.
+
 .TP
 .BR \-s ", " \-\-scan
 Scan config file or
@@ -2976,6 +2989,11 @@ they contain MD super block, and gives identifying information
 .BR mdadm.conf (5)
 for more details.
 
+.SS /etc/mdadm.conf.d
+
+A directory containing configuration files which are read in lexical
+order.
+
 .SS {MAP_PATH}
 When
 .B \-\-incremental