]>
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. */
198 int parse_auto(char *str
, char *msg
, int config
)
201 if (str
== NULL
|| *str
== 0)
203 else if (strcasecmp(str
,"no")==0)
205 else if (strcasecmp(str
,"yes")==0)
207 else if (strcasecmp(str
,"md")==0)
210 /* There might be digits, and maybe a hypen, at the end */
211 char *e
= str
+ strlen(str
);
214 while (e
> str
&& isdigit(e
[-1]))
218 if (num
<= 0) num
= 1;
220 if (e
> str
&& e
[-1] == '-')
223 if ((len
== 2 && strncasecmp(str
,"md",2)==0)) {
224 autof
= config
? 5 : 3;
225 } else if ((len
== 3 && strncasecmp(str
,"yes",3)==0)) {
227 } else if ((len
== 3 && strncasecmp(str
,"mdp",3)==0)) {
228 autof
= config
? 6 : 4;
229 } else if ((len
== 1 && strncasecmp(str
,"p",1)==0) ||
230 (len
>= 4 && strncasecmp(str
,"part",4)==0)) {
233 pr_err("%s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
234 " optionally followed by a number.\n",
243 static void createline(char *line
)
248 for (w
=dl_next(line
); w
!=line
; w
=dl_next(w
)) {
249 if (strncasecmp(w
, "auto=", 5) == 0)
250 createinfo
.autof
= parse_auto(w
+5, "auto=", 1);
251 else if (strncasecmp(w
, "owner=", 6) == 0) {
253 pr_err("missing owner name\n");
256 createinfo
.uid
= strtoul(w
+6, &ep
, 10);
262 createinfo
.uid
= pw
->pw_uid
;
264 pr_err("CREATE user %s not found\n", w
+6);
266 } else if (strncasecmp(w
, "group=", 6) == 0) {
268 pr_err("missing group name\n");
271 createinfo
.gid
= strtoul(w
+6, &ep
, 10);
277 createinfo
.gid
= gr
->gr_gid
;
279 pr_err("CREATE group %s not found\n", w
+6);
281 } else if (strncasecmp(w
, "mode=", 5) == 0) {
283 pr_err("missing CREATE mode\n");
286 createinfo
.mode
= strtoul(w
+5, &ep
, 8);
288 createinfo
.mode
= 0600;
289 pr_err("unrecognised CREATE mode %s\n",
292 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
293 /* style of metadata to use by default */
295 for (i
=0; superlist
[i
] && !createinfo
.supertype
; i
++)
296 createinfo
.supertype
=
297 superlist
[i
]->match_metadata_desc(w
+9);
298 if (!createinfo
.supertype
)
299 pr_err("metadata format %s unknown, ignoring\n",
301 } else if (strncasecmp(w
, "symlinks=yes", 12) == 0)
302 createinfo
.symlinks
= 1;
303 else if (strncasecmp(w
, "symlinks=no", 11) == 0)
304 createinfo
.symlinks
= 0;
305 else if (strncasecmp(w
, "names=yes", 12) == 0)
306 createinfo
.names
= 1;
307 else if (strncasecmp(w
, "names=no", 11) == 0)
308 createinfo
.names
= 0;
310 pr_err("unrecognised word on CREATE line: %s\n",
316 void devline(char *line
)
321 for (w
=dl_next(line
); w
!= line
; w
=dl_next(w
)) {
322 if (w
[0] == '/' || strcasecmp(w
, "partitions") == 0 ||
323 strcasecmp(w
, "containers") == 0) {
324 cd
= xmalloc(sizeof(*cd
));
325 cd
->name
= xstrdup(w
);
329 pr_err("unreconised word on DEVICE line: %s\n",
335 struct mddev_ident
*mddevlist
= NULL
;
336 struct mddev_ident
**mddevlp
= &mddevlist
;
338 static int is_number(char *w
)
340 /* check if there are 1 or more digits and nothing else */
342 while (*w
&& isdigit(*w
)) {
346 return (digits
&& ! *w
);
349 void arrayline(char *line
)
353 struct mddev_ident mis
;
354 struct mddev_ident
*mi
;
357 mis
.super_minor
= UnSet
;
359 mis
.raid_disks
= UnSet
;
363 mis
.spare_group
= NULL
;
368 mis
.bitmap_file
= NULL
;
370 mis
.container
= NULL
;
373 for (w
=dl_next(line
); w
!=line
; w
=dl_next(w
)) {
374 if (w
[0] == '/' || strchr(w
, '=') == NULL
) {
375 /* This names the device, or is '<ignore>'.
376 * The rules match those in create_mddev.
382 * or anything that doesn't start '/' or '<'
384 if (strcasecmp(w
, "<ignore>") == 0 ||
385 strncmp(w
, "/dev/md/", 8) == 0 ||
386 (w
[0] != '/' && w
[0] != '<') ||
387 (strncmp(w
, "/dev/md", 7) == 0 &&
389 (strncmp(w
, "/dev/md_d", 9) == 0 &&
392 /* This is acceptable */;
394 pr_err("only give one "
395 "device per ARRAY line: %s and %s\n",
400 pr_err("%s is an invalid name for "
401 "an md device - ignored.\n", w
);
403 } else if (strncasecmp(w
, "uuid=", 5)==0 ) {
405 pr_err("only specify uuid once, %s ignored.\n",
408 if (parse_uuid(w
+5, mis
.uuid
))
411 pr_err("bad uuid: %s\n", w
);
413 } else if (strncasecmp(w
, "super-minor=", 12)==0 ) {
414 if (mis
.super_minor
!= UnSet
)
415 pr_err("only specify super-minor once, %s ignored.\n",
419 int minor
= strtol(w
+12, &endptr
, 10);
421 if (w
[12]==0 || endptr
[0]!=0 || minor
< 0)
422 pr_err("invalid super-minor number: %s\n",
425 mis
.super_minor
= minor
;
427 } else if (strncasecmp(w
, "name=", 5)==0) {
429 pr_err("only specify name once, %s ignored.\n",
431 else if (strlen(w
+5) > 32)
432 pr_err("name too long, ignoring %s\n", w
);
434 strcpy(mis
.name
, w
+5);
436 } else if (strncasecmp(w
, "bitmap=", 7) == 0) {
438 pr_err("only specify bitmap file once. %s ignored\n",
441 mis
.bitmap_file
= xstrdup(w
+7);
443 } else if (strncasecmp(w
, "devices=", 8 ) == 0 ) {
445 pr_err("only specify devices once (use a comma separated list). %s ignored\n",
448 mis
.devices
= xstrdup(w
+8);
449 } else if (strncasecmp(w
, "spare-group=", 12) == 0 ) {
451 pr_err("only specify one spare group per array. %s ignored.\n",
454 mis
.spare_group
= xstrdup(w
+12);
455 } else if (strncasecmp(w
, "level=", 6) == 0 ) {
456 /* this is mainly for compatability with --brief output */
457 mis
.level
= map_name(pers
, w
+6);
458 } else if (strncasecmp(w
, "disks=", 6) == 0 ) {
459 /* again, for compat */
460 mis
.raid_disks
= atoi(w
+6);
461 } else if (strncasecmp(w
, "num-devices=", 12) == 0 ) {
462 /* again, for compat */
463 mis
.raid_disks
= atoi(w
+12);
464 } else if (strncasecmp(w
, "spares=", 7) == 0 ) {
465 /* for warning if not all spares present */
466 mis
.spare_disks
= atoi(w
+7);
467 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
468 /* style of metadata on the devices. */
471 for(i
=0; superlist
[i
] && !mis
.st
; i
++)
472 mis
.st
= superlist
[i
]->match_metadata_desc(w
+9);
475 pr_err("metadata format %s unknown, ignored.\n", w
+9);
476 } else if (strncasecmp(w
, "auto=", 5) == 0 ) {
477 /* whether to create device special files as needed */
478 mis
.autof
= parse_auto(w
+5, "auto type", 0);
479 } else if (strncasecmp(w
, "member=", 7) == 0) {
480 /* subarray within a container */
481 mis
.member
= xstrdup(w
+7);
482 } else if (strncasecmp(w
, "container=", 10) == 0) {
483 /* the container holding this subarray. Either a device name
485 mis
.container
= xstrdup(w
+10);
487 pr_err("unrecognised word on ARRAY line: %s\n",
491 if (mis
.uuid_set
== 0 && mis
.devices
== NULL
&&
492 mis
.super_minor
== UnSet
&& mis
.name
[0] == 0 &&
493 (mis
.container
== NULL
|| mis
.member
== NULL
))
494 pr_err("ARRAY line %s has no identity information.\n", mis
.devname
);
496 mi
= xmalloc(sizeof(*mi
));
498 mi
->devname
= mis
.devname
? xstrdup(mis
.devname
) : NULL
;
505 static char *alert_email
= NULL
;
506 void mailline(char *line
)
510 for (w
=dl_next(line
); w
!= line
; w
=dl_next(w
))
511 if (alert_email
== NULL
)
512 alert_email
= xstrdup(w
);
515 static char *alert_mail_from
= NULL
;
516 void mailfromline(char *line
)
520 for (w
=dl_next(line
); w
!= line
; w
=dl_next(w
)) {
521 if (alert_mail_from
== NULL
)
522 alert_mail_from
= xstrdup(w
);
526 if (xasprintf(&t
, "%s %s", alert_mail_from
, w
) > 0) {
527 free(alert_mail_from
);
534 static char *alert_program
= NULL
;
535 void programline(char *line
)
539 for (w
=dl_next(line
); w
!= line
; w
=dl_next(w
))
540 if (alert_program
== NULL
)
541 alert_program
= xstrdup(w
);
544 static char *home_host
= NULL
;
545 static int require_homehost
= 1;
546 void homehostline(char *line
)
550 for (w
=dl_next(line
); w
!= line
; w
=dl_next(w
)) {
551 if (strcasecmp(w
, "<ignore>")==0)
552 require_homehost
= 0;
553 else if (home_host
== NULL
) {
554 if (strcasecmp(w
, "<none>")==0)
555 home_host
= xstrdup("");
557 home_host
= xstrdup(w
);
562 char auto_yes
[] = "yes";
563 char auto_no
[] = "no";
564 char auto_homehost
[] = "homehost";
566 static int auto_seen
= 0;
567 void autoline(char *line
)
572 char *dflt
= auto_yes
;
580 /* Parse the 'auto' line creating policy statements for the 'auto' policy.
582 * The default is 'yes' but the 'auto' line might over-ride that.
583 * Words in the line are processed in order with the first
586 * +version - that version can be assembled
587 * -version - that version cannot be auto-assembled
588 * yes or +all - any other version can be assembled
589 * no or -all - no other version can be assembled.
590 * homehost - any array associated by 'homehost' to this
591 * host can be assembled.
594 * +ddf -0.90 homehost -all
595 * will auto-assemble any ddf array, no 0.90 array, and
596 * any other array (imsm, 1.x) if and only if it is identified
597 * as belonging to this host.
599 * We translate that to policy by creating 'auto=yes' when we see
600 * a '+version' line, 'auto=no' if we see '-version' before 'homehost',
601 * or 'auto=homehost' if we see '-version' after 'homehost'.
602 * When we see yes, no, +all or -all we stop and any version that hasn't
603 * been seen gets an appropriate auto= entry.
606 /* If environment variable MDADM_CONF_AUTO is defined, then
607 * it is prepended to the auto line. This allow a script
608 * to easily disable some metadata types.
610 w
= getenv("MDADM_CONF_AUTO");
612 char *l
= xstrdup(w
);
614 w
= strtok(l
, " \t");
616 char *nw
= dl_strdup(w
);
619 w
= strtok(NULL
, " \t");
624 for (super_cnt
= 0; superlist
[super_cnt
]; super_cnt
++)
626 seen
= xcalloc(super_cnt
, 1);
628 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
631 if (strcasecmp(w
, "yes") == 0) {
635 if (strcasecmp(w
, "no") == 0) {
637 dflt
= auto_homehost
;
642 if (strcasecmp(w
, "homehost") == 0) {
648 else if (w
[0] == '-') {
656 if (strcasecmp(w
+1, "all") == 0) {
660 for (i
= 0; superlist
[i
]; i
++) {
661 const char *version
= superlist
[i
]->name
;
662 if (strcasecmp(w
+1, version
) == 0)
664 /* 1 matches 1.x, 0 matches 0.90 */
665 if (version
[1] == '.' &&
669 /* 1.anything matches 1.x */
670 if (strcmp(version
, "1.x") == 0 &&
671 strncmp(w
+1, "1.", 2) == 0)
674 if (superlist
[i
] == NULL
)
675 /* ignore this word */
678 /* already know about this metadata */
680 policy_add(rule_policy
, pol_auto
, val
, pol_metadata
, superlist
[i
]->name
, NULL
);
683 for (i
= 0; i
< super_cnt
; i
++)
685 policy_add(rule_policy
, pol_auto
, dflt
, pol_metadata
, superlist
[i
]->name
, NULL
);
692 static char *conffile
= NULL
;
693 void set_conffile(char *file
)
698 void conf_file(FILE *f
)
701 while ((line
=conf_line(f
))) {
702 switch(match_keyword(line
)) {
728 policyline(line
, rule_policy
);
731 policyline(line
, rule_part
);
734 pr_err("Unknown keyword %s\n", line
);
745 void conf_file_or_dir(FILE *f
)
750 struct fname
*list
= NULL
;
752 fstat(fileno(f
), &st
);
753 if (S_ISREG(st
.st_mode
))
755 else if (!S_ISDIR(st
.st_mode
))
757 #if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
758 dir
= fdopendir(fileno(f
));
761 while ((dp
= readdir(dir
)) != NULL
) {
763 struct fname
*fn
, **p
;
766 if (dp
->d_name
[0] == '.')
768 l
= strlen(dp
->d_name
);
769 if (l
< 6 || strcmp(dp
->d_name
+l
-5, ".conf") != 0)
771 fn
= xmalloc(sizeof(*fn
)+l
+1);
772 strcpy(fn
->name
, dp
->d_name
);
774 *p
&& strcmp((*p
)->name
, fn
->name
) < 0;
783 struct fname
*fn
= list
;
785 fd
= openat(fileno(f
), fn
->name
, O_RDONLY
);
789 f2
= fdopen(fd
, "r");
801 void load_conffile(void)
804 char *confdir
= NULL
;
809 if (conffile
== NULL
) {
810 conffile
= DefaultConfFile
;
811 confdir
= DefaultConfDir
;
814 if (strcmp(conffile
, "partitions")==0) {
815 char *list
= dl_strdup("DEV");
817 dl_add(list
, dl_strdup("partitions"));
820 } else if (strcmp(conffile
, "none") != 0) {
821 f
= fopen(conffile
, "r");
822 /* Debian chose to relocate mdadm.conf into /etc/mdadm/.
823 * To allow Debian users to compile from clean source and still
824 * have a working mdadm, we read /etc/mdadm/mdadm.conf
825 * if /etc/mdadm.conf doesn't exist
828 conffile
== DefaultConfFile
) {
829 f
= fopen(DefaultAltConfFile
, "r");
831 conffile
= DefaultAltConfFile
;
832 confdir
= DefaultAltConfDir
;
840 f
= fopen(confdir
, "r");
847 /* If there was no AUTO line, process an empty line
848 * now so that the MDADM_CONF_AUTO env var gets processed.
850 head
= dl_strdup("AUTO");
858 char *conf_get_mailaddr(void)
864 char *conf_get_mailfrom(void)
867 return alert_mail_from
;
870 char *conf_get_program(void)
873 return alert_program
;
876 char *conf_get_homehost(int *require_homehostp
)
879 if (require_homehostp
)
880 *require_homehostp
= require_homehost
;
884 struct createinfo
*conf_get_create_info(void)
890 struct mddev_ident
*conf_get_ident(char *dev
)
892 struct mddev_ident
*rv
;
895 while (dev
&& rv
&& (rv
->devname
== NULL
896 || !devname_matches(dev
, rv
->devname
)))
901 static void append_dlist(struct mddev_dev
**dlp
, struct mddev_dev
*list
)
908 struct mddev_dev
*conf_get_devs()
913 static struct mddev_dev
*dlist
= NULL
;
917 struct mddev_dev
*t
= dlist
;
925 if (cdevlist
== NULL
) {
926 /* default to 'partitions' and 'containers' */
927 dlist
= load_partitions();
928 append_dlist(&dlist
, load_containers());
931 for (cd
=cdevlist
; cd
; cd
=cd
->next
) {
932 if (strcasecmp(cd
->name
, "partitions")==0)
933 append_dlist(&dlist
, load_partitions());
934 else if (strcasecmp(cd
->name
, "containers")==0)
935 append_dlist(&dlist
, load_containers());
937 glob(cd
->name
, flags
, NULL
, &globbuf
);
938 flags
|= GLOB_APPEND
;
941 if (flags
& GLOB_APPEND
) {
942 for (i
=0; i
<globbuf
.gl_pathc
; i
++) {
943 struct mddev_dev
*t
= xmalloc(sizeof(*t
));
944 memset(t
, 0, sizeof(*t
));
945 t
->devname
= xstrdup(globbuf
.gl_pathv
[i
]);
948 /* printf("one dev is %s\n", t->devname);*/
956 int conf_test_dev(char *devname
)
959 if (cdevlist
== NULL
)
960 /* allow anything by default */
962 for (cd
= cdevlist
; cd
; cd
= cd
->next
) {
963 if (strcasecmp(cd
->name
, "partitions") == 0)
965 if (fnmatch(cd
->name
, devname
, FNM_PATHNAME
) == 0)
971 int conf_test_metadata(const char *version
, struct dev_policy
*pol
, int is_homehost
)
973 /* If anyone said 'yes', that sticks.
974 * else if homehost applies, use that
975 * else if there is a 'no', say 'no'.
978 struct dev_policy
*p
;
979 int no
=0, found_homehost
=0;
982 pol
= pol_find(pol
, pol_auto
);
983 pol_for_each(p
, pol
, version
) {
984 if (strcmp(p
->value
, "yes") == 0)
986 if (strcmp(p
->value
, "homehost") == 0)
988 if (strcmp(p
->value
, "no") == 0)
991 if (is_homehost
&& found_homehost
)
998 int match_oneof(char *devices
, char *devname
)
1000 /* check if one of the comma separated patterns in devices
1004 while (devices
&& *devices
) {
1007 devices
= strchr(devices
, ',');
1009 devices
= p
+ strlen(p
);
1010 if (devices
-p
< 1024) {
1011 strncpy(patn
, p
, devices
-p
);
1012 patn
[devices
-p
] = 0;
1013 if (fnmatch(patn
, devname
, FNM_PATHNAME
)==0)
1016 if (*devices
== ',')
1022 int devname_matches(char *name
, char *match
)
1024 /* See if the given array name matches the
1025 * given match from config file.
1027 * First strip and /dev/md/ or /dev/, then
1028 * see if there might be a numeric match of
1032 if (strncmp(name
, "/dev/md/", 8) == 0)
1034 else if (strncmp(name
, "/dev/", 5) == 0)
1037 if (strncmp(match
, "/dev/md/", 8) == 0)
1039 else if (strncmp(match
, "/dev/", 5) == 0)
1042 if (strncmp(name
, "md", 2) == 0 &&
1045 if (strncmp(match
, "md", 2) == 0 &&
1049 return (strcmp(name
, match
) == 0);
1052 int conf_name_is_free(char *name
)
1054 /* Check if this name is already taken by an ARRAY entry in
1056 * It can be taken either by a match on devname, name, or
1059 struct mddev_ident
*dev
;
1062 for (dev
= mddevlist
; dev
; dev
= dev
->next
) {
1064 if (dev
->devname
&& devname_matches(name
, dev
->devname
))
1066 if (dev
->name
[0] && devname_matches(name
, dev
->name
))
1068 sprintf(nbuf
, "%d", dev
->super_minor
);
1069 if (dev
->super_minor
!= UnSet
&&
1070 devname_matches(name
, nbuf
))
1076 struct mddev_ident
*conf_match(struct supertype
*st
,
1077 struct mdinfo
*info
,
1079 int verbose
, int *rvp
)
1081 struct mddev_ident
*array_list
, *match
;
1082 array_list
= conf_get_ident(NULL
);
1084 for (; array_list
; array_list
= array_list
->next
) {
1085 if (array_list
->uuid_set
&&
1086 same_uuid(array_list
->uuid
, info
->uuid
, st
->ss
->swapuuid
)
1088 if (verbose
>= 2 && array_list
->devname
)
1089 pr_err("UUID differs from %s.\n",
1090 array_list
->devname
);
1093 if (array_list
->name
[0] &&
1094 strcasecmp(array_list
->name
, info
->name
) != 0) {
1095 if (verbose
>= 2 && array_list
->devname
)
1096 pr_err("Name differs from %s.\n",
1097 array_list
->devname
);
1100 if (array_list
->devices
&& devname
&&
1101 !match_oneof(array_list
->devices
, devname
)) {
1102 if (verbose
>= 2 && array_list
->devname
)
1103 pr_err("Not a listed device for %s.\n",
1104 array_list
->devname
);
1107 if (array_list
->super_minor
!= UnSet
&&
1108 array_list
->super_minor
!= info
->array
.md_minor
) {
1109 if (verbose
>= 2 && array_list
->devname
)
1110 pr_err("Different super-minor to %s.\n",
1111 array_list
->devname
);
1114 if (!array_list
->uuid_set
&&
1115 !array_list
->name
[0] &&
1116 !array_list
->devices
&&
1117 array_list
->super_minor
== UnSet
) {
1118 if (verbose
>= 2 && array_list
->devname
)
1119 pr_err("%s doesn't have any identifying"
1121 array_list
->devname
);
1124 /* FIXME, should I check raid_disks and level too?? */
1128 if (match
->devname
&& array_list
->devname
)
1129 pr_err("we match both %s and %s - "
1130 "cannot decide which to use.\n",
1132 array_list
->devname
);
1134 pr_err("multiple lines in mdadm.conf"
1147 int conf_verify_devnames(struct mddev_ident
*array_list
)
1149 struct mddev_ident
*a1
, *a2
;
1151 for (a1
= array_list
; a1
; a1
= a1
->next
) {
1154 if (strcmp(a1
->devname
, "<ignore>") == 0)
1156 for (a2
= a1
->next
; a2
; a2
= a2
->next
) {
1159 if (strcmp(a1
->devname
, a2
->devname
) != 0)
1162 if (a1
->uuid_set
&& a2
->uuid_set
) {
1164 __fname_from_uuid(a1
->uuid
, 0, nbuf
, ':');
1165 pr_err("Devices %s and ",
1167 __fname_from_uuid(a2
->uuid
, 0, nbuf
, ':');
1169 "%s have the same name: %s\n",
1172 pr_err("Device %s given twice"
1173 " in config file\n", a1
->devname
);