]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
config: allow Array line to contain array name without /dev/md/ prefix.
authorNeilBrown <neilb@suse.de>
Mon, 11 May 2009 05:18:35 +0000 (15:18 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 11 May 2009 05:18:35 +0000 (15:18 +1000)
For consistency with --create and --assemble, allow the array name
given in mdadm.conf to exclude the "/dev/md/" prefix.  So e.g.

  ARRAY home uuid=whatever

is treated like

  ARRAY /dev/md/home uuid=whatever

Also exclude names which create_mddev will reject.

Signed-off-by: NeilBrown <neilb@suse.de>
Monitor.c
config.c
mdadm.conf.5

index 4b660e492cb596a77cc131fabd11cd30b6e74bdd..e43175f186d878acc6c0f5591ea1187f5bc8e0b9 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -173,7 +173,13 @@ int Monitor(mddev_dev_t devlist,
                        st = malloc(sizeof *st);
                        if (st == NULL)
                                continue;
-                       st->devname = strdup(mdlist->devname);
+                       if (mdlist->devname[0] == '/')
+                               st->devname = strdup(mdlist->devname);
+                       else {
+                               st->devname = malloc(8+strlen(mdlist->devname)+1);
+                               strcpy(strcpy(st->devname, "/dev/md/"),
+                                      mdlist->devname);
+                       }
                        st->utime = 0;
                        st->next = statelist;
                        st->err = 0;
index fd757ad009ddca3c52cb5f88d1c3960ee44182d7..41428ae9f21a625a35508461b08f059562eff846 100644 (file)
--- a/config.c
+++ b/config.c
@@ -448,6 +448,17 @@ void devline(char *line)
 mddev_ident_t mddevlist = NULL;
 mddev_ident_t *mddevlp = &mddevlist;
 
+static int is_number(char *w)
+{
+       /* check if there are 1 or more digits and nothing else */
+       int digits = 0;
+       while (*w && isdigit(*w)) {
+               digits++;
+               w++;
+       }
+       return (digits && ! *w);
+}
+
 void arrayline(char *line)
 {
        char *w;
@@ -473,11 +484,35 @@ void arrayline(char *line)
        mis.member = NULL;
 
        for (w=dl_next(line); w!=line; w=dl_next(w)) {
-               if (w[0] == '/' || strcasecmp(w, "<ignore>") == 0) {
-                       if (mis.devname)
-                               fprintf(stderr, Name ": only give one device per ARRAY line: %s and %s\n",
-                                       mis.devname, w);
-                       else mis.devname = w;
+               if (w[0] == '/' || strchr(w, '=') == NULL) {
+                       /* This names the device, or is '<ignore>'.
+                        * The rules match those in create_mddev.
+                        * 'w' must be:
+                        *  /dev/md/{anything}
+                        *  /dev/mdNN
+                        *  /dev/md_dNN
+                        *  <ignore>
+                        *  or anything that doesn't start '/' or '<'
+                        */
+                       if (strcasecmp(w, "<ignore>") == 0 ||
+                           strncmp(w, "/dev/md/", 8) == 0 ||
+                           (w[0] != '/' && w[0] != '<') ||
+                           (strncmp(w, "/dev/md", 7) == 0 && 
+                            is_number(w+7)) ||
+                           (strncmp(w, "/dev/md_d", 9) == 0 &&
+                            is_number(w+9))
+                               ) {
+                               /* This is acceptable */;
+                               if (mis.devname)
+                                       fprintf(stderr, Name ": only give one "
+                                               "device per ARRAY line: %s and %s\n",
+                                               mis.devname, w);
+                               else
+                                       mis.devname = w;
+                       }else {
+                               fprintf(stderr, Name ": %s is an invalid name for "
+                                       "an md device - ignored.\n", w);
+                       }
                } else if (strncasecmp(w, "uuid=", 5)==0 ) {
                        if (mis.uuid_set)
                                fprintf(stderr, Name ": only specify uuid once, %s ignored.\n",
index f69c0b0f700d4b42b51b75670682c95f61a57cd9..9876d279dc38af4f852494264c0e84a70b3b8d84 100644 (file)
@@ -95,14 +95,20 @@ DEVICE partitions
 The ARRAY lines identify actual arrays.  The second word on the line
 may be the name of the device where the array is normally
 assembled, such as
-.BR  /dev/md1 .
+.B /dev/md1
+or
+.BR /dev/md/backup .
+If the name does not start with a slash
+.RB (' / '),
+it is treated as being in
+.BR /dev/md/ .
 Alternately the word
 .B <ignore>
 (complete with angle brackets) can be given in which case any array
 which matches the rest of the line will never be automatically assembled.
 If no device name is given,
 .I mdadm
-will use various heuristic to determine an appropriate name.
+will use various heuristics to determine an appropriate name.
 .PP
 Subsequent words identify the array, or identify the array as a member
 of a group. If multiple identities are given,