]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Incremental.c
Incremental: fix 'name_to_use' in the container case
[thirdparty/mdadm.git] / Incremental.c
1 /*
2 * Incremental.c - support --incremental. Part of:
3 * mdadm - manage Linux "md" devices aka RAID arrays.
4 *
5 * Copyright (C) 2006 Neil Brown <neilb@suse.de>
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 * Author: Neil Brown
23 * Email: <neilb@suse.de>
24 * Paper: Neil Brown
25 * Novell Inc
26 * GPO Box Q1283
27 * QVB Post Office, NSW 1230
28 * Australia
29 */
30
31 #include "mdadm.h"
32
33 static int count_active(struct supertype *st, int mdfd, char **availp,
34 struct mdinfo *info);
35 static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
36 int number, __u64 events, int verbose,
37 char *array_name);
38
39 int Incremental(char *devname, int verbose, int runstop,
40 struct supertype *st, char *homehost, int autof)
41 {
42 /* Add this device to an array, creating the array if necessary
43 * and starting the array if sensible or - if runstop>0 - if possible.
44 *
45 * This has several steps:
46 *
47 * 1/ Check if device is permitted by mdadm.conf, reject if not.
48 * 2/ Find metadata, reject if none appropriate (check
49 * version/name from args)
50 * 3/ Check if there is a match in mdadm.conf
51 * 3a/ if not, check for homehost match. If no match, assemble as
52 * a 'foreign' array.
53 * 4/ Determine device number.
54 * - If in mdadm.conf with std name, use that
55 * - UUID in /var/run/mdadm.map use that
56 * - If name is suggestive, use that. unless in use with different uuid.
57 * - Choose a free, high number.
58 * - Use a partitioned device unless strong suggestion not to.
59 * e.g. auto=md
60 * Don't choose partitioned for containers.
61 * 5/ Find out if array already exists
62 * 5a/ if it does not
63 * - choose a name, from mdadm.conf or 'name' field in array.
64 * - create the array
65 * - add the device
66 * 5b/ if it does
67 * - check one drive in array to make sure metadata is a reasonably
68 * close match. Reject if not (e.g. different type)
69 * - add the device
70 * 6/ Make sure /var/run/mdadm.map contains this array.
71 * 7/ Is there enough devices to possibly start the array?
72 * For a container, this means running Incremental_container.
73 * 7a/ if not, finish with success.
74 * 7b/ if yes,
75 * - read all metadata and arrange devices like -A does
76 * - if number of OK devices match expected, or -R and there are enough,
77 * start the array (auto-readonly).
78 */
79 struct stat stb;
80 struct mdinfo info;
81 struct mddev_ident_s *array_list, *match;
82 char chosen_name[1024];
83 int rv;
84 struct map_ent *mp, *map = NULL;
85 int dfd, mdfd;
86 char *avail;
87 int active_disks;
88 int trustworthy = FOREIGN;
89 char *name_to_use;
90 mdu_array_info_t ainf;
91
92 struct createinfo *ci = conf_get_create_info();
93
94
95 /* 1/ Check if device is permitted by mdadm.conf */
96
97 if (!conf_test_dev(devname)) {
98 if (verbose >= 0)
99 fprintf(stderr, Name
100 ": %s not permitted by mdadm.conf.\n",
101 devname);
102 return 1;
103 }
104
105 /* 2/ Find metadata, reject if none appropriate (check
106 * version/name from args) */
107
108 dfd = dev_open(devname, O_RDONLY|O_EXCL);
109 if (dfd < 0) {
110 if (verbose >= 0)
111 fprintf(stderr, Name ": cannot open %s: %s.\n",
112 devname, strerror(errno));
113 return 1;
114 }
115 if (fstat(dfd, &stb) < 0) {
116 if (verbose >= 0)
117 fprintf(stderr, Name ": fstat failed for %s: %s.\n",
118 devname, strerror(errno));
119 close(dfd);
120 return 1;
121 }
122 if ((stb.st_mode & S_IFMT) != S_IFBLK) {
123 if (verbose >= 0)
124 fprintf(stderr, Name ": %s is not a block device.\n",
125 devname);
126 close(dfd);
127 return 1;
128 }
129
130 if (st == NULL && (st = guess_super(dfd)) == NULL) {
131 if (verbose >= 0)
132 fprintf(stderr, Name
133 ": no recognisable superblock on %s.\n",
134 devname);
135 close(dfd);
136 return 1;
137 }
138 if (st->ss->load_super(st, dfd, NULL)) {
139 if (verbose >= 0)
140 fprintf(stderr, Name ": no RAID superblock on %s.\n",
141 devname);
142 close(dfd);
143 return 1;
144 }
145 close (dfd);
146
147 memset(&info, 0, sizeof(info));
148 st->ss->getinfo_super(st, &info);
149 /* 3/ Check if there is a match in mdadm.conf */
150
151 array_list = conf_get_ident(NULL);
152 match = NULL;
153 for (; array_list; array_list = array_list->next) {
154 if (array_list->uuid_set &&
155 same_uuid(array_list->uuid, info.uuid, st->ss->swapuuid)
156 == 0) {
157 if (verbose >= 2 && array_list->devname)
158 fprintf(stderr, Name
159 ": UUID differs from %s.\n",
160 array_list->devname);
161 continue;
162 }
163 if (array_list->name[0] &&
164 strcasecmp(array_list->name, info.name) != 0) {
165 if (verbose >= 2 && array_list->devname)
166 fprintf(stderr, Name
167 ": Name differs from %s.\n",
168 array_list->devname);
169 continue;
170 }
171 if (array_list->devices &&
172 !match_oneof(array_list->devices, devname)) {
173 if (verbose >= 2 && array_list->devname)
174 fprintf(stderr, Name
175 ": Not a listed device for %s.\n",
176 array_list->devname);
177 continue;
178 }
179 if (array_list->super_minor != UnSet &&
180 array_list->super_minor != info.array.md_minor) {
181 if (verbose >= 2 && array_list->devname)
182 fprintf(stderr, Name
183 ": Different super-minor to %s.\n",
184 array_list->devname);
185 continue;
186 }
187 if (!array_list->uuid_set &&
188 !array_list->name[0] &&
189 !array_list->devices &&
190 array_list->super_minor == UnSet) {
191 if (verbose >= 2 && array_list->devname)
192 fprintf(stderr, Name
193 ": %s doesn't have any identifying information.\n",
194 array_list->devname);
195 continue;
196 }
197 /* FIXME, should I check raid_disks and level too?? */
198
199 if (match) {
200 if (verbose >= 0) {
201 if (match->devname && array_list->devname)
202 fprintf(stderr, Name
203 ": we match both %s and %s - cannot decide which to use.\n",
204 match->devname, array_list->devname);
205 else
206 fprintf(stderr, Name
207 ": multiple lines in mdadm.conf match\n");
208 }
209 return 2;
210 }
211 match = array_list;
212 }
213
214 /* 3a/ if not, check for homehost match. If no match, continue
215 * but don't trust the 'name' in the array. Thus a 'random' minor
216 * number will be assigned, and the device name will be based
217 * on that. */
218 if (match)
219 trustworthy = LOCAL;
220 else if (homehost == NULL ||
221 st->ss->match_home(st, homehost) != 1)
222 trustworthy = FOREIGN;
223 name_to_use = strchr(info.name, ':');
224 if (name_to_use)
225 name_to_use++;
226 else
227 name_to_use = info.name;
228
229 if ((!name_to_use || name_to_use[0] == 0) &&
230 info.array.level == LEVEL_CONTAINER &&
231 trustworthy == LOCAL) {
232 name_to_use = info.text_version;
233 trustworthy = METADATA;
234 }
235
236
237 /* There are three possible sources for 'autof': command line,
238 * ARRAY line in mdadm.conf, or CREATE line in mdadm.conf.
239 * ARRAY takes precedence, then command line, then
240 * CREATE.
241 */
242 if (match && match->autof)
243 autof = match->autof;
244 if (autof == 0)
245 autof = ci->autof;
246
247 if (st->ss->container_content && st->loaded_container) {
248 /* This is a pre-built container array, so we do something
249 * rather different.
250 */
251 return Incremental_container(st, devname, verbose, runstop,
252 autof, trustworthy);
253 }
254 /* 4/ Check if array exists.
255 */
256 map_lock(&map);
257 mp = map_by_uuid(&map, info.uuid);
258 if (mp) {
259 mdfd = open_mddev(mp->path, 0);
260 if (mdfd < 0 && mddev_busy(mp->devnum)) {
261 /* maybe udev hasn't created it yet. */
262 char buf[50];
263 sprintf(buf, "%d:%d", dev2major(mp->devnum),
264 dev2minor(mp->devnum));
265 mdfd = dev_open(buf, O_RDWR);
266 }
267 } else
268 mdfd = -1;
269
270 if (mdfd < 0) {
271 struct mdinfo *sra;
272 struct mdinfo dinfo;
273
274 /* Couldn't find an existing array, maybe make a new one */
275 mdfd = create_mddev(match ? match->devname : NULL,
276 name_to_use, autof, trustworthy, chosen_name);
277
278 if (mdfd < 0)
279 return 1;
280
281 sysfs_init(&info, mdfd, 0);
282
283 if (set_array_info(mdfd, st, &info) != 0) {
284 fprintf(stderr, Name ": failed to set array info for %s: %s\n",
285 chosen_name, strerror(errno));
286 close(mdfd);
287 return 2;
288 }
289
290 dinfo = info;
291 dinfo.disk.major = major(stb.st_rdev);
292 dinfo.disk.minor = minor(stb.st_rdev);
293 if (add_disk(mdfd, st, &info, &dinfo) != 0) {
294 fprintf(stderr, Name ": failed to add %s to %s: %s.\n",
295 devname, chosen_name, strerror(errno));
296 ioctl(mdfd, STOP_ARRAY, 0);
297 close(mdfd);
298 return 2;
299 }
300 sra = sysfs_read(mdfd, fd2devnum(mdfd), GET_DEVS);
301 if (!sra || !sra->devs || sra->devs->disk.raid_disk >= 0) {
302 /* It really should be 'none' - must be old buggy
303 * kernel, and mdadm -I may not be able to complete.
304 * So reject it.
305 */
306 ioctl(mdfd, STOP_ARRAY, NULL);
307 fprintf(stderr, Name
308 ": You have an old buggy kernel which cannot support\n"
309 " --incremental reliably. Aborting.\n");
310 close(mdfd);
311 sysfs_free(sra);
312 return 2;
313 }
314 info.array.working_disks = 1;
315 sysfs_free(sra);
316 /* 6/ Make sure /var/run/mdadm.map contains this array. */
317 map_update(&map, fd2devnum(mdfd),
318 info.text_version,
319 info.uuid, chosen_name);
320 } else {
321 /* 5b/ if it does */
322 /* - check one drive in array to make sure metadata is a reasonably */
323 /* close match. Reject if not (e.g. different type) */
324 /* - add the device */
325 char dn[20];
326 int dfd2;
327 int err;
328 struct mdinfo *sra;
329 struct supertype *st2;
330 struct mdinfo info2, *d;
331
332 strcpy(chosen_name, mp->path);
333
334 sra = sysfs_read(mdfd, fd2devnum(mdfd), (GET_DEVS | GET_STATE));
335
336 sprintf(dn, "%d:%d", sra->devs->disk.major,
337 sra->devs->disk.minor);
338 dfd2 = dev_open(dn, O_RDONLY);
339 st2 = dup_super(st);
340 if (st2->ss->load_super(st2, dfd2, NULL) ||
341 st->ss->compare_super(st, st2) != 0) {
342 fprintf(stderr, Name
343 ": metadata mismatch between %s and "
344 "chosen array %s\n",
345 devname, chosen_name);
346 close(mdfd);
347 close(dfd2);
348 return 2;
349 }
350 close(dfd2);
351 memset(&info2, 0, sizeof(info2));
352 st2->ss->getinfo_super(st2, &info2);
353 st2->ss->free_super(st2);
354 if (info.array.level != info2.array.level ||
355 memcmp(info.uuid, info2.uuid, 16) != 0 ||
356 info.array.raid_disks != info2.array.raid_disks) {
357 fprintf(stderr, Name
358 ": unexpected difference between %s and %s.\n",
359 chosen_name, devname);
360 close(mdfd);
361 return 2;
362 }
363 info2.disk.major = major(stb.st_rdev);
364 info2.disk.minor = minor(stb.st_rdev);
365 /* add disk needs to know about containers */
366 if (st->ss->external)
367 sra->array.level = LEVEL_CONTAINER;
368 err = add_disk(mdfd, st2, sra, &info2);
369 if (err < 0 && errno == EBUSY) {
370 /* could be another device present with the same
371 * disk.number. Find and reject any such
372 */
373 find_reject(mdfd, st, sra, info.disk.number,
374 info.events, verbose, chosen_name);
375 err = add_disk(mdfd, st2, sra, &info2);
376 }
377 if (err < 0) {
378 fprintf(stderr, Name ": failed to add %s to %s: %s.\n",
379 devname, chosen_name, strerror(errno));
380 close(mdfd);
381 return 2;
382 }
383 info.array.working_disks = 0;
384 for (d = sra->devs; d; d=d->next)
385 info.array.working_disks ++;
386
387 }
388
389 /* 7/ Is there enough devices to possibly start the array? */
390 /* 7a/ if not, finish with success. */
391 if (info.array.level == LEVEL_CONTAINER) {
392 /* Try to assemble within the container */
393 close(mdfd);
394 map_unlock(&map);
395 sysfs_uevent(&info, "change");
396 if (verbose >= 0)
397 fprintf(stderr, Name
398 ": container %s now has %d devices\n",
399 chosen_name, info.array.working_disks);
400 wait_for(chosen_name);
401 return Incremental(chosen_name, verbose, runstop,
402 NULL, homehost, autof);
403 }
404 avail = NULL;
405 active_disks = count_active(st, mdfd, &avail, &info);
406 if (enough(info.array.level, info.array.raid_disks,
407 info.array.layout, info.array.state & 1,
408 avail, active_disks) == 0) {
409 free(avail);
410 if (verbose >= 0)
411 fprintf(stderr, Name
412 ": %s attached to %s, not enough to start (%d).\n",
413 devname, chosen_name, active_disks);
414 map_unlock(&map);
415 close(mdfd);
416 return 0;
417 }
418 free(avail);
419
420 /* 7b/ if yes, */
421 /* - if number of OK devices match expected, or -R and there */
422 /* are enough, */
423 /* + add any bitmap file */
424 /* + start the array (auto-readonly). */
425
426 if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
427 if (verbose >= 0)
428 fprintf(stderr, Name
429 ": %s attached to %s which is already active.\n",
430 devname, chosen_name);
431 close(mdfd);
432 map_unlock(&map);
433 return 0;
434 }
435
436 map_unlock(&map);
437 if (runstop > 0 || active_disks >= info.array.working_disks) {
438 struct mdinfo *sra;
439 /* Let's try to start it */
440 if (match && match->bitmap_file) {
441 int bmfd = open(match->bitmap_file, O_RDWR);
442 if (bmfd < 0) {
443 fprintf(stderr, Name
444 ": Could not open bitmap file %s.\n",
445 match->bitmap_file);
446 close(mdfd);
447 return 1;
448 }
449 if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
450 close(bmfd);
451 fprintf(stderr, Name
452 ": Failed to set bitmapfile for %s.\n",
453 chosen_name);
454 close(mdfd);
455 return 1;
456 }
457 close(bmfd);
458 }
459 sra = sysfs_read(mdfd, fd2devnum(mdfd), 0);
460 if ((sra == NULL || active_disks >= info.array.working_disks)
461 && trustworthy != FOREIGN)
462 rv = ioctl(mdfd, RUN_ARRAY, NULL);
463 else
464 rv = sysfs_set_str(sra, NULL,
465 "array_state", "read-auto");
466 if (rv == 0) {
467 if (verbose >= 0)
468 fprintf(stderr, Name
469 ": %s attached to %s, which has been started.\n",
470 devname, chosen_name);
471 rv = 0;
472 wait_for(chosen_name);
473 } else {
474 fprintf(stderr, Name
475 ": %s attached to %s, but failed to start: %s.\n",
476 devname, chosen_name, strerror(errno));
477 rv = 1;
478 }
479 } else {
480 if (verbose >= 0)
481 fprintf(stderr, Name
482 ": %s attached to %s, not enough to start safely.\n",
483 devname, chosen_name);
484 rv = 0;
485 }
486 close(mdfd);
487 return rv;
488 }
489
490 static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra,
491 int number, __u64 events, int verbose,
492 char *array_name)
493 {
494 /* Find a device attached to this array with a disk.number of number
495 * and events less than the passed events, and remove the device.
496 */
497 struct mdinfo *d;
498 mdu_array_info_t ra;
499
500 if (ioctl(mdfd, GET_ARRAY_INFO, &ra) == 0)
501 return; /* not safe to remove from active arrays
502 * without thinking more */
503
504 for (d = sra->devs; d ; d = d->next) {
505 char dn[10];
506 int dfd;
507 struct mdinfo info;
508 sprintf(dn, "%d:%d", d->disk.major, d->disk.minor);
509 dfd = dev_open(dn, O_RDONLY);
510 if (dfd < 0)
511 continue;
512 if (st->ss->load_super(st, dfd, NULL)) {
513 close(dfd);
514 continue;
515 }
516 st->ss->getinfo_super(st, &info);
517 st->ss->free_super(st);
518 close(dfd);
519
520 if (info.disk.number != number ||
521 info.events >= events)
522 continue;
523
524 if (d->disk.raid_disk > -1)
525 sysfs_set_str(sra, d, "slot", "none");
526 if (sysfs_set_str(sra, d, "state", "remove") == 0)
527 if (verbose >= 0)
528 fprintf(stderr, Name
529 ": removing old device %s from %s\n",
530 d->sys_name+4, array_name);
531 }
532 }
533
534 static int count_active(struct supertype *st, int mdfd, char **availp,
535 struct mdinfo *bestinfo)
536 {
537 /* count how many devices in sra think they are active */
538 struct mdinfo *d;
539 int cnt = 0, cnt1 = 0;
540 __u64 max_events = 0;
541 struct mdinfo *sra = sysfs_read(mdfd, -1, GET_DEVS | GET_STATE);
542 char *avail = NULL;
543
544 for (d = sra->devs ; d ; d = d->next) {
545 char dn[30];
546 int dfd;
547 int ok;
548 struct mdinfo info;
549
550 sprintf(dn, "%d:%d", d->disk.major, d->disk.minor);
551 dfd = dev_open(dn, O_RDONLY);
552 if (dfd < 0)
553 continue;
554 ok = st->ss->load_super(st, dfd, NULL);
555 close(dfd);
556 if (ok != 0)
557 continue;
558 st->ss->getinfo_super(st, &info);
559 if (!avail) {
560 avail = malloc(info.array.raid_disks);
561 if (!avail) {
562 fprintf(stderr, Name ": out of memory.\n");
563 exit(1);
564 }
565 memset(avail, 0, info.array.raid_disks);
566 *availp = avail;
567 }
568
569 if (info.disk.state & (1<<MD_DISK_SYNC))
570 {
571 if (cnt == 0) {
572 cnt++;
573 max_events = info.events;
574 avail[info.disk.raid_disk] = 2;
575 st->ss->getinfo_super(st, bestinfo);
576 } else if (info.events == max_events) {
577 cnt++;
578 avail[info.disk.raid_disk] = 2;
579 } else if (info.events == max_events-1) {
580 cnt1++;
581 avail[info.disk.raid_disk] = 1;
582 } else if (info.events < max_events - 1)
583 ;
584 else if (info.events == max_events+1) {
585 int i;
586 cnt1 = cnt;
587 cnt = 1;
588 max_events = info.events;
589 for (i=0; i<info.array.raid_disks; i++)
590 if (avail[i])
591 avail[i]--;
592 avail[info.disk.raid_disk] = 2;
593 st->ss->getinfo_super(st, bestinfo);
594 } else { /* info.events much bigger */
595 cnt = 1; cnt1 = 0;
596 memset(avail, 0, info.disk.raid_disk);
597 max_events = info.events;
598 st->ss->getinfo_super(st, bestinfo);
599 }
600 }
601 st->ss->free_super(st);
602 }
603 return cnt + cnt1;
604 }
605
606 int IncrementalScan(int verbose)
607 {
608 /* look at every device listed in the 'map' file.
609 * If one is found that is not running then:
610 * look in mdadm.conf for bitmap file.
611 * if one exists, but array has none, add it.
612 * try to start array in auto-readonly mode
613 */
614 struct map_ent *mapl = NULL;
615 struct map_ent *me;
616 mddev_ident_t devs, mddev;
617 int rv = 0;
618
619 map_read(&mapl);
620 devs = conf_get_ident(NULL);
621
622 for (me = mapl ; me ; me = me->next) {
623 mdu_array_info_t array;
624 mdu_bitmap_file_t bmf;
625 struct mdinfo *sra;
626 int mdfd = open_mddev(me->path, 0);
627
628 if (mdfd < 0)
629 continue;
630 if (ioctl(mdfd, GET_ARRAY_INFO, &array) == 0 ||
631 errno != ENODEV) {
632 close(mdfd);
633 continue;
634 }
635 /* Ok, we can try this one. Maybe it needs a bitmap */
636 for (mddev = devs ; mddev ; mddev = mddev->next)
637 if (mddev->devname
638 && strcmp(mddev->devname, me->path) == 0)
639 break;
640 if (mddev && mddev->bitmap_file) {
641 /*
642 * Note: early kernels will wrongly fail this, so it
643 * is a hint only
644 */
645 int added = -1;
646 if (ioctl(mdfd, GET_ARRAY_INFO, &bmf) < 0) {
647 int bmfd = open(mddev->bitmap_file, O_RDWR);
648 if (bmfd >= 0) {
649 added = ioctl(mdfd, SET_BITMAP_FILE,
650 bmfd);
651 close(bmfd);
652 }
653 }
654 if (verbose >= 0) {
655 if (added == 0)
656 fprintf(stderr, Name
657 ": Added bitmap %s to %s\n",
658 mddev->bitmap_file, me->path);
659 else if (errno != EEXIST)
660 fprintf(stderr, Name
661 ": Failed to add bitmap to %s: %s\n",
662 me->path, strerror(errno));
663 }
664 }
665 sra = sysfs_read(mdfd, 0, 0);
666 if (sra) {
667 if (sysfs_set_str(sra, NULL,
668 "array_state", "read-auto") == 0) {
669 if (verbose >= 0)
670 fprintf(stderr, Name
671 ": started array %s\n",
672 me->path);
673 } else {
674 fprintf(stderr, Name
675 ": failed to start array %s: %s\n",
676 me->path, strerror(errno));
677 rv = 1;
678 }
679 }
680 }
681 return rv;
682 }
683
684 static char *container2devname(char *devname)
685 {
686 char *mdname = NULL;
687
688 if (devname[0] == '/') {
689 int fd = open(devname, O_RDONLY);
690 if (fd >= 0) {
691 mdname = devnum2devname(fd2devnum(fd));
692 close(fd);
693 }
694 } else {
695 int uuid[4];
696 struct map_ent *mp, *map = NULL;
697
698 if (!parse_uuid(devname, uuid))
699 return mdname;
700 mp = map_by_uuid(&map, uuid);
701 if (mp)
702 mdname = devnum2devname(mp->devnum);
703 map_free(map);
704 }
705
706 return mdname;
707 }
708
709 int Incremental_container(struct supertype *st, char *devname, int verbose,
710 int runstop, int autof, int trustworthy)
711 {
712 /* Collect the contents of this container and for each
713 * array, choose a device name and assemble the array.
714 */
715
716 struct mdinfo *list = st->ss->container_content(st);
717 struct mdinfo *ra;
718 struct map_ent *map = NULL;
719
720 map_lock(&map);
721
722 for (ra = list ; ra ; ra = ra->next) {
723 int mdfd;
724 char chosen_name[1024];
725 struct map_ent *mp;
726 struct mddev_ident_s *match = NULL;
727 int err;
728
729 mp = map_by_uuid(&map, ra->uuid);
730
731 if (!mp) {
732
733 /* Check in mdadm.conf for devices == devname and
734 * member == ra->text_version after second slash.
735 */
736 char *sub = strchr(ra->text_version+1, '/');
737 struct mddev_ident_s *array_list;
738 if (sub) {
739 sub++;
740 array_list = conf_get_ident(NULL);
741 } else
742 array_list = NULL;
743 for(; array_list ; array_list = array_list->next) {
744 char *dn;
745 if (array_list->member == NULL ||
746 array_list->container == NULL)
747 continue;
748 if (strcmp(array_list->member, sub) != 0)
749 continue;
750 if (array_list->uuid_set &&
751 !same_uuid(ra->uuid, array_list->uuid, st->ss->swapuuid))
752 continue;
753 dn = container2devname(array_list->container);
754 if (dn == NULL)
755 continue;
756 if (strncmp(dn, ra->text_version+1,
757 strlen(dn)) != 0 ||
758 ra->text_version[strlen(dn)+1] != '/') {
759 free(dn);
760 continue;
761 }
762 free(dn);
763 /* we have a match */
764 match = array_list;
765 if (verbose>0)
766 fprintf(stderr, Name ": match found for member %s\n",
767 array_list->member);
768 break;
769 }
770 }
771
772 mdfd = create_mddev(match ? match->devname : NULL,
773 ra->name,
774 autof,
775 trustworthy,
776 chosen_name);
777
778 if (mdfd < 0) {
779 fprintf(stderr, Name ": failed to open %s: %s.\n",
780 chosen_name, strerror(errno));
781 return 2;
782 }
783
784 err = assemble_container_content(st, mdfd, ra, runstop,
785 chosen_name, verbose);
786 if (err)
787 return err;
788 }
789 map_unlock(&map);
790 return 0;
791 }