]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Assemble.c
Just updaqte copyright dates and email address
[thirdparty/mdadm.git] / Assemble.c
1 /*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
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
22 * Email: <neilb@cse.unsw.edu.au>
23 * Paper: Neil Brown
24 * School of Computer Science and Engineering
25 * The University of New South Wales
26 * Sydney, 2052
27 * Australia
28 */
29
30 #include "mdadm.h"
31
32 int Assemble(struct supertype *st, char *mddev, int mdfd,
33 mddev_ident_t ident, char *conffile,
34 mddev_dev_t devlist, char *backup_file,
35 int readonly, int runstop,
36 char *update,
37 int verbose, int force)
38 {
39 /*
40 * The task of Assemble is to find a collection of
41 * devices that should (according to their superblocks)
42 * form an array, and to give this collection to the MD driver.
43 * In Linux-2.4 and later, this involves submitting a
44 * SET_ARRAY_INFO ioctl with no arg - to prepare
45 * the array - and then submit a number of
46 * ADD_NEW_DISK ioctls to add disks into
47 * the array. Finally RUN_ARRAY might
48 * be submitted to start the array.
49 *
50 * Much of the work of Assemble is in finding and/or
51 * checking the disks to make sure they look right.
52 *
53 * If mddev is not set, then scan must be set and we
54 * read through the config file for dev+uuid mapping
55 * We recurse, setting mddev, for each device that
56 * - isn't running
57 * - has a valid uuid (or any uuid if !uuidset)
58 *
59 * If mddev is set, we try to determine state of md.
60 * check version - must be at least 0.90.0
61 * check kernel version. must be at least 2.4.
62 * If not, we can possibly fall back on START_ARRAY
63 * Try to GET_ARRAY_INFO.
64 * If possible, give up
65 * If not, try to STOP_ARRAY just to make sure
66 *
67 * If !uuidset and scan, look in conf-file for uuid
68 * If not found, give up
69 * If !devlist and scan and uuidset, get list of devs from conf-file
70 *
71 * For each device:
72 * Check superblock - discard if bad
73 * Check uuid (set if we don't have one) - discard if no match
74 * Check superblock similarity if we have a superblock - discard if different
75 * Record events, devicenum
76 * This should give us a list of devices for the array
77 * We should collect the most recent event number
78 *
79 * Count disks with recent enough event count
80 * While force && !enough disks
81 * Choose newest rejected disks, update event count
82 * mark clean and rewrite superblock
83 * If recent kernel:
84 * SET_ARRAY_INFO
85 * foreach device with recent events : ADD_NEW_DISK
86 * if runstop == 1 || "enough" disks and runstop==0 -> RUN_ARRAY
87 * If old kernel:
88 * Check the device numbers in superblock are right
89 * update superblock if any changes
90 * START_ARRAY
91 *
92 */
93 int old_linux = 0;
94 int vers;
95 void *first_super = NULL, *super = NULL;
96 struct {
97 char *devname;
98 unsigned int major, minor;
99 unsigned int oldmajor, oldminor;
100 long long events;
101 int uptodate;
102 int state;
103 int raid_disk;
104 int disk_nr;
105 } *devices;
106 int *best = NULL; /* indexed by raid_disk */
107 unsigned int bestcnt = 0;
108 int devcnt = 0;
109 unsigned int okcnt, sparecnt;
110 unsigned int req_cnt;
111 unsigned int i;
112 int most_recent = 0;
113 int chosen_drive;
114 int change = 0;
115 int inargv = 0;
116 int start_partial_ok = (runstop >= 0) && (force || devlist==NULL);
117 unsigned int num_devs;
118 mddev_dev_t tmpdev;
119 struct mdinfo info;
120 char *avail;
121 int nextspare = 0;
122
123 vers = md_get_version(mdfd);
124 if (vers <= 0) {
125 fprintf(stderr, Name ": %s appears not to be an md device.\n", mddev);
126 return 1;
127 }
128 if (vers < 9000) {
129 fprintf(stderr, Name ": Assemble requires driver version 0.90.0 or later.\n"
130 " Upgrade your kernel or try --build\n");
131 return 1;
132 }
133 if (get_linux_version() < 2004000)
134 old_linux = 1;
135
136 if (ioctl(mdfd, GET_ARRAY_INFO, &info.array)>=0) {
137 fprintf(stderr, Name ": device %s already active - cannot assemble it\n",
138 mddev);
139 return 1;
140 }
141 ioctl(mdfd, STOP_ARRAY, NULL); /* just incase it was started but has no content */
142
143 /*
144 * If any subdevs are listed, then any that don't
145 * match ident are discarded. Remainder must all match and
146 * become the array.
147 * If no subdevs, then we scan all devices in the config file, but
148 * there must be something in the identity
149 */
150
151 if (!devlist &&
152 ident->uuid_set == 0 &&
153 ident->super_minor < 0 &&
154 ident->devices == NULL) {
155 fprintf(stderr, Name ": No identity information available for %s - cannot assemble.\n",
156 mddev);
157 return 1;
158 }
159 if (devlist == NULL)
160 devlist = conf_get_devs(conffile);
161 else inargv = 1;
162
163 tmpdev = devlist; num_devs = 0;
164 while (tmpdev) {
165 num_devs++;
166 tmpdev = tmpdev->next;
167 }
168 devices = malloc(num_devs * sizeof(*devices));
169
170 if (!st && ident->st) st = ident->st;
171
172 if (verbose>0)
173 fprintf(stderr, Name ": looking for devices for %s\n",
174 mddev);
175
176 while ( devlist) {
177 char *devname;
178 int dfd;
179 struct stat stb;
180 struct supertype *tst = st;
181
182 devname = devlist->devname;
183 devlist = devlist->next;
184
185 if (ident->devices &&
186 !match_oneof(ident->devices, devname)) {
187 if ((inargv && verbose>=0) || verbose > 0)
188 fprintf(stderr, Name ": %s is not one of %s\n", devname, ident->devices);
189 continue;
190 }
191
192 if (super) {
193 free(super);
194 super = NULL;
195 }
196
197 dfd = dev_open(devname, O_RDONLY|O_EXCL);
198 if (dfd < 0) {
199 if ((inargv && verbose >= 0) || verbose > 0)
200 fprintf(stderr, Name ": cannot open device %s: %s\n",
201 devname, strerror(errno));
202 } else if (fstat(dfd, &stb)< 0) {
203 /* Impossible! */
204 fprintf(stderr, Name ": fstat failed for %s: %s\n",
205 devname, strerror(errno));
206 } else if ((stb.st_mode & S_IFMT) != S_IFBLK) {
207 fprintf(stderr, Name ": %s is not a block device.\n",
208 devname);
209 } else if (!tst && (tst = guess_super(dfd)) == NULL) {
210 if ((inargv && verbose >= 0) || verbose > 0)
211 fprintf(stderr, Name ": no recogniseable superblock\n");
212 } else if (tst->ss->load_super(tst,dfd, &super, NULL)) {
213 if ((inargv && verbose >= 0) || verbose > 0)
214 fprintf( stderr, Name ": no RAID superblock on %s\n",
215 devname);
216 } else {
217 tst->ss->getinfo_super(&info, super);
218 }
219 if (dfd >= 0) close(dfd);
220
221 if (ident->uuid_set && (!update || strcmp(update, "uuid")!= 0) &&
222 (!super || same_uuid(info.uuid, ident->uuid, tst->ss->swapuuid)==0)) {
223 if ((inargv && verbose >= 0) || verbose > 0)
224 fprintf(stderr, Name ": %s has wrong uuid.\n",
225 devname);
226 continue;
227 }
228 if (ident->name[0] &&
229 (!super || strncmp(info.name, ident->name, 32)!=0)) {
230 if ((inargv && verbose >= 0) || verbose > 0)
231 fprintf(stderr, Name ": %s has wrong name.\n",
232 devname);
233 continue;
234 }
235 if (ident->super_minor != UnSet &&
236 (!super || ident->super_minor != info.array.md_minor)) {
237 if ((inargv && verbose >= 0) || verbose > 0)
238 fprintf(stderr, Name ": %s has wrong super-minor.\n",
239 devname);
240 continue;
241 }
242 if (ident->level != UnSet &&
243 (!super|| ident->level != info.array.level)) {
244 if ((inargv && verbose >= 0) || verbose > 0)
245 fprintf(stderr, Name ": %s has wrong raid level.\n",
246 devname);
247 continue;
248 }
249 if (ident->raid_disks != UnSet &&
250 (!super || ident->raid_disks!= info.array.raid_disks)) {
251 if ((inargv && verbose >= 0) || verbose > 0)
252 fprintf(stderr, Name ": %s requires wrong number of drives.\n",
253 devname);
254 continue;
255 }
256
257 /* If we are this far, then we are commited to this device.
258 * If the super_block doesn't exist, or doesn't match others,
259 * then we cannot continue
260 */
261
262 if (!super) {
263 fprintf(stderr, Name ": %s has no superblock - assembly aborted\n",
264 devname);
265 free(first_super);
266 return 1;
267 }
268
269
270 st = tst; /* commit to this format, if haven't already */
271 if (st->ss->compare_super(&first_super, super)) {
272 fprintf(stderr, Name ": superblock on %s doesn't match others - assembly aborted\n",
273 devname);
274 free(super);
275 free(first_super);
276 return 1;
277 }
278
279 /* looks like a good enough match to update the super block if needed */
280 if (update) {
281 /* prepare useful information in info structures */
282 struct stat stb2;
283 fstat(mdfd, &stb2);
284 info.array.md_minor = minor(stb2.st_rdev);
285
286 if (strcmp(update, "uuid")==0 &&
287 !ident->uuid_set) {
288 int rfd;
289 if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
290 read(rfd, ident->uuid, 16) != 16) {
291 *(__u32*)(ident->uuid) = random();
292 *(__u32*)(ident->uuid+1) = random();
293 *(__u32*)(ident->uuid+2) = random();
294 *(__u32*)(ident->uuid+3) = random();
295 }
296 if (rfd >= 0) close(rfd);
297 ident->uuid_set = 1;
298 }
299 memcpy(info.uuid, ident->uuid, 16);
300 st->ss->update_super(&info, super, update, devname, verbose);
301
302 dfd = dev_open(devname, O_RDWR|O_EXCL);
303 if (dfd < 0)
304 fprintf(stderr, Name ": Cannot open %s for superblock update\n",
305 devname);
306 else if (st->ss->store_super(st, dfd, super))
307 fprintf(stderr, Name ": Could not re-write superblock on %s.\n",
308 devname);
309 if (dfd >= 0)
310 close(dfd);
311
312 if (strcmp(update, "uuid")==0 &&
313 ident->bitmap_fd)
314 bitmap_update_uuid(ident->bitmap_fd, info.uuid);
315 }
316
317 if (verbose > 0)
318 fprintf(stderr, Name ": %s is identified as a member of %s, slot %d.\n",
319 devname, mddev, info.disk.raid_disk);
320 devices[devcnt].devname = devname;
321 devices[devcnt].major = major(stb.st_rdev);
322 devices[devcnt].minor = minor(stb.st_rdev);
323 devices[devcnt].oldmajor = info.disk.major;
324 devices[devcnt].oldminor = info.disk.minor;
325 devices[devcnt].events = info.events;
326 devices[devcnt].raid_disk = info.disk.raid_disk;
327 devices[devcnt].disk_nr = info.disk.number;
328 devices[devcnt].uptodate = 0;
329 devices[devcnt].state = info.disk.state;
330 if (most_recent < devcnt) {
331 if (devices[devcnt].events
332 > devices[most_recent].events)
333 most_recent = devcnt;
334 }
335 if (info.array.level == -4)
336 /* with multipath, the raid_disk from the superblock is meaningless */
337 i = devcnt;
338 else
339 i = devices[devcnt].raid_disk;
340 if (i+1 == 0) {
341 if (nextspare < info.array.raid_disks)
342 nextspare = info.array.raid_disks;
343 i = nextspare++;
344 }
345 if (i < 10000) {
346 if (i >= bestcnt) {
347 unsigned int newbestcnt = i+10;
348 int *newbest = malloc(sizeof(int)*newbestcnt);
349 unsigned int c;
350 for (c=0; c < newbestcnt; c++)
351 if (c < bestcnt)
352 newbest[c] = best[c];
353 else
354 newbest[c] = -1;
355 if (best)free(best);
356 best = newbest;
357 bestcnt = newbestcnt;
358 }
359 if (best[i] == -1
360 || devices[best[i]].events < devices[devcnt].events)
361 best[i] = devcnt;
362 }
363 devcnt++;
364 }
365
366 if (super)
367 free(super);
368 super = NULL;
369
370 if (update && strcmp(update, "byteorder")==0)
371 st->minor_version = 90;
372
373 if (devcnt == 0) {
374 fprintf(stderr, Name ": no devices found for %s\n",
375 mddev);
376 free(first_super);
377 return 1;
378 }
379
380 st->ss->getinfo_super(&info, first_super);
381
382 /* now we have some devices that might be suitable.
383 * I wonder how many
384 */
385 avail = malloc(info.array.raid_disks);
386 memset(avail, 0, info.array.raid_disks);
387 okcnt = 0;
388 sparecnt=0;
389 for (i=0; i< bestcnt ;i++) {
390 int j = best[i];
391 int event_margin = 1; /* always allow a difference of '1'
392 * like the kernel does
393 */
394 if (j < 0) continue;
395 /* note: we ignore error flags in multipath arrays
396 * as they don't make sense
397 */
398 if (info.array.level != -4)
399 if (!(devices[j].state & (1<<MD_DISK_SYNC))) {
400 if (!(devices[j].state & (1<<MD_DISK_FAULTY)))
401 sparecnt++;
402 continue;
403 }
404 if (devices[j].events+event_margin >=
405 devices[most_recent].events) {
406 devices[j].uptodate = 1;
407 if (i < info.array.raid_disks) {
408 okcnt++;
409 avail[i]=1;
410 } else
411 sparecnt++;
412 }
413 }
414 while (force && !enough(info.array.level, info.array.raid_disks,
415 info.array.layout,
416 avail, okcnt)) {
417 /* Choose the newest best drive which is
418 * not up-to-date, update the superblock
419 * and add it.
420 */
421 int fd;
422 chosen_drive = -1;
423 for (i=0; i<info.array.raid_disks && i < bestcnt; i++) {
424 int j = best[i];
425 if (j>=0 &&
426 !devices[j].uptodate &&
427 devices[j].events > 0 &&
428 (chosen_drive < 0 ||
429 devices[j].events > devices[chosen_drive].events))
430 chosen_drive = j;
431 }
432 if (chosen_drive < 0)
433 break;
434 if (verbose >= 0)
435 fprintf(stderr, Name ": forcing event count in %s(%d) from %d upto %d\n",
436 devices[chosen_drive].devname, devices[chosen_drive].raid_disk,
437 (int)(devices[chosen_drive].events),
438 (int)(devices[most_recent].events));
439 fd = dev_open(devices[chosen_drive].devname, O_RDWR|O_EXCL);
440 if (fd < 0) {
441 fprintf(stderr, Name ": Couldn't open %s for write - not updating\n",
442 devices[chosen_drive].devname);
443 devices[chosen_drive].events = 0;
444 continue;
445 }
446 if (st->ss->load_super(st,fd, &super, NULL)) {
447 close(fd);
448 fprintf(stderr, Name ": RAID superblock disappeared from %s - not updating.\n",
449 devices[chosen_drive].devname);
450 devices[chosen_drive].events = 0;
451 continue;
452 }
453 info.events = devices[most_recent].events;
454 st->ss->update_super(&info, super, "force", devices[chosen_drive].devname, verbose);
455
456 if (st->ss->store_super(st, fd, super)) {
457 close(fd);
458 fprintf(stderr, Name ": Could not re-write superblock on %s\n",
459 devices[chosen_drive].devname);
460 devices[chosen_drive].events = 0;
461 free(super);
462 continue;
463 }
464 close(fd);
465 devices[chosen_drive].events = devices[most_recent].events;
466 devices[chosen_drive].uptodate = 1;
467 avail[chosen_drive] = 1;
468 okcnt++;
469 free(super);
470 }
471
472 /* Now we want to look at the superblock which the kernel will base things on
473 * and compare the devices that we think are working with the devices that the
474 * superblock thinks are working.
475 * If there are differences and --force is given, then update this chosen
476 * superblock.
477 */
478 chosen_drive = -1;
479 super = NULL;
480 for (i=0; chosen_drive < 0 && i<bestcnt; i++) {
481 int j = best[i];
482 int fd;
483
484 if (j<0)
485 continue;
486 if (!devices[j].uptodate)
487 continue;
488 chosen_drive = j;
489 if ((fd=dev_open(devices[j].devname, O_RDONLY|O_EXCL))< 0) {
490 fprintf(stderr, Name ": Cannot open %s: %s\n",
491 devices[j].devname, strerror(errno));
492 return 1;
493 }
494 if (st->ss->load_super(st,fd, &super, NULL)) {
495 close(fd);
496 fprintf(stderr, Name ": RAID superblock has disappeared from %s\n",
497 devices[j].devname);
498 return 1;
499 }
500 close(fd);
501 }
502 if (super == NULL) {
503 fprintf(stderr, Name ": No suitable drives found for %s\n", mddev);
504 return 1;
505 }
506 st->ss->getinfo_super(&info, super);
507 for (i=0; i<bestcnt; i++) {
508 int j = best[i];
509 unsigned int desired_state;
510
511 if (i < info.array.raid_disks)
512 desired_state = (1<<MD_DISK_ACTIVE) | (1<<MD_DISK_SYNC);
513 else
514 desired_state = 0;
515
516 if (j<0)
517 continue;
518 if (!devices[j].uptodate)
519 continue;
520 info.disk.number = devices[j].disk_nr;
521 info.disk.raid_disk = i;
522 info.disk.state = desired_state;
523
524 if (devices[j].uptodate &&
525 st->ss->update_super(&info, super, "assemble", NULL, verbose)) {
526 if (force) {
527 if (verbose >= 0)
528 fprintf(stderr, Name ": "
529 "clearing FAULTY flag for device %d in %s for %s\n",
530 j, mddev, devices[j].devname);
531 change = 1;
532 } else {
533 if (verbose >= -1)
534 fprintf(stderr, Name ": "
535 "device %d in %s has wrong state in superblock, but %s seems ok\n",
536 i, mddev, devices[j].devname);
537 }
538 }
539 #if 0
540 if (!devices[j].uptodate &&
541 !(super.disks[i].state & (1 << MD_DISK_FAULTY))) {
542 fprintf(stderr, Name ": devices %d of %s is not marked FAULTY in superblock, but cannot be found\n",
543 i, mddev);
544 }
545 #endif
546 }
547 if (force && okcnt == info.array.raid_disks-1) {
548 /* FIXME check event count */
549 change += st->ss->update_super(&info, super, "force",
550 devices[chosen_drive].devname, verbose);
551 }
552
553 if (change) {
554 int fd;
555 fd = dev_open(devices[chosen_drive].devname, O_RDWR|O_EXCL);
556 if (fd < 0) {
557 fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n",
558 devices[chosen_drive].devname);
559 return 1;
560 }
561 if (st->ss->store_super(st, fd, super)) {
562 close(fd);
563 fprintf(stderr, Name ": Could not re-write superblock on %s\n",
564 devices[chosen_drive].devname);
565 return 1;
566 }
567 close(fd);
568 }
569
570 /* If we are in the middle of a reshape we may need to restore saved data
571 * that was moved aside due to the reshape overwriting live data
572 * The code of doing this lives in Grow.c
573 */
574 #ifndef MDASSEMBLE
575 if (info.reshape_active) {
576 int err = 0;
577 int *fdlist = malloc(sizeof(int)* bestcnt);
578 for (i=0; i<bestcnt; i++) {
579 int j = best[i];
580 if (j >= 0) {
581 fdlist[i] = dev_open(devices[j].devname, O_RDWR|O_EXCL);
582 if (fdlist[i] < 0) {
583 fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n",
584 devices[j].devname);
585 err = 1;
586 break;
587 }
588 } else
589 fdlist[i] = -1;
590 }
591 if (!err)
592 err = Grow_restart(st, &info, fdlist, bestcnt, backup_file);
593 while (i>0) {
594 i--;
595 if (fdlist[i]>=0) close(fdlist[i]);
596 }
597 if (err) {
598 fprintf(stderr, Name ": Failed to restore critical section for reshape, sorry.\n");
599 return err;
600 }
601 }
602 #endif
603 /* count number of in-sync devices according to the superblock.
604 * We must have this number to start the array without -s or -R
605 */
606 req_cnt = info.array.working_disks;
607
608 /* Almost ready to actually *do* something */
609 if (!old_linux) {
610 int rv;
611 if ((vers % 100) >= 1) { /* can use different versions */
612 mdu_array_info_t inf;
613 memset(&inf, 0, sizeof(inf));
614 inf.major_version = st->ss->major;
615 inf.minor_version = st->minor_version;
616 rv = ioctl(mdfd, SET_ARRAY_INFO, &inf);
617 } else
618 rv = ioctl(mdfd, SET_ARRAY_INFO, NULL);
619
620 if (rv) {
621 fprintf(stderr, Name ": SET_ARRAY_INFO failed for %s: %s\n",
622 mddev, strerror(errno));
623 return 1;
624 }
625 if (ident->bitmap_fd >= 0) {
626 if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) {
627 fprintf(stderr, Name ": SET_BITMAP_FILE failed.\n");
628 return 1;
629 }
630 } else if (ident->bitmap_file) {
631 /* From config file */
632 int bmfd = open(ident->bitmap_file, O_RDWR);
633 if (bmfd < 0) {
634 fprintf(stderr, Name ": Could not open bitmap file %s\n",
635 ident->bitmap_file);
636 return 1;
637 }
638 if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
639 fprintf(stderr, Name ": Failed to set bitmapfile for %s\n", mddev);
640 close(bmfd);
641 return 1;
642 }
643 close(bmfd);
644 }
645
646 /* First, add the raid disks, but add the chosen one last */
647 for (i=0; i<= bestcnt; i++) {
648 int j;
649 if (i < bestcnt) {
650 j = best[i];
651 if (j == chosen_drive)
652 continue;
653 } else
654 j = chosen_drive;
655
656 if (j >= 0 /* && devices[j].uptodate */) {
657 mdu_disk_info_t disk;
658 memset(&disk, 0, sizeof(disk));
659 disk.major = devices[j].major;
660 disk.minor = devices[j].minor;
661 if (ioctl(mdfd, ADD_NEW_DISK, &disk)!=0) {
662 fprintf(stderr, Name ": failed to add %s to %s: %s\n",
663 devices[j].devname,
664 mddev,
665 strerror(errno));
666 if (i < info.array.raid_disks || i == bestcnt)
667 okcnt--;
668 else
669 sparecnt--;
670 } else if (verbose > 0)
671 fprintf(stderr, Name ": added %s to %s as %d\n",
672 devices[j].devname, mddev, devices[j].raid_disk);
673 } else if (verbose > 0 && i < info.array.raid_disks)
674 fprintf(stderr, Name ": no uptodate device for slot %d of %s\n",
675 i, mddev);
676 }
677
678 if (runstop == 1 ||
679 (runstop <= 0 &&
680 ( enough(info.array.level, info.array.raid_disks, info.array.layout, avail, okcnt) &&
681 (okcnt >= req_cnt || start_partial_ok)
682 ))) {
683 if (ioctl(mdfd, RUN_ARRAY, NULL)==0) {
684 if (verbose >= 0) {
685 fprintf(stderr, Name ": %s has been started with %d drive%s",
686 mddev, okcnt, okcnt==1?"":"s");
687 if (okcnt < info.array.raid_disks)
688 fprintf(stderr, " (out of %d)", info.array.raid_disks);
689 if (sparecnt)
690 fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
691 fprintf(stderr, ".\n");
692 }
693 return 0;
694 }
695 fprintf(stderr, Name ": failed to RUN_ARRAY %s: %s\n",
696 mddev, strerror(errno));
697 return 1;
698 }
699 if (runstop == -1) {
700 fprintf(stderr, Name ": %s assembled from %d drive%s",
701 mddev, okcnt, okcnt==1?"":"s");
702 if (okcnt != info.array.raid_disks)
703 fprintf(stderr, " (out of %d)", info.array.raid_disks);
704 fprintf(stderr, ", but not started.\n");
705 return 0;
706 }
707 if (verbose >= 0) {
708 fprintf(stderr, Name ": %s assembled from %d drive%s", mddev, okcnt, okcnt==1?"":"s");
709 if (sparecnt)
710 fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
711 if (!enough(info.array.level, info.array.raid_disks, info.array.layout, avail, okcnt))
712 fprintf(stderr, " - not enough to start the array.\n");
713 else {
714 if (req_cnt == info.array.raid_disks)
715 fprintf(stderr, " - need all %d to start it", req_cnt);
716 else
717 fprintf(stderr, " - need %d of %d to start", req_cnt, info.array.raid_disks);
718 fprintf(stderr, " (use --run to insist).\n");
719 }
720 }
721 return 1;
722 } else {
723 /* The "chosen_drive" is a good choice, and if necessary, the superblock has
724 * been updated to point to the current locations of devices.
725 * so we can just start the array
726 */
727 unsigned long dev;
728 dev = makedev(devices[chosen_drive].major,
729 devices[chosen_drive].minor);
730 if (ioctl(mdfd, START_ARRAY, dev)) {
731 fprintf(stderr, Name ": Cannot start array: %s\n",
732 strerror(errno));
733 }
734
735 }
736 return 0;
737 }