]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - config.c
Discard devnum in favour of devnm
[thirdparty/mdadm.git] / config.c
index c79d38265c7a96c9d195f8b5bbe55d1e7937bbeb..0eb2c8d1c7f7275cb8ff0b275733be8bb568ffbe 100644 (file)
--- a/config.c
+++ b/config.c
@@ -149,8 +149,8 @@ void free_line(char *line)
 
 
 struct conf_dev {
-    struct conf_dev *next;
-    char *name;
+       struct conf_dev *next;
+       char *name;
 } *cdevlist = NULL;
 
 struct mddev_dev *load_partitions(void)
@@ -178,8 +178,8 @@ struct mddev_dev *load_partitions(void)
                name = map_dev(major, minor, 1);
                if (!name)
                        continue;
-               d = malloc(sizeof(*d));
-               d->devname = strdup(name);
+               d = xmalloc(sizeof(*d));
+               d->devname = xstrdup(name);
                d->next = rv;
                d->used = 0;
                rv = d;
@@ -202,9 +202,7 @@ struct mddev_dev *load_containers(void)
                if (ent->metadata_version &&
                    strncmp(ent->metadata_version, "external:", 9) == 0 &&
                    !is_subarray(&ent->metadata_version[9])) {
-                       d = malloc(sizeof(*d));
-                       if (!d)
-                               continue;
+                       d = xmalloc(sizeof(*d));
                        if (asprintf(&d->devname, "/dev/%s", ent->dev) < 0) {
                                free(d);
                                continue;
@@ -351,8 +349,8 @@ void devline(char *line)
        for (w=dl_next(line); w != line; w=dl_next(w)) {
                if (w[0] == '/' || strcasecmp(w, "partitions") == 0 ||
                    strcasecmp(w, "containers") == 0) {
-                       cd = malloc(sizeof(*cd));
-                       cd->name = strdup(w);
+                       cd = xmalloc(sizeof(*cd));
+                       cd->name = xstrdup(w);
                        cd->next = cdevlist;
                        cdevlist = cd;
                } else {
@@ -468,20 +466,20 @@ void arrayline(char *line)
                                pr_err("only specify bitmap file once. %s ignored\n",
                                        w);
                        else
-                               mis.bitmap_file = strdup(w+7);
+                               mis.bitmap_file = xstrdup(w+7);
 
                } else if (strncasecmp(w, "devices=", 8 ) == 0 ) {
                        if (mis.devices)
                                pr_err("only specify devices once (use a comma separated list). %s ignored\n",
                                        w);
                        else
-                               mis.devices = strdup(w+8);
+                               mis.devices = xstrdup(w+8);
                } else if (strncasecmp(w, "spare-group=", 12) == 0 ) {
                        if (mis.spare_group)
                                pr_err("only specify one spare group per array. %s ignored.\n",
                                        w);
                        else
-                               mis.spare_group = strdup(w+12);
+                               mis.spare_group = xstrdup(w+12);
                } else if (strncasecmp(w, "level=", 6) == 0 ) {
                        /* this is mainly for compatability with --brief output */
                        mis.level = map_name(pers, w+6);
@@ -508,11 +506,11 @@ void arrayline(char *line)
                        mis.autof = parse_auto(w+5, "auto type", 0);
                } else if (strncasecmp(w, "member=", 7) == 0) {
                        /* subarray within a container */
-                       mis.member = strdup(w+7);
+                       mis.member = xstrdup(w+7);
                } else if (strncasecmp(w, "container=", 10) == 0) {
                        /* the container holding this subarray.  Either a device name
                         * or a uuid */
-                       mis.container = strdup(w+10);
+                       mis.container = xstrdup(w+10);
                } else {
                        pr_err("unrecognised word on ARRAY line: %s\n",
                                w);
@@ -523,9 +521,9 @@ void arrayline(char *line)
            (mis.container == NULL || mis.member == NULL))
                pr_err("ARRAY line %s has no identity information.\n", mis.devname);
        else {
-               mi = malloc(sizeof(*mi));
+               mi = xmalloc(sizeof(*mi));
                *mi = mis;
-               mi->devname = mis.devname ? strdup(mis.devname) : NULL;
+               mi->devname = mis.devname ? xstrdup(mis.devname) : NULL;
                mi->next = NULL;
                *mddevlp = mi;
                mddevlp = &mi->next;
@@ -539,7 +537,7 @@ void mailline(char *line)
 
        for (w=dl_next(line); w != line ; w=dl_next(w)) {
                if (alert_email == NULL)
-                       alert_email = strdup(w);
+                       alert_email = xstrdup(w);
                else
                        pr_err("excess address on MAIL line: %s - ignored\n",
                                w);
@@ -553,7 +551,7 @@ void mailfromline(char *line)
 
        for (w=dl_next(line); w != line ; w=dl_next(w)) {
                if (alert_mail_from == NULL)
-                       alert_mail_from = strdup(w);
+                       alert_mail_from = xstrdup(w);
                else {
                        char *t = NULL;
 
@@ -573,7 +571,7 @@ void programline(char *line)
 
        for (w=dl_next(line); w != line ; w=dl_next(w)) {
                if (alert_program == NULL)
-                       alert_program = strdup(w);
+                       alert_program = xstrdup(w);
                else
                        pr_err("excess program on PROGRAM line: %s - ignored\n",
                                w);
@@ -591,9 +589,9 @@ void homehostline(char *line)
                        require_homehost = 0;
                else if (home_host == NULL) {
                        if (strcasecmp(w, "<none>")==0)
-                               home_host = strdup("");
+                               home_host = xstrdup("");
                        else
-                               home_host = strdup(w);
+                               home_host = xstrdup(w);
                }else
                        pr_err("excess host name on HOMEHOST line: %s - ignored\n",
                                w);
@@ -647,7 +645,7 @@ void autoline(char *line)
 
        for (super_cnt = 0; superlist[super_cnt]; super_cnt++)
                ;
-       seen = calloc(super_cnt, 1);
+       seen = xcalloc(super_cnt, 1);
 
        for (w = dl_next(line); w != line ; w = dl_next(w)) {
                char *val;
@@ -885,8 +883,8 @@ struct mddev_dev *conf_get_devs()
        }
        if (flags & GLOB_APPEND) {
                for (i=0; i<globbuf.gl_pathc; i++) {
-                       struct mddev_dev *t = malloc(sizeof(*t));
-                       t->devname = strdup(globbuf.gl_pathv[i]);
+                       struct mddev_dev *t = xmalloc(sizeof(*t));
+                       t->devname = xstrdup(globbuf.gl_pathv[i]);
                        t->next = dlist;
                        t->used = 0;
                        dlist = t;
@@ -942,26 +940,26 @@ int conf_test_metadata(const char *version, struct dev_policy *pol, int is_homeh
 
 int match_oneof(char *devices, char *devname)
 {
-    /* check if one of the comma separated patterns in devices
-     * matches devname
-     */
-
-    while (devices && *devices) {
-       char patn[1024];
-       char *p = devices;
-       devices = strchr(devices, ',');
-       if (!devices)
-           devices = p + strlen(p);
-       if (devices-p < 1024) {
-               strncpy(patn, p, devices-p);
-               patn[devices-p] = 0;
-               if (fnmatch(patn, devname, FNM_PATHNAME)==0)
-                       return 1;
+       /* check if one of the comma separated patterns in devices
+        * matches devname
+        */
+
+       while (devices && *devices) {
+               char patn[1024];
+               char *p = devices;
+               devices = strchr(devices, ',');
+               if (!devices)
+                       devices = p + strlen(p);
+               if (devices-p < 1024) {
+                       strncpy(patn, p, devices-p);
+                       patn[devices-p] = 0;
+                       if (fnmatch(patn, devname, FNM_PATHNAME)==0)
+                               return 1;
+               }
+               if (*devices == ',')
+                       devices++;
        }
-       if (*devices == ',')
-               devices++;
-    }
-    return 0;
+       return 0;
 }
 
 int devname_matches(char *name, char *match)
@@ -997,7 +995,7 @@ int devname_matches(char *name, char *match)
 
 int conf_name_is_free(char *name)
 {
-       /* Check if this name is already take by an ARRAY entry in
+       /* Check if this name is already taken by an ARRAY entry in
         * the config file.
         * It can be taken either by a match on devname, name, or
         * even super-minor.
@@ -1097,6 +1095,8 @@ int conf_verify_devnames(struct mddev_ident *array_list)
        for (a1 = array_list; a1; a1 = a1->next) {
                if (!a1->devname)
                        continue;
+               if (strcmp(a1->devname, "<ignore>") == 0)
+                       continue;
                for (a2 = a1->next; a2; a2 = a2->next) {
                        if (!a2->devname)
                                continue;