]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - config.c
{platform,super}-intel: Fix two resource leaks
[thirdparty/mdadm.git] / config.c
index f1a70c59f971575212a2c4d1937f6c586316b6f1..b308b6cc5bac58fb42cbde97f35d83595be4b9d2 100644 (file)
--- a/config.c
+++ b/config.c
@@ -63,6 +63,9 @@
  * but may not wrap over lines
  *
  */
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 200809L
+#endif
 
 #ifndef CONFFILE
 #define CONFFILE "/etc/mdadm.conf"
@@ -77,7 +80,7 @@ char DefaultAltConfFile[] = CONFFILE2;
 char DefaultAltConfDir[] = CONFFILE2 ".d";
 
 enum linetype { Devices, Array, Mailaddr, Mailfrom, Program, CreateDev,
-               Homehost, AutoMode, Policy, PartPolicy, LTEnd };
+               Homehost, HomeCluster, AutoMode, Policy, PartPolicy, LTEnd };
 char *keywords[] = {
        [Devices]  = "devices",
        [Array]    = "array",
@@ -86,6 +89,7 @@ char *keywords[] = {
        [Program]  = "program",
        [CreateDev]= "create",
        [Homehost] = "homehost",
+       [HomeCluster] = "homecluster",
        [AutoMode] = "auto",
        [Policy]   = "policy",
        [PartPolicy]="part-policy",
@@ -167,10 +171,10 @@ struct mddev_dev *load_containers(void)
                    !is_subarray(&ent->metadata_version[9])) {
                        d = xmalloc(sizeof(*d));
                        memset(d, 0, sizeof(*d));
-                       me = map_by_devnm(&map, ent->dev);
+                       me = map_by_devnm(&map, ent->devnm);
                        if (me)
                                d->devname = xstrdup(me->path);
-                       else if (asprintf(&d->devname, "/dev/%s", ent->dev) < 0) {
+                       else if (asprintf(&d->devname, "/dev/%s", ent->devnm) < 0) {
                                free(d);
                                continue;
                        }
@@ -187,6 +191,7 @@ struct createinfo createinfo = {
        .autof = 2, /* by default, create devices with standard names */
        .symlinks = 1,
        .names = 0, /* By default, stick with numbered md devices. */
+       .bblist = 1, /* Use a bad block list by default */
 #ifdef DEBIAN
        .gid = 6, /* disk */
        .mode = 0660,
@@ -306,6 +311,10 @@ static void createline(char *line)
                        createinfo.names = 1;
                else if  (strncasecmp(w, "names=no", 11) == 0)
                        createinfo.names = 0;
+               else if  (strncasecmp(w, "bbl=no", 11) == 0)
+                       createinfo.bblist = 0;
+               else if  (strncasecmp(w, "bbl=yes", 11) == 0)
+                       createinfo.bblist = 1;
                else {
                        pr_err("unrecognised word on CREATE line: %s\n",
                                w);
@@ -391,14 +400,12 @@ void arrayline(char *line)
                                ) {
                                /* This is acceptable */;
                                if (mis.devname)
-                                       pr_err("only give one "
-                                               "device per ARRAY line: %s and %s\n",
+                                       pr_err("only give one device per ARRAY line: %s and %s\n",
                                                mis.devname, w);
                                else
                                        mis.devname = w;
                        }else {
-                               pr_err("%s is an invalid name for "
-                                       "an md device - ignored.\n", w);
+                               pr_err("%s is an invalid name for an md device - ignored.\n", w);
                        }
                } else if (strncasecmp(w, "uuid=", 5)==0 ) {
                        if (mis.uuid_set)
@@ -559,6 +566,21 @@ void homehostline(char *line)
        }
 }
 
+static char *home_cluster = NULL;
+void homeclusterline(char *line)
+{
+       char *w;
+
+       for (w=dl_next(line); w != line ; w=dl_next(w)) {
+               if (home_cluster == NULL) {
+                       if (strcasecmp(w, "<none>")==0)
+                               home_cluster = xstrdup("");
+                       else
+                               home_cluster = xstrdup(w);
+               }
+       }
+}
+
 char auto_yes[] = "yes";
 char auto_no[] = "no";
 char auto_homehost[] = "homehost";
@@ -575,6 +597,7 @@ void autoline(char *line)
 
        if (auto_seen)
                return;
+       auto_seen = 1;
 
        /* Parse the 'auto' line creating policy statements for the 'auto' policy.
         *
@@ -720,6 +743,9 @@ void conf_file(FILE *f)
                case Homehost:
                        homehostline(line);
                        break;
+               case HomeCluster:
+                       homeclusterline(line);
+                       break;
                case AutoMode:
                        autoline(line);
                        break;
@@ -880,6 +906,12 @@ char *conf_get_homehost(int *require_homehostp)
        return home_host;
 }
 
+char *conf_get_homecluster(void)
+{
+       load_conffile();
+       return home_cluster;
+}
+
 struct createinfo *conf_get_create_info(void)
 {
        load_conffile();
@@ -1115,8 +1147,7 @@ struct mddev_ident *conf_match(struct supertype *st,
                    !array_list->devices &&
                    array_list->super_minor == UnSet) {
                        if (verbose >= 2 && array_list->devname)
-                               pr_err("%s doesn't have any identifying"
-                                      " information.\n",
+                               pr_err("%s doesn't have any identifying information.\n",
                                       array_list->devname);
                        continue;
                }
@@ -1125,13 +1156,11 @@ struct mddev_ident *conf_match(struct supertype *st,
                if (match) {
                        if (verbose >= 0) {
                                if (match->devname && array_list->devname)
-                                       pr_err("we match both %s and %s - "
-                                              "cannot decide which to use.\n",
+                                       pr_err("we match both %s and %s - cannot decide which to use.\n",
                                               match->devname,
                                               array_list->devname);
                                else
-                                       pr_err("multiple lines in mdadm.conf"
-                                              " match\n");
+                                       pr_err("multiple lines in mdadm.conf match\n");
                        }
                        if (rvp)
                                *rvp = 2;
@@ -1168,8 +1197,7 @@ int conf_verify_devnames(struct mddev_ident *array_list)
                                        "%s have the same name: %s\n",
                                        nbuf, a1->devname);
                        } else
-                               pr_err("Device %s given twice"
-                                       " in config file\n", a1->devname);
+                               pr_err("Device %s given twice in config file\n", a1->devname);
                        return 1;
                }
        }