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>
37 * Read the config file
39 * conf_get_uuids gets a list of devicename+uuid pairs
40 * conf_get_devs gets device names after expanding wildcards
42 * Each keeps the returned list and frees it when asked to make
45 * The format of the config file needs to be fairly extensible.
46 * Now, arrays only have names and uuids and devices merely are.
47 * But later arrays might want names, and devices might want superblock
48 * versions, and who knows what else.
49 * I like free format, abhore backslash line continuation, adore
50 * indentation for structure and am ok about # comments.
52 * So, each line that isn't blank or a #comment must either start
53 * with a key word, and not be indented, or must start with a
54 * non-key-word and must be indented.
56 * Keywords are DEVICE and ARRAY ... and several others.
57 * DEV{ICE} introduces some devices that might contain raid components.
59 * DEV style=0 /dev/sda* /dev/hd*
60 * DEV style=1 /dev/sd[b-f]*
61 * ARR{AY} describes an array giving md device and attributes like uuid=whatever
63 * ARRAY /dev/md0 uuid=whatever name=something
64 * Spaces separate words on each line. Quoting, with "" or '' protects them,
65 * but may not wrap over lines
68 #ifndef _POSIX_C_SOURCE
69 #define _POSIX_C_SOURCE 200809L
73 #define CONFFILE "/etc/mdadm.conf"
76 /* for Debian compatibility .... */
77 #define CONFFILE2 "/etc/mdadm/mdadm.conf"
79 char DefaultConfFile
[] = CONFFILE
;
80 char DefaultConfDir
[] = CONFFILE
".d";
81 char DefaultAltConfFile
[] = CONFFILE2
;
82 char DefaultAltConfDir
[] = CONFFILE2
".d";
84 enum linetype
{ Devices
, Array
, Mailaddr
, Mailfrom
, Program
, CreateDev
,
85 Homehost
, HomeCluster
, AutoMode
, Policy
, PartPolicy
, Sysfs
,
86 MonitorDelay
, EncryptionNoVerify
, LTEnd
};
88 [Devices
] = "devices",
90 [Mailaddr
] = "mailaddr",
91 [Mailfrom
] = "mailfrom",
92 [Program
] = "program",
93 [CreateDev
]= "create",
94 [Homehost
] = "homehost",
95 [HomeCluster
] = "homecluster",
98 [PartPolicy
]="part-policy",
100 [MonitorDelay
] = "monitordelay",
101 [EncryptionNoVerify
] = "ENCRYPTION_NO_VERIFY",
106 * match_keyword returns an index into the keywords array, or -1 for no match
107 * case is ignored, and at least three characters must be given
110 int match_keyword(char *word
)
112 int len
= strlen(word
);
117 for (n
= 0; keywords
[n
]; n
++) {
118 if (strncasecmp(word
, keywords
[n
], len
) == 0)
126 * is_devname_ignore() - check if &devname is a special "<ignore>" keyword.
128 bool is_devname_ignore(const char *devname
)
130 static const char keyword
[] = "<ignore>";
132 if (strcasecmp(devname
, keyword
) == 0)
138 * ident_log() - generate and write message to the user.
139 * @param_name: name of the property.
140 * @value: value of the property.
141 * @reason: meaningful description.
142 * @cmdline: context dependent actions, see below.
144 * The function is made to provide similar error handling for both config and cmdline. The behavior
145 * is configurable via @cmdline. Message has following format:
146 * "Value "@value" cannot be set for @param_name. Reason: @reason."
149 * - message is written to stderr.
151 * - message is written to stdout.
152 * - "Value ignored" is added at the end of the message.
154 static void ident_log(const char *param_name
, const char *value
, const char *reason
,
158 pr_err("Value \"%s\" cannot be set as %s. Reason: %s.\n", value
, param_name
,
161 pr_info("Value \"%s\" cannot be set as %s. Reason: %s. Value ignored.\n", value
,
166 * ident_init() - Set defaults.
167 * @ident: ident pointer, not NULL.
169 inline void ident_init(struct mddev_ident
*ident
)
173 ident
->assembled
= false;
174 ident
->btype
= BitmapUnknown
;
175 ident
->container
= NULL
;
176 ident
->devices
= NULL
;
177 ident
->devname
= NULL
;
178 ident
->level
= UnSet
;
179 ident
->member
= NULL
;
182 ident
->raid_disks
= UnSet
;
183 ident
->spare_group
= NULL
;
184 ident
->spare_disks
= 0;
186 ident
->super_minor
= UnSet
;
192 * _ident_set_devname() - verify devname and set it in &mddev_ident.
193 * @ident: pointer to &mddev_ident.
194 * @devname: devname to be set.
195 * @cmdline: context dependent actions. If set, ignore keyword is not allowed.
197 * @devname can have following forms:
198 * '<ignore>' keyword (if allowed)
200 * /dev/md_d{number} (legacy)
205 * If verification passed, duplicate memory and set devname in @ident.
207 * Return: %MDADM_STATUS_SUCCESS or %MDADM_STATUS_ERROR.
209 mdadm_status_t
_ident_set_devname(struct mddev_ident
*ident
, const char *devname
,
215 static const char named_dev_pref
[] = DEV_NUM_PREF
"_";
216 static const int named_dev_pref_size
= sizeof(named_dev_pref
) - 1;
217 const char *prop_name
= "devname";
220 if (ident
->devname
) {
221 ident_log(prop_name
, devname
, "Already defined", cmdline
);
222 return MDADM_STATUS_ERROR
;
225 if (is_devname_ignore(devname
) == true) {
229 ident_log(prop_name
, devname
, "Special keyword is invalid in this context",
231 return MDADM_STATUS_ERROR
;
234 if (is_devname_md_numbered(devname
) == true || is_devname_md_d_numbered(devname
) == true)
237 if (strncmp(devname
, DEV_MD_DIR
, DEV_MD_DIR_LEN
) == 0)
238 name
= devname
+ DEV_MD_DIR_LEN
;
239 else if (strncmp(devname
, named_dev_pref
, named_dev_pref_size
) == 0)
240 name
= devname
+ named_dev_pref_size
;
244 if (!is_string_lq(name
, MD_NAME_MAX
+ 1)) {
245 ident_log(prop_name
, name
, "Too long or empty", cmdline
);
246 return MDADM_STATUS_ERROR
;
250 ident
->devname
= xstrdup(devname
);
251 return MDADM_STATUS_SUCCESS
;
255 * _ident_set_name() - set name in &mddev_ident.
256 * @ident: pointer to &mddev_ident.
257 * @name: name to be set.
259 * If criteria passed, set name in @ident.
260 * Note: name is not used by config file, it for cmdline only.
262 * Return: %MDADM_STATUS_SUCCESS or %MDADM_STATUS_ERROR.
264 mdadm_status_t
ident_set_name(struct mddev_ident
*ident
, const char *name
)
269 const char *prop_name
= "name";
271 if (ident
->name
[0]) {
272 ident_log(prop_name
, name
, "Already defined", true);
273 return MDADM_STATUS_ERROR
;
276 if (!is_string_lq(name
, MD_NAME_MAX
+ 1)) {
277 ident_log(prop_name
, name
, "Too long or empty", true);
278 return MDADM_STATUS_ERROR
;
281 snprintf(ident
->name
, MD_NAME_MAX
+ 1, "%s", name
);
282 return MDADM_STATUS_SUCCESS
;
286 * ident_set_devname()- exported, for cmdline.
288 mdadm_status_t
ident_set_devname(struct mddev_ident
*ident
, const char *name
)
290 return _ident_set_devname(ident
, name
, true);
294 struct conf_dev
*next
;
298 struct mddev_dev
*load_partitions(void)
300 FILE *f
= fopen("/proc/partitions", "r");
302 struct mddev_dev
*rv
= NULL
;
305 pr_err("cannot open /proc/partitions\n");
308 while (fgets(buf
, 1024, f
)) {
316 major
= strtoul(buf
, &mp
, 10);
317 if (mp
== buf
|| *mp
!= ' ')
319 minor
= strtoul(mp
, NULL
, 10);
321 name
= map_dev(major
, minor
, 1);
324 d
= xcalloc(1, sizeof(*d
));
325 d
->devname
= xstrdup(name
);
333 struct mddev_dev
*load_containers(void)
335 struct mdstat_ent
*mdstat
= mdstat_read(0, 0);
336 struct mddev_dev
*dev_list
= NULL
;
337 struct map_ent
*map_list
= NULL
;
338 struct mdstat_ent
*ent
;
340 for (ent
= mdstat
; ent
; ent
= ent
->next
) {
344 if (!is_mdstat_ent_external(ent
))
347 if (is_mdstat_ent_subarray(ent
))
350 d
= xcalloc(1, sizeof(*d
));
352 map
= map_by_devnm(&map_list
, ent
->devnm
);
354 d
->devname
= xstrdup(map
->path
);
355 } else if (asprintf(&d
->devname
, "/dev/%s", ent
->devnm
) < 0) {
370 struct createinfo createinfo
= {
371 .names
= 0, /* By default, stick with numbered md devices. */
372 .bblist
= 1, /* Use a bad block list by default */
381 static void createline(char *line
)
386 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
387 if (strncasecmp(w
, "auto=", 5) == 0)
388 /* auto is no supported now, ignore it silently */
390 else if (strncasecmp(w
, "owner=", 6) == 0) {
392 pr_err("missing owner name\n");
395 createinfo
.uid
= strtoul(w
+ 6, &ep
, 10);
399 pw
= getpwnam(w
+ 6);
401 createinfo
.uid
= pw
->pw_uid
;
403 pr_err("CREATE user %s not found\n",
406 } else if (strncasecmp(w
, "group=", 6) == 0) {
408 pr_err("missing group name\n");
411 createinfo
.gid
= strtoul(w
+ 6, &ep
, 10);
415 gr
= getgrnam(w
+ 6);
417 createinfo
.gid
= gr
->gr_gid
;
419 pr_err("CREATE group %s not found\n",
422 } else if (strncasecmp(w
, "mode=", 5) == 0) {
424 pr_err("missing CREATE mode\n");
427 createinfo
.mode
= strtoul(w
+ 5, &ep
, 8);
429 createinfo
.mode
= 0600;
430 pr_err("unrecognised CREATE mode %s\n",
433 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
434 /* style of metadata to use by default */
436 for (i
= 0; superlist
[i
] && !createinfo
.supertype
; i
++)
437 createinfo
.supertype
= superlist
[i
]->match_metadata_desc(w
+ 9);
438 if (!createinfo
.supertype
)
439 pr_err("metadata format %s unknown, ignoring\n",
441 } else if (strncasecmp(w
, "names=yes", 12) == 0)
442 createinfo
.names
= 1;
443 else if (strncasecmp(w
, "names=no", 11) == 0)
444 createinfo
.names
= 0;
445 else if (strncasecmp(w
, "bbl=no", 11) == 0)
446 createinfo
.bblist
= 0;
447 else if (strncasecmp(w
, "bbl=yes", 11) == 0)
448 createinfo
.bblist
= 1;
450 pr_err("unrecognised word on CREATE line: %s\n",
456 void devline(char *line
)
461 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
462 if (w
[0] == '/' || strcasecmp(w
, "partitions") == 0 ||
463 strcasecmp(w
, "containers") == 0) {
464 cd
= xmalloc(sizeof(*cd
));
465 cd
->name
= xstrdup(w
);
469 pr_err("unreconised word on DEVICE line: %s\n", w
);
474 struct mddev_ident
*mddevlist
= NULL
;
475 struct mddev_ident
**mddevlp
= &mddevlist
;
477 void arrayline(char *line
)
481 struct mddev_ident mis
;
482 struct mddev_ident
*mi
;
486 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
487 if (w
[0] == '/' || strchr(w
, '=') == NULL
) {
488 _ident_set_devname(&mis
, w
, false);
489 } else if (strncasecmp(w
, "uuid=", 5) == 0) {
491 pr_err("only specify uuid once, %s ignored.\n",
494 if (parse_uuid(w
+ 5, mis
.uuid
))
497 pr_err("bad uuid: %s\n", w
);
499 } else if (strncasecmp(w
, "super-minor=", 12) == 0) {
500 if (mis
.super_minor
!= UnSet
)
501 pr_err("only specify super-minor once, %s ignored.\n",
505 int minor
= strtol(w
+ 12, &endptr
, 10);
507 if (w
[12] == 0 || endptr
[0] != 0 || minor
< 0)
508 pr_err("invalid super-minor number: %s\n",
511 mis
.super_minor
= minor
;
513 } else if (strncasecmp(w
, "name=", 5) == 0) {
514 /* Ignore name in confile */
516 } else if (strncasecmp(w
, "bitmap=", 7) == 0) {
517 if (mis
.btype
!= BitmapUnknown
)
518 pr_err("only specify bitmap file once. %s ignored\n",
521 char *bname
= xstrdup(w
+ 7);
523 if (strcmp(bname
, STR_COMMON_NONE
) == 0)
524 mis
.btype
= BitmapNone
;
525 else if (strcmp(bname
, "internal") == 0)
526 mis
.btype
= BitmapInternal
;
527 else if (strcmp(bname
, "clustered") == 0)
528 mis
.btype
= BitmapCluster
;
531 } else if (strncasecmp(w
, "devices=", 8 ) == 0) {
533 pr_err("only specify devices once (use a comma separated list). %s ignored\n",
536 mis
.devices
= xstrdup(w
+ 8);
537 } else if (strncasecmp(w
, "spare-group=", 12) == 0) {
539 pr_err("only specify one spare group per array. %s ignored.\n",
542 mis
.spare_group
= xstrdup(w
+ 12);
543 } else if (strncasecmp(w
, "level=", 6) == 0 ) {
544 /* this is mainly for compatability with --brief output */
545 mis
.level
= map_name(pers
, w
+ 6);
546 } else if (strncasecmp(w
, "disks=", 6) == 0) {
547 /* again, for compat */
548 mis
.raid_disks
= atoi(w
+ 6);
549 } else if (strncasecmp(w
, "num-devices=", 12) == 0) {
550 /* again, for compat */
551 mis
.raid_disks
= atoi(w
+ 12);
552 } else if (strncasecmp(w
, "spares=", 7) == 0) {
553 /* for warning if not all spares present */
554 mis
.spare_disks
= atoi(w
+ 7);
555 } else if (strncasecmp(w
, "metadata=", 9) == 0) {
556 /* style of metadata on the devices. */
559 for(i
=0; superlist
[i
] && !mis
.st
; i
++)
560 mis
.st
= superlist
[i
]->
561 match_metadata_desc(w
+ 9);
564 pr_err("metadata format %s unknown, ignored.\n",
566 } else if (strncasecmp(w
, "auto=", 5) == 0) {
567 /* Ignore for backward compatibility */
569 } else if (strncasecmp(w
, "member=", 7) == 0) {
570 /* subarray within a container */
571 mis
.member
= xstrdup(w
+ 7);
572 } else if (strncasecmp(w
, "container=", 10) == 0) {
573 /* The container holding this subarray.
574 * Either a device name or a uuid */
575 mis
.container
= xstrdup(w
+ 10);
577 pr_err("unrecognised word on ARRAY line: %s\n",
581 if (mis
.uuid_set
== 0 && mis
.devices
== NULL
&&
582 mis
.super_minor
== UnSet
&& mis
.name
[0] == 0 &&
583 (mis
.container
== NULL
|| mis
.member
== NULL
))
584 pr_err("ARRAY line %s has no identity information.\n",
587 mi
= xmalloc(sizeof(*mi
));
589 mi
->devname
= mis
.devname
? xstrdup(mis
.devname
) : NULL
;
596 static char *alert_email
= NULL
;
597 void mailline(char *line
)
601 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
))
602 if (alert_email
== NULL
)
603 alert_email
= xstrdup(w
);
606 static char *alert_mail_from
= NULL
;
607 void mailfromline(char *line
)
611 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
612 if (alert_mail_from
== NULL
)
613 alert_mail_from
= xstrdup(w
);
617 if (xasprintf(&t
, "%s %s", alert_mail_from
, w
) > 0) {
618 free(alert_mail_from
);
625 static char *alert_program
= NULL
;
626 void programline(char *line
)
630 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
))
631 if (alert_program
== NULL
)
632 alert_program
= xstrdup(w
);
635 static char *home_host
= NULL
;
636 static int require_homehost
= 1;
637 void homehostline(char *line
)
641 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
642 if (is_devname_ignore(w
) == true)
643 require_homehost
= 0;
644 else if (home_host
== NULL
) {
645 if (strcasecmp(w
, "<none>") == 0)
646 home_host
= xstrdup("");
648 home_host
= xstrdup(w
);
653 static char *home_cluster
= NULL
;
654 void homeclusterline(char *line
)
658 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
659 if (home_cluster
== NULL
) {
660 if (strcasecmp(w
, "<none>") == 0)
661 home_cluster
= xstrdup("");
663 home_cluster
= xstrdup(w
);
668 static int monitor_delay
;
669 void monitordelayline(char *line
)
673 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
674 if (monitor_delay
== 0)
675 monitor_delay
= strtol(w
, NULL
, 10);
679 static bool sata_opal_encryption_no_verify
;
680 void encryption_no_verify_line(char *line
)
684 for (word
= dl_next(line
); word
!= line
; word
= dl_next(word
)) {
685 if (strcasecmp(word
, "sata_opal") == 0)
686 sata_opal_encryption_no_verify
= true;
688 pr_err("unrecognised word on ENCRYPTION_NO_VERIFY line: %s\n", word
);
692 char auto_yes
[] = "yes";
693 char auto_no
[] = "no";
694 char auto_homehost
[] = "homehost";
696 static int auto_seen
= 0;
697 void autoline(char *line
)
702 char *dflt
= auto_yes
;
711 * Parse the 'auto' line creating policy statements for the 'auto'
714 * The default is 'yes' but the 'auto' line might over-ride that.
715 * Words in the line are processed in order with the first
718 * +version - that version can be assembled
719 * -version - that version cannot be auto-assembled
720 * yes or +all - any other version can be assembled
721 * no or -all - no other version can be assembled.
722 * homehost - any array associated by 'homehost' to this
723 * host can be assembled.
726 * +ddf -0.90 homehost -all
727 * will auto-assemble any ddf array, no 0.90 array, and
728 * any other array (imsm, 1.x) if and only if it is identified
729 * as belonging to this host.
731 * We translate that to policy by creating 'auto=yes' when we see
732 * a '+version' line, 'auto=no' if we see '-version' before 'homehost',
733 * or 'auto=homehost' if we see '-version' after 'homehost'.
734 * When we see yes, no, +all or -all we stop and any version that hasn't
735 * been seen gets an appropriate auto= entry.
739 * If environment variable MDADM_CONF_AUTO is defined, then
740 * it is prepended to the auto line. This allow a script
741 * to easily disable some metadata types.
743 w
= getenv("MDADM_CONF_AUTO");
745 char *l
= xstrdup(w
);
747 w
= strtok(l
, " \t");
749 char *nw
= dl_strdup(w
);
752 w
= strtok(NULL
, " \t");
757 for (super_cnt
= 0; superlist
[super_cnt
]; super_cnt
++)
759 seen
= xcalloc(super_cnt
, 1);
761 for (w
= dl_next(line
); w
!= line
; w
= dl_next(w
)) {
764 if (strcasecmp(w
, "yes") == 0) {
768 if (strcasecmp(w
, "no") == 0) {
770 dflt
= auto_homehost
;
775 if (strcasecmp(w
, "homehost") == 0) {
781 else if (w
[0] == '-') {
789 if (strcasecmp(w
+ 1, "all") == 0) {
793 for (i
= 0; superlist
[i
]; i
++) {
794 const char *version
= superlist
[i
]->name
;
795 if (strcasecmp(w
+ 1, version
) == 0)
797 /* 1 matches 1.x, 0 matches 0.90 */
798 if (version
[1] == '.' && strlen(w
+ 1) == 1 &&
801 /* 1.anything matches 1.x */
802 if (strcmp(version
, "1.x") == 0 &&
803 strncmp(w
+ 1, "1.", 2) == 0)
806 if (superlist
[i
] == NULL
)
807 /* ignore this word */
810 /* already know about this metadata */
812 policy_add(rule_policy
, pol_auto
, val
, pol_metadata
,
813 superlist
[i
]->name
, NULL
);
816 for (i
= 0; i
< super_cnt
; i
++)
818 policy_add(rule_policy
, pol_auto
, dflt
, pol_metadata
,
819 superlist
[i
]->name
, NULL
);
826 static char *conffile
= NULL
;
827 void set_conffile(char *file
)
832 void conf_file(FILE *f
)
835 while ((line
= conf_line(f
))) {
836 switch(match_keyword(line
)) {
859 homeclusterline(line
);
865 policyline(line
, rule_policy
);
868 policyline(line
, rule_part
);
874 monitordelayline(line
);
876 case EncryptionNoVerify
:
877 encryption_no_verify_line(line
);
880 pr_err("Unknown keyword %s\n", line
);
891 void conf_file_or_dir(FILE *f
)
896 struct fname
*list
= NULL
;
898 if (fstat(fileno(f
), &st
) != 0)
900 if (S_ISREG(st
.st_mode
))
902 else if (!S_ISDIR(st
.st_mode
))
904 #if _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
905 dir
= fdopendir(fileno(f
));
908 while ((dp
= readdir(dir
)) != NULL
) {
910 struct fname
*fn
, **p
;
913 if (dp
->d_name
[0] == '.')
915 l
= strlen(dp
->d_name
);
916 if (l
< 6 || strcmp(dp
->d_name
+ l
- 5, ".conf") != 0)
918 fn
= xmalloc(sizeof(*fn
) + l
+ 1);
919 strcpy(fn
->name
, dp
->d_name
);
921 *p
&& strcmp((*p
)->name
, fn
->name
) < 0;
930 struct fname
*fn
= list
;
932 fd
= openat(fileno(f
), fn
->name
, O_RDONLY
);
936 f2
= fdopen(fd
, "r");
948 void load_conffile(void)
951 char *confdir
= NULL
;
956 if (conffile
== NULL
) {
957 conffile
= DefaultConfFile
;
958 confdir
= DefaultConfDir
;
961 if (strcmp(conffile
, "partitions") == 0) {
962 char *list
= dl_strdup("DEV");
964 dl_add(list
, dl_strdup("partitions"));
967 } else if (str_is_none(conffile
) == false) {
968 f
= fopen(conffile
, "r");
969 /* Debian chose to relocate mdadm.conf into /etc/mdadm/.
970 * To allow Debian users to compile from clean source and still
971 * have a working mdadm, we read /etc/mdadm/mdadm.conf
972 * if /etc/mdadm.conf doesn't exist
974 if (f
== NULL
&& conffile
== DefaultConfFile
) {
975 f
= fopen(DefaultAltConfFile
, "r");
977 conffile
= DefaultAltConfFile
;
978 confdir
= DefaultAltConfDir
;
986 f
= fopen(confdir
, "r");
993 /* If there was no AUTO line, process an empty line
994 * now so that the MDADM_CONF_AUTO env var gets processed.
996 head
= dl_strdup("AUTO");
1004 char *conf_get_mailaddr(void)
1010 char *conf_get_mailfrom(void)
1013 return alert_mail_from
;
1016 char *conf_get_program(void)
1019 return alert_program
;
1022 char *conf_get_homehost(int *require_homehostp
)
1025 if (require_homehostp
)
1026 *require_homehostp
= require_homehost
;
1030 char *conf_get_homecluster(void)
1033 return home_cluster
;
1036 int conf_get_monitor_delay(void)
1039 return monitor_delay
;
1042 bool conf_get_sata_opal_encryption_no_verify(void)
1045 return sata_opal_encryption_no_verify
;
1048 struct createinfo
*conf_get_create_info(void)
1054 struct mddev_ident
*conf_get_ident(char *dev
)
1056 struct mddev_ident
*rv
;
1059 while (dev
&& rv
&& (rv
->devname
== NULL
||
1060 !devname_matches(dev
, rv
->devname
)))
1065 static void append_dlist(struct mddev_dev
**dlp
, struct mddev_dev
*list
)
1068 dlp
= &(*dlp
)->next
;
1072 struct mddev_dev
*conf_get_devs()
1075 struct conf_dev
*cd
;
1077 static struct mddev_dev
*dlist
= NULL
;
1081 struct mddev_dev
*t
= dlist
;
1082 dlist
= dlist
->next
;
1089 if (cdevlist
== NULL
) {
1090 /* default to 'partitions' and 'containers' */
1091 dlist
= load_partitions();
1092 append_dlist(&dlist
, load_containers());
1095 for (cd
= cdevlist
; cd
; cd
= cd
->next
) {
1096 if (strcasecmp(cd
->name
, "partitions") == 0)
1097 append_dlist(&dlist
, load_partitions());
1098 else if (strcasecmp(cd
->name
, "containers") == 0)
1099 append_dlist(&dlist
, load_containers());
1101 glob(cd
->name
, flags
, NULL
, &globbuf
);
1102 flags
|= GLOB_APPEND
;
1105 if (flags
& GLOB_APPEND
) {
1106 for (i
= 0; i
< globbuf
.gl_pathc
; i
++) {
1107 struct mddev_dev
*t
;
1108 t
= xcalloc(1, sizeof(*t
));
1109 t
->devname
= xstrdup(globbuf
.gl_pathv
[i
]);
1112 /* printf("one dev is %s\n", t->devname);*/
1120 int conf_test_dev(char *devname
)
1122 struct conf_dev
*cd
;
1123 if (cdevlist
== NULL
)
1124 /* allow anything by default */
1126 for (cd
= cdevlist
; cd
; cd
= cd
->next
) {
1127 if (strcasecmp(cd
->name
, "partitions") == 0)
1129 if (fnmatch(cd
->name
, devname
, FNM_PATHNAME
) == 0)
1135 int conf_test_metadata(const char *version
, struct dev_policy
*pol
, int is_homehost
)
1137 /* If anyone said 'yes', that sticks.
1138 * else if homehost applies, use that
1139 * else if there is a 'no', say 'no'.
1142 struct dev_policy
*p
;
1143 int no
= 0, found_homehost
= 0;
1146 pol
= pol_find(pol
, pol_auto
);
1147 pol_for_each(p
, pol
, version
) {
1148 if (strcmp(p
->value
, "yes") == 0)
1150 if (strcmp(p
->value
, "homehost") == 0)
1152 if (strcmp(p
->value
, "no") == 0)
1155 if (is_homehost
&& found_homehost
)
1162 int match_oneof(char *devices
, char *devname
)
1164 /* check if one of the comma separated patterns in devices
1168 while (devices
&& *devices
) {
1171 devices
= strchr(devices
, ',');
1173 devices
= p
+ strlen(p
);
1174 if (devices
-p
< 1024) {
1175 strncpy(patn
, p
, devices
- p
);
1176 patn
[devices
-p
] = 0;
1177 if (fnmatch(patn
, devname
, FNM_PATHNAME
) == 0)
1180 if (*devices
== ',')
1186 int devname_matches(char *name
, char *match
)
1188 /* See if the given array name matches the
1189 * given match from config file.
1191 * First strip and /dev/md/ or /dev/, then
1192 * see if there might be a numeric match of
1196 if (strncmp(name
, DEV_MD_DIR
, DEV_MD_DIR_LEN
) == 0)
1197 name
+= DEV_MD_DIR_LEN
;
1198 else if (strncmp(name
, "/dev/", 5) == 0)
1201 if (strncmp(match
, DEV_MD_DIR
, DEV_MD_DIR_LEN
) == 0)
1202 match
+= DEV_MD_DIR_LEN
;
1203 else if (strncmp(match
, "/dev/", 5) == 0)
1206 if (strncmp(name
, "md", 2) == 0 && isdigit(name
[2]))
1208 if (strncmp(match
, "md", 2) == 0 && isdigit(match
[2]))
1211 return (strcmp(name
, match
) == 0);
1214 int conf_name_is_free(char *name
)
1216 /* Check if this name is already taken by an ARRAY entry in
1218 * It can be taken either by a match on devname, name, or
1221 struct mddev_ident
*dev
;
1224 for (dev
= mddevlist
; dev
; dev
= dev
->next
) {
1226 if (dev
->devname
&& devname_matches(name
, dev
->devname
))
1228 if (dev
->name
[0] && devname_matches(name
, dev
->name
))
1230 sprintf(nbuf
, "%d", dev
->super_minor
);
1231 if (dev
->super_minor
!= UnSet
&& devname_matches(name
, nbuf
))
1237 struct mddev_ident
*conf_match(struct supertype
*st
,
1238 struct mdinfo
*info
,
1240 int verbose
, int *rvp
)
1242 struct mddev_ident
*array_list
, *match
;
1243 array_list
= conf_get_ident(NULL
);
1245 for (; array_list
; array_list
= array_list
->next
) {
1246 if (array_list
->uuid_set
&&
1247 same_uuid(array_list
->uuid
, info
->uuid
,
1248 st
->ss
->swapuuid
) == 0) {
1249 if (verbose
>= 2 && array_list
->devname
)
1250 pr_err("UUID differs from %s.\n",
1251 array_list
->devname
);
1255 if (array_list
->devices
&& devname
&&
1256 !match_oneof(array_list
->devices
, devname
)) {
1257 if (verbose
>= 2 && array_list
->devname
)
1258 pr_err("Not a listed device for %s.\n",
1259 array_list
->devname
);
1262 if (array_list
->super_minor
!= UnSet
&&
1263 array_list
->super_minor
!= info
->array
.md_minor
) {
1264 if (verbose
>= 2 && array_list
->devname
)
1265 pr_err("Different super-minor to %s.\n",
1266 array_list
->devname
);
1269 if (!array_list
->uuid_set
&& !array_list
->name
[0] &&
1270 !array_list
->devices
&& array_list
->super_minor
== UnSet
) {
1271 if (verbose
>= 2 && array_list
->devname
)
1272 pr_err("%s doesn't have any identifying information.\n",
1273 array_list
->devname
);
1276 /* FIXME, should I check raid_disks and level too?? */
1280 if (match
->devname
&& array_list
->devname
)
1281 pr_err("we match both %s and %s - cannot decide which to use.\n",
1283 array_list
->devname
);
1285 pr_err("multiple lines in mdadm.conf match\n");
1297 int conf_verify_devnames(struct mddev_ident
*array_list
)
1299 struct mddev_ident
*a1
, *a2
;
1301 for (a1
= array_list
; a1
; a1
= a1
->next
) {
1304 if (strcmp(a1
->devname
, "<ignore>") == 0)
1306 for (a2
= a1
->next
; a2
; a2
= a2
->next
) {
1309 if (strcmp(a1
->devname
, a2
->devname
) != 0)
1312 if (a1
->uuid_set
&& a2
->uuid_set
) {
1314 __fname_from_uuid(a1
->uuid
, 0, nbuf
, ':');
1315 pr_err("Devices %s and ",
1317 __fname_from_uuid(a2
->uuid
, 0, nbuf
, ':');
1319 "%s have the same name: %s\n",
1322 pr_err("Device %s given twice in config file\n", a1
->devname
);