summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2009-05-11 15:46:46 +1000
committerNeilBrown <neilb@suse.de>2009-05-11 15:46:46 +1000
commit0ac91628b93b31636979b637c1ac7258064dea4e (patch)
tree88971a9e037c1519a8db205e8d6d1338ddfe8131 /config.c
parent603f24a05f48063a7239e323e2aeab497cb0feb6 (diff)
Allow homehost to be largely ignored when assembling arrays.
If mdadm.conf contains HOMEHOST <ignore> or commandline contains --homehost=<ignore> then the check that array metadata mentions the given homehost is replace by a check that the name recorded in the metadata is not already used by some other array mentioned in mdadm.conf. This allows more arrays to use their native name rather than having an _NN suffix added. This should only be used during boot time if all arrays required for normal boot are listed in mdadm.conf. If auto-assembly is used to find all array during boot, then the HOMEHOST feature should be used to ensure there is no room for confusion in choosing array names, and so it should not be set to <ignore>. Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'config.c')
-rw-r--r--config.c64
1 files changed, 62 insertions, 2 deletions
diff --git a/config.c b/config.c
index 41428ae9..284896ed 100644
--- a/config.c
+++ b/config.c
@@ -663,12 +663,15 @@ void programline(char *line)
}
static char *home_host = NULL;
+static int require_homehost = 1;
void homehostline(char *line)
{
char *w;
for (w=dl_next(line); w != line ; w=dl_next(w)) {
- if (home_host == NULL)
+ if (strcasecmp(w, "<ignore>")==0)
+ require_homehost = 0;
+ else if (home_host == NULL)
home_host = strdup(w);
else
fprintf(stderr, Name ": excess host name on HOMEHOST line: %s - ignored\n",
@@ -788,9 +791,11 @@ char *conf_get_program(void)
return alert_program;
}
-char *conf_get_homehost(void)
+char *conf_get_homehost(int *require_homehostp)
{
load_conffile();
+ if (require_homehostp)
+ *require_homehostp = require_homehost;
return home_host;
}
@@ -953,3 +958,58 @@ int match_oneof(char *devices, char *devname)
}
return 0;
}
+
+int devname_matches(char *name, char *match)
+{
+ /* See if the given array name matches the
+ * given match from config file.
+ *
+ * First strip and /dev/md/ or /dev/, then
+ * see if there might be a numeric match of
+ * mdNN with NN
+ * then just strcmp
+ */
+ if (strncmp(name, "/dev/md/", 8) == 0)
+ name += 8;
+ else if (strncmp(name, "/dev/", 5) == 0)
+ name += 5;
+
+ if (strncmp(match, "/dev/md/", 8) == 0)
+ match += 8;
+ else if (strncmp(match, "/dev/", 5) == 0)
+ match += 5;
+
+
+ if (strncmp(name, "md", 2) == 0 &&
+ isdigit(name[2]))
+ name += 2;
+ if (strncmp(match, "md", 2) == 0 &&
+ isdigit(match[2]))
+ match += 2;
+
+ return (strcmp(name, match) == 0);
+}
+
+int conf_name_is_free(char *name)
+{
+ /* Check if this name is already take by an ARRAY entry in
+ * the config file.
+ * It can be taken either by a match on devname, name, or
+ * even super-minor.
+ */
+ mddev_ident_t dev;
+
+ load_conffile();
+ for (dev = mddevlist; dev; dev = dev->next) {
+ char nbuf[100];
+ if (dev->devname && devname_matches(name, dev->devname))
+ return 0;
+ if (dev->name[0] && devname_matches(name, dev->name))
+ return 0;
+ sprintf(nbuf, "%d", dev->super_minor);
+ if (dev->super_minor != UnSet &&
+ devname_matches(name, nbuf))
+ return 0;
+ }
+ return 1;
+}