]>
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
66 #ifndef _POSIX_C_SOURCE
67 #define _POSIX_C_SOURCE 200809L
71 #define CONFFILE "/etc/mdadm.conf"
74 /* for Debian compatibility .... */
75 #define CONFFILE2 "/etc/mdadm/mdadm.conf"
77 char DefaultConfFile
[] = CONFFILE
;
78 char DefaultConfDir
[] = CONFFILE
".d";
79 char DefaultAltConfFile
[] = CONFFILE2
;
80 char DefaultAltConfDir
[] = CONFFILE2
".d";
82 enum linetype
{ Devices
, Array
, Mailaddr
, Mailfrom
, Program
, CreateDev
,
83 Homehost
, HomeCluster
, AutoMode
, Policy
, PartPolicy
, Sysfs
,
84 MonitorDelay
, LTEnd
};
86 [Devices
] = "devices",
88 [Mailaddr
] = "mailaddr",
89 [Mailfrom
] = "mailfrom",
90 [Program
] = "program",
91 [CreateDev
]= "create",
92 [Homehost
] = "homehost",
93 [HomeCluster
] = "homecluster",
96 [PartPolicy
]="part-policy",
98 [MonitorDelay
] = "monitordelay",
103 * match_keyword returns an index into the keywords array, or -1 for no match
104 * case is ignored, and at least three characters must be given
107 int match_keyword(char *word
)
109 int len
= strlen(word
);
114 for (n
= 0; keywords
[n
]; n
++) {
115 if (strncasecmp(word
, keywords
[n
], len
) == 0)
123 struct conf_dev
*next
;
127 struct mddev_dev
*load_partitions(void)
129 FILE *f
= fopen("/proc/partitions", "r");
131 struct mddev_dev
*rv
= NULL
;
134 pr_err("cannot open /proc/partitions\n");
137 while (fgets(buf
, 1024, f
)) {
145 major
= strtoul(buf
, &mp
, 10);
146 if (mp
== buf
|| *mp
!= ' ')
148 minor
= strtoul(mp
, NULL
, 10);
150 name
= map_dev(major
, minor
, 1);
153 d
= xcalloc(1, sizeof(*d
));
154 d
->devname
= xstrdup(name
);
162 struct mddev_dev
*load_containers(void)
164 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
165 struct mdstat_ent
*ent
;
167 struct mddev_dev
*rv
= NULL
;
168 struct map_ent
*map
= NULL
, *me
;
173 for (ent
= mdstat
; ent
; ent
= ent
->next
)
174 if (ent
->metadata_version
&&
175 strncmp(ent
->metadata_version
, "external:", 9) == 0 &&
176 !is_subarray(&ent
->metadata_version
[9])) {
177 d
= xcalloc(1, sizeof(*d
));
178 me
= map_by_devnm(&map
, ent
->devnm
);
180 d
->devname
= xstrdup(me
->path
);
181 else if (asprintf(&d
->devname
, "/dev/%s", ent
->devnm
) < 0) {
195 struct createinfo createinfo
= {
196 .autof
= 2, /* by default, create devices with standard names */
197 .names
= 0, /* By default, stick with numbered md devices. */
198 .bblist
= 1, /* Use a bad block list by default */
207 int parse_auto(char *str
, char *msg
, int config
)
210 if (str
== NULL
|| *str
== 0)
212 else if (strcasecmp(str
, "no") == 0)
214 else if (strcasecmp(str
, "yes") == 0)
216 else if (strcasecmp(str
, "md") == 0)
217 autof
= config
? 5:3;
219 /* There might be digits, and maybe a hypen, at the end */
220 char *e
= str
+ strlen(str
);
223 while (e
> str
&& isdigit(e
[-1]))
230 if (e
> str
&& e
[-1] == '-')
233 if ((len
== 2 && strncasecmp(str
, "md", 2) == 0)) {
234 autof
= config
? 5 : 3;
235 } else if ((len
== 3 && strncasecmp(str
, "yes", 3) == 0)) {
237 } else if ((len
== 3 && strncasecmp(str
, "mdp", 3) == 0)) {
238 autof
= config
? 6 : 4;
239 } else if ((len
== 1 && strncasecmp(str
, "p", 1) == 0) ||
240 (len
>= 4 && strncasecmp(str
, "part", 4) == 0)) {
243 pr_err("%s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
244 " optionally followed by a number.\n",
253 static void createline(char *line
)
258 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
259 if (strncasecmp(w
, "auto=", 5) == 0)
260 createinfo
.autof
= parse_auto(w
+ 5, "auto=", 1);
261 else if (strncasecmp(w
, "owner=", 6) == 0) {
263 pr_err("missing owner name\n");
266 createinfo
.uid
= strtoul(w
+ 6, &ep
, 10);
270 pw
= getpwnam(w
+ 6);
272 createinfo
.uid
= pw
->pw_uid
;
274 pr_err("CREATE user %s not found\n",
277 } else if (strncasecmp(w
, "group=", 6) == 0) {
279 pr_err("missing group name\n");
282 createinfo
.gid
= strtoul(w
+ 6, &ep
, 10);
286 gr
= getgrnam(w
+ 6);
288 createinfo
.gid
= gr
->gr_gid
;
290 pr_err("CREATE group %s not found\n",
293 } else if (strncasecmp(w
, "mode=", 5) == 0) {
295 pr_err("missing CREATE mode\n");
298 createinfo
.mode
= strtoul(w
+ 5, &ep
, 8);
300 createinfo
.mode
= 0600;
301 pr_err("unrecognised CREATE mode %s\n",
304 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
305 /* style of metadata to use by default */
307 for (i
= 0; superlist
[i
] && !createinfo
.supertype
; i
++)
308 createinfo
.supertype
= superlist
[i
]->match_metadata_desc(w
+ 9);
309 if (!createinfo
.supertype
)
310 pr_err("metadata format %s unknown, ignoring\n",
312 } else if (strncasecmp(w
, "names=yes", 12) == 0)
313 createinfo
.names
= 1;
314 else if (strncasecmp(w
, "names=no", 11) == 0)
315 createinfo
.names
= 0;
316 else if (strncasecmp(w
, "bbl=no", 11) == 0)
317 createinfo
.bblist
= 0;
318 else if (strncasecmp(w
, "bbl=yes", 11) == 0)
319 createinfo
.bblist
= 1;
321 pr_err("unrecognised word on CREATE line: %s\n",
327 void devline(char *line
)
332 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
333 if (w
[0] == '/' || strcasecmp(w
, "partitions") == 0 ||
334 strcasecmp(w
, "containers") == 0) {
335 cd
= xmalloc(sizeof(*cd
));
336 cd
->name
= xstrdup(w
);
340 pr_err("unreconised word on DEVICE line: %s\n", w
);
345 struct mddev_ident
*mddevlist
= NULL
;
346 struct mddev_ident
**mddevlp
= &mddevlist
;
348 static int is_number(char *w
)
350 /* check if there are 1 or more digits and nothing else */
352 while (*w
&& isdigit(*w
)) {
356 return (digits
&& ! *w
);
359 void arrayline(char *line
)
363 struct mddev_ident mis
;
364 struct mddev_ident
*mi
;
367 mis
.super_minor
= UnSet
;
369 mis
.raid_disks
= UnSet
;
373 mis
.spare_group
= NULL
;
378 mis
.bitmap_file
= NULL
;
380 mis
.container
= NULL
;
383 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
384 if (w
[0] == '/' || strchr(w
, '=') == NULL
) {
385 /* This names the device, or is '<ignore>'.
386 * The rules match those in create_mddev.
392 * or anything that doesn't start '/' or '<'
394 if (strcasecmp(w
, "<ignore>") == 0 ||
395 strncmp(w
, "/dev/md/", 8) == 0 ||
396 (w
[0] != '/' && w
[0] != '<') ||
397 (strncmp(w
, "/dev/md", 7) == 0 &&
399 (strncmp(w
, "/dev/md_d", 9) == 0 &&
401 /* This is acceptable */;
403 pr_err("only give one device per ARRAY line: %s and %s\n",
408 pr_err("%s is an invalid name for an md device - ignored.\n", w
);
410 } else if (strncasecmp(w
, "uuid=", 5) == 0) {
412 pr_err("only specify uuid once, %s ignored.\n",
415 if (parse_uuid(w
+ 5, mis
.uuid
))
418 pr_err("bad uuid: %s\n", w
);
420 } else if (strncasecmp(w
, "super-minor=", 12) == 0) {
421 if (mis
.super_minor
!= UnSet
)
422 pr_err("only specify super-minor once, %s ignored.\n",
426 int minor
= strtol(w
+ 12, &endptr
, 10);
428 if (w
[12] == 0 || endptr
[0] != 0 || minor
< 0)
429 pr_err("invalid super-minor number: %s\n",
432 mis
.super_minor
= minor
;
434 } else if (strncasecmp(w
, "name=", 5) == 0) {
436 pr_err("only specify name once, %s ignored.\n",
438 else if (strlen(w
+ 5) > 32)
439 pr_err("name too long, ignoring %s\n", w
);
441 strcpy(mis
.name
, w
+ 5);
443 } else if (strncasecmp(w
, "bitmap=", 7) == 0) {
445 pr_err("only specify bitmap file once. %s ignored\n",
448 mis
.bitmap_file
= xstrdup(w
+ 7);
450 } else if (strncasecmp(w
, "devices=", 8 ) == 0) {
452 pr_err("only specify devices once (use a comma separated list). %s ignored\n",
455 mis
.devices
= xstrdup(w
+ 8);
456 } else if (strncasecmp(w
, "spare-group=", 12) == 0) {
458 pr_err("only specify one spare group per array. %s ignored.\n",
461 mis
.spare_group
= xstrdup(w
+ 12);
462 } else if (strncasecmp(w
, "level=", 6) == 0 ) {
463 /* this is mainly for compatability with --brief output */
464 mis
.level
= map_name(pers
, w
+ 6);
465 } else if (strncasecmp(w
, "disks=", 6) == 0) {
466 /* again, for compat */
467 mis
.raid_disks
= atoi(w
+ 6);
468 } else if (strncasecmp(w
, "num-devices=", 12) == 0) {
469 /* again, for compat */
470 mis
.raid_disks
= atoi(w
+ 12);
471 } else if (strncasecmp(w
, "spares=", 7) == 0) {
472 /* for warning if not all spares present */
473 mis
.spare_disks
= atoi(w
+ 7);
474 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
475 /* style of metadata on the devices. */
478 for(i
=0; superlist
[i
] && !mis
.st
; i
++)
479 mis
.st
= superlist
[i
]->
480 match_metadata_desc(w
+ 9);
483 pr_err("metadata format %s unknown, ignored.\n",
485 } else if (strncasecmp(w
, "auto=", 5) == 0 ) {
486 /* whether to create device special files as needed */
487 mis
.autof
= parse_auto(w
+ 5, "auto type", 0);
488 } else if (strncasecmp(w
, "member=", 7) == 0) {
489 /* subarray within a container */
490 mis
.member
= xstrdup(w
+ 7);
491 } else if (strncasecmp(w
, "container=", 10) == 0) {
492 /* The container holding this subarray.
493 * Either a device name or a uuid */
494 mis
.container
= xstrdup(w
+ 10);
496 pr_err("unrecognised word on ARRAY line: %s\n",
500 if (mis
.uuid_set
== 0 && mis
.devices
== NULL
&&
501 mis
.super_minor
== UnSet
&& mis
.name
[0] == 0 &&
502 (mis
.container
== NULL
|| mis
.member
== NULL
))
503 pr_err("ARRAY line %s has no identity information.\n",
506 mi
= xmalloc(sizeof(*mi
));
508 mi
->devname
= mis
.devname
? xstrdup(mis
.devname
) : NULL
;
515 static char *alert_email
= NULL
;
516 void mailline(char *line
)
520 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
))
521 if (alert_email
== NULL
)
522 alert_email
= xstrdup(w
);
525 static char *alert_mail_from
= NULL
;
526 void mailfromline(char *line
)
530 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
531 if (alert_mail_from
== NULL
)
532 alert_mail_from
= xstrdup(w
);
536 if (xasprintf(&t
, "%s %s", alert_mail_from
, w
) > 0) {
537 free(alert_mail_from
);
544 static char *alert_program
= NULL
;
545 void programline(char *line
)
549 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
))
550 if (alert_program
== NULL
)
551 alert_program
= xstrdup(w
);
554 static char *home_host
= NULL
;
555 static int require_homehost
= 1;
556 void homehostline(char *line
)
560 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
561 if (strcasecmp(w
, "<ignore>") == 0)
562 require_homehost
= 0;
563 else if (home_host
== NULL
) {
564 if (strcasecmp(w
, "<none>") == 0)
565 home_host
= xstrdup("");
567 home_host
= xstrdup(w
);
572 static char *home_cluster
= NULL
;
573 void homeclusterline(char *line
)
577 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
578 if (home_cluster
== NULL
) {
579 if (strcasecmp(w
, "<none>") == 0)
580 home_cluster
= xstrdup("");
582 home_cluster
= xstrdup(w
);
587 static int monitor_delay
;
588 void monitordelayline(char *line
)
592 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
593 if (monitor_delay
== 0)
594 monitor_delay
= strtol(w
, NULL
, 10);
598 char auto_yes
[] = "yes";
599 char auto_no
[] = "no";
600 char auto_homehost
[] = "homehost";
602 static int auto_seen
= 0;
603 void autoline(char *line
)
608 char *dflt
= auto_yes
;
617 * Parse the 'auto' line creating policy statements for the 'auto'
620 * The default is 'yes' but the 'auto' line might over-ride that.
621 * Words in the line are processed in order with the first
624 * +version - that version can be assembled
625 * -version - that version cannot be auto-assembled
626 * yes or +all - any other version can be assembled
627 * no or -all - no other version can be assembled.
628 * homehost - any array associated by 'homehost' to this
629 * host can be assembled.
632 * +ddf -0.90 homehost -all
633 * will auto-assemble any ddf array, no 0.90 array, and
634 * any other array (imsm, 1.x) if and only if it is identified
635 * as belonging to this host.
637 * We translate that to policy by creating 'auto=yes' when we see
638 * a '+version' line, 'auto=no' if we see '-version' before 'homehost',
639 * or 'auto=homehost' if we see '-version' after 'homehost'.
640 * When we see yes, no, +all or -all we stop and any version that hasn't
641 * been seen gets an appropriate auto= entry.
645 * If environment variable MDADM_CONF_AUTO is defined, then
646 * it is prepended to the auto line. This allow a script
647 * to easily disable some metadata types.
649 w
= getenv("MDADM_CONF_AUTO");
651 char *l
= xstrdup(w
);
653 w
= strtok(l
, " \t");
655 char *nw
= dl_strdup(w
);
658 w
= strtok(NULL
, " \t");
663 for (super_cnt
= 0; superlist
[super_cnt
]; super_cnt
++)
665 seen
= xcalloc(super_cnt
, 1);
667 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
670 if (strcasecmp(w
, "yes") == 0) {
674 if (strcasecmp(w
, "no") == 0) {
676 dflt
= auto_homehost
;
681 if (strcasecmp(w
, "homehost") == 0) {
687 else if (w
[0] == '-') {
695 if (strcasecmp(w
+ 1, "all") == 0) {
699 for (i
= 0; superlist
[i
]; i
++) {
700 const char *version
= superlist
[i
]->name
;
701 if (strcasecmp(w
+ 1, version
) == 0)
703 /* 1 matches 1.x, 0 matches 0.90 */
704 if (version
[1] == '.' && strlen(w
+ 1) == 1 &&
707 /* 1.anything matches 1.x */
708 if (strcmp(version
, "1.x") == 0 &&
709 strncmp(w
+ 1, "1.", 2) == 0)
712 if (superlist
[i
] == NULL
)
713 /* ignore this word */
716 /* already know about this metadata */
718 policy_add(rule_policy
, pol_auto
, val
, pol_metadata
,
719 superlist
[i
]->name
, NULL
);
722 for (i
= 0; i
< super_cnt
; i
++)
724 policy_add(rule_policy
, pol_auto
, dflt
, pol_metadata
,
725 superlist
[i
]->name
, NULL
);
732 static char *conffile
= NULL
;
733 void set_conffile(char *file
)
738 void conf_file(FILE *f
)
741 while ((line
= conf_line(f
))) {
742 switch(match_keyword(line
)) {
765 homeclusterline(line
);
771 policyline(line
, rule_policy
);
774 policyline(line
, rule_part
);
780 monitordelayline(line
);
783 pr_err("Unknown keyword %s\n", line
);
794 void conf_file_or_dir(FILE *f
)
799 struct fname
*list
= NULL
;
801 fstat(fileno(f
), &st
);
802 if (S_ISREG(st
.st_mode
))
804 else if (!S_ISDIR(st
.st_mode
))
806 #if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
807 dir
= fdopendir(fileno(f
));
810 while ((dp
= readdir(dir
)) != NULL
) {
812 struct fname
*fn
, **p
;
815 if (dp
->d_name
[0] == '.')
817 l
= strlen(dp
->d_name
);
818 if (l
< 6 || strcmp(dp
->d_name
+ l
- 5, ".conf") != 0)
820 fn
= xmalloc(sizeof(*fn
) + l
+ 1);
821 strcpy(fn
->name
, dp
->d_name
);
823 *p
&& strcmp((*p
)->name
, fn
->name
) < 0;
832 struct fname
*fn
= list
;
834 fd
= openat(fileno(f
), fn
->name
, O_RDONLY
);
838 f2
= fdopen(fd
, "r");
850 void load_conffile(void)
853 char *confdir
= NULL
;
858 if (conffile
== NULL
) {
859 conffile
= DefaultConfFile
;
860 confdir
= DefaultConfDir
;
863 if (strcmp(conffile
, "partitions") == 0) {
864 char *list
= dl_strdup("DEV");
866 dl_add(list
, dl_strdup("partitions"));
869 } else if (strcmp(conffile
, "none") != 0) {
870 f
= fopen(conffile
, "r");
871 /* Debian chose to relocate mdadm.conf into /etc/mdadm/.
872 * To allow Debian users to compile from clean source and still
873 * have a working mdadm, we read /etc/mdadm/mdadm.conf
874 * if /etc/mdadm.conf doesn't exist
876 if (f
== NULL
&& conffile
== DefaultConfFile
) {
877 f
= fopen(DefaultAltConfFile
, "r");
879 conffile
= DefaultAltConfFile
;
880 confdir
= DefaultAltConfDir
;
888 f
= fopen(confdir
, "r");
895 /* If there was no AUTO line, process an empty line
896 * now so that the MDADM_CONF_AUTO env var gets processed.
898 head
= dl_strdup("AUTO");
906 char *conf_get_mailaddr(void)
912 char *conf_get_mailfrom(void)
915 return alert_mail_from
;
918 char *conf_get_program(void)
921 return alert_program
;
924 char *conf_get_homehost(int *require_homehostp
)
927 if (require_homehostp
)
928 *require_homehostp
= require_homehost
;
932 char *conf_get_homecluster(void)
938 int conf_get_monitor_delay(void)
941 return monitor_delay
;
944 struct createinfo
*conf_get_create_info(void)
950 struct mddev_ident
*conf_get_ident(char *dev
)
952 struct mddev_ident
*rv
;
955 while (dev
&& rv
&& (rv
->devname
== NULL
||
956 !devname_matches(dev
, rv
->devname
)))
961 static void append_dlist(struct mddev_dev
**dlp
, struct mddev_dev
*list
)
968 struct mddev_dev
*conf_get_devs()
973 static struct mddev_dev
*dlist
= NULL
;
977 struct mddev_dev
*t
= dlist
;
985 if (cdevlist
== NULL
) {
986 /* default to 'partitions' and 'containers' */
987 dlist
= load_partitions();
988 append_dlist(&dlist
, load_containers());
991 for (cd
= cdevlist
; cd
; cd
= cd
->next
) {
992 if (strcasecmp(cd
->name
, "partitions") == 0)
993 append_dlist(&dlist
, load_partitions());
994 else if (strcasecmp(cd
->name
, "containers") == 0)
995 append_dlist(&dlist
, load_containers());
997 glob(cd
->name
, flags
, NULL
, &globbuf
);
998 flags
|= GLOB_APPEND
;
1001 if (flags
& GLOB_APPEND
) {
1002 for (i
= 0; i
< globbuf
.gl_pathc
; i
++) {
1003 struct mddev_dev
*t
;
1004 t
= xcalloc(1, sizeof(*t
));
1005 t
->devname
= xstrdup(globbuf
.gl_pathv
[i
]);
1008 /* printf("one dev is %s\n", t->devname);*/
1016 int conf_test_dev(char *devname
)
1018 struct conf_dev
*cd
;
1019 if (cdevlist
== NULL
)
1020 /* allow anything by default */
1022 for (cd
= cdevlist
; cd
; cd
= cd
->next
) {
1023 if (strcasecmp(cd
->name
, "partitions") == 0)
1025 if (fnmatch(cd
->name
, devname
, FNM_PATHNAME
) == 0)
1031 int conf_test_metadata(const char *version
, struct dev_policy
*pol
, int is_homehost
)
1033 /* If anyone said 'yes', that sticks.
1034 * else if homehost applies, use that
1035 * else if there is a 'no', say 'no'.
1038 struct dev_policy
*p
;
1039 int no
= 0, found_homehost
= 0;
1042 pol
= pol_find(pol
, pol_auto
);
1043 pol_for_each(p
, pol
, version
) {
1044 if (strcmp(p
->value
, "yes") == 0)
1046 if (strcmp(p
->value
, "homehost") == 0)
1048 if (strcmp(p
->value
, "no") == 0)
1051 if (is_homehost
&& found_homehost
)
1058 int match_oneof(char *devices
, char *devname
)
1060 /* check if one of the comma separated patterns in devices
1064 while (devices
&& *devices
) {
1067 devices
= strchr(devices
, ',');
1069 devices
= p
+ strlen(p
);
1070 if (devices
-p
< 1024) {
1071 strncpy(patn
, p
, devices
- p
);
1072 patn
[devices
-p
] = 0;
1073 if (fnmatch(patn
, devname
, FNM_PATHNAME
) == 0)
1076 if (*devices
== ',')
1082 int devname_matches(char *name
, char *match
)
1084 /* See if the given array name matches the
1085 * given match from config file.
1087 * First strip and /dev/md/ or /dev/, then
1088 * see if there might be a numeric match of
1092 if (strncmp(name
, "/dev/md/", 8) == 0)
1094 else if (strncmp(name
, "/dev/", 5) == 0)
1097 if (strncmp(match
, "/dev/md/", 8) == 0)
1099 else if (strncmp(match
, "/dev/", 5) == 0)
1102 if (strncmp(name
, "md", 2) == 0 && isdigit(name
[2]))
1104 if (strncmp(match
, "md", 2) == 0 && isdigit(match
[2]))
1107 return (strcmp(name
, match
) == 0);
1110 int conf_name_is_free(char *name
)
1112 /* Check if this name is already taken by an ARRAY entry in
1114 * It can be taken either by a match on devname, name, or
1117 struct mddev_ident
*dev
;
1120 for (dev
= mddevlist
; dev
; dev
= dev
->next
) {
1122 if (dev
->devname
&& devname_matches(name
, dev
->devname
))
1124 if (dev
->name
[0] && devname_matches(name
, dev
->name
))
1126 sprintf(nbuf
, "%d", dev
->super_minor
);
1127 if (dev
->super_minor
!= UnSet
&& devname_matches(name
, nbuf
))
1133 struct mddev_ident
*conf_match(struct supertype
*st
,
1134 struct mdinfo
*info
,
1136 int verbose
, int *rvp
)
1138 struct mddev_ident
*array_list
, *match
;
1139 array_list
= conf_get_ident(NULL
);
1141 for (; array_list
; array_list
= array_list
->next
) {
1142 if (array_list
->uuid_set
&&
1143 same_uuid(array_list
->uuid
, info
->uuid
,
1144 st
->ss
->swapuuid
) == 0) {
1145 if (verbose
>= 2 && array_list
->devname
)
1146 pr_err("UUID differs from %s.\n",
1147 array_list
->devname
);
1150 if (array_list
->name
[0] &&
1151 strcasecmp(array_list
->name
, info
->name
) != 0) {
1152 if (verbose
>= 2 && array_list
->devname
)
1153 pr_err("Name differs from %s.\n",
1154 array_list
->devname
);
1157 if (array_list
->devices
&& devname
&&
1158 !match_oneof(array_list
->devices
, devname
)) {
1159 if (verbose
>= 2 && array_list
->devname
)
1160 pr_err("Not a listed device for %s.\n",
1161 array_list
->devname
);
1164 if (array_list
->super_minor
!= UnSet
&&
1165 array_list
->super_minor
!= info
->array
.md_minor
) {
1166 if (verbose
>= 2 && array_list
->devname
)
1167 pr_err("Different super-minor to %s.\n",
1168 array_list
->devname
);
1171 if (!array_list
->uuid_set
&& !array_list
->name
[0] &&
1172 !array_list
->devices
&& array_list
->super_minor
== UnSet
) {
1173 if (verbose
>= 2 && array_list
->devname
)
1174 pr_err("%s doesn't have any identifying information.\n",
1175 array_list
->devname
);
1178 /* FIXME, should I check raid_disks and level too?? */
1182 if (match
->devname
&& array_list
->devname
)
1183 pr_err("we match both %s and %s - cannot decide which to use.\n",
1185 array_list
->devname
);
1187 pr_err("multiple lines in mdadm.conf match\n");
1199 int conf_verify_devnames(struct mddev_ident
*array_list
)
1201 struct mddev_ident
*a1
, *a2
;
1203 for (a1
= array_list
; a1
; a1
= a1
->next
) {
1206 if (strcmp(a1
->devname
, "<ignore>") == 0)
1208 for (a2
= a1
->next
; a2
; a2
= a2
->next
) {
1211 if (strcmp(a1
->devname
, a2
->devname
) != 0)
1214 if (a1
->uuid_set
&& a2
->uuid_set
) {
1216 __fname_from_uuid(a1
->uuid
, 0, nbuf
, ':');
1217 pr_err("Devices %s and ",
1219 __fname_from_uuid(a2
->uuid
, 0, nbuf
, ':');
1221 "%s have the same name: %s\n",
1224 pr_err("Device %s given twice in config file\n", a1
->devname
);