]>
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 * is_devname_ignore() - check if &devname is a special "<ignore>" keyword.
125 bool is_devname_ignore(char *devname
)
127 static const char keyword
[] = "<ignore>";
129 if (strcasecmp(devname
, keyword
) == 0)
135 * ident_init() - Set defaults.
136 * @ident: ident pointer, not NULL.
138 inline void ident_init(struct mddev_ident
*ident
)
142 ident
->assembled
= false;
144 ident
->bitmap_fd
= -1;
145 ident
->bitmap_file
= NULL
;
146 ident
->container
= NULL
;
147 ident
->devices
= NULL
;
148 ident
->devname
= NULL
;
149 ident
->level
= UnSet
;
150 ident
->member
= NULL
;
153 ident
->raid_disks
= UnSet
;
154 ident
->spare_group
= NULL
;
155 ident
->spare_disks
= 0;
157 ident
->super_minor
= UnSet
;
163 struct conf_dev
*next
;
167 struct mddev_dev
*load_partitions(void)
169 FILE *f
= fopen("/proc/partitions", "r");
171 struct mddev_dev
*rv
= NULL
;
174 pr_err("cannot open /proc/partitions\n");
177 while (fgets(buf
, 1024, f
)) {
185 major
= strtoul(buf
, &mp
, 10);
186 if (mp
== buf
|| *mp
!= ' ')
188 minor
= strtoul(mp
, NULL
, 10);
190 name
= map_dev(major
, minor
, 1);
193 d
= xcalloc(1, sizeof(*d
));
194 d
->devname
= xstrdup(name
);
202 struct mddev_dev
*load_containers(void)
204 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
205 struct mdstat_ent
*ent
;
207 struct mddev_dev
*rv
= NULL
;
208 struct map_ent
*map
= NULL
, *me
;
213 for (ent
= mdstat
; ent
; ent
= ent
->next
)
214 if (ent
->metadata_version
&&
215 strncmp(ent
->metadata_version
, "external:", 9) == 0 &&
216 !is_subarray(&ent
->metadata_version
[9])) {
217 d
= xcalloc(1, sizeof(*d
));
218 me
= map_by_devnm(&map
, ent
->devnm
);
220 d
->devname
= xstrdup(me
->path
);
221 else if (asprintf(&d
->devname
, "/dev/%s", ent
->devnm
) < 0) {
235 struct createinfo createinfo
= {
236 .autof
= 2, /* by default, create devices with standard names */
237 .names
= 0, /* By default, stick with numbered md devices. */
238 .bblist
= 1, /* Use a bad block list by default */
247 int parse_auto(char *str
, char *msg
, int config
)
250 if (str
== NULL
|| *str
== 0)
252 else if (strcasecmp(str
, "no") == 0)
254 else if (strcasecmp(str
, "yes") == 0)
256 else if (strcasecmp(str
, "md") == 0)
257 autof
= config
? 5:3;
259 /* There might be digits, and maybe a hypen, at the end */
260 char *e
= str
+ strlen(str
);
263 while (e
> str
&& isdigit(e
[-1]))
270 if (e
> str
&& e
[-1] == '-')
273 if ((len
== 2 && strncasecmp(str
, "md", 2) == 0)) {
274 autof
= config
? 5 : 3;
275 } else if ((len
== 3 && strncasecmp(str
, "yes", 3) == 0)) {
277 } else if ((len
== 3 && strncasecmp(str
, "mdp", 3) == 0)) {
278 autof
= config
? 6 : 4;
279 } else if ((len
== 1 && strncasecmp(str
, "p", 1) == 0) ||
280 (len
>= 4 && strncasecmp(str
, "part", 4) == 0)) {
283 pr_err("%s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
284 " optionally followed by a number.\n",
293 static void createline(char *line
)
298 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
299 if (strncasecmp(w
, "auto=", 5) == 0)
300 createinfo
.autof
= parse_auto(w
+ 5, "auto=", 1);
301 else if (strncasecmp(w
, "owner=", 6) == 0) {
303 pr_err("missing owner name\n");
306 createinfo
.uid
= strtoul(w
+ 6, &ep
, 10);
310 pw
= getpwnam(w
+ 6);
312 createinfo
.uid
= pw
->pw_uid
;
314 pr_err("CREATE user %s not found\n",
317 } else if (strncasecmp(w
, "group=", 6) == 0) {
319 pr_err("missing group name\n");
322 createinfo
.gid
= strtoul(w
+ 6, &ep
, 10);
326 gr
= getgrnam(w
+ 6);
328 createinfo
.gid
= gr
->gr_gid
;
330 pr_err("CREATE group %s not found\n",
333 } else if (strncasecmp(w
, "mode=", 5) == 0) {
335 pr_err("missing CREATE mode\n");
338 createinfo
.mode
= strtoul(w
+ 5, &ep
, 8);
340 createinfo
.mode
= 0600;
341 pr_err("unrecognised CREATE mode %s\n",
344 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
345 /* style of metadata to use by default */
347 for (i
= 0; superlist
[i
] && !createinfo
.supertype
; i
++)
348 createinfo
.supertype
= superlist
[i
]->match_metadata_desc(w
+ 9);
349 if (!createinfo
.supertype
)
350 pr_err("metadata format %s unknown, ignoring\n",
352 } else if (strncasecmp(w
, "names=yes", 12) == 0)
353 createinfo
.names
= 1;
354 else if (strncasecmp(w
, "names=no", 11) == 0)
355 createinfo
.names
= 0;
356 else if (strncasecmp(w
, "bbl=no", 11) == 0)
357 createinfo
.bblist
= 0;
358 else if (strncasecmp(w
, "bbl=yes", 11) == 0)
359 createinfo
.bblist
= 1;
361 pr_err("unrecognised word on CREATE line: %s\n",
367 void devline(char *line
)
372 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
373 if (w
[0] == '/' || strcasecmp(w
, "partitions") == 0 ||
374 strcasecmp(w
, "containers") == 0) {
375 cd
= xmalloc(sizeof(*cd
));
376 cd
->name
= xstrdup(w
);
380 pr_err("unreconised word on DEVICE line: %s\n", w
);
385 struct mddev_ident
*mddevlist
= NULL
;
386 struct mddev_ident
**mddevlp
= &mddevlist
;
388 void arrayline(char *line
)
392 struct mddev_ident mis
;
393 struct mddev_ident
*mi
;
397 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
398 if (w
[0] == '/' || strchr(w
, '=') == NULL
) {
399 /* This names the device, or is '<ignore>'.
400 * The rules match those in create_mddev.
406 * or anything that doesn't start '/' or '<'
408 if (is_devname_ignore(w
) == true ||
409 strncmp(w
, DEV_MD_DIR
, DEV_MD_DIR_LEN
) == 0 ||
410 (w
[0] != '/' && w
[0] != '<') ||
411 is_devname_md_numbered(w
) == true ||
412 is_devname_md_d_numbered(w
) == true) {
413 /* This is acceptable */;
415 pr_err("only give one device per ARRAY line: %s and %s\n",
420 pr_err("%s is an invalid name for an md device - ignored.\n", w
);
422 } else if (strncasecmp(w
, "uuid=", 5) == 0) {
424 pr_err("only specify uuid once, %s ignored.\n",
427 if (parse_uuid(w
+ 5, mis
.uuid
))
430 pr_err("bad uuid: %s\n", w
);
432 } else if (strncasecmp(w
, "super-minor=", 12) == 0) {
433 if (mis
.super_minor
!= UnSet
)
434 pr_err("only specify super-minor once, %s ignored.\n",
438 int minor
= strtol(w
+ 12, &endptr
, 10);
440 if (w
[12] == 0 || endptr
[0] != 0 || minor
< 0)
441 pr_err("invalid super-minor number: %s\n",
444 mis
.super_minor
= minor
;
446 } else if (strncasecmp(w
, "name=", 5) == 0) {
448 pr_err("only specify name once, %s ignored.\n",
450 else if (strlen(w
+ 5) > 32)
451 pr_err("name too long, ignoring %s\n", w
);
453 strcpy(mis
.name
, w
+ 5);
455 } else if (strncasecmp(w
, "bitmap=", 7) == 0) {
457 pr_err("only specify bitmap file once. %s ignored\n",
460 mis
.bitmap_file
= xstrdup(w
+ 7);
462 } else if (strncasecmp(w
, "devices=", 8 ) == 0) {
464 pr_err("only specify devices once (use a comma separated list). %s ignored\n",
467 mis
.devices
= xstrdup(w
+ 8);
468 } else if (strncasecmp(w
, "spare-group=", 12) == 0) {
470 pr_err("only specify one spare group per array. %s ignored.\n",
473 mis
.spare_group
= xstrdup(w
+ 12);
474 } else if (strncasecmp(w
, "level=", 6) == 0 ) {
475 /* this is mainly for compatability with --brief output */
476 mis
.level
= map_name(pers
, w
+ 6);
477 } else if (strncasecmp(w
, "disks=", 6) == 0) {
478 /* again, for compat */
479 mis
.raid_disks
= atoi(w
+ 6);
480 } else if (strncasecmp(w
, "num-devices=", 12) == 0) {
481 /* again, for compat */
482 mis
.raid_disks
= atoi(w
+ 12);
483 } else if (strncasecmp(w
, "spares=", 7) == 0) {
484 /* for warning if not all spares present */
485 mis
.spare_disks
= atoi(w
+ 7);
486 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
487 /* style of metadata on the devices. */
490 for(i
=0; superlist
[i
] && !mis
.st
; i
++)
491 mis
.st
= superlist
[i
]->
492 match_metadata_desc(w
+ 9);
495 pr_err("metadata format %s unknown, ignored.\n",
497 } else if (strncasecmp(w
, "auto=", 5) == 0 ) {
498 /* whether to create device special files as needed */
499 mis
.autof
= parse_auto(w
+ 5, "auto type", 0);
500 } else if (strncasecmp(w
, "member=", 7) == 0) {
501 /* subarray within a container */
502 mis
.member
= xstrdup(w
+ 7);
503 } else if (strncasecmp(w
, "container=", 10) == 0) {
504 /* The container holding this subarray.
505 * Either a device name or a uuid */
506 mis
.container
= xstrdup(w
+ 10);
508 pr_err("unrecognised word on ARRAY line: %s\n",
512 if (mis
.uuid_set
== 0 && mis
.devices
== NULL
&&
513 mis
.super_minor
== UnSet
&& mis
.name
[0] == 0 &&
514 (mis
.container
== NULL
|| mis
.member
== NULL
))
515 pr_err("ARRAY line %s has no identity information.\n",
518 mi
= xmalloc(sizeof(*mi
));
520 mi
->devname
= mis
.devname
? xstrdup(mis
.devname
) : NULL
;
527 static char *alert_email
= NULL
;
528 void mailline(char *line
)
532 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
))
533 if (alert_email
== NULL
)
534 alert_email
= xstrdup(w
);
537 static char *alert_mail_from
= NULL
;
538 void mailfromline(char *line
)
542 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
543 if (alert_mail_from
== NULL
)
544 alert_mail_from
= xstrdup(w
);
548 if (xasprintf(&t
, "%s %s", alert_mail_from
, w
) > 0) {
549 free(alert_mail_from
);
556 static char *alert_program
= NULL
;
557 void programline(char *line
)
561 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
))
562 if (alert_program
== NULL
)
563 alert_program
= xstrdup(w
);
566 static char *home_host
= NULL
;
567 static int require_homehost
= 1;
568 void homehostline(char *line
)
572 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
573 if (is_devname_ignore(w
) == true)
574 require_homehost
= 0;
575 else if (home_host
== NULL
) {
576 if (strcasecmp(w
, "<none>") == 0)
577 home_host
= xstrdup("");
579 home_host
= xstrdup(w
);
584 static char *home_cluster
= NULL
;
585 void homeclusterline(char *line
)
589 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
590 if (home_cluster
== NULL
) {
591 if (strcasecmp(w
, "<none>") == 0)
592 home_cluster
= xstrdup("");
594 home_cluster
= xstrdup(w
);
599 static int monitor_delay
;
600 void monitordelayline(char *line
)
604 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
605 if (monitor_delay
== 0)
606 monitor_delay
= strtol(w
, NULL
, 10);
610 char auto_yes
[] = "yes";
611 char auto_no
[] = "no";
612 char auto_homehost
[] = "homehost";
614 static int auto_seen
= 0;
615 void autoline(char *line
)
620 char *dflt
= auto_yes
;
629 * Parse the 'auto' line creating policy statements for the 'auto'
632 * The default is 'yes' but the 'auto' line might over-ride that.
633 * Words in the line are processed in order with the first
636 * +version - that version can be assembled
637 * -version - that version cannot be auto-assembled
638 * yes or +all - any other version can be assembled
639 * no or -all - no other version can be assembled.
640 * homehost - any array associated by 'homehost' to this
641 * host can be assembled.
644 * +ddf -0.90 homehost -all
645 * will auto-assemble any ddf array, no 0.90 array, and
646 * any other array (imsm, 1.x) if and only if it is identified
647 * as belonging to this host.
649 * We translate that to policy by creating 'auto=yes' when we see
650 * a '+version' line, 'auto=no' if we see '-version' before 'homehost',
651 * or 'auto=homehost' if we see '-version' after 'homehost'.
652 * When we see yes, no, +all or -all we stop and any version that hasn't
653 * been seen gets an appropriate auto= entry.
657 * If environment variable MDADM_CONF_AUTO is defined, then
658 * it is prepended to the auto line. This allow a script
659 * to easily disable some metadata types.
661 w
= getenv("MDADM_CONF_AUTO");
663 char *l
= xstrdup(w
);
665 w
= strtok(l
, " \t");
667 char *nw
= dl_strdup(w
);
670 w
= strtok(NULL
, " \t");
675 for (super_cnt
= 0; superlist
[super_cnt
]; super_cnt
++)
677 seen
= xcalloc(super_cnt
, 1);
679 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
682 if (strcasecmp(w
, "yes") == 0) {
686 if (strcasecmp(w
, "no") == 0) {
688 dflt
= auto_homehost
;
693 if (strcasecmp(w
, "homehost") == 0) {
699 else if (w
[0] == '-') {
707 if (strcasecmp(w
+ 1, "all") == 0) {
711 for (i
= 0; superlist
[i
]; i
++) {
712 const char *version
= superlist
[i
]->name
;
713 if (strcasecmp(w
+ 1, version
) == 0)
715 /* 1 matches 1.x, 0 matches 0.90 */
716 if (version
[1] == '.' && strlen(w
+ 1) == 1 &&
719 /* 1.anything matches 1.x */
720 if (strcmp(version
, "1.x") == 0 &&
721 strncmp(w
+ 1, "1.", 2) == 0)
724 if (superlist
[i
] == NULL
)
725 /* ignore this word */
728 /* already know about this metadata */
730 policy_add(rule_policy
, pol_auto
, val
, pol_metadata
,
731 superlist
[i
]->name
, NULL
);
734 for (i
= 0; i
< super_cnt
; i
++)
736 policy_add(rule_policy
, pol_auto
, dflt
, pol_metadata
,
737 superlist
[i
]->name
, NULL
);
744 static char *conffile
= NULL
;
745 void set_conffile(char *file
)
750 void conf_file(FILE *f
)
753 while ((line
= conf_line(f
))) {
754 switch(match_keyword(line
)) {
777 homeclusterline(line
);
783 policyline(line
, rule_policy
);
786 policyline(line
, rule_part
);
792 monitordelayline(line
);
795 pr_err("Unknown keyword %s\n", line
);
806 void conf_file_or_dir(FILE *f
)
811 struct fname
*list
= NULL
;
813 fstat(fileno(f
), &st
);
814 if (S_ISREG(st
.st_mode
))
816 else if (!S_ISDIR(st
.st_mode
))
818 #if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
819 dir
= fdopendir(fileno(f
));
822 while ((dp
= readdir(dir
)) != NULL
) {
824 struct fname
*fn
, **p
;
827 if (dp
->d_name
[0] == '.')
829 l
= strlen(dp
->d_name
);
830 if (l
< 6 || strcmp(dp
->d_name
+ l
- 5, ".conf") != 0)
832 fn
= xmalloc(sizeof(*fn
) + l
+ 1);
833 strcpy(fn
->name
, dp
->d_name
);
835 *p
&& strcmp((*p
)->name
, fn
->name
) < 0;
844 struct fname
*fn
= list
;
846 fd
= openat(fileno(f
), fn
->name
, O_RDONLY
);
850 f2
= fdopen(fd
, "r");
862 void load_conffile(void)
865 char *confdir
= NULL
;
870 if (conffile
== NULL
) {
871 conffile
= DefaultConfFile
;
872 confdir
= DefaultConfDir
;
875 if (strcmp(conffile
, "partitions") == 0) {
876 char *list
= dl_strdup("DEV");
878 dl_add(list
, dl_strdup("partitions"));
881 } else if (strcmp(conffile
, "none") != 0) {
882 f
= fopen(conffile
, "r");
883 /* Debian chose to relocate mdadm.conf into /etc/mdadm/.
884 * To allow Debian users to compile from clean source and still
885 * have a working mdadm, we read /etc/mdadm/mdadm.conf
886 * if /etc/mdadm.conf doesn't exist
888 if (f
== NULL
&& conffile
== DefaultConfFile
) {
889 f
= fopen(DefaultAltConfFile
, "r");
891 conffile
= DefaultAltConfFile
;
892 confdir
= DefaultAltConfDir
;
900 f
= fopen(confdir
, "r");
907 /* If there was no AUTO line, process an empty line
908 * now so that the MDADM_CONF_AUTO env var gets processed.
910 head
= dl_strdup("AUTO");
918 char *conf_get_mailaddr(void)
924 char *conf_get_mailfrom(void)
927 return alert_mail_from
;
930 char *conf_get_program(void)
933 return alert_program
;
936 char *conf_get_homehost(int *require_homehostp
)
939 if (require_homehostp
)
940 *require_homehostp
= require_homehost
;
944 char *conf_get_homecluster(void)
950 int conf_get_monitor_delay(void)
953 return monitor_delay
;
956 struct createinfo
*conf_get_create_info(void)
962 struct mddev_ident
*conf_get_ident(char *dev
)
964 struct mddev_ident
*rv
;
967 while (dev
&& rv
&& (rv
->devname
== NULL
||
968 !devname_matches(dev
, rv
->devname
)))
973 static void append_dlist(struct mddev_dev
**dlp
, struct mddev_dev
*list
)
980 struct mddev_dev
*conf_get_devs()
985 static struct mddev_dev
*dlist
= NULL
;
989 struct mddev_dev
*t
= dlist
;
997 if (cdevlist
== NULL
) {
998 /* default to 'partitions' and 'containers' */
999 dlist
= load_partitions();
1000 append_dlist(&dlist
, load_containers());
1003 for (cd
= cdevlist
; cd
; cd
= cd
->next
) {
1004 if (strcasecmp(cd
->name
, "partitions") == 0)
1005 append_dlist(&dlist
, load_partitions());
1006 else if (strcasecmp(cd
->name
, "containers") == 0)
1007 append_dlist(&dlist
, load_containers());
1009 glob(cd
->name
, flags
, NULL
, &globbuf
);
1010 flags
|= GLOB_APPEND
;
1013 if (flags
& GLOB_APPEND
) {
1014 for (i
= 0; i
< globbuf
.gl_pathc
; i
++) {
1015 struct mddev_dev
*t
;
1016 t
= xcalloc(1, sizeof(*t
));
1017 t
->devname
= xstrdup(globbuf
.gl_pathv
[i
]);
1020 /* printf("one dev is %s\n", t->devname);*/
1028 int conf_test_dev(char *devname
)
1030 struct conf_dev
*cd
;
1031 if (cdevlist
== NULL
)
1032 /* allow anything by default */
1034 for (cd
= cdevlist
; cd
; cd
= cd
->next
) {
1035 if (strcasecmp(cd
->name
, "partitions") == 0)
1037 if (fnmatch(cd
->name
, devname
, FNM_PATHNAME
) == 0)
1043 int conf_test_metadata(const char *version
, struct dev_policy
*pol
, int is_homehost
)
1045 /* If anyone said 'yes', that sticks.
1046 * else if homehost applies, use that
1047 * else if there is a 'no', say 'no'.
1050 struct dev_policy
*p
;
1051 int no
= 0, found_homehost
= 0;
1054 pol
= pol_find(pol
, pol_auto
);
1055 pol_for_each(p
, pol
, version
) {
1056 if (strcmp(p
->value
, "yes") == 0)
1058 if (strcmp(p
->value
, "homehost") == 0)
1060 if (strcmp(p
->value
, "no") == 0)
1063 if (is_homehost
&& found_homehost
)
1070 int match_oneof(char *devices
, char *devname
)
1072 /* check if one of the comma separated patterns in devices
1076 while (devices
&& *devices
) {
1079 devices
= strchr(devices
, ',');
1081 devices
= p
+ strlen(p
);
1082 if (devices
-p
< 1024) {
1083 strncpy(patn
, p
, devices
- p
);
1084 patn
[devices
-p
] = 0;
1085 if (fnmatch(patn
, devname
, FNM_PATHNAME
) == 0)
1088 if (*devices
== ',')
1094 int devname_matches(char *name
, char *match
)
1096 /* See if the given array name matches the
1097 * given match from config file.
1099 * First strip and /dev/md/ or /dev/, then
1100 * see if there might be a numeric match of
1104 if (strncmp(name
, DEV_MD_DIR
, DEV_MD_DIR_LEN
) == 0)
1105 name
+= DEV_MD_DIR_LEN
;
1106 else if (strncmp(name
, "/dev/", 5) == 0)
1109 if (strncmp(match
, DEV_MD_DIR
, DEV_MD_DIR_LEN
) == 0)
1110 match
+= DEV_MD_DIR_LEN
;
1111 else if (strncmp(match
, "/dev/", 5) == 0)
1114 if (strncmp(name
, "md", 2) == 0 && isdigit(name
[2]))
1116 if (strncmp(match
, "md", 2) == 0 && isdigit(match
[2]))
1119 return (strcmp(name
, match
) == 0);
1122 int conf_name_is_free(char *name
)
1124 /* Check if this name is already taken by an ARRAY entry in
1126 * It can be taken either by a match on devname, name, or
1129 struct mddev_ident
*dev
;
1132 for (dev
= mddevlist
; dev
; dev
= dev
->next
) {
1134 if (dev
->devname
&& devname_matches(name
, dev
->devname
))
1136 if (dev
->name
[0] && devname_matches(name
, dev
->name
))
1138 sprintf(nbuf
, "%d", dev
->super_minor
);
1139 if (dev
->super_minor
!= UnSet
&& devname_matches(name
, nbuf
))
1145 struct mddev_ident
*conf_match(struct supertype
*st
,
1146 struct mdinfo
*info
,
1148 int verbose
, int *rvp
)
1150 struct mddev_ident
*array_list
, *match
;
1151 array_list
= conf_get_ident(NULL
);
1153 for (; array_list
; array_list
= array_list
->next
) {
1154 if (array_list
->uuid_set
&&
1155 same_uuid(array_list
->uuid
, info
->uuid
,
1156 st
->ss
->swapuuid
) == 0) {
1157 if (verbose
>= 2 && array_list
->devname
)
1158 pr_err("UUID differs from %s.\n",
1159 array_list
->devname
);
1162 if (array_list
->name
[0] &&
1163 strcasecmp(array_list
->name
, info
->name
) != 0) {
1164 if (verbose
>= 2 && array_list
->devname
)
1165 pr_err("Name differs from %s.\n",
1166 array_list
->devname
);
1169 if (array_list
->devices
&& devname
&&
1170 !match_oneof(array_list
->devices
, devname
)) {
1171 if (verbose
>= 2 && array_list
->devname
)
1172 pr_err("Not a listed device for %s.\n",
1173 array_list
->devname
);
1176 if (array_list
->super_minor
!= UnSet
&&
1177 array_list
->super_minor
!= info
->array
.md_minor
) {
1178 if (verbose
>= 2 && array_list
->devname
)
1179 pr_err("Different super-minor to %s.\n",
1180 array_list
->devname
);
1183 if (!array_list
->uuid_set
&& !array_list
->name
[0] &&
1184 !array_list
->devices
&& array_list
->super_minor
== UnSet
) {
1185 if (verbose
>= 2 && array_list
->devname
)
1186 pr_err("%s doesn't have any identifying information.\n",
1187 array_list
->devname
);
1190 /* FIXME, should I check raid_disks and level too?? */
1194 if (match
->devname
&& array_list
->devname
)
1195 pr_err("we match both %s and %s - cannot decide which to use.\n",
1197 array_list
->devname
);
1199 pr_err("multiple lines in mdadm.conf match\n");
1211 int conf_verify_devnames(struct mddev_ident
*array_list
)
1213 struct mddev_ident
*a1
, *a2
;
1215 for (a1
= array_list
; a1
; a1
= a1
->next
) {
1218 if (strcmp(a1
->devname
, "<ignore>") == 0)
1220 for (a2
= a1
->next
; a2
; a2
= a2
->next
) {
1223 if (strcmp(a1
->devname
, a2
->devname
) != 0)
1226 if (a1
->uuid_set
&& a2
->uuid_set
) {
1228 __fname_from_uuid(a1
->uuid
, 0, nbuf
, ':');
1229 pr_err("Devices %s and ",
1231 __fname_from_uuid(a2
->uuid
, 0, nbuf
, ':');
1233 "%s have the same name: %s\n",
1236 pr_err("Device %s given twice in config file\n", a1
->devname
);