]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - config.c
Remove lots of unnecessary white space.
[thirdparty/mdadm.git] / config.c
index c79d38265c7a96c9d195f8b5bbe55d1e7937bbeb..16517e1efd127da63f25d2b37329b60c902a2678 100644 (file)
--- a/config.c
+++ b/config.c
@@ -147,10 +147,9 @@ void free_line(char *line)
        dl_free(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,10 +177,10 @@ 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));
+               memset(d, 0, sizeof(*d));
+               d->devname = xstrdup(name);
                d->next = rv;
-               d->used = 0;
                rv = d;
        }
        fclose(f);
@@ -202,15 +201,13 @@ 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));
+                       memset(d, 0, sizeof(*d));
                        if (asprintf(&d->devname, "/dev/%s", ent->dev) < 0) {
                                free(d);
                                continue;
                        }
                        d->next = rv;
-                       d->used = 0;
                        rv = d;
                }
        free_mdstat(mdstat);
@@ -221,6 +218,7 @@ struct mddev_dev *load_containers(void)
 struct createinfo createinfo = {
        .autof = 2, /* by default, create devices with standard names */
        .symlinks = 1,
+       .names = 0, /* By default, stick with numbered md devices. */
 #ifdef DEBIAN
        .gid = 6, /* disk */
        .mode = 0660,
@@ -336,6 +334,10 @@ static void createline(char *line)
                        createinfo.symlinks = 1;
                else if  (strncasecmp(w, "symlinks=no", 11) == 0)
                        createinfo.symlinks = 0;
+               else if (strncasecmp(w, "names=yes", 12) == 0)
+                       createinfo.names = 1;
+               else if  (strncasecmp(w, "names=no", 11) == 0)
+                       createinfo.names = 0;
                else {
                        pr_err("unrecognised word on CREATE line: %s\n",
                                w);
@@ -351,8 +353,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 {
@@ -414,7 +416,7 @@ void arrayline(char *line)
                        if (strcasecmp(w, "<ignore>") == 0 ||
                            strncmp(w, "/dev/md/", 8) == 0 ||
                            (w[0] != '/' && w[0] != '<') ||
-                           (strncmp(w, "/dev/md", 7) == 0 && 
+                           (strncmp(w, "/dev/md", 7) == 0 &&
                             is_number(w+7)) ||
                            (strncmp(w, "/dev/md_d", 9) == 0 &&
                             is_number(w+9))
@@ -468,20 +470,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 +510,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 +525,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 +541,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 +555,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;
 
@@ -565,7 +567,6 @@ void mailfromline(char *line)
        }
 }
 
-
 static char *alert_program = NULL;
 void programline(char *line)
 {
@@ -573,7 +574,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 +592,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 +648,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,10 +886,10 @@ 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));
+                       memset(t, 0, sizeof(*t));
+                       t->devname = xstrdup(globbuf.gl_pathv[i]);
                        t->next = dlist;
-                       t->used = 0;
                        dlist = t;
 /*     printf("one dev is %s\n", t->devname);*/
                }
@@ -942,26 +943,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)
@@ -984,7 +985,6 @@ int devname_matches(char *name, char *match)
        else if (strncmp(match, "/dev/", 5) == 0)
                match += 5;
 
-
        if (strncmp(name, "md", 2) == 0 &&
            isdigit(name[2]))
                name += 2;
@@ -997,7 +997,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 +1097,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;