Minimal support for policy lines in config file. From: NeilBrown Just enough to allow re-add to be requested as a default. Signed-off-by: NeilBrown --- config.c | 30 +++++++++++++++++++++++++++++- mdadm.conf.5 | 21 +++++++++++++++++++++ mdadm.h | 1 + 3 files changed, 51 insertions(+), 1 deletions(-) diff --git a/config.c b/config.c index c962afd..ca863bd 100644 --- a/config.c +++ b/config.c @@ -75,7 +75,7 @@ char DefaultConfFile[] = CONFFILE; char DefaultAltConfFile[] = CONFFILE2; enum linetype { Devices, Array, Mailaddr, Mailfrom, Program, CreateDev, - Homehost, AutoMode, LTEnd }; + Homehost, AutoMode, Policy, LTEnd }; char *keywords[] = { [Devices] = "devices", [Array] = "array", @@ -85,6 +85,7 @@ char *keywords[] = { [CreateDev]= "create", [Homehost] = "homehost", [AutoMode] = "auto", + [Policy] = "policy", [LTEnd] = NULL }; @@ -685,6 +686,24 @@ void autoline(char *line) auto_options = line; } +static int auto_re_add = 0; +void policyline(char *line) +{ + /* This is a very minimal implementation of + * 'policy' that just allows 'action=re-add' to be + * specified. It applies to all devices. + */ + char *w; + + for (w = dl_next(line); w != line ; w = dl_next(w)) { + if (strcasecmp(w, "action=re-add") == 0) + auto_re_add = 1; + else + fprintf(stderr, Name ": unknown policy command '%s' ignored.\n", + w); + } +} + int loaded = 0; static char *conffile = NULL; @@ -757,6 +776,9 @@ void load_conffile(void) case AutoMode: autoline(line); break; + case Policy: + policyline(line); + break; default: fprintf(stderr, Name ": Unknown keyword %s\n", line); } @@ -800,6 +822,12 @@ struct createinfo *conf_get_create_info(void) return &createinfo; } +int conf_get_readd(void) +{ + load_conffile(); + return auto_re_add; +} + mddev_ident_t conf_get_ident(char *dev) { mddev_ident_t rv; diff --git a/mdadm.conf.5 b/mdadm.conf.5 index 002e2b3..481cf02 100644 --- a/mdadm.conf.5 +++ b/mdadm.conf.5 @@ -404,6 +404,27 @@ The known metadata types are .BR ddf , .BR imsm . +.TP +.B POLICY +A list of policy statements to guide some the actions that +.I mdadm +takes automatically. +Currently only one policy statement is recongised and, when +given, it applies to all devices and all arrays. That statement is +.BR action=re-add . +This policy affects the assembling of arrays (either by +.B -A +or +.BR -I ) +and particularly the handling of devices which appear to have +previously failed. The default action is to not include these devices +in the array. However if this policy is in force, then any devices +which were previously members of the array but have since failed are +re-added (as if by the +-B \-\-re\-add +command) so that they return to fully active status after any +necessary rebuilding. + .SH EXAMPLE DEVICE /dev/sd[bcdjkl]1 .br diff --git a/mdadm.h b/mdadm.h index fe20337..ac6494d 100644 --- a/mdadm.h +++ b/mdadm.h @@ -805,6 +805,7 @@ extern char *conf_get_mailaddr(void); extern char *conf_get_mailfrom(void); extern char *conf_get_program(void); extern char *conf_get_homehost(int *require_homehostp); +extern int conf_get_readd(void); extern char *conf_line(FILE *file); extern char *conf_word(FILE *file, int allow_key); extern int conf_name_is_free(char *name);