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