]>
Commit | Line | Data |
---|---|---|
64c4757e | 1 | /* |
9a9dab36 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. |
64c4757e | 3 | * |
e736b623 | 4 | * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de> |
64c4757e NB |
5 | * |
6 | * | |
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. | |
11 | * | |
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. | |
16 | * | |
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 | |
20 | * | |
21 | * Author: Neil Brown | |
e736b623 | 22 | * Email: <neilb@suse.de> |
64c4757e NB |
23 | */ |
24 | ||
9a9dab36 | 25 | #include "mdadm.h" |
82b27616 | 26 | #include "dlink.h" |
ff7f2ebb | 27 | #include <dirent.h> |
82b27616 | 28 | #include <glob.h> |
52826846 | 29 | #include <fnmatch.h> |
dd0781e5 | 30 | #include <ctype.h> |
5bbb4842 NB |
31 | #include <pwd.h> |
32 | #include <grp.h> | |
52826846 | 33 | |
64c4757e NB |
34 | /* |
35 | * Read the config file | |
36 | * | |
37 | * conf_get_uuids gets a list of devicename+uuid pairs | |
38 | * conf_get_devs gets device names after expanding wildcards | |
39 | * | |
40 | * Each keeps the returned list and frees it when asked to make | |
41 | * a new list. | |
42 | * | |
82b27616 NB |
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. | |
49 | * | |
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. | |
53 | * | |
31015d57 | 54 | * Keywords are DEVICE and ARRAY ... and several others. |
82b27616 NB |
55 | * DEV{ICE} introduces some devices that might contain raid components. |
56 | * e.g. | |
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 | |
60 | * e.g. | |
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 | |
64 | * | |
64c4757e NB |
65 | */ |
66 | ||
11a3e71d NB |
67 | #ifndef CONFFILE |
68 | #define CONFFILE "/etc/mdadm.conf" | |
69 | #endif | |
ce4fafd6 NB |
70 | #ifndef CONFFILE2 |
71 | /* for Debian compatibility .... */ | |
72 | #define CONFFILE2 "/etc/mdadm/mdadm.conf" | |
73 | #endif | |
11a3e71d | 74 | char DefaultConfFile[] = CONFFILE; |
ce4fafd6 | 75 | char DefaultAltConfFile[] = CONFFILE2; |
64c4757e | 76 | |
31015d57 | 77 | enum linetype { Devices, Array, Mailaddr, Mailfrom, Program, CreateDev, |
5527fc74 | 78 | Homehost, AutoMode, Policy, PartPolicy, LTEnd }; |
8fe9db0f NB |
79 | char *keywords[] = { |
80 | [Devices] = "devices", | |
81 | [Array] = "array", | |
82 | [Mailaddr] = "mailaddr", | |
83 | [Mailfrom] = "mailfrom", | |
84 | [Program] = "program", | |
8382f19b | 85 | [CreateDev]= "create", |
8fe9db0f | 86 | [Homehost] = "homehost", |
31015d57 | 87 | [AutoMode] = "auto", |
5527fc74 N |
88 | [Policy] = "policy", |
89 | [PartPolicy]="part-policy", | |
8fe9db0f NB |
90 | [LTEnd] = NULL |
91 | }; | |
82b27616 NB |
92 | |
93 | /* | |
94 | * match_keyword returns an index into the keywords array, or -1 for no match | |
95 | * case is ignored, and at least three characters must be given | |
96 | */ | |
97 | ||
98 | int match_keyword(char *word) | |
99 | { | |
52826846 NB |
100 | int len = strlen(word); |
101 | int n; | |
aba69144 | 102 | |
52826846 NB |
103 | if (len < 3) return -1; |
104 | for (n=0; keywords[n]; n++) { | |
105 | if (strncasecmp(word, keywords[n], len)==0) | |
106 | return n; | |
107 | } | |
108 | return -1; | |
82b27616 NB |
109 | } |
110 | ||
111 | /* conf_word gets one word from the conf file. | |
112 | * if "allow_key", then accept words at the start of a line, | |
113 | * otherwise stop when such a word is found. | |
114 | * We assume that the file pointer is at the end of a word, so the | |
115 | * next character is a space, or a newline. If not, it is the start of a line. | |
116 | */ | |
117 | ||
118 | char *conf_word(FILE *file, int allow_key) | |
119 | { | |
52826846 NB |
120 | int wsize = 100; |
121 | int len = 0; | |
122 | int c; | |
123 | int quote; | |
124 | int wordfound = 0; | |
125 | char *word = malloc(wsize); | |
82b27616 | 126 | |
52826846 NB |
127 | if (!word) abort(); |
128 | ||
129 | while (wordfound==0) { | |
130 | /* at the end of a word.. */ | |
82b27616 | 131 | c = getc(file); |
52826846 NB |
132 | if (c == '#') |
133 | while (c != EOF && c != '\n') | |
134 | c = getc(file); | |
135 | if (c == EOF) break; | |
136 | if (c == '\n') continue; | |
137 | ||
138 | if (c != ' ' && c != '\t' && ! allow_key) { | |
139 | ungetc(c, file); | |
140 | break; | |
141 | } | |
142 | /* looks like it is safe to get a word here, if there is one */ | |
143 | quote = 0; | |
144 | /* first, skip any spaces */ | |
145 | while (c == ' ' || c == '\t') | |
146 | c = getc(file); | |
147 | if (c != EOF && c != '\n' && c != '#') { | |
148 | /* we really have a character of a word, so start saving it */ | |
149 | while (c != EOF && c != '\n' && (quote || (c!=' ' && c != '\t'))) { | |
150 | wordfound = 1; | |
151 | if (quote && c == quote) quote = 0; | |
152 | else if (quote == 0 && (c == '\'' || c == '"')) | |
153 | quote = c; | |
154 | else { | |
155 | if (len == wsize-1) { | |
156 | wsize += 100; | |
157 | word = realloc(word, wsize); | |
158 | if (!word) abort(); | |
159 | } | |
160 | word[len++] = c; | |
161 | } | |
162 | c = getc(file); | |
2cdb6489 NB |
163 | /* Hack for broken kernels (2.6.14-.24) that put |
164 | * "active(auto-read-only)" | |
165 | * in /proc/mdstat instead of | |
166 | * "active (auto-read-only)" | |
167 | */ | |
168 | if (c == '(' && len >= 6 | |
169 | && strncmp(word+len-6, "active", 6) == 0) | |
170 | c = ' '; | |
52826846 NB |
171 | } |
172 | } | |
173 | if (c != EOF) ungetc(c, file); | |
82b27616 | 174 | } |
52826846 | 175 | word[len] = 0; |
2cdb6489 NB |
176 | |
177 | /* Further HACK for broken kernels.. 2.6.14-2.6.24 */ | |
178 | if (strcmp(word, "auto-read-only)") == 0) | |
179 | strcpy(word, "(auto-read-only)"); | |
180 | ||
82b27616 | 181 | /* printf("word is <%s>\n", word); */ |
52826846 NB |
182 | if (!wordfound) { |
183 | free(word); | |
184 | word = NULL; | |
185 | } | |
186 | return word; | |
82b27616 | 187 | } |
aba69144 | 188 | |
82b27616 NB |
189 | /* |
190 | * conf_line reads one logical line from the conffile. | |
191 | * It skips comments and continues until it finds a line that starts | |
192 | * with a non blank/comment. This character is pushed back for the next call | |
193 | * A doubly linked list of words is returned. | |
194 | * the first word will be a keyword. Other words will have had quotes removed. | |
195 | */ | |
196 | ||
197 | char *conf_line(FILE *file) | |
198 | { | |
52826846 NB |
199 | char *w; |
200 | char *list; | |
82b27616 | 201 | |
52826846 NB |
202 | w = conf_word(file, 1); |
203 | if (w == NULL) return NULL; | |
82b27616 | 204 | |
52826846 | 205 | list = dl_strdup(w); |
82b27616 | 206 | free(w); |
52826846 NB |
207 | dl_init(list); |
208 | ||
209 | while ((w = conf_word(file,0))){ | |
210 | char *w2 = dl_strdup(w); | |
211 | free(w); | |
212 | dl_add(list, w2); | |
213 | } | |
82b27616 | 214 | /* printf("got a line\n");*/ |
52826846 | 215 | return list; |
82b27616 NB |
216 | } |
217 | ||
218 | void free_line(char *line) | |
219 | { | |
52826846 NB |
220 | char *w; |
221 | for (w=dl_next(line); w != line; w=dl_next(line)) { | |
222 | dl_del(w); | |
223 | dl_free(w); | |
224 | } | |
225 | dl_free(line); | |
82b27616 NB |
226 | } |
227 | ||
228 | ||
229 | struct conf_dev { | |
230 | struct conf_dev *next; | |
231 | char *name; | |
232 | } *cdevlist = NULL; | |
233 | ||
057bd352 | 234 | mddev_dev_t load_partitions(void) |
5787fa49 NB |
235 | { |
236 | FILE *f = fopen("/proc/partitions", "r"); | |
237 | char buf[1024]; | |
057bd352 | 238 | mddev_dev_t rv = NULL; |
5787fa49 NB |
239 | if (f == NULL) { |
240 | fprintf(stderr, Name ": cannot open /proc/partitions\n"); | |
057bd352 | 241 | return NULL; |
5787fa49 NB |
242 | } |
243 | while (fgets(buf, 1024, f)) { | |
244 | int major, minor; | |
98c6faba | 245 | char *name, *mp; |
8b0dabea NB |
246 | mddev_dev_t d; |
247 | ||
5787fa49 NB |
248 | buf[1023] = '\0'; |
249 | if (buf[0] != ' ') | |
250 | continue; | |
98c6faba | 251 | major = strtoul(buf, &mp, 10); |
aba69144 | 252 | if (mp == buf || *mp != ' ') |
5787fa49 | 253 | continue; |
98c6faba NB |
254 | minor = strtoul(mp, NULL, 10); |
255 | ||
16c6fa80 | 256 | name = map_dev(major, minor, 1); |
e81cdd9f NB |
257 | if (!name) |
258 | continue; | |
8b0dabea NB |
259 | d = malloc(sizeof(*d)); |
260 | d->devname = strdup(name); | |
261 | d->next = rv; | |
da6b5ca9 | 262 | d->used = 0; |
9008ed1c | 263 | d->content = NULL; |
8b0dabea | 264 | rv = d; |
5787fa49 | 265 | } |
dd0781e5 | 266 | fclose(f); |
057bd352 | 267 | return rv; |
5787fa49 | 268 | } |
82b27616 | 269 | |
f64165f7 DW |
270 | mddev_dev_t load_containers(void) |
271 | { | |
272 | struct mdstat_ent *mdstat = mdstat_read(1, 0); | |
273 | struct mdstat_ent *ent; | |
274 | mddev_dev_t d; | |
275 | mddev_dev_t rv = NULL; | |
276 | ||
277 | if (!mdstat) | |
278 | return NULL; | |
279 | ||
280 | for (ent = mdstat; ent; ent = ent->next) | |
281 | if (ent->metadata_version && | |
282 | strncmp(ent->metadata_version, "external:", 9) == 0 && | |
283 | !is_subarray(&ent->metadata_version[9])) { | |
284 | d = malloc(sizeof(*d)); | |
285 | if (!d) | |
286 | continue; | |
287 | if (asprintf(&d->devname, "/dev/%s", ent->dev) < 0) { | |
288 | free(d); | |
289 | continue; | |
290 | } | |
291 | d->next = rv; | |
292 | d->used = 0; | |
9008ed1c | 293 | d->content = NULL; |
f64165f7 DW |
294 | rv = d; |
295 | } | |
296 | free_mdstat(mdstat); | |
297 | ||
298 | return rv; | |
299 | } | |
300 | ||
5bbb4842 | 301 | struct createinfo createinfo = { |
75723446 | 302 | .autof = 2, /* by default, create devices with standard names */ |
38098016 | 303 | .symlinks = 1, |
5bbb4842 NB |
304 | #ifdef DEBIAN |
305 | .gid = 6, /* disk */ | |
306 | .mode = 0660, | |
307 | #else | |
308 | .mode = 0600, | |
309 | #endif | |
310 | }; | |
311 | ||
f1ae21c4 | 312 | int parse_auto(char *str, char *msg, int config) |
5bbb4842 NB |
313 | { |
314 | int autof; | |
315 | if (str == NULL || *str == 0) | |
f1ae21c4 | 316 | autof = 2; |
5bbb4842 | 317 | else if (strcasecmp(str,"no")==0) |
f1ae21c4 | 318 | autof = 1; |
5bbb4842 | 319 | else if (strcasecmp(str,"yes")==0) |
f1ae21c4 | 320 | autof = 2; |
5bbb4842 | 321 | else if (strcasecmp(str,"md")==0) |
f1ae21c4 | 322 | autof = config?5:3; |
5bbb4842 NB |
323 | else { |
324 | /* There might be digits, and maybe a hypen, at the end */ | |
325 | char *e = str + strlen(str); | |
326 | int num = 4; | |
327 | int len; | |
328 | while (e > str && isdigit(e[-1])) | |
329 | e--; | |
330 | if (*e) { | |
331 | num = atoi(e); | |
332 | if (num <= 0) num = 1; | |
333 | } | |
334 | if (e > str && e[-1] == '-') | |
335 | e--; | |
336 | len = e - str; | |
f1ae21c4 NB |
337 | if ((len == 2 && strncasecmp(str,"md",2)==0)) { |
338 | autof = config ? 5 : 3; | |
6ba83b5f NB |
339 | } else if ((len == 3 && strncasecmp(str,"yes",3)==0)) { |
340 | autof = 2; | |
f1ae21c4 NB |
341 | } else if ((len == 3 && strncasecmp(str,"mdp",3)==0)) { |
342 | autof = config ? 6 : 4; | |
343 | } else if ((len == 1 && strncasecmp(str,"p",1)==0) || | |
344 | (len >= 4 && strncasecmp(str,"part",4)==0)) { | |
345 | autof = 6; | |
346 | } else { | |
5bbb4842 NB |
347 | fprintf(stderr, Name ": %s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n" |
348 | " optionally followed by a number.\n", | |
349 | msg, str); | |
350 | exit(2); | |
351 | } | |
f1ae21c4 | 352 | autof |= num << 3; |
5bbb4842 NB |
353 | } |
354 | return autof; | |
355 | } | |
f1ae21c4 | 356 | |
5bbb4842 NB |
357 | static void createline(char *line) |
358 | { | |
359 | char *w; | |
360 | char *ep; | |
361 | ||
362 | for (w=dl_next(line); w!=line; w=dl_next(w)) { | |
363 | if (strncasecmp(w, "auto=", 5) == 0) | |
f1ae21c4 | 364 | createinfo.autof = parse_auto(w+5, "auto=", 1); |
5bbb4842 NB |
365 | else if (strncasecmp(w, "owner=", 6) == 0) { |
366 | if (w[6] == 0) { | |
367 | fprintf(stderr, Name ": missing owner name\n"); | |
368 | continue; | |
369 | } | |
370 | createinfo.uid = strtoul(w+6, &ep, 10); | |
371 | if (*ep != 0) { | |
5bbb4842 NB |
372 | struct passwd *pw; |
373 | /* must be a name */ | |
374 | pw = getpwnam(w+6); | |
375 | if (pw) | |
376 | createinfo.uid = pw->pw_uid; | |
377 | else | |
5bbb4842 NB |
378 | fprintf(stderr, Name ": CREATE user %s not found\n", w+6); |
379 | } | |
380 | } else if (strncasecmp(w, "group=", 6) == 0) { | |
381 | if (w[6] == 0) { | |
382 | fprintf(stderr, Name ": missing group name\n"); | |
383 | continue; | |
384 | } | |
385 | createinfo.gid = strtoul(w+6, &ep, 10); | |
386 | if (*ep != 0) { | |
5bbb4842 NB |
387 | struct group *gr; |
388 | /* must be a name */ | |
389 | gr = getgrnam(w+6); | |
390 | if (gr) | |
391 | createinfo.gid = gr->gr_gid; | |
392 | else | |
5bbb4842 NB |
393 | fprintf(stderr, Name ": CREATE group %s not found\n", w+6); |
394 | } | |
395 | } else if (strncasecmp(w, "mode=", 5) == 0) { | |
396 | if (w[5] == 0) { | |
397 | fprintf(stderr, Name ": missing CREATE mode\n"); | |
398 | continue; | |
399 | } | |
400 | createinfo.mode = strtoul(w+5, &ep, 8); | |
401 | if (*ep != 0) { | |
402 | createinfo.mode = 0600; | |
403 | fprintf(stderr, Name ": unrecognised CREATE mode %s\n", | |
404 | w+5); | |
405 | } | |
058574b1 NB |
406 | } else if (strncasecmp(w, "metadata=", 9) == 0) { |
407 | /* style of metadata to use by default */ | |
408 | int i; | |
409 | for (i=0; superlist[i] && !createinfo.supertype; i++) | |
410 | createinfo.supertype = | |
411 | superlist[i]->match_metadata_desc(w+9); | |
412 | if (!createinfo.supertype) | |
413 | fprintf(stderr, Name ": metadata format %s unknown, ignoring\n", | |
414 | w+9); | |
38098016 NB |
415 | } else if (strncasecmp(w, "symlinks=yes", 12) == 0) |
416 | createinfo.symlinks = 1; | |
417 | else if (strncasecmp(w, "symlinks=no", 11) == 0) | |
418 | createinfo.symlinks = 0; | |
419 | else { | |
5bbb4842 NB |
420 | fprintf(stderr, Name ": unrecognised word on CREATE line: %s\n", |
421 | w); | |
422 | } | |
423 | } | |
424 | } | |
82b27616 | 425 | |
aba69144 | 426 | void devline(char *line) |
82b27616 | 427 | { |
52826846 NB |
428 | char *w; |
429 | struct conf_dev *cd; | |
430 | ||
431 | for (w=dl_next(line); w != line; w=dl_next(w)) { | |
f64165f7 DW |
432 | if (w[0] == '/' || strcasecmp(w, "partitions") == 0 || |
433 | strcasecmp(w, "containers") == 0) { | |
52826846 NB |
434 | cd = malloc(sizeof(*cd)); |
435 | cd->name = strdup(w); | |
436 | cd->next = cdevlist; | |
437 | cdevlist = cd; | |
438 | } else { | |
439 | fprintf(stderr, Name ": unreconised word on DEVICE line: %s\n", | |
440 | w); | |
441 | } | |
82b27616 | 442 | } |
82b27616 NB |
443 | } |
444 | ||
52826846 NB |
445 | mddev_ident_t mddevlist = NULL; |
446 | mddev_ident_t *mddevlp = &mddevlist; | |
82b27616 | 447 | |
db2d001c N |
448 | static int is_number(char *w) |
449 | { | |
450 | /* check if there are 1 or more digits and nothing else */ | |
451 | int digits = 0; | |
452 | while (*w && isdigit(*w)) { | |
453 | digits++; | |
454 | w++; | |
455 | } | |
456 | return (digits && ! *w); | |
457 | } | |
458 | ||
82b27616 NB |
459 | void arrayline(char *line) |
460 | { | |
52826846 NB |
461 | char *w; |
462 | ||
463 | struct mddev_ident_s mis; | |
464 | mddev_ident_t mi; | |
465 | ||
466 | mis.uuid_set = 0; | |
98c6faba NB |
467 | mis.super_minor = UnSet; |
468 | mis.level = UnSet; | |
469 | mis.raid_disks = UnSet; | |
4ccdb956 | 470 | mis.spare_disks = 0; |
52826846 NB |
471 | mis.devices = NULL; |
472 | mis.devname = NULL; | |
e0d19036 | 473 | mis.spare_group = NULL; |
dd0781e5 | 474 | mis.autof = 0; |
92919398 | 475 | mis.next = NULL; |
f277ce36 NB |
476 | mis.st = NULL; |
477 | mis.bitmap_fd = -1; | |
7ef02d01 | 478 | mis.bitmap_file = NULL; |
947fd4dd | 479 | mis.name[0] = 0; |
71d60c48 DW |
480 | mis.container = NULL; |
481 | mis.member = NULL; | |
52826846 NB |
482 | |
483 | for (w=dl_next(line); w!=line; w=dl_next(w)) { | |
db2d001c N |
484 | if (w[0] == '/' || strchr(w, '=') == NULL) { |
485 | /* This names the device, or is '<ignore>'. | |
486 | * The rules match those in create_mddev. | |
487 | * 'w' must be: | |
488 | * /dev/md/{anything} | |
489 | * /dev/mdNN | |
490 | * /dev/md_dNN | |
491 | * <ignore> | |
492 | * or anything that doesn't start '/' or '<' | |
493 | */ | |
494 | if (strcasecmp(w, "<ignore>") == 0 || | |
495 | strncmp(w, "/dev/md/", 8) == 0 || | |
496 | (w[0] != '/' && w[0] != '<') || | |
497 | (strncmp(w, "/dev/md", 7) == 0 && | |
498 | is_number(w+7)) || | |
499 | (strncmp(w, "/dev/md_d", 9) == 0 && | |
500 | is_number(w+9)) | |
501 | ) { | |
502 | /* This is acceptable */; | |
503 | if (mis.devname) | |
504 | fprintf(stderr, Name ": only give one " | |
505 | "device per ARRAY line: %s and %s\n", | |
506 | mis.devname, w); | |
507 | else | |
508 | mis.devname = w; | |
509 | }else { | |
510 | fprintf(stderr, Name ": %s is an invalid name for " | |
511 | "an md device - ignored.\n", w); | |
512 | } | |
52826846 NB |
513 | } else if (strncasecmp(w, "uuid=", 5)==0 ) { |
514 | if (mis.uuid_set) | |
515 | fprintf(stderr, Name ": only specify uuid once, %s ignored.\n", | |
516 | w); | |
517 | else { | |
518 | if (parse_uuid(w+5, mis.uuid)) | |
519 | mis.uuid_set = 1; | |
520 | else | |
521 | fprintf(stderr, Name ": bad uuid: %s\n", w); | |
522 | } | |
523 | } else if (strncasecmp(w, "super-minor=", 12)==0 ) { | |
f277ce36 | 524 | if (mis.super_minor != UnSet) |
52826846 NB |
525 | fprintf(stderr, Name ": only specify super-minor once, %s ignored.\n", |
526 | w); | |
527 | else { | |
528 | char *endptr; | |
f21e18ca N |
529 | int minor = strtol(w+12, &endptr, 10); |
530 | ||
531 | if (w[12]==0 || endptr[0]!=0 || minor < 0) | |
52826846 NB |
532 | fprintf(stderr, Name ": invalid super-minor number: %s\n", |
533 | w); | |
f21e18ca N |
534 | else |
535 | mis.super_minor = minor; | |
52826846 | 536 | } |
947fd4dd NB |
537 | } else if (strncasecmp(w, "name=", 5)==0) { |
538 | if (mis.name[0]) | |
539 | fprintf(stderr, Name ": only specify name once, %s ignored.\n", | |
540 | w); | |
541 | else if (strlen(w+5) > 32) | |
542 | fprintf(stderr, Name ": name too long, ignoring %s\n", w); | |
543 | else | |
544 | strcpy(mis.name, w+5); | |
545 | ||
7ef02d01 NB |
546 | } else if (strncasecmp(w, "bitmap=", 7) == 0) { |
547 | if (mis.bitmap_file) | |
548 | fprintf(stderr, Name ": only specify bitmap file once. %s ignored\n", | |
549 | w); | |
550 | else | |
d87d0978 | 551 | mis.bitmap_file = strdup(w+7); |
7ef02d01 | 552 | |
52826846 NB |
553 | } else if (strncasecmp(w, "devices=", 8 ) == 0 ) { |
554 | if (mis.devices) | |
555 | fprintf(stderr, Name ": only specify devices once (use a comma separated list). %s ignored\n", | |
556 | w); | |
557 | else | |
558 | mis.devices = strdup(w+8); | |
559 | } else if (strncasecmp(w, "spare-group=", 12) == 0 ) { | |
560 | if (mis.spare_group) | |
561 | fprintf(stderr, Name ": only specify one spare group per array. %s ignored.\n", | |
562 | w); | |
563 | else | |
564 | mis.spare_group = strdup(w+12); | |
cd29a5c8 NB |
565 | } else if (strncasecmp(w, "level=", 6) == 0 ) { |
566 | /* this is mainly for compatability with --brief output */ | |
567 | mis.level = map_name(pers, w+6); | |
568 | } else if (strncasecmp(w, "disks=", 6) == 0 ) { | |
569 | /* again, for compat */ | |
feb716e9 | 570 | mis.raid_disks = atoi(w+6); |
b83d95f3 NB |
571 | } else if (strncasecmp(w, "num-devices=", 12) == 0 ) { |
572 | /* again, for compat */ | |
feb716e9 NB |
573 | mis.raid_disks = atoi(w+12); |
574 | } else if (strncasecmp(w, "spares=", 7) == 0 ) { | |
575 | /* for warning if not all spares present */ | |
576 | mis.spare_disks = atoi(w+7); | |
f9ce90ba NB |
577 | } else if (strncasecmp(w, "metadata=", 9) == 0) { |
578 | /* style of metadata on the devices. */ | |
579 | int i; | |
aba69144 | 580 | |
82d9eba6 NB |
581 | for(i=0; superlist[i] && !mis.st; i++) |
582 | mis.st = superlist[i]->match_metadata_desc(w+9); | |
583 | ||
584 | if (!mis.st) | |
f9ce90ba | 585 | fprintf(stderr, Name ": metadata format %s unknown, ignored.\n", w+9); |
dd0781e5 NB |
586 | } else if (strncasecmp(w, "auto=", 5) == 0 ) { |
587 | /* whether to create device special files as needed */ | |
f1ae21c4 | 588 | mis.autof = parse_auto(w+5, "auto type", 0); |
dbb44303 N |
589 | } else if (strncasecmp(w, "member=", 7) == 0) { |
590 | /* subarray within a container */ | |
591 | mis.member = strdup(w+7); | |
592 | } else if (strncasecmp(w, "container=", 10) == 0) { | |
1771a6e2 N |
593 | /* the container holding this subarray. Either a device name |
594 | * or a uuid */ | |
dbb44303 | 595 | mis.container = strdup(w+10); |
52826846 NB |
596 | } else { |
597 | fprintf(stderr, Name ": unrecognised word on ARRAY line: %s\n", | |
598 | w); | |
599 | } | |
600 | } | |
b1b12d58 N |
601 | if (mis.uuid_set == 0 && mis.devices == NULL && |
602 | mis.super_minor == UnSet && mis.name[0] == 0 && | |
aa7c284c | 603 | (mis.container == NULL || mis.member == NULL)) |
52826846 NB |
604 | fprintf(stderr, Name ": ARRAY line %s has no identity information.\n", mis.devname); |
605 | else { | |
606 | mi = malloc(sizeof(*mi)); | |
607 | *mi = mis; | |
fe056d1f | 608 | mi->devname = mis.devname ? strdup(mis.devname) : NULL; |
52826846 NB |
609 | mi->next = NULL; |
610 | *mddevlp = mi; | |
611 | mddevlp = &mi->next; | |
82b27616 | 612 | } |
82b27616 | 613 | } |
e0d19036 NB |
614 | |
615 | static char *alert_email = NULL; | |
616 | void mailline(char *line) | |
617 | { | |
618 | char *w; | |
619 | ||
620 | for (w=dl_next(line); w != line ; w=dl_next(w)) { | |
621 | if (alert_email == NULL) | |
622 | alert_email = strdup(w); | |
623 | else | |
624 | fprintf(stderr, Name ": excess address on MAIL line: %s - ignored\n", | |
625 | w); | |
626 | } | |
627 | } | |
628 | ||
4948b8f7 NB |
629 | static char *alert_mail_from = NULL; |
630 | void mailfromline(char *line) | |
631 | { | |
632 | char *w; | |
633 | ||
634 | for (w=dl_next(line); w != line ; w=dl_next(w)) { | |
635 | if (alert_mail_from == NULL) | |
636 | alert_mail_from = strdup(w); | |
637 | else { | |
3d2c4fc7 DW |
638 | char *t = NULL; |
639 | ||
78fbcc10 | 640 | if (xasprintf(&t, "%s %s", alert_mail_from, w) > 0) { |
3d2c4fc7 DW |
641 | free(alert_mail_from); |
642 | alert_mail_from = t; | |
643 | } | |
4948b8f7 NB |
644 | } |
645 | } | |
646 | } | |
647 | ||
e0d19036 NB |
648 | |
649 | static char *alert_program = NULL; | |
650 | void programline(char *line) | |
651 | { | |
652 | char *w; | |
653 | ||
654 | for (w=dl_next(line); w != line ; w=dl_next(w)) { | |
655 | if (alert_program == NULL) | |
656 | alert_program = strdup(w); | |
657 | else | |
658 | fprintf(stderr, Name ": excess program on PROGRAM line: %s - ignored\n", | |
659 | w); | |
660 | } | |
661 | } | |
662 | ||
997aed5d | 663 | static char *home_host = NULL; |
0ac91628 | 664 | static int require_homehost = 1; |
997aed5d NB |
665 | void homehostline(char *line) |
666 | { | |
667 | char *w; | |
668 | ||
669 | for (w=dl_next(line); w != line ; w=dl_next(w)) { | |
0ac91628 N |
670 | if (strcasecmp(w, "<ignore>")==0) |
671 | require_homehost = 0; | |
672 | else if (home_host == NULL) | |
997aed5d NB |
673 | home_host = strdup(w); |
674 | else | |
675 | fprintf(stderr, Name ": excess host name on HOMEHOST line: %s - ignored\n", | |
676 | w); | |
677 | } | |
678 | } | |
679 | ||
4e8d9f0a N |
680 | char auto_yes[] = "yes"; |
681 | char auto_no[] = "no"; | |
682 | char auto_homehost[] = "homehost"; | |
683 | ||
684 | static int auto_seen = 0; | |
31015d57 N |
685 | void autoline(char *line) |
686 | { | |
4d0b563b | 687 | char *w; |
4e8d9f0a N |
688 | char *seen; |
689 | int super_cnt; | |
690 | char *dflt = auto_yes; | |
691 | int homehost = 0; | |
692 | int i; | |
4d0b563b | 693 | |
4e8d9f0a | 694 | if (auto_seen) { |
31015d57 N |
695 | fprintf(stderr, Name ": AUTO line may only be give once." |
696 | " Subsequent lines ignored\n"); | |
697 | return; | |
698 | } | |
4e8d9f0a N |
699 | /* Parse the 'auto' line creating policy statements for the 'auto' policy. |
700 | * | |
701 | * The default is 'yes' but the 'auto' line might over-ride that. | |
702 | * Words in the line are processed in order with the first | |
703 | * match winning. | |
704 | * word can be: | |
705 | * +version - that version can be assembled | |
706 | * -version - that version cannot be auto-assembled | |
707 | * yes or +all - any other version can be assembled | |
708 | * no or -all - no other version can be assembled. | |
709 | * homehost - any array associated by 'homehost' to this | |
710 | * host can be assembled. | |
711 | * | |
712 | * Thus: | |
713 | * +ddf -0.90 homehost -all | |
714 | * will auto-assemble any ddf array, no 0.90 array, and | |
715 | * any other array (imsm, 1.x) if and only if it is identified | |
716 | * as belonging to this host. | |
717 | * | |
718 | * We translate that to policy by creating 'auto=yes' when we see | |
719 | * a '+version' line, 'auto=no' if we see '-version' before 'homehost', | |
720 | * or 'auto=homehost' if we see '-version' after 'homehost'. | |
721 | * When we see yes, no, +all or -all we stop an any version that hasn't | |
722 | * been seen gets an appropriate auto= entry. | |
723 | */ | |
4d0b563b | 724 | |
4e8d9f0a N |
725 | for (super_cnt = 0; superlist[super_cnt]; super_cnt++) |
726 | ; | |
727 | seen = calloc(super_cnt, 1); | |
4d0b563b | 728 | |
4e8d9f0a N |
729 | for (w = dl_next(line); w != line ; w = dl_next(w)) { |
730 | char *val; | |
731 | ||
732 | if (strcasecmp(w, "yes") == 0) { | |
733 | dflt = auto_yes; | |
734 | break; | |
735 | } | |
736 | if (strcasecmp(w, "no") == 0) { | |
737 | if (homehost) | |
738 | dflt = auto_homehost; | |
739 | else | |
740 | dflt = auto_no; | |
741 | break; | |
742 | } | |
743 | if (strcasecmp(w, "homehost") == 0) { | |
744 | homehost = 1; | |
745 | continue; | |
746 | } | |
747 | if (w[0] == '+') | |
748 | val = auto_yes; | |
749 | else if (w[0] == '-') { | |
750 | if (homehost) | |
751 | val = auto_homehost; | |
752 | else | |
753 | val = auto_no; | |
754 | } else | |
755 | continue; | |
756 | ||
757 | if (strcasecmp(w+1, "all") == 0) { | |
758 | dflt = val; | |
759 | break; | |
760 | } | |
761 | for (i = 0; superlist[i]; i++) { | |
762 | const char *version = superlist[i]->name; | |
763 | if (strcasecmp(w+1, version) == 0) | |
764 | break; | |
765 | /* 1 matches 1.x, 0 matches 0.90 */ | |
766 | if (version[1] == '.' && | |
767 | strlen(w+1) == 1 && | |
768 | w[1] == version[0]) | |
769 | break; | |
770 | /* 1.anything matches 1.x */ | |
771 | if (strcmp(version, "1.x") == 0 && | |
772 | strncmp(w+1, "1.", 2) == 0) | |
773 | break; | |
774 | } | |
775 | if (superlist[i] == NULL) | |
776 | /* ignore this word */ | |
777 | continue; | |
778 | if (seen[i]) | |
779 | /* already know about this metadata */ | |
780 | continue; | |
781 | policy_add(rule_policy, pol_auto, val, pol_metadata, superlist[i]->name, NULL); | |
782 | seen[i] = 1; | |
4d0b563b | 783 | } |
4e8d9f0a N |
784 | for (i = 0; i < super_cnt; i++) |
785 | if (!seen[i]) | |
786 | policy_add(rule_policy, pol_auto, dflt, pol_metadata, superlist[i]->name, NULL); | |
31015d57 | 787 | } |
e0d19036 | 788 | |
82b27616 NB |
789 | int loaded = 0; |
790 | ||
8aec876d NB |
791 | static char *conffile = NULL; |
792 | void set_conffile(char *file) | |
793 | { | |
794 | conffile = file; | |
795 | } | |
796 | ||
797 | void load_conffile(void) | |
82b27616 | 798 | { |
52826846 NB |
799 | FILE *f; |
800 | char *line; | |
801 | ||
802 | if (loaded) return; | |
803 | if (conffile == NULL) | |
804 | conffile = DefaultConfFile; | |
805 | ||
d013a55e NB |
806 | if (strcmp(conffile, "none") == 0) { |
807 | loaded = 1; | |
808 | return; | |
809 | } | |
5787fa49 | 810 | if (strcmp(conffile, "partitions")==0) { |
b5687415 NB |
811 | char *list = dl_strdup("DEV"); |
812 | dl_init(list); | |
813 | dl_add(list, dl_strdup("partitions")); | |
814 | devline(list); | |
815 | free_line(list); | |
d013a55e | 816 | loaded = 1; |
5787fa49 NB |
817 | return; |
818 | } | |
52826846 | 819 | f = fopen(conffile, "r"); |
ce4fafd6 NB |
820 | /* Debian chose to relocate mdadm.conf into /etc/mdadm/. |
821 | * To allow Debian users to compile from clean source and still | |
822 | * have a working mdadm, we read /etc/mdadm/mdadm.conf | |
823 | * if /etc/mdadm.conf doesn't exist | |
824 | */ | |
825 | if (f == NULL && | |
826 | conffile == DefaultConfFile) { | |
827 | f = fopen(DefaultAltConfFile, "r"); | |
828 | if (f) | |
829 | conffile = DefaultAltConfFile; | |
830 | } | |
831 | if (f == NULL) | |
52826846 NB |
832 | return; |
833 | ||
834 | loaded = 1; | |
835 | while ((line=conf_line(f))) { | |
836 | switch(match_keyword(line)) { | |
8fe9db0f | 837 | case Devices: |
52826846 NB |
838 | devline(line); |
839 | break; | |
8fe9db0f | 840 | case Array: |
52826846 NB |
841 | arrayline(line); |
842 | break; | |
8fe9db0f | 843 | case Mailaddr: |
e0d19036 NB |
844 | mailline(line); |
845 | break; | |
8fe9db0f | 846 | case Mailfrom: |
4948b8f7 NB |
847 | mailfromline(line); |
848 | break; | |
8fe9db0f NB |
849 | case Program: |
850 | programline(line); | |
851 | break; | |
852 | case CreateDev: | |
5bbb4842 NB |
853 | createline(line); |
854 | break; | |
997aed5d NB |
855 | case Homehost: |
856 | homehostline(line); | |
857 | break; | |
31015d57 N |
858 | case AutoMode: |
859 | autoline(line); | |
860 | break; | |
5527fc74 N |
861 | case Policy: |
862 | policyline(line, rule_policy); | |
863 | break; | |
864 | case PartPolicy: | |
865 | policyline(line, rule_part); | |
866 | break; | |
52826846 NB |
867 | default: |
868 | fprintf(stderr, Name ": Unknown keyword %s\n", line); | |
869 | } | |
870 | free_line(line); | |
82b27616 | 871 | } |
aba69144 | 872 | |
dd0781e5 | 873 | fclose(f); |
82b27616 NB |
874 | |
875 | /* printf("got file\n"); */ | |
876 | } | |
877 | ||
8aec876d | 878 | char *conf_get_mailaddr(void) |
e0d19036 | 879 | { |
8aec876d | 880 | load_conffile(); |
e0d19036 NB |
881 | return alert_email; |
882 | } | |
883 | ||
8aec876d | 884 | char *conf_get_mailfrom(void) |
4948b8f7 | 885 | { |
8aec876d | 886 | load_conffile(); |
4948b8f7 NB |
887 | return alert_mail_from; |
888 | } | |
889 | ||
8aec876d | 890 | char *conf_get_program(void) |
e0d19036 | 891 | { |
8aec876d | 892 | load_conffile(); |
e0d19036 NB |
893 | return alert_program; |
894 | } | |
895 | ||
0ac91628 | 896 | char *conf_get_homehost(int *require_homehostp) |
997aed5d | 897 | { |
8aec876d | 898 | load_conffile(); |
0ac91628 N |
899 | if (require_homehostp) |
900 | *require_homehostp = require_homehost; | |
997aed5d NB |
901 | return home_host; |
902 | } | |
903 | ||
8aec876d | 904 | struct createinfo *conf_get_create_info(void) |
5bbb4842 | 905 | { |
8aec876d | 906 | load_conffile(); |
5bbb4842 NB |
907 | return &createinfo; |
908 | } | |
82b27616 | 909 | |
8aec876d | 910 | mddev_ident_t conf_get_ident(char *dev) |
64c4757e | 911 | { |
52826846 | 912 | mddev_ident_t rv; |
8aec876d | 913 | load_conffile(); |
52826846 | 914 | rv = mddevlist; |
fe056d1f | 915 | while (dev && rv && (rv->devname == NULL |
5c4c9ab1 | 916 | || !devname_matches(dev, rv->devname))) |
52826846 NB |
917 | rv = rv->next; |
918 | return rv; | |
64c4757e NB |
919 | } |
920 | ||
f64165f7 DW |
921 | static void append_dlist(mddev_dev_t *dlp, mddev_dev_t list) |
922 | { | |
923 | while (*dlp) | |
924 | dlp = &(*dlp)->next; | |
925 | *dlp = list; | |
926 | } | |
927 | ||
8aec876d | 928 | mddev_dev_t conf_get_devs() |
64c4757e | 929 | { |
52826846 NB |
930 | glob_t globbuf; |
931 | struct conf_dev *cd; | |
932 | int flags = 0; | |
933 | static mddev_dev_t dlist = NULL; | |
98c6faba | 934 | unsigned int i; |
52826846 NB |
935 | |
936 | while (dlist) { | |
937 | mddev_dev_t t = dlist; | |
938 | dlist = dlist->next; | |
939 | free(t->devname); | |
940 | free(t); | |
941 | } | |
aba69144 | 942 | |
8aec876d | 943 | load_conffile(); |
a99d6b66 | 944 | |
f8f84cd5 DW |
945 | if (cdevlist == NULL) { |
946 | /* default to 'partitions' and 'containers' */ | |
a99d6b66 | 947 | dlist = load_partitions(); |
f8f84cd5 DW |
948 | append_dlist(&dlist, load_containers()); |
949 | } | |
a99d6b66 | 950 | |
52826846 | 951 | for (cd=cdevlist; cd; cd=cd->next) { |
f64165f7 DW |
952 | if (strcasecmp(cd->name, "partitions")==0) |
953 | append_dlist(&dlist, load_partitions()); | |
954 | else if (strcasecmp(cd->name, "containers")==0) | |
955 | append_dlist(&dlist, load_containers()); | |
057bd352 NB |
956 | else { |
957 | glob(cd->name, flags, NULL, &globbuf); | |
958 | flags |= GLOB_APPEND; | |
959 | } | |
52826846 | 960 | } |
e0d19036 NB |
961 | if (flags & GLOB_APPEND) { |
962 | for (i=0; i<globbuf.gl_pathc; i++) { | |
963 | mddev_dev_t t = malloc(sizeof(*t)); | |
964 | t->devname = strdup(globbuf.gl_pathv[i]); | |
965 | t->next = dlist; | |
da6b5ca9 | 966 | t->used = 0; |
9008ed1c | 967 | t->content = NULL; |
e0d19036 | 968 | dlist = t; |
82b27616 | 969 | /* printf("one dev is %s\n", t->devname);*/ |
e0d19036 NB |
970 | } |
971 | globfree(&globbuf); | |
52826846 | 972 | } |
82b27616 | 973 | |
52826846 | 974 | return dlist; |
64c4757e NB |
975 | } |
976 | ||
8382f19b NB |
977 | int conf_test_dev(char *devname) |
978 | { | |
979 | struct conf_dev *cd; | |
980 | if (cdevlist == NULL) | |
981 | /* allow anything by default */ | |
982 | return 1; | |
983 | for (cd = cdevlist ; cd ; cd = cd->next) { | |
984 | if (strcasecmp(cd->name, "partitions") == 0) | |
985 | return 1; | |
986 | if (fnmatch(cd->name, devname, FNM_PATHNAME) == 0) | |
987 | return 1; | |
988 | } | |
989 | return 0; | |
990 | } | |
991 | ||
4e8d9f0a | 992 | int conf_test_metadata(const char *version, struct dev_policy *pol, int is_homehost) |
31015d57 | 993 | { |
4e8d9f0a N |
994 | /* If anyone said 'yes', that sticks. |
995 | * else if homehost applies, use that | |
996 | * else if there is a 'no', say 'no'. | |
997 | * else 'yes'. | |
31015d57 | 998 | */ |
4e8d9f0a N |
999 | struct dev_policy *p; |
1000 | int no=0, found_auto=0; | |
31015d57 | 1001 | load_conffile(); |
4e8d9f0a N |
1002 | |
1003 | pol = pol_find(pol, pol_auto); | |
1004 | pol_for_each(p, pol, version) { | |
1005 | if (strcmp(p->value, "yes") == 0) | |
31015d57 | 1006 | return 1; |
4e8d9f0a N |
1007 | if (strcmp(p->value, "auto") == 0) |
1008 | found_auto = 1; | |
1009 | if (strcmp(p->value, "no") == 0) | |
1010 | no = 1; | |
31015d57 | 1011 | } |
4e8d9f0a N |
1012 | if (is_homehost && found_auto) |
1013 | return 1; | |
1014 | if (no) | |
1015 | return 0; | |
31015d57 N |
1016 | return 1; |
1017 | } | |
8382f19b | 1018 | |
52826846 NB |
1019 | int match_oneof(char *devices, char *devname) |
1020 | { | |
1021 | /* check if one of the comma separated patterns in devices | |
1022 | * matches devname | |
1023 | */ | |
1024 | ||
52826846 NB |
1025 | while (devices && *devices) { |
1026 | char patn[1024]; | |
1027 | char *p = devices; | |
1028 | devices = strchr(devices, ','); | |
1029 | if (!devices) | |
1030 | devices = p + strlen(p); | |
1031 | if (devices-p < 1024) { | |
1032 | strncpy(patn, p, devices-p); | |
1033 | patn[devices-p] = 0; | |
1034 | if (fnmatch(patn, devname, FNM_PATHNAME)==0) | |
1035 | return 1; | |
1036 | } | |
1037 | if (*devices == ',') | |
1038 | devices++; | |
1039 | } | |
1040 | return 0; | |
1041 | } | |
0ac91628 N |
1042 | |
1043 | int devname_matches(char *name, char *match) | |
1044 | { | |
1045 | /* See if the given array name matches the | |
1046 | * given match from config file. | |
1047 | * | |
1048 | * First strip and /dev/md/ or /dev/, then | |
1049 | * see if there might be a numeric match of | |
1050 | * mdNN with NN | |
1051 | * then just strcmp | |
1052 | */ | |
1053 | if (strncmp(name, "/dev/md/", 8) == 0) | |
1054 | name += 8; | |
1055 | else if (strncmp(name, "/dev/", 5) == 0) | |
1056 | name += 5; | |
1057 | ||
1058 | if (strncmp(match, "/dev/md/", 8) == 0) | |
1059 | match += 8; | |
1060 | else if (strncmp(match, "/dev/", 5) == 0) | |
1061 | match += 5; | |
1062 | ||
1063 | ||
1064 | if (strncmp(name, "md", 2) == 0 && | |
1065 | isdigit(name[2])) | |
1066 | name += 2; | |
1067 | if (strncmp(match, "md", 2) == 0 && | |
1068 | isdigit(match[2])) | |
1069 | match += 2; | |
1070 | ||
1071 | return (strcmp(name, match) == 0); | |
1072 | } | |
1073 | ||
1074 | int conf_name_is_free(char *name) | |
1075 | { | |
1076 | /* Check if this name is already take by an ARRAY entry in | |
1077 | * the config file. | |
1078 | * It can be taken either by a match on devname, name, or | |
1079 | * even super-minor. | |
1080 | */ | |
1081 | mddev_ident_t dev; | |
1082 | ||
1083 | load_conffile(); | |
1084 | for (dev = mddevlist; dev; dev = dev->next) { | |
1085 | char nbuf[100]; | |
1086 | if (dev->devname && devname_matches(name, dev->devname)) | |
1087 | return 0; | |
1088 | if (dev->name[0] && devname_matches(name, dev->name)) | |
1089 | return 0; | |
1090 | sprintf(nbuf, "%d", dev->super_minor); | |
1091 | if (dev->super_minor != UnSet && | |
1092 | devname_matches(name, nbuf)) | |
1093 | return 0; | |
1094 | } | |
1095 | return 1; | |
1096 | } | |
360b4636 N |
1097 | |
1098 | struct mddev_ident_s *conf_match(struct mdinfo *info, struct supertype *st) | |
1099 | { | |
1100 | struct mddev_ident_s *array_list, *match; | |
1101 | int verbose = 0; | |
1102 | char *devname = NULL; | |
1103 | array_list = conf_get_ident(NULL); | |
1104 | match = NULL; | |
1105 | for (; array_list; array_list = array_list->next) { | |
1106 | if (array_list->uuid_set && | |
1107 | same_uuid(array_list->uuid, info->uuid, st->ss->swapuuid) | |
1108 | == 0) { | |
1109 | if (verbose >= 2 && array_list->devname) | |
1110 | fprintf(stderr, Name | |
1111 | ": UUID differs from %s.\n", | |
1112 | array_list->devname); | |
1113 | continue; | |
1114 | } | |
1115 | if (array_list->name[0] && | |
1116 | strcasecmp(array_list->name, info->name) != 0) { | |
1117 | if (verbose >= 2 && array_list->devname) | |
1118 | fprintf(stderr, Name | |
1119 | ": Name differs from %s.\n", | |
1120 | array_list->devname); | |
1121 | continue; | |
1122 | } | |
1123 | if (array_list->devices && devname && | |
1124 | !match_oneof(array_list->devices, devname)) { | |
1125 | if (verbose >= 2 && array_list->devname) | |
1126 | fprintf(stderr, Name | |
1127 | ": Not a listed device for %s.\n", | |
1128 | array_list->devname); | |
1129 | continue; | |
1130 | } | |
1131 | if (array_list->super_minor != UnSet && | |
1132 | array_list->super_minor != info->array.md_minor) { | |
1133 | if (verbose >= 2 && array_list->devname) | |
1134 | fprintf(stderr, Name | |
1135 | ": Different super-minor to %s.\n", | |
1136 | array_list->devname); | |
1137 | continue; | |
1138 | } | |
1139 | if (!array_list->uuid_set && | |
1140 | !array_list->name[0] && | |
1141 | !array_list->devices && | |
1142 | array_list->super_minor == UnSet) { | |
1143 | if (verbose >= 2 && array_list->devname) | |
1144 | fprintf(stderr, Name | |
1145 | ": %s doesn't have any identifying information.\n", | |
1146 | array_list->devname); | |
1147 | continue; | |
1148 | } | |
1149 | /* FIXME, should I check raid_disks and level too?? */ | |
1150 | ||
1151 | if (match) { | |
1152 | if (verbose >= 0) { | |
1153 | if (match->devname && array_list->devname) | |
1154 | fprintf(stderr, Name | |
1155 | ": we match both %s and %s - cannot decide which to use.\n", | |
1156 | match->devname, array_list->devname); | |
1157 | else | |
1158 | fprintf(stderr, Name | |
1159 | ": multiple lines in mdadm.conf match\n"); | |
1160 | } | |
1161 | return NULL; | |
1162 | } | |
1163 | match = array_list; | |
1164 | } | |
1165 | return match; | |
1166 | } |