From 2dfb675b94852f4a1a4ec24528292dd0e8f96c89 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 3 Sep 2013 13:25:02 +1000 Subject: [PATCH] config: support MDADM_CONF_AUTO= env var. If a distribution allows the choice between using mdadm and dmraid for DDF and IMSM to be made by some config file (/etc/defaults/ /sys/sysconfig/ etc) which is queried by /etc/init.d scripts, then the fact that mdadm implements this choce through the config file is not very helpful. So allow the "AUTO" line to be specified in part using MDADM_CONF_AUTO in environment. Signed-off-by: NeilBrown --- config.c | 27 +++++++++++++++++++++++++++ mdadm.8.in | 22 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/config.c b/config.c index edadf02a..f1a70c59 100644 --- a/config.c +++ b/config.c @@ -602,6 +602,24 @@ void autoline(char *line) * been seen gets an appropriate auto= entry. */ + /* If environment variable MDADM_CONF_AUTO is defined, then + * it is prepended to the auto line. This allow a script + * to easily disable some metadata types. + */ + w = getenv("MDADM_CONF_AUTO"); + if (w && *w) { + char *l = xstrdup(w); + char *head = line; + w = strtok(l, " \t"); + while (w) { + char *nw = dl_strdup(w); + dl_insert(head, nw); + head = nw; + w = strtok(NULL, " \t"); + } + free(l); + } + for (super_cnt = 0; superlist[super_cnt]; super_cnt++) ; seen = xcalloc(super_cnt, 1); @@ -783,6 +801,7 @@ void load_conffile(void) { FILE *f; char *confdir = NULL; + char *head; if (loaded) return; @@ -824,6 +843,14 @@ void load_conffile(void) } } } + /* If there was no AUTO line, process an empty line + * now so that the MDADM_CONF_AUTO env var gets processed. + */ + head = dl_strdup("AUTO"); + dl_init(head); + autoline(head); + free_line(head); + loaded = 1; } diff --git a/mdadm.8.in b/mdadm.8.in index fbb37c63..ef05233c 100644 --- a/mdadm.8.in +++ b/mdadm.8.in @@ -2838,6 +2838,28 @@ These checks can be suppressed by setting IMSM_NO_PLATFORM=1 in the environment. This can be useful for testing or for disaster recovery. You should be aware that interoperability may be compromised by setting this value. + +.TP +.B MDADM_CONF_AUTO +Any string given in this variable is added to the start of the +.B AUTO +line in the config file, or treated as the whole +.B AUTO +line if none is given. It can be used to disable certain metadata +types when +.I mdadm +is called from a boot script. For example +.br +.B " export MDADM_CONF_AUTO='-ddf -imsm' +.br +will make sure that +.I mdadm +does not automatically assemble any DDF or +IMSM arrays that are found. This can be useful on systems configured +to manage such arrays with +.BR dmraid . + + .SH EXAMPLES .B " mdadm \-\-query /dev/name-of-device" -- 2.39.2