]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - config.c
2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Email: <neilb@suse.de>
35 * Read the config file
37 * conf_get_uuids gets a list of devicename+uuid pairs
38 * conf_get_devs gets device names after expanding wildcards
40 * Each keeps the returned list and frees it when asked to make
43 * The format of the config file needs to be fairly extensible.
44 * Now, arrays only have names and uuids and devices merely are.
45 * But later arrays might want names, and devices might want superblock
46 * versions, and who knows what else.
47 * I like free format, abhore backslash line continuation, adore
48 * indentation for structure and am ok about # comments.
50 * So, each line that isn't blank or a #comment must either start
51 * with a key word, and not be indented, or must start with a
52 * non-key-word and must be indented.
54 * Keywords are DEVICE and ARRAY ... and several others.
55 * DEV{ICE} introduces some devices that might contain raid components.
57 * DEV style=0 /dev/sda* /dev/hd*
58 * DEV style=1 /dev/sd[b-f]*
59 * ARR{AY} describes an array giving md device and attributes like uuid=whatever
61 * ARRAY /dev/md0 uuid=whatever name=something
62 * Spaces separate words on each line. Quoting, with "" or '' protects them,
63 * but may not wrap over lines
68 #define CONFFILE "/etc/mdadm.conf"
71 /* for Debian compatibility .... */
72 #define CONFFILE2 "/etc/mdadm/mdadm.conf"
74 char DefaultConfFile
[] = CONFFILE
;
75 char DefaultConfDir
[] = CONFFILE
".d";
76 char DefaultAltConfFile
[] = CONFFILE2
;
77 char DefaultAltConfDir
[] = CONFFILE2
".d";
79 enum linetype
{ Devices
, Array
, Mailaddr
, Mailfrom
, Program
, CreateDev
,
80 Homehost
, AutoMode
, Policy
, PartPolicy
, LTEnd
};
82 [Devices
] = "devices",
84 [Mailaddr
] = "mailaddr",
85 [Mailfrom
] = "mailfrom",
86 [Program
] = "program",
87 [CreateDev
]= "create",
88 [Homehost
] = "homehost",
91 [PartPolicy
]="part-policy",
96 * match_keyword returns an index into the keywords array, or -1 for no match
97 * case is ignored, and at least three characters must be given
100 int match_keyword(char *word
)
102 int len
= strlen(word
);
105 if (len
< 3) return -1;
106 for (n
=0; keywords
[n
]; n
++) {
107 if (strncasecmp(word
, keywords
[n
], len
)==0)
114 struct conf_dev
*next
;
118 struct mddev_dev
*load_partitions(void)
120 FILE *f
= fopen("/proc/partitions", "r");
122 struct mddev_dev
*rv
= NULL
;
124 pr_err("cannot open /proc/partitions\n");
127 while (fgets(buf
, 1024, f
)) {
135 major
= strtoul(buf
, &mp
, 10);
136 if (mp
== buf
|| *mp
!= ' ')
138 minor
= strtoul(mp
, NULL
, 10);
140 name
= map_dev(major
, minor
, 1);
143 d
= xmalloc(sizeof(*d
));
144 memset(d
, 0, sizeof(*d
));
145 d
->devname
= xstrdup(name
);
153 struct mddev_dev
*load_containers(void)
155 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
156 struct mdstat_ent
*ent
;
158 struct mddev_dev
*rv
= NULL
;
159 struct map_ent
*map
= NULL
, *me
;
164 for (ent
= mdstat
; ent
; ent
= ent
->next
)
165 if (ent
->metadata_version
&&
166 strncmp(ent
->metadata_version
, "external:", 9) == 0 &&
167 !is_subarray(&ent
->metadata_version
[9])) {
168 d
= xmalloc(sizeof(*d
));
169 memset(d
, 0, sizeof(*d
));
170 me
= map_by_devnm(&map
, ent
->dev
);
172 d
->devname
= xstrdup(me
->path
);
173 else if (asprintf(&d
->devname
, "/dev/%s", ent
->dev
) < 0) {
186 struct createinfo createinfo
= {
187 .autof
= 2, /* by default, create devices with standard names */
189 .names
= 0, /* By default, stick with numbered md devices. */
190 .bblist
= 1, /* Use a bad block list by default */
199 int parse_auto(char *str
, char *msg
, int config
)
202 if (str
== NULL
|| *str
== 0)
204 else if (strcasecmp(str
,"no")==0)
206 else if (strcasecmp(str
,"yes")==0)
208 else if (strcasecmp(str
,"md")==0)
211 /* There might be digits, and maybe a hypen, at the end */
212 char *e
= str
+ strlen(str
);
215 while (e
> str
&& isdigit(e
[-1]))
219 if (num
<= 0) num
= 1;
221 if (e
> str
&& e
[-1] == '-')
224 if ((len
== 2 && strncasecmp(str
,"md",2)==0)) {
225 autof
= config
? 5 : 3;
226 } else if ((len
== 3 && strncasecmp(str
,"yes",3)==0)) {
228 } else if ((len
== 3 && strncasecmp(str
,"mdp",3)==0)) {
229 autof
= config
? 6 : 4;
230 } else if ((len
== 1 && strncasecmp(str
,"p",1)==0) ||
231 (len
>= 4 && strncasecmp(str
,"part",4)==0)) {
234 pr_err("%s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
235 " optionally followed by a number.\n",
244 static void createline(char *line
)
249 for (w
=dl_next(line
); w
!=line
; w
=dl_next(w
)) {
250 if (strncasecmp(w
, "auto=", 5) == 0)
251 createinfo
.autof
= parse_auto(w
+5, "auto=", 1);
252 else if (strncasecmp(w
, "owner=", 6) == 0) {
254 pr_err("missing owner name\n");
257 createinfo
.uid
= strtoul(w
+6, &ep
, 10);
263 createinfo
.uid
= pw
->pw_uid
;
265 pr_err("CREATE user %s not found\n", w
+6);
267 } else if (strncasecmp(w
, "group=", 6) == 0) {
269 pr_err("missing group name\n");
272 createinfo
.gid
= strtoul(w
+6, &ep
, 10);
278 createinfo
.gid
= gr
->gr_gid
;
280 pr_err("CREATE group %s not found\n", w
+6);
282 } else if (strncasecmp(w
, "mode=", 5) == 0) {
284 pr_err("missing CREATE mode\n");
287 createinfo
.mode
= strtoul(w
+5, &ep
, 8);
289 createinfo
.mode
= 0600;
290 pr_err("unrecognised CREATE mode %s\n",
293 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
294 /* style of metadata to use by default */
296 for (i
=0; superlist
[i
] && !createinfo
.supertype
; i
++)
297 createinfo
.supertype
=
298 superlist
[i
]->match_metadata_desc(w
+9);
299 if (!createinfo
.supertype
)
300 pr_err("metadata format %s unknown, ignoring\n",
302 } else if (strncasecmp(w
, "symlinks=yes", 12) == 0)
303 createinfo
.symlinks
= 1;
304 else if (strncasecmp(w
, "symlinks=no", 11) == 0)
305 createinfo
.symlinks
= 0;
306 else if (strncasecmp(w
, "names=yes", 12) == 0)
307 createinfo
.names
= 1;
308 else if (strncasecmp(w
, "names=no", 11) == 0)
309 createinfo
.names
= 0;
310 else if (strncasecmp(w
, "bbl=no", 11) == 0)
311 createinfo
.bblist
= 0;
312 else if (strncasecmp(w
, "bbl=yes", 11) == 0)
313 createinfo
.bblist
= 1;
315 pr_err("unrecognised word on CREATE line: %s\n",
321 void devline(char *line
)
326 for (w
=dl_next(line
); w
!= line
; w
=dl_next(w
)) {
327 if (w
[0] == '/' || strcasecmp(w
, "partitions") == 0 ||
328 strcasecmp(w
, "containers") == 0) {
329 cd
= xmalloc(sizeof(*cd
));
330 cd
->name
= xstrdup(w
);
334 pr_err("unreconised word on DEVICE line: %s\n",
340 struct mddev_ident
*mddevlist
= NULL
;
341 struct mddev_ident
**mddevlp
= &mddevlist
;
343 static int is_number(char *w
)
345 /* check if there are 1 or more digits and nothing else */
347 while (*w
&& isdigit(*w
)) {
351 return (digits
&& ! *w
);
354 void arrayline(char *line
)
358 struct mddev_ident mis
;
359 struct mddev_ident
*mi
;
362 mis
.super_minor
= UnSet
;
364 mis
.raid_disks
= UnSet
;
368 mis
.spare_group
= NULL
;
373 mis
.bitmap_file
= NULL
;
375 mis
.container
= NULL
;
378 for (w
=dl_next(line
); w
!=line
; w
=dl_next(w
)) {
379 if (w
[0] == '/' || strchr(w
, '=') == NULL
) {
380 /* This names the device, or is '<ignore>'.
381 * The rules match those in create_mddev.
387 * or anything that doesn't start '/' or '<'
389 if (strcasecmp(w
, "<ignore>") == 0 ||
390 strncmp(w
, "/dev/md/", 8) == 0 ||
391 (w
[0] != '/' && w
[0] != '<') ||
392 (strncmp(w
, "/dev/md", 7) == 0 &&
394 (strncmp(w
, "/dev/md_d", 9) == 0 &&
397 /* This is acceptable */;
399 pr_err("only give one "
400 "device per ARRAY line: %s and %s\n",
405 pr_err("%s is an invalid name for "
406 "an md device - ignored.\n", w
);
408 } else if (strncasecmp(w
, "uuid=", 5)==0 ) {
410 pr_err("only specify uuid once, %s ignored.\n",
413 if (parse_uuid(w
+5, mis
.uuid
))
416 pr_err("bad uuid: %s\n", w
);
418 } else if (strncasecmp(w
, "super-minor=", 12)==0 ) {
419 if (mis
.super_minor
!= UnSet
)
420 pr_err("only specify super-minor once, %s ignored.\n",
424 int minor
= strtol(w
+12, &endptr
, 10);
426 if (w
[12]==0 || endptr
[0]!=0 || minor
< 0)
427 pr_err("invalid super-minor number: %s\n",
430 mis
.super_minor
= minor
;
432 } else if (strncasecmp(w
, "name=", 5)==0) {
434 pr_err("only specify name once, %s ignored.\n",
436 else if (strlen(w
+5) > 32)
437 pr_err("name too long, ignoring %s\n", w
);
439 strcpy(mis
.name
, w
+5);
441 } else if (strncasecmp(w
, "bitmap=", 7) == 0) {
443 pr_err("only specify bitmap file once. %s ignored\n",
446 mis
.bitmap_file
= xstrdup(w
+7);
448 } else if (strncasecmp(w
, "devices=", 8 ) == 0 ) {
450 pr_err("only specify devices once (use a comma separated list). %s ignored\n",
453 mis
.devices
= xstrdup(w
+8);
454 } else if (strncasecmp(w
, "spare-group=", 12) == 0 ) {
456 pr_err("only specify one spare group per array. %s ignored.\n",
459 mis
.spare_group
= xstrdup(w
+12);
460 } else if (strncasecmp(w
, "level=", 6) == 0 ) {
461 /* this is mainly for compatability with --brief output */
462 mis
.level
= map_name(pers
, w
+6);
463 } else if (strncasecmp(w
, "disks=", 6) == 0 ) {
464 /* again, for compat */
465 mis
.raid_disks
= atoi(w
+6);
466 } else if (strncasecmp(w
, "num-devices=", 12) == 0 ) {
467 /* again, for compat */
468 mis
.raid_disks
= atoi(w
+12);
469 } else if (strncasecmp(w
, "spares=", 7) == 0 ) {
470 /* for warning if not all spares present */
471 mis
.spare_disks
= atoi(w
+7);
472 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
473 /* style of metadata on the devices. */
476 for(i
=0; superlist
[i
] && !mis
.st
; i
++)
477 mis
.st
= superlist
[i
]->match_metadata_desc(w
+9);
480 pr_err("metadata format %s unknown, ignored.\n", w
+9);
481 } else if (strncasecmp(w
, "auto=", 5) == 0 ) {
482 /* whether to create device special files as needed */
483 mis
.autof
= parse_auto(w
+5, "auto type", 0);
484 } else if (strncasecmp(w
, "member=", 7) == 0) {
485 /* subarray within a container */
486 mis
.member
= xstrdup(w
+7);
487 } else if (strncasecmp(w
, "container=", 10) == 0) {
488 /* the container holding this subarray. Either a device name
490 mis
.container
= xstrdup(w
+10);
492 pr_err("unrecognised word on ARRAY line: %s\n",
496 if (mis
.uuid_set
== 0 && mis
.devices
== NULL
&&
497 mis
.super_minor
== UnSet
&& mis
.name
[0] == 0 &&
498 (mis
.container
== NULL
|| mis
.member
== NULL
))
499 pr_err("ARRAY line %s has no identity information.\n", mis
.devname
);
501 mi
= xmalloc(sizeof(*mi
));
503 mi
->devname
= mis
.devname
? xstrdup(mis
.devname
) : NULL
;
510 static char *alert_email
= NULL
;
511 void mailline(char *line
)
515 for (w
=dl_next(line
); w
!= line
; w
=dl_next(w
))
516 if (alert_email
== NULL
)
517 alert_email
= xstrdup(w
);
520 static char *alert_mail_from
= NULL
;
521 void mailfromline(char *line
)
525 for (w
=dl_next(line
); w
!= line
; w
=dl_next(w
)) {
526 if (alert_mail_from
== NULL
)
527 alert_mail_from
= xstrdup(w
);
531 if (xasprintf(&t
, "%s %s", alert_mail_from
, w
) > 0) {
532 free(alert_mail_from
);
539 static char *alert_program
= NULL
;
540 void programline(char *line
)
544 for (w
=dl_next(line
); w
!= line
; w
=dl_next(w
))
545 if (alert_program
== NULL
)
546 alert_program
= xstrdup(w
);
549 static char *home_host
= NULL
;
550 static int require_homehost
= 1;
551 void homehostline(char *line
)
555 for (w
=dl_next(line
); w
!= line
; w
=dl_next(w
)) {
556 if (strcasecmp(w
, "<ignore>")==0)
557 require_homehost
= 0;
558 else if (home_host
== NULL
) {
559 if (strcasecmp(w
, "<none>")==0)
560 home_host
= xstrdup("");
562 home_host
= xstrdup(w
);
567 char auto_yes
[] = "yes";
568 char auto_no
[] = "no";
569 char auto_homehost
[] = "homehost";
571 static int auto_seen
= 0;
572 void autoline(char *line
)
577 char *dflt
= auto_yes
;
585 /* Parse the 'auto' line creating policy statements for the 'auto' policy.
587 * The default is 'yes' but the 'auto' line might over-ride that.
588 * Words in the line are processed in order with the first
591 * +version - that version can be assembled
592 * -version - that version cannot be auto-assembled
593 * yes or +all - any other version can be assembled
594 * no or -all - no other version can be assembled.
595 * homehost - any array associated by 'homehost' to this
596 * host can be assembled.
599 * +ddf -0.90 homehost -all
600 * will auto-assemble any ddf array, no 0.90 array, and
601 * any other array (imsm, 1.x) if and only if it is identified
602 * as belonging to this host.
604 * We translate that to policy by creating 'auto=yes' when we see
605 * a '+version' line, 'auto=no' if we see '-version' before 'homehost',
606 * or 'auto=homehost' if we see '-version' after 'homehost'.
607 * When we see yes, no, +all or -all we stop and any version that hasn't
608 * been seen gets an appropriate auto= entry.
611 /* If environment variable MDADM_CONF_AUTO is defined, then
612 * it is prepended to the auto line. This allow a script
613 * to easily disable some metadata types.
615 w
= getenv("MDADM_CONF_AUTO");
617 char *l
= xstrdup(w
);
619 w
= strtok(l
, " \t");
621 char *nw
= dl_strdup(w
);
624 w
= strtok(NULL
, " \t");
629 for (super_cnt
= 0; superlist
[super_cnt
]; super_cnt
++)
631 seen
= xcalloc(super_cnt
, 1);
633 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
636 if (strcasecmp(w
, "yes") == 0) {
640 if (strcasecmp(w
, "no") == 0) {
642 dflt
= auto_homehost
;
647 if (strcasecmp(w
, "homehost") == 0) {
653 else if (w
[0] == '-') {
661 if (strcasecmp(w
+1, "all") == 0) {
665 for (i
= 0; superlist
[i
]; i
++) {
666 const char *version
= superlist
[i
]->name
;
667 if (strcasecmp(w
+1, version
) == 0)
669 /* 1 matches 1.x, 0 matches 0.90 */
670 if (version
[1] == '.' &&
674 /* 1.anything matches 1.x */
675 if (strcmp(version
, "1.x") == 0 &&
676 strncmp(w
+1, "1.", 2) == 0)
679 if (superlist
[i
] == NULL
)
680 /* ignore this word */
683 /* already know about this metadata */
685 policy_add(rule_policy
, pol_auto
, val
, pol_metadata
, superlist
[i
]->name
, NULL
);
688 for (i
= 0; i
< super_cnt
; i
++)
690 policy_add(rule_policy
, pol_auto
, dflt
, pol_metadata
, superlist
[i
]->name
, NULL
);
697 static char *conffile
= NULL
;
698 void set_conffile(char *file
)
703 void conf_file(FILE *f
)
706 while ((line
=conf_line(f
))) {
707 switch(match_keyword(line
)) {
733 policyline(line
, rule_policy
);
736 policyline(line
, rule_part
);
739 pr_err("Unknown keyword %s\n", line
);
750 void conf_file_or_dir(FILE *f
)
755 struct fname
*list
= NULL
;
757 fstat(fileno(f
), &st
);
758 if (S_ISREG(st
.st_mode
))
760 else if (!S_ISDIR(st
.st_mode
))
762 #if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
763 dir
= fdopendir(fileno(f
));
766 while ((dp
= readdir(dir
)) != NULL
) {
768 struct fname
*fn
, **p
;
771 if (dp
->d_name
[0] == '.')
773 l
= strlen(dp
->d_name
);
774 if (l
< 6 || strcmp(dp
->d_name
+l
-5, ".conf") != 0)
776 fn
= xmalloc(sizeof(*fn
)+l
+1);
777 strcpy(fn
->name
, dp
->d_name
);
779 *p
&& strcmp((*p
)->name
, fn
->name
) < 0;
788 struct fname
*fn
= list
;
790 fd
= openat(fileno(f
), fn
->name
, O_RDONLY
);
794 f2
= fdopen(fd
, "r");
806 void load_conffile(void)
809 char *confdir
= NULL
;
814 if (conffile
== NULL
) {
815 conffile
= DefaultConfFile
;
816 confdir
= DefaultConfDir
;
819 if (strcmp(conffile
, "partitions")==0) {
820 char *list
= dl_strdup("DEV");
822 dl_add(list
, dl_strdup("partitions"));
825 } else if (strcmp(conffile
, "none") != 0) {
826 f
= fopen(conffile
, "r");
827 /* Debian chose to relocate mdadm.conf into /etc/mdadm/.
828 * To allow Debian users to compile from clean source and still
829 * have a working mdadm, we read /etc/mdadm/mdadm.conf
830 * if /etc/mdadm.conf doesn't exist
833 conffile
== DefaultConfFile
) {
834 f
= fopen(DefaultAltConfFile
, "r");
836 conffile
= DefaultAltConfFile
;
837 confdir
= DefaultAltConfDir
;
845 f
= fopen(confdir
, "r");
852 /* If there was no AUTO line, process an empty line
853 * now so that the MDADM_CONF_AUTO env var gets processed.
855 head
= dl_strdup("AUTO");
863 char *conf_get_mailaddr(void)
869 char *conf_get_mailfrom(void)
872 return alert_mail_from
;
875 char *conf_get_program(void)
878 return alert_program
;
881 char *conf_get_homehost(int *require_homehostp
)
884 if (require_homehostp
)
885 *require_homehostp
= require_homehost
;
889 struct createinfo
*conf_get_create_info(void)
895 struct mddev_ident
*conf_get_ident(char *dev
)
897 struct mddev_ident
*rv
;
900 while (dev
&& rv
&& (rv
->devname
== NULL
901 || !devname_matches(dev
, rv
->devname
)))
906 static void append_dlist(struct mddev_dev
**dlp
, struct mddev_dev
*list
)
913 struct mddev_dev
*conf_get_devs()
918 static struct mddev_dev
*dlist
= NULL
;
922 struct mddev_dev
*t
= dlist
;
930 if (cdevlist
== NULL
) {
931 /* default to 'partitions' and 'containers' */
932 dlist
= load_partitions();
933 append_dlist(&dlist
, load_containers());
936 for (cd
=cdevlist
; cd
; cd
=cd
->next
) {
937 if (strcasecmp(cd
->name
, "partitions")==0)
938 append_dlist(&dlist
, load_partitions());
939 else if (strcasecmp(cd
->name
, "containers")==0)
940 append_dlist(&dlist
, load_containers());
942 glob(cd
->name
, flags
, NULL
, &globbuf
);
943 flags
|= GLOB_APPEND
;
946 if (flags
& GLOB_APPEND
) {
947 for (i
=0; i
<globbuf
.gl_pathc
; i
++) {
948 struct mddev_dev
*t
= xmalloc(sizeof(*t
));
949 memset(t
, 0, sizeof(*t
));
950 t
->devname
= xstrdup(globbuf
.gl_pathv
[i
]);
953 /* printf("one dev is %s\n", t->devname);*/
961 int conf_test_dev(char *devname
)
964 if (cdevlist
== NULL
)
965 /* allow anything by default */
967 for (cd
= cdevlist
; cd
; cd
= cd
->next
) {
968 if (strcasecmp(cd
->name
, "partitions") == 0)
970 if (fnmatch(cd
->name
, devname
, FNM_PATHNAME
) == 0)
976 int conf_test_metadata(const char *version
, struct dev_policy
*pol
, int is_homehost
)
978 /* If anyone said 'yes', that sticks.
979 * else if homehost applies, use that
980 * else if there is a 'no', say 'no'.
983 struct dev_policy
*p
;
984 int no
=0, found_homehost
=0;
987 pol
= pol_find(pol
, pol_auto
);
988 pol_for_each(p
, pol
, version
) {
989 if (strcmp(p
->value
, "yes") == 0)
991 if (strcmp(p
->value
, "homehost") == 0)
993 if (strcmp(p
->value
, "no") == 0)
996 if (is_homehost
&& found_homehost
)
1003 int match_oneof(char *devices
, char *devname
)
1005 /* check if one of the comma separated patterns in devices
1009 while (devices
&& *devices
) {
1012 devices
= strchr(devices
, ',');
1014 devices
= p
+ strlen(p
);
1015 if (devices
-p
< 1024) {
1016 strncpy(patn
, p
, devices
-p
);
1017 patn
[devices
-p
] = 0;
1018 if (fnmatch(patn
, devname
, FNM_PATHNAME
)==0)
1021 if (*devices
== ',')
1027 int devname_matches(char *name
, char *match
)
1029 /* See if the given array name matches the
1030 * given match from config file.
1032 * First strip and /dev/md/ or /dev/, then
1033 * see if there might be a numeric match of
1037 if (strncmp(name
, "/dev/md/", 8) == 0)
1039 else if (strncmp(name
, "/dev/", 5) == 0)
1042 if (strncmp(match
, "/dev/md/", 8) == 0)
1044 else if (strncmp(match
, "/dev/", 5) == 0)
1047 if (strncmp(name
, "md", 2) == 0 &&
1050 if (strncmp(match
, "md", 2) == 0 &&
1054 return (strcmp(name
, match
) == 0);
1057 int conf_name_is_free(char *name
)
1059 /* Check if this name is already taken by an ARRAY entry in
1061 * It can be taken either by a match on devname, name, or
1064 struct mddev_ident
*dev
;
1067 for (dev
= mddevlist
; dev
; dev
= dev
->next
) {
1069 if (dev
->devname
&& devname_matches(name
, dev
->devname
))
1071 if (dev
->name
[0] && devname_matches(name
, dev
->name
))
1073 sprintf(nbuf
, "%d", dev
->super_minor
);
1074 if (dev
->super_minor
!= UnSet
&&
1075 devname_matches(name
, nbuf
))
1081 struct mddev_ident
*conf_match(struct supertype
*st
,
1082 struct mdinfo
*info
,
1084 int verbose
, int *rvp
)
1086 struct mddev_ident
*array_list
, *match
;
1087 array_list
= conf_get_ident(NULL
);
1089 for (; array_list
; array_list
= array_list
->next
) {
1090 if (array_list
->uuid_set
&&
1091 same_uuid(array_list
->uuid
, info
->uuid
, st
->ss
->swapuuid
)
1093 if (verbose
>= 2 && array_list
->devname
)
1094 pr_err("UUID differs from %s.\n",
1095 array_list
->devname
);
1098 if (array_list
->name
[0] &&
1099 strcasecmp(array_list
->name
, info
->name
) != 0) {
1100 if (verbose
>= 2 && array_list
->devname
)
1101 pr_err("Name differs from %s.\n",
1102 array_list
->devname
);
1105 if (array_list
->devices
&& devname
&&
1106 !match_oneof(array_list
->devices
, devname
)) {
1107 if (verbose
>= 2 && array_list
->devname
)
1108 pr_err("Not a listed device for %s.\n",
1109 array_list
->devname
);
1112 if (array_list
->super_minor
!= UnSet
&&
1113 array_list
->super_minor
!= info
->array
.md_minor
) {
1114 if (verbose
>= 2 && array_list
->devname
)
1115 pr_err("Different super-minor to %s.\n",
1116 array_list
->devname
);
1119 if (!array_list
->uuid_set
&&
1120 !array_list
->name
[0] &&
1121 !array_list
->devices
&&
1122 array_list
->super_minor
== UnSet
) {
1123 if (verbose
>= 2 && array_list
->devname
)
1124 pr_err("%s doesn't have any identifying"
1126 array_list
->devname
);
1129 /* FIXME, should I check raid_disks and level too?? */
1133 if (match
->devname
&& array_list
->devname
)
1134 pr_err("we match both %s and %s - "
1135 "cannot decide which to use.\n",
1137 array_list
->devname
);
1139 pr_err("multiple lines in mdadm.conf"
1152 int conf_verify_devnames(struct mddev_ident
*array_list
)
1154 struct mddev_ident
*a1
, *a2
;
1156 for (a1
= array_list
; a1
; a1
= a1
->next
) {
1159 if (strcmp(a1
->devname
, "<ignore>") == 0)
1161 for (a2
= a1
->next
; a2
; a2
= a2
->next
) {
1164 if (strcmp(a1
->devname
, a2
->devname
) != 0)
1167 if (a1
->uuid_set
&& a2
->uuid_set
) {
1169 __fname_from_uuid(a1
->uuid
, 0, nbuf
, ':');
1170 pr_err("Devices %s and ",
1172 __fname_from_uuid(a2
->uuid
, 0, nbuf
, ':');
1174 "%s have the same name: %s\n",
1177 pr_err("Device %s given twice"
1178 " in config file\n", a1
->devname
);