]>
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
, LTEnd
};
85 [Devices
] = "devices",
87 [Mailaddr
] = "mailaddr",
88 [Mailfrom
] = "mailfrom",
89 [Program
] = "program",
90 [CreateDev
]= "create",
91 [Homehost
] = "homehost",
92 [HomeCluster
] = "homecluster",
95 [PartPolicy
]="part-policy",
100 * match_keyword returns an index into the keywords array, or -1 for no match
101 * case is ignored, and at least three characters must be given
104 int match_keyword(char *word
)
106 int len
= strlen(word
);
111 for (n
= 0; keywords
[n
]; n
++) {
112 if (strncasecmp(word
, keywords
[n
], len
) == 0)
120 struct conf_dev
*next
;
124 struct mddev_dev
*load_partitions(void)
126 FILE *f
= fopen("/proc/partitions", "r");
128 struct mddev_dev
*rv
= NULL
;
131 pr_err("cannot open /proc/partitions\n");
134 while (fgets(buf
, 1024, f
)) {
142 major
= strtoul(buf
, &mp
, 10);
143 if (mp
== buf
|| *mp
!= ' ')
145 minor
= strtoul(mp
, NULL
, 10);
147 name
= map_dev(major
, minor
, 1);
150 d
= xcalloc(1, sizeof(*d
));
151 d
->devname
= xstrdup(name
);
159 struct mddev_dev
*load_containers(void)
161 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
162 struct mdstat_ent
*ent
;
164 struct mddev_dev
*rv
= NULL
;
165 struct map_ent
*map
= NULL
, *me
;
170 for (ent
= mdstat
; ent
; ent
= ent
->next
)
171 if (ent
->metadata_version
&&
172 strncmp(ent
->metadata_version
, "external:", 9) == 0 &&
173 !is_subarray(&ent
->metadata_version
[9])) {
174 d
= xcalloc(1, sizeof(*d
));
175 me
= map_by_devnm(&map
, ent
->devnm
);
177 d
->devname
= xstrdup(me
->path
);
178 else if (asprintf(&d
->devname
, "/dev/%s", ent
->devnm
) < 0) {
192 struct createinfo createinfo
= {
193 .autof
= 2, /* by default, create devices with standard names */
195 .names
= 0, /* By default, stick with numbered md devices. */
196 .bblist
= 1, /* Use a bad block list by default */
205 int parse_auto(char *str
, char *msg
, int config
)
208 if (str
== NULL
|| *str
== 0)
210 else if (strcasecmp(str
, "no") == 0)
212 else if (strcasecmp(str
, "yes") == 0)
214 else if (strcasecmp(str
, "md") == 0)
215 autof
= config
? 5:3;
217 /* There might be digits, and maybe a hypen, at the end */
218 char *e
= str
+ strlen(str
);
221 while (e
> str
&& isdigit(e
[-1]))
228 if (e
> str
&& e
[-1] == '-')
231 if ((len
== 2 && strncasecmp(str
, "md", 2) == 0)) {
232 autof
= config
? 5 : 3;
233 } else if ((len
== 3 && strncasecmp(str
, "yes", 3) == 0)) {
235 } else if ((len
== 3 && strncasecmp(str
, "mdp", 3) == 0)) {
236 autof
= config
? 6 : 4;
237 } else if ((len
== 1 && strncasecmp(str
, "p", 1) == 0) ||
238 (len
>= 4 && strncasecmp(str
, "part", 4) == 0)) {
241 pr_err("%s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
242 " optionally followed by a number.\n",
251 static void createline(char *line
)
256 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
257 if (strncasecmp(w
, "auto=", 5) == 0)
258 createinfo
.autof
= parse_auto(w
+ 5, "auto=", 1);
259 else if (strncasecmp(w
, "owner=", 6) == 0) {
261 pr_err("missing owner name\n");
264 createinfo
.uid
= strtoul(w
+ 6, &ep
, 10);
268 pw
= getpwnam(w
+ 6);
270 createinfo
.uid
= pw
->pw_uid
;
272 pr_err("CREATE user %s not found\n",
275 } else if (strncasecmp(w
, "group=", 6) == 0) {
277 pr_err("missing group name\n");
280 createinfo
.gid
= strtoul(w
+ 6, &ep
, 10);
284 gr
= getgrnam(w
+ 6);
286 createinfo
.gid
= gr
->gr_gid
;
288 pr_err("CREATE group %s not found\n",
291 } else if (strncasecmp(w
, "mode=", 5) == 0) {
293 pr_err("missing CREATE mode\n");
296 createinfo
.mode
= strtoul(w
+ 5, &ep
, 8);
298 createinfo
.mode
= 0600;
299 pr_err("unrecognised CREATE mode %s\n",
302 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
303 /* style of metadata to use by default */
305 for (i
= 0; superlist
[i
] && !createinfo
.supertype
; i
++)
306 createinfo
.supertype
= superlist
[i
]->match_metadata_desc(w
+ 9);
307 if (!createinfo
.supertype
)
308 pr_err("metadata format %s unknown, ignoring\n",
310 } else if (strncasecmp(w
, "symlinks=yes", 12) == 0)
311 createinfo
.symlinks
= 1;
312 else if (strncasecmp(w
, "symlinks=no", 11) == 0)
313 createinfo
.symlinks
= 0;
314 else if (strncasecmp(w
, "names=yes", 12) == 0)
315 createinfo
.names
= 1;
316 else if (strncasecmp(w
, "names=no", 11) == 0)
317 createinfo
.names
= 0;
318 else if (strncasecmp(w
, "bbl=no", 11) == 0)
319 createinfo
.bblist
= 0;
320 else if (strncasecmp(w
, "bbl=yes", 11) == 0)
321 createinfo
.bblist
= 1;
323 pr_err("unrecognised word on CREATE line: %s\n",
329 void devline(char *line
)
334 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
335 if (w
[0] == '/' || strcasecmp(w
, "partitions") == 0 ||
336 strcasecmp(w
, "containers") == 0) {
337 cd
= xmalloc(sizeof(*cd
));
338 cd
->name
= xstrdup(w
);
342 pr_err("unreconised word on DEVICE line: %s\n", w
);
347 struct mddev_ident
*mddevlist
= NULL
;
348 struct mddev_ident
**mddevlp
= &mddevlist
;
350 static int is_number(char *w
)
352 /* check if there are 1 or more digits and nothing else */
354 while (*w
&& isdigit(*w
)) {
358 return (digits
&& ! *w
);
361 void arrayline(char *line
)
365 struct mddev_ident mis
;
366 struct mddev_ident
*mi
;
369 mis
.super_minor
= UnSet
;
371 mis
.raid_disks
= UnSet
;
375 mis
.spare_group
= NULL
;
380 mis
.bitmap_file
= NULL
;
382 mis
.container
= NULL
;
385 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
386 if (w
[0] == '/' || strchr(w
, '=') == NULL
) {
387 /* This names the device, or is '<ignore>'.
388 * The rules match those in create_mddev.
394 * or anything that doesn't start '/' or '<'
396 if (strcasecmp(w
, "<ignore>") == 0 ||
397 strncmp(w
, "/dev/md/", 8) == 0 ||
398 (w
[0] != '/' && w
[0] != '<') ||
399 (strncmp(w
, "/dev/md", 7) == 0 &&
401 (strncmp(w
, "/dev/md_d", 9) == 0 &&
403 /* This is acceptable */;
405 pr_err("only give one device per ARRAY line: %s and %s\n",
410 pr_err("%s is an invalid name for an md device - ignored.\n", w
);
412 } else if (strncasecmp(w
, "uuid=", 5) == 0) {
414 pr_err("only specify uuid once, %s ignored.\n",
417 if (parse_uuid(w
+ 5, mis
.uuid
))
420 pr_err("bad uuid: %s\n", w
);
422 } else if (strncasecmp(w
, "super-minor=", 12) == 0) {
423 if (mis
.super_minor
!= UnSet
)
424 pr_err("only specify super-minor once, %s ignored.\n",
428 int minor
= strtol(w
+ 12, &endptr
, 10);
430 if (w
[12] == 0 || endptr
[0] != 0 || minor
< 0)
431 pr_err("invalid super-minor number: %s\n",
434 mis
.super_minor
= minor
;
436 } else if (strncasecmp(w
, "name=", 5) == 0) {
438 pr_err("only specify name once, %s ignored.\n",
440 else if (strlen(w
+ 5) > 32)
441 pr_err("name too long, ignoring %s\n", w
);
443 strcpy(mis
.name
, w
+ 5);
445 } else if (strncasecmp(w
, "bitmap=", 7) == 0) {
447 pr_err("only specify bitmap file once. %s ignored\n",
450 mis
.bitmap_file
= xstrdup(w
+ 7);
452 } else if (strncasecmp(w
, "devices=", 8 ) == 0) {
454 pr_err("only specify devices once (use a comma separated list). %s ignored\n",
457 mis
.devices
= xstrdup(w
+ 8);
458 } else if (strncasecmp(w
, "spare-group=", 12) == 0) {
460 pr_err("only specify one spare group per array. %s ignored.\n",
463 mis
.spare_group
= xstrdup(w
+ 12);
464 } else if (strncasecmp(w
, "level=", 6) == 0 ) {
465 /* this is mainly for compatability with --brief output */
466 mis
.level
= map_name(pers
, w
+ 6);
467 } else if (strncasecmp(w
, "disks=", 6) == 0) {
468 /* again, for compat */
469 mis
.raid_disks
= atoi(w
+ 6);
470 } else if (strncasecmp(w
, "num-devices=", 12) == 0) {
471 /* again, for compat */
472 mis
.raid_disks
= atoi(w
+ 12);
473 } else if (strncasecmp(w
, "spares=", 7) == 0) {
474 /* for warning if not all spares present */
475 mis
.spare_disks
= atoi(w
+ 7);
476 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
477 /* style of metadata on the devices. */
480 for(i
=0; superlist
[i
] && !mis
.st
; i
++)
481 mis
.st
= superlist
[i
]->
482 match_metadata_desc(w
+ 9);
485 pr_err("metadata format %s unknown, ignored.\n",
487 } else if (strncasecmp(w
, "auto=", 5) == 0 ) {
488 /* whether to create device special files as needed */
489 mis
.autof
= parse_auto(w
+ 5, "auto type", 0);
490 } else if (strncasecmp(w
, "member=", 7) == 0) {
491 /* subarray within a container */
492 mis
.member
= xstrdup(w
+ 7);
493 } else if (strncasecmp(w
, "container=", 10) == 0) {
494 /* The container holding this subarray.
495 * Either a device name or a uuid */
496 mis
.container
= xstrdup(w
+ 10);
498 pr_err("unrecognised word on ARRAY line: %s\n",
502 if (mis
.uuid_set
== 0 && mis
.devices
== NULL
&&
503 mis
.super_minor
== UnSet
&& mis
.name
[0] == 0 &&
504 (mis
.container
== NULL
|| mis
.member
== NULL
))
505 pr_err("ARRAY line %s has no identity information.\n",
508 mi
= xmalloc(sizeof(*mi
));
510 mi
->devname
= mis
.devname
? xstrdup(mis
.devname
) : NULL
;
517 static char *alert_email
= NULL
;
518 void mailline(char *line
)
522 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
))
523 if (alert_email
== NULL
)
524 alert_email
= xstrdup(w
);
527 static char *alert_mail_from
= NULL
;
528 void mailfromline(char *line
)
532 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
533 if (alert_mail_from
== NULL
)
534 alert_mail_from
= xstrdup(w
);
538 if (xasprintf(&t
, "%s %s", alert_mail_from
, w
) > 0) {
539 free(alert_mail_from
);
546 static char *alert_program
= NULL
;
547 void programline(char *line
)
551 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
))
552 if (alert_program
== NULL
)
553 alert_program
= xstrdup(w
);
556 static char *home_host
= NULL
;
557 static int require_homehost
= 1;
558 void homehostline(char *line
)
562 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
563 if (strcasecmp(w
, "<ignore>") == 0)
564 require_homehost
= 0;
565 else if (home_host
== NULL
) {
566 if (strcasecmp(w
, "<none>") == 0)
567 home_host
= xstrdup("");
569 home_host
= xstrdup(w
);
574 static char *home_cluster
= NULL
;
575 void homeclusterline(char *line
)
579 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
580 if (home_cluster
== NULL
) {
581 if (strcasecmp(w
, "<none>") == 0)
582 home_cluster
= xstrdup("");
584 home_cluster
= xstrdup(w
);
589 char auto_yes
[] = "yes";
590 char auto_no
[] = "no";
591 char auto_homehost
[] = "homehost";
593 static int auto_seen
= 0;
594 void autoline(char *line
)
599 char *dflt
= auto_yes
;
608 * Parse the 'auto' line creating policy statements for the 'auto'
611 * The default is 'yes' but the 'auto' line might over-ride that.
612 * Words in the line are processed in order with the first
615 * +version - that version can be assembled
616 * -version - that version cannot be auto-assembled
617 * yes or +all - any other version can be assembled
618 * no or -all - no other version can be assembled.
619 * homehost - any array associated by 'homehost' to this
620 * host can be assembled.
623 * +ddf -0.90 homehost -all
624 * will auto-assemble any ddf array, no 0.90 array, and
625 * any other array (imsm, 1.x) if and only if it is identified
626 * as belonging to this host.
628 * We translate that to policy by creating 'auto=yes' when we see
629 * a '+version' line, 'auto=no' if we see '-version' before 'homehost',
630 * or 'auto=homehost' if we see '-version' after 'homehost'.
631 * When we see yes, no, +all or -all we stop and any version that hasn't
632 * been seen gets an appropriate auto= entry.
636 * If environment variable MDADM_CONF_AUTO is defined, then
637 * it is prepended to the auto line. This allow a script
638 * to easily disable some metadata types.
640 w
= getenv("MDADM_CONF_AUTO");
642 char *l
= xstrdup(w
);
644 w
= strtok(l
, " \t");
646 char *nw
= dl_strdup(w
);
649 w
= strtok(NULL
, " \t");
654 for (super_cnt
= 0; superlist
[super_cnt
]; super_cnt
++)
656 seen
= xcalloc(super_cnt
, 1);
658 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
661 if (strcasecmp(w
, "yes") == 0) {
665 if (strcasecmp(w
, "no") == 0) {
667 dflt
= auto_homehost
;
672 if (strcasecmp(w
, "homehost") == 0) {
678 else if (w
[0] == '-') {
686 if (strcasecmp(w
+ 1, "all") == 0) {
690 for (i
= 0; superlist
[i
]; i
++) {
691 const char *version
= superlist
[i
]->name
;
692 if (strcasecmp(w
+ 1, version
) == 0)
694 /* 1 matches 1.x, 0 matches 0.90 */
695 if (version
[1] == '.' && strlen(w
+ 1) == 1 &&
698 /* 1.anything matches 1.x */
699 if (strcmp(version
, "1.x") == 0 &&
700 strncmp(w
+ 1, "1.", 2) == 0)
703 if (superlist
[i
] == NULL
)
704 /* ignore this word */
707 /* already know about this metadata */
709 policy_add(rule_policy
, pol_auto
, val
, pol_metadata
,
710 superlist
[i
]->name
, NULL
);
713 for (i
= 0; i
< super_cnt
; i
++)
715 policy_add(rule_policy
, pol_auto
, dflt
, pol_metadata
,
716 superlist
[i
]->name
, NULL
);
723 static char *conffile
= NULL
;
724 void set_conffile(char *file
)
729 void conf_file(FILE *f
)
732 while ((line
= conf_line(f
))) {
733 switch(match_keyword(line
)) {
756 homeclusterline(line
);
762 policyline(line
, rule_policy
);
765 policyline(line
, rule_part
);
768 pr_err("Unknown keyword %s\n", line
);
779 void conf_file_or_dir(FILE *f
)
784 struct fname
*list
= NULL
;
786 fstat(fileno(f
), &st
);
787 if (S_ISREG(st
.st_mode
))
789 else if (!S_ISDIR(st
.st_mode
))
791 #if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
792 dir
= fdopendir(fileno(f
));
795 while ((dp
= readdir(dir
)) != NULL
) {
797 struct fname
*fn
, **p
;
800 if (dp
->d_name
[0] == '.')
802 l
= strlen(dp
->d_name
);
803 if (l
< 6 || strcmp(dp
->d_name
+ l
- 5, ".conf") != 0)
805 fn
= xmalloc(sizeof(*fn
) + l
+ 1);
806 strcpy(fn
->name
, dp
->d_name
);
808 *p
&& strcmp((*p
)->name
, fn
->name
) < 0;
817 struct fname
*fn
= list
;
819 fd
= openat(fileno(f
), fn
->name
, O_RDONLY
);
823 f2
= fdopen(fd
, "r");
835 void load_conffile(void)
838 char *confdir
= NULL
;
843 if (conffile
== NULL
) {
844 conffile
= DefaultConfFile
;
845 confdir
= DefaultConfDir
;
848 if (strcmp(conffile
, "partitions") == 0) {
849 char *list
= dl_strdup("DEV");
851 dl_add(list
, dl_strdup("partitions"));
854 } else if (strcmp(conffile
, "none") != 0) {
855 f
= fopen(conffile
, "r");
856 /* Debian chose to relocate mdadm.conf into /etc/mdadm/.
857 * To allow Debian users to compile from clean source and still
858 * have a working mdadm, we read /etc/mdadm/mdadm.conf
859 * if /etc/mdadm.conf doesn't exist
861 if (f
== NULL
&& conffile
== DefaultConfFile
) {
862 f
= fopen(DefaultAltConfFile
, "r");
864 conffile
= DefaultAltConfFile
;
865 confdir
= DefaultAltConfDir
;
873 f
= fopen(confdir
, "r");
880 /* If there was no AUTO line, process an empty line
881 * now so that the MDADM_CONF_AUTO env var gets processed.
883 head
= dl_strdup("AUTO");
891 char *conf_get_mailaddr(void)
897 char *conf_get_mailfrom(void)
900 return alert_mail_from
;
903 char *conf_get_program(void)
906 return alert_program
;
909 char *conf_get_homehost(int *require_homehostp
)
912 if (require_homehostp
)
913 *require_homehostp
= require_homehost
;
917 char *conf_get_homecluster(void)
923 struct createinfo
*conf_get_create_info(void)
929 struct mddev_ident
*conf_get_ident(char *dev
)
931 struct mddev_ident
*rv
;
934 while (dev
&& rv
&& (rv
->devname
== NULL
||
935 !devname_matches(dev
, rv
->devname
)))
940 static void append_dlist(struct mddev_dev
**dlp
, struct mddev_dev
*list
)
947 struct mddev_dev
*conf_get_devs()
952 static struct mddev_dev
*dlist
= NULL
;
956 struct mddev_dev
*t
= dlist
;
964 if (cdevlist
== NULL
) {
965 /* default to 'partitions' and 'containers' */
966 dlist
= load_partitions();
967 append_dlist(&dlist
, load_containers());
970 for (cd
= cdevlist
; cd
; cd
= cd
->next
) {
971 if (strcasecmp(cd
->name
, "partitions") == 0)
972 append_dlist(&dlist
, load_partitions());
973 else if (strcasecmp(cd
->name
, "containers") == 0)
974 append_dlist(&dlist
, load_containers());
976 glob(cd
->name
, flags
, NULL
, &globbuf
);
977 flags
|= GLOB_APPEND
;
980 if (flags
& GLOB_APPEND
) {
981 for (i
= 0; i
< globbuf
.gl_pathc
; i
++) {
983 t
= xcalloc(1, sizeof(*t
));
984 t
->devname
= xstrdup(globbuf
.gl_pathv
[i
]);
987 /* printf("one dev is %s\n", t->devname);*/
995 int conf_test_dev(char *devname
)
998 if (cdevlist
== NULL
)
999 /* allow anything by default */
1001 for (cd
= cdevlist
; cd
; cd
= cd
->next
) {
1002 if (strcasecmp(cd
->name
, "partitions") == 0)
1004 if (fnmatch(cd
->name
, devname
, FNM_PATHNAME
) == 0)
1010 int conf_test_metadata(const char *version
, struct dev_policy
*pol
, int is_homehost
)
1012 /* If anyone said 'yes', that sticks.
1013 * else if homehost applies, use that
1014 * else if there is a 'no', say 'no'.
1017 struct dev_policy
*p
;
1018 int no
= 0, found_homehost
= 0;
1021 pol
= pol_find(pol
, pol_auto
);
1022 pol_for_each(p
, pol
, version
) {
1023 if (strcmp(p
->value
, "yes") == 0)
1025 if (strcmp(p
->value
, "homehost") == 0)
1027 if (strcmp(p
->value
, "no") == 0)
1030 if (is_homehost
&& found_homehost
)
1037 int match_oneof(char *devices
, char *devname
)
1039 /* check if one of the comma separated patterns in devices
1043 while (devices
&& *devices
) {
1046 devices
= strchr(devices
, ',');
1048 devices
= p
+ strlen(p
);
1049 if (devices
-p
< 1024) {
1050 strncpy(patn
, p
, devices
- p
);
1051 patn
[devices
-p
] = 0;
1052 if (fnmatch(patn
, devname
, FNM_PATHNAME
) == 0)
1055 if (*devices
== ',')
1061 int devname_matches(char *name
, char *match
)
1063 /* See if the given array name matches the
1064 * given match from config file.
1066 * First strip and /dev/md/ or /dev/, then
1067 * see if there might be a numeric match of
1071 if (strncmp(name
, "/dev/md/", 8) == 0)
1073 else if (strncmp(name
, "/dev/", 5) == 0)
1076 if (strncmp(match
, "/dev/md/", 8) == 0)
1078 else if (strncmp(match
, "/dev/", 5) == 0)
1081 if (strncmp(name
, "md", 2) == 0 && isdigit(name
[2]))
1083 if (strncmp(match
, "md", 2) == 0 && isdigit(match
[2]))
1086 return (strcmp(name
, match
) == 0);
1089 int conf_name_is_free(char *name
)
1091 /* Check if this name is already taken by an ARRAY entry in
1093 * It can be taken either by a match on devname, name, or
1096 struct mddev_ident
*dev
;
1099 for (dev
= mddevlist
; dev
; dev
= dev
->next
) {
1101 if (dev
->devname
&& devname_matches(name
, dev
->devname
))
1103 if (dev
->name
[0] && devname_matches(name
, dev
->name
))
1105 sprintf(nbuf
, "%d", dev
->super_minor
);
1106 if (dev
->super_minor
!= UnSet
&& devname_matches(name
, nbuf
))
1112 struct mddev_ident
*conf_match(struct supertype
*st
,
1113 struct mdinfo
*info
,
1115 int verbose
, int *rvp
)
1117 struct mddev_ident
*array_list
, *match
;
1118 array_list
= conf_get_ident(NULL
);
1120 for (; array_list
; array_list
= array_list
->next
) {
1121 if (array_list
->uuid_set
&&
1122 same_uuid(array_list
->uuid
, info
->uuid
,
1123 st
->ss
->swapuuid
) == 0) {
1124 if (verbose
>= 2 && array_list
->devname
)
1125 pr_err("UUID differs from %s.\n",
1126 array_list
->devname
);
1129 if (array_list
->name
[0] &&
1130 strcasecmp(array_list
->name
, info
->name
) != 0) {
1131 if (verbose
>= 2 && array_list
->devname
)
1132 pr_err("Name differs from %s.\n",
1133 array_list
->devname
);
1136 if (array_list
->devices
&& devname
&&
1137 !match_oneof(array_list
->devices
, devname
)) {
1138 if (verbose
>= 2 && array_list
->devname
)
1139 pr_err("Not a listed device for %s.\n",
1140 array_list
->devname
);
1143 if (array_list
->super_minor
!= UnSet
&&
1144 array_list
->super_minor
!= info
->array
.md_minor
) {
1145 if (verbose
>= 2 && array_list
->devname
)
1146 pr_err("Different super-minor to %s.\n",
1147 array_list
->devname
);
1150 if (!array_list
->uuid_set
&& !array_list
->name
[0] &&
1151 !array_list
->devices
&& array_list
->super_minor
== UnSet
) {
1152 if (verbose
>= 2 && array_list
->devname
)
1153 pr_err("%s doesn't have any identifying information.\n",
1154 array_list
->devname
);
1157 /* FIXME, should I check raid_disks and level too?? */
1161 if (match
->devname
&& array_list
->devname
)
1162 pr_err("we match both %s and %s - cannot decide which to use.\n",
1164 array_list
->devname
);
1166 pr_err("multiple lines in mdadm.conf match\n");
1178 int conf_verify_devnames(struct mddev_ident
*array_list
)
1180 struct mddev_ident
*a1
, *a2
;
1182 for (a1
= array_list
; a1
; a1
= a1
->next
) {
1185 if (strcmp(a1
->devname
, "<ignore>") == 0)
1187 for (a2
= a1
->next
; a2
; a2
= a2
->next
) {
1190 if (strcmp(a1
->devname
, a2
->devname
) != 0)
1193 if (a1
->uuid_set
&& a2
->uuid_set
) {
1195 __fname_from_uuid(a1
->uuid
, 0, nbuf
, ':');
1196 pr_err("Devices %s and ",
1198 __fname_from_uuid(a2
->uuid
, 0, nbuf
, ':');
1200 "%s have the same name: %s\n",
1203 pr_err("Device %s given twice in config file\n", a1
->devname
);