]> git.ipfire.org Git - thirdparty/mdadm.git/blame - Assemble.c
Change Monitor to take a struct context
[thirdparty/mdadm.git] / Assemble.c
CommitLineData
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"
41a3b72a 26#include <ctype.h>
64c4757e 27
624920bb
NB
28static int name_matches(char *found, char *required, char *homehost)
29{
30 /* See if the name found matches the required name, possibly
31 * prefixed with 'homehost'
32 */
33 char fnd[33];
34
35 strncpy(fnd, found, 32);
36 fnd[32] = 0;
37 if (strcmp(found, required)==0)
38 return 1;
39 if (homehost) {
40 int l = strlen(homehost);
41 if (l < 32 && fnd[l] == ':' &&
42 strcmp(fnd+l+1, required)==0)
43 return 1;
44 }
45 return 0;
46}
47
9008ed1c 48static int is_member_busy(char *metadata_version)
2de8884f
DW
49{
50 /* check if the given member array is active */
51 struct mdstat_ent *mdstat = mdstat_read(1, 0);
52 struct mdstat_ent *ent;
53 int busy = 0;
54
55 for (ent = mdstat; ent; ent = ent->next) {
56 if (ent->metadata_version == NULL)
57 continue;
58 if (strncmp(ent->metadata_version, "external:", 9) != 0)
59 continue;
60 if (!is_subarray(&ent->metadata_version[9]))
61 continue;
62 /* Skip first char - it can be '/' or '-' */
63 if (strcmp(&ent->metadata_version[10], metadata_version+1) == 0) {
64 busy = 1;
65 break;
66 }
67 }
68 free_mdstat(mdstat);
69
70 return busy;
71}
72
fa56eddb 73static int ident_matches(struct mddev_ident *ident,
08fb91a3
N
74 struct mdinfo *content,
75 struct supertype *tst,
76 char *homehost,
77 char *update, char *devname)
78{
79
80 if (ident->uuid_set && (!update || strcmp(update, "uuid")!= 0) &&
cbeeb0e5
AC
81 same_uuid(content->uuid, ident->uuid, tst->ss->swapuuid)==0 &&
82 memcmp(content->uuid, uuid_zero, sizeof(int[4])) != 0) {
08fb91a3 83 if (devname)
e7b84f9d 84 pr_err("%s has wrong uuid.\n", devname);
08fb91a3
N
85 return 0;
86 }
87 if (ident->name[0] && (!update || strcmp(update, "name")!= 0) &&
88 name_matches(content->name, ident->name, homehost)==0) {
89 if (devname)
e7b84f9d 90 pr_err("%s has wrong name.\n", devname);
08fb91a3
N
91 return 0;
92 }
93 if (ident->super_minor != UnSet &&
94 ident->super_minor != content->array.md_minor) {
95 if (devname)
e7b84f9d
N
96 pr_err("%s has wrong super-minor.\n",
97 devname);
08fb91a3
N
98 return 0;
99 }
100 if (ident->level != UnSet &&
101 ident->level != content->array.level) {
102 if (devname)
e7b84f9d
N
103 pr_err("%s has wrong raid level.\n",
104 devname);
08fb91a3
N
105 return 0;
106 }
107 if (ident->raid_disks != UnSet &&
108 ident->raid_disks!= content->array.raid_disks) {
109 if (devname)
e7b84f9d
N
110 pr_err("%s requires wrong number of drives.\n",
111 devname);
08fb91a3
N
112 return 0;
113 }
805d30b2
N
114 if (ident->member && ident->member[0]) {
115 /* content->text_version must match */
116 char *s = strchr(content->text_version+1, '/');
117 if (s == NULL) {
118 if (devname)
e7b84f9d
N
119 pr_err("%s is not a container and one is required.\n",
120 devname);
805d30b2
N
121 return 0;
122 } else if (strcmp(ident->member, s+1) != 0) {
123 if (devname)
e7b84f9d
N
124 pr_err("skipping wrong member %s is %s\n",
125 content->text_version, devname);
805d30b2
N
126 return 0;
127 }
128 }
08fb91a3
N
129 return 1;
130}
131
132
7f91af49 133int Assemble(struct supertype *st, char *mddev,
fa56eddb 134 struct mddev_ident *ident,
87f26d14 135 struct mddev_dev *devlist,
4977146a 136 struct context *c)
64c4757e
NB
137{
138 /*
52826846
NB
139 * The task of Assemble is to find a collection of
140 * devices that should (according to their superblocks)
141 * form an array, and to give this collection to the MD driver.
142 * In Linux-2.4 and later, this involves submitting a
64c4757e
NB
143 * SET_ARRAY_INFO ioctl with no arg - to prepare
144 * the array - and then submit a number of
145 * ADD_NEW_DISK ioctls to add disks into
146 * the array. Finally RUN_ARRAY might
147 * be submitted to start the array.
148 *
149 * Much of the work of Assemble is in finding and/or
150 * checking the disks to make sure they look right.
151 *
4b1ac34b 152 * If mddev is not set, then scan must be set and we
64c4757e
NB
153 * read through the config file for dev+uuid mapping
154 * We recurse, setting mddev, for each device that
155 * - isn't running
4b1ac34b 156 * - has a valid uuid (or any uuid if !uuidset)
64c4757e
NB
157 *
158 * If mddev is set, we try to determine state of md.
159 * check version - must be at least 0.90.0
160 * check kernel version. must be at least 2.4.
161 * If not, we can possibly fall back on START_ARRAY
162 * Try to GET_ARRAY_INFO.
163 * If possible, give up
164 * If not, try to STOP_ARRAY just to make sure
165 *
166 * If !uuidset and scan, look in conf-file for uuid
167 * If not found, give up
b8a8ccf9 168 * If !devlist and scan and uuidset, get list of devs from conf-file
64c4757e
NB
169 *
170 * For each device:
171 * Check superblock - discard if bad
172 * Check uuid (set if we don't have one) - discard if no match
5787fa49 173 * Check superblock similarity if we have a superblock - discard if different
4b1ac34b 174 * Record events, devicenum
64c4757e 175 * This should give us a list of devices for the array
4b1ac34b 176 * We should collect the most recent event number
64c4757e
NB
177 *
178 * Count disks with recent enough event count
179 * While force && !enough disks
180 * Choose newest rejected disks, update event count
181 * mark clean and rewrite superblock
182 * If recent kernel:
183 * SET_ARRAY_INFO
184 * foreach device with recent events : ADD_NEW_DISK
185 * if runstop == 1 || "enough" disks and runstop==0 -> RUN_ARRAY
186 * If old kernel:
187 * Check the device numbers in superblock are right
188 * update superblock if any changes
189 * START_ARRAY
190 *
191 */
c30e5369
N
192 int mdfd;
193 int clean;
f05641cf
N
194 int auto_assem = (mddev == NULL && !ident->uuid_set &&
195 ident->super_minor == UnSet && ident->name[0] == 0
aa7c284c 196 && (ident->container == NULL || ident->member == NULL));
64c4757e 197 int old_linux = 0;
c30e5369 198 int vers = vers; /* Keep gcc quite - it really is initialised */
64c4757e
NB
199 struct {
200 char *devname;
213ee40b
NB
201 int uptodate; /* set once we decide that this device is as
202 * recent as everything else in the array.
203 */
204 struct mdinfo i;
5787fa49 205 } *devices;
02e7c5b7 206 char *devmap;
56eedc1a 207 int *best = NULL; /* indexed by raid_disk */
f21e18ca 208 int bestcnt = 0;
98c6faba 209 int devcnt = 0;
1ff98339 210 unsigned int okcnt, sparecnt, rebuilding_cnt;
98c6faba 211 unsigned int req_cnt;
f21e18ca 212 int i;
64c4757e 213 int most_recent = 0;
cd29a5c8 214 int chosen_drive;
52826846 215 int change = 0;
cd29a5c8 216 int inargv = 0;
52437b4f 217 int report_missmatch;
a6482415 218#ifndef MDASSEMBLE
bf4fb153 219 int bitmap_done;
a6482415 220#endif
4977146a
N
221 int start_partial_ok = (c->runstop >= 0) &&
222 (c->force || devlist==NULL || auto_assem);
98c6faba 223 unsigned int num_devs;
a655e550 224 struct mddev_dev *tmpdev;
4b1ac34b 225 struct mdinfo info;
98dbd966 226 struct mdinfo *content = NULL;
265e0f17 227 char *avail;
308e1801 228 int nextspare = 0;
197e3eb6 229 char *name = NULL;
69207ff6 230 int trustworthy;
a04d5763 231 char chosen_name[1024];
cbeeb0e5 232 struct domainlist *domains = NULL;
8a46fe84 233
682c7051 234 if (get_linux_version() < 2004000)
64c4757e
NB
235 old_linux = 1;
236
64c4757e 237 /*
52826846
NB
238 * If any subdevs are listed, then any that don't
239 * match ident are discarded. Remainder must all match and
240 * become the array.
241 * If no subdevs, then we scan all devices in the config file, but
242 * there must be something in the identity
64c4757e 243 */
64c4757e 244
cd29a5c8 245 if (!devlist &&
52826846 246 ident->uuid_set == 0 &&
f21e18ca 247 (ident->super_minor < 0 || ident->super_minor == UnSet) &&
e0fe762a
N
248 ident->name[0] == 0 &&
249 (ident->container == NULL || ident->member == NULL) &&
52826846 250 ident->devices == NULL) {
e7b84f9d
N
251 pr_err("No identity information available for %s - cannot assemble.\n",
252 mddev ? mddev : "further assembly");
52826846 253 return 1;
64c4757e 254 }
71d60c48 255
cd29a5c8 256 if (devlist == NULL)
8aec876d 257 devlist = conf_get_devs();
7f91af49 258 else if (mddev)
da6b5ca9 259 inargv = 1;
64c4757e 260
4977146a 261 report_missmatch = ((inargv && c->verbose >= 0) || c->verbose > 0);
60e1bc1a 262 try_again:
c30e5369
N
263 /* We come back here when doing auto-assembly and attempting some
264 * set of devices failed. Those are now marked as ->used==2 and
265 * we ignore them and try again
266 */
60e1bc1a 267
5787fa49
NB
268 tmpdev = devlist; num_devs = 0;
269 while (tmpdev) {
da6b5ca9
NB
270 if (tmpdev->used)
271 tmpdev->used = 2;
272 else
273 num_devs++;
5787fa49
NB
274 tmpdev = tmpdev->next;
275 }
5787fa49 276
82d9eba6 277 if (!st && ident->st) st = ident->st;
64c4757e 278
4977146a 279 if (c->verbose>0)
e7b84f9d
N
280 pr_err("looking for devices for %s\n",
281 mddev ? mddev : "further assembly");
82b27616 282
811e6cbe
NB
283 /* first walk the list of devices to find a consistent set
284 * that match the criterea, if that is possible.
c30e5369 285 * We flag the ones we like with 'used'.
811e6cbe
NB
286 */
287 for (tmpdev = devlist;
288 tmpdev;
5083d66b 289 tmpdev = tmpdev ? tmpdev->next : NULL) {
811e6cbe 290 char *devname = tmpdev->devname;
64c4757e
NB
291 int dfd;
292 struct stat stb;
518a60f3 293 struct supertype *tst;
4e8d9f0a 294 struct dev_policy *pol = NULL;
5083d66b 295 int found_container = 0;
52826846 296
da6b5ca9
NB
297 if (tmpdev->used > 1) continue;
298
52826846 299 if (ident->devices &&
56eedc1a 300 !match_oneof(ident->devices, devname)) {
52437b4f 301 if (report_missmatch)
e7b84f9d 302 pr_err("%s is not one of %s\n", devname, ident->devices);
52826846 303 continue;
56eedc1a 304 }
4b1ac34b 305
518a60f3
JS
306 tst = dup_super(st);
307
56d18859 308 dfd = dev_open(devname, O_RDONLY);
64c4757e 309 if (dfd < 0) {
52437b4f 310 if (report_missmatch)
e7b84f9d
N
311 pr_err("cannot open device %s: %s\n",
312 devname, strerror(errno));
da6b5ca9 313 tmpdev->used = 2;
52826846
NB
314 } else if (fstat(dfd, &stb)< 0) {
315 /* Impossible! */
e7b84f9d
N
316 pr_err("fstat failed for %s: %s\n",
317 devname, strerror(errno));
da6b5ca9 318 tmpdev->used = 2;
cd29a5c8 319 } else if ((stb.st_mode & S_IFMT) != S_IFBLK) {
e7b84f9d
N
320 pr_err("%s is not a block device.\n",
321 devname);
da6b5ca9 322 tmpdev->used = 2;
5083d66b
N
323 } else if (must_be_container(dfd)) {
324 if (st) {
325 /* already found some components, this cannot
326 * be another one.
327 */
328 if (report_missmatch)
e7b84f9d
N
329 pr_err("%s is a container, but we are looking for components\n",
330 devname);
5083d66b 331 tmpdev->used = 2;
71204a50 332#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
5083d66b
N
333 } if (!tst && (tst = super_by_fd(dfd, NULL)) == NULL) {
334 if (report_missmatch)
e7b84f9d
N
335 pr_err("not a recognisable container: %s\n",
336 devname);
5083d66b 337 tmpdev->used = 2;
71204a50 338#endif
417f346e
HCP
339 } else if (!tst->ss->load_container
340 || tst->ss->load_container(tst, dfd, NULL)) {
5083d66b 341 if (report_missmatch)
e7b84f9d
N
342 pr_err("no correct container type: %s\n",
343 devname);
5083d66b
N
344 tmpdev->used = 2;
345 } else if (auto_assem &&
346 !conf_test_metadata(tst->ss->name, (pol = devnum_policy(stb.st_rdev)),
4977146a 347 tst->ss->match_home(tst, c->homehost) == 1)) {
5083d66b 348 if (report_missmatch)
e7b84f9d
N
349 pr_err("%s has metadata type %s for which "
350 "auto-assembly is disabled\n",
351 devname, tst->ss->name);
5083d66b
N
352 tmpdev->used = 2;
353 } else
354 found_container = 1;
52826846 355 } else {
5083d66b
N
356 if (!tst && (tst = guess_super(dfd)) == NULL) {
357 if (report_missmatch)
e7b84f9d
N
358 pr_err("no recogniseable superblock on %s\n",
359 devname);
5083d66b
N
360 tmpdev->used = 2;
361 } else if (tst->ss->load_super(tst,dfd, NULL)) {
362 if (report_missmatch)
e7b84f9d
N
363 pr_err("no RAID superblock on %s\n",
364 devname);
5083d66b
N
365 tmpdev->used = 2;
366 } else if (tst->ss->compare_super == NULL) {
367 if (report_missmatch)
e7b84f9d
N
368 pr_err("Cannot assemble %s metadata on %s\n",
369 tst->ss->name, devname);
5083d66b
N
370 tmpdev->used = 2;
371 } else if (auto_assem && st == NULL &&
372 !conf_test_metadata(tst->ss->name, (pol = devnum_policy(stb.st_rdev)),
4977146a 373 tst->ss->match_home(tst, c->homehost) == 1)) {
5083d66b 374 if (report_missmatch)
e7b84f9d
N
375 pr_err("%s has metadata type %s for which "
376 "auto-assembly is disabled\n",
377 devname, tst->ss->name);
5083d66b
N
378 tmpdev->used = 2;
379 }
64c4757e 380 }
c06487ce 381 if (dfd >= 0) close(dfd);
d68ea4d7 382 if (tmpdev->used == 2) {
d4386799 383 if (auto_assem || !inargv)
d68ea4d7
N
384 /* Ignore unrecognised devices during auto-assembly */
385 goto loop;
386 if (ident->uuid_set || ident->name[0] ||
387 ident->super_minor != UnSet)
388 /* Ignore unrecognised device if looking for
389 * specific array */
390 goto loop;
391
392
e7b84f9d 393 pr_err("%s has no superblock - assembly aborted\n",
d68ea4d7
N
394 devname);
395 if (st)
396 st->ss->free_super(st);
397 dev_policy_free(pol);
cbeeb0e5 398 domain_free(domains);
d68ea4d7
N
399 return 1;
400 }
52826846 401
5083d66b 402 if (found_container) {
9008ed1c
N
403 /* tmpdev is a container. We need to be either
404 * looking for a member, or auto-assembling
405 */
56d18859
N
406 /* should be safe to try an exclusive open now, we
407 * have rejected anything that some other mdadm might
408 * be looking at
409 */
410 dfd = dev_open(devname, O_RDONLY | O_EXCL);
411 if (dfd < 0) {
412 if (report_missmatch)
e7b84f9d 413 pr_err("%s is busy - skipping\n", devname);
56d18859
N
414 goto loop;
415 }
416 close(dfd);
9008ed1c
N
417
418 if (ident->container) {
419 if (ident->container[0] == '/' &&
420 !same_dev(ident->container, devname)) {
421 if (report_missmatch)
e7b84f9d 422 pr_err("%s is not the container required (%s)\n",
9008ed1c
N
423 devname, ident->container);
424 goto loop;
425 }
426 if (ident->container[0] != '/') {
427 /* we have a uuid */
428 int uuid[4];
87477e6d
N
429
430 content = &info;
87477e6d
N
431 tst->ss->getinfo_super(tst, content, NULL);
432
9008ed1c
N
433 if (!parse_uuid(ident->container, uuid) ||
434 !same_uuid(content->uuid, uuid, tst->ss->swapuuid)) {
435 if (report_missmatch)
e7b84f9d 436 pr_err("%s has wrong UUID to be required container\n",
9008ed1c
N
437 devname);
438 goto loop;
439 }
440 }
441 }
442 /* It is worth looking inside this container.
443 */
4977146a 444 if (c->verbose > 0)
e7b84f9d 445 pr_err("looking in container %s\n",
7636b5a8 446 devname);
1415fe4b 447
88cef9b3
N
448 for (content = tst->ss->container_content(tst, NULL);
449 content;
450 content = content->next) {
1415fe4b 451
88cef9b3 452 if (!ident_matches(ident, content, tst,
4977146a 453 c->homehost, c->update,
88cef9b3
N
454 report_missmatch ? devname : NULL))
455 /* message already printed */;
456 else if (is_member_busy(content->text_version)) {
457 if (report_missmatch)
e7b84f9d 458 pr_err("member %s in %s is already assembled\n",
88cef9b3
N
459 content->text_version,
460 devname);
81219e70
LM
461 } else if (content->array.state & (1<<MD_SB_BLOCK_VOLUME)) {
462 /* do not assemble arrays with unsupported configurations */
e7b84f9d 463 pr_err("Cannot activate member %s in %s.\n",
81219e70
LM
464 content->text_version,
465 devname);
88cef9b3
N
466 } else
467 break;
468 }
469 if (!content) {
f7ad3ccc 470 tmpdev->used = 2;
88cef9b3 471 goto loop; /* empty container */
fa031239 472 }
88cef9b3 473
9008ed1c 474 st = tst; tst = NULL;
4c1c3ad8 475 if (!auto_assem && inargv && tmpdev->next != NULL) {
e7b84f9d 476 pr_err("%s is a container, but is not "
9008ed1c
N
477 "only device given: confused and aborting\n",
478 devname);
479 st->ss->free_super(st);
4e8d9f0a 480 dev_policy_free(pol);
cbeeb0e5 481 domain_free(domains);
9008ed1c
N
482 return 1;
483 }
4977146a 484 if (c->verbose > 0)
e7b84f9d 485 pr_err("found match on member %s in %s\n",
7636b5a8 486 content->text_version, devname);
bac0d92e 487
5083d66b
N
488 /* make sure we finished the loop */
489 tmpdev = NULL;
bac0d92e 490 goto loop;
5083d66b 491 } else {
bac0d92e 492
5083d66b 493 content = &info;
5083d66b
N
494 tst->ss->getinfo_super(tst, content, NULL);
495
496 if (!ident_matches(ident, content, tst,
4977146a 497 c->homehost, c->update,
5083d66b 498 report_missmatch ? devname : NULL))
df37ffc0 499 goto loop;
cbeeb0e5 500
56d18859
N
501 /* should be safe to try an exclusive open now, we
502 * have rejected anything that some other mdadm might
503 * be looking at
504 */
505 dfd = dev_open(devname, O_RDONLY | O_EXCL);
506 if (dfd < 0) {
507 if (report_missmatch)
e7b84f9d 508 pr_err("%s is busy - skipping\n", devname);
56d18859
N
509 goto loop;
510 }
511 close(dfd);
512
5083d66b
N
513 if (st == NULL)
514 st = dup_super(tst);
515 if (st->minor_version == -1)
516 st->minor_version = tst->minor_version;
ed7fc6b4
AC
517
518 if (memcmp(content->uuid, uuid_zero,
519 sizeof(int[4])) == 0) {
520 /* this is a floating spare. It cannot define
521 * an array unless there are no more arrays of
522 * this type to be found. It can be included
523 * in an array of this type though.
524 */
525 tmpdev->used = 3;
526 goto loop;
527 }
528
5083d66b
N
529 if (st->ss != tst->ss ||
530 st->minor_version != tst->minor_version ||
531 st->ss->compare_super(st, tst) != 0) {
532 /* Some mismatch. If exactly one array matches this host,
533 * we can resolve on that one.
534 * Or, if we are auto assembling, we just ignore the second
535 * for now.
536 */
537 if (auto_assem)
538 goto loop;
4977146a
N
539 if (c->homehost) {
540 int first = st->ss->match_home(st, c->homehost);
541 int last = tst->ss->match_home(tst, c->homehost);
5083d66b
N
542 if (first != last &&
543 (first == 1 || last == 1)) {
544 /* We can do something */
545 if (first) {/* just ignore this one */
546 if (report_missmatch)
e7b84f9d 547 pr_err("%s misses out due to wrong homehost\n",
5083d66b
N
548 devname);
549 goto loop;
550 } else { /* reject all those sofar */
551 struct mddev_dev *td;
552 if (report_missmatch)
e7b84f9d 553 pr_err("%s overrides previous devices due to good homehost\n",
5083d66b
N
554 devname);
555 for (td=devlist; td != tmpdev; td=td->next)
556 if (td->used == 1)
557 td->used = 0;
558 tmpdev->used = 1;
559 goto loop;
560 }
83b6208e
NB
561 }
562 }
e7b84f9d 563 pr_err("superblock on %s doesn't match others - assembly aborted\n",
5083d66b
N
564 devname);
565 tst->ss->free_super(tst);
566 st->ss->free_super(st);
567 dev_policy_free(pol);
cbeeb0e5 568 domain_free(domains);
5083d66b 569 return 1;
83b6208e 570 }
5083d66b 571 tmpdev->used = 1;
64c4757e 572 }
df37ffc0 573 loop:
cbeeb0e5 574 /* Collect domain information from members only */
26b05aea
AC
575 if (tmpdev && tmpdev->used == 1) {
576 if (!pol)
577 pol = devnum_policy(stb.st_rdev);
cbeeb0e5 578 domain_merge(&domains, pol, tst?tst->ss->name:NULL);
26b05aea 579 }
4e8d9f0a
N
580 dev_policy_free(pol);
581 pol = NULL;
3d2b16e7
NB
582 if (tst)
583 tst->ss->free_super(tst);
811e6cbe
NB
584 }
585
ed7fc6b4 586 /* Check if we found some imsm spares but no members */
3c7b4a25
CA
587 if ((auto_assem ||
588 (ident->uuid_set &&
589 memcmp(uuid_zero, ident->uuid,sizeof(uuid_zero)) == 0)) &&
590 (!st || !st->sb))
ed7fc6b4
AC
591 for (tmpdev = devlist; tmpdev; tmpdev = tmpdev->next) {
592 if (tmpdev->used != 3)
593 continue;
594 tmpdev->used = 1;
595 content = &info;
596
597 if (!st->sb) {
598 /* we need sb from one of the spares */
599 int dfd = dev_open(tmpdev->devname, O_RDONLY);
600 if (dfd < 0 ||
601 st->ss->load_super(st, dfd, NULL))
602 tmpdev->used = 2;
603 if (dfd > 0)
604 close(dfd);
605 }
606 }
607
cbeeb0e5
AC
608 /* Now reject spares that don't match domains of identified members */
609 for (tmpdev = devlist; tmpdev; tmpdev = tmpdev->next) {
610 struct stat stb;
611 if (tmpdev->used != 3)
612 continue;
613 if (stat(tmpdev->devname, &stb)< 0) {
e7b84f9d 614 pr_err("fstat failed for %s: %s\n",
cbeeb0e5
AC
615 tmpdev->devname, strerror(errno));
616 tmpdev->used = 2;
617 } else {
a5d10dce
N
618 struct dev_policy *pol = devnum_policy(stb.st_rdev);
619 int dt = domain_test(domains, pol, NULL);
620 if (inargv && dt != 0)
621 /* take this spare as domains match
622 * if there are any */
623 tmpdev->used = 1;
624 else if (!inargv && dt == 1)
625 /* device wasn't explicitly listed, so need
626 * explicit domain match - which we have */
cbeeb0e5
AC
627 tmpdev->used = 1;
628 else
629 /* if domains don't match mark as unused */
630 tmpdev->used = 0;
631 dev_policy_free(pol);
632 }
633 }
634 domain_free(domains);
635
98dbd966 636 if (!st || !st->sb || !content)
c30e5369
N
637 return 2;
638
05833051 639 /* Now need to open the array device. Use create_mddev */
98dbd966 640 if (content == &info)
a5d85af7 641 st->ss->getinfo_super(st, content, NULL);
3d2c4fc7 642
69207ff6 643 trustworthy = FOREIGN;
05833051 644 name = content->name;
4977146a 645 switch (st->ss->match_home(st, c->homehost)
745f72f6 646 ?: st->ss->match_home(st, "any")) {
69207ff6
N
647 case 1:
648 trustworthy = LOCAL;
98dbd966 649 name = strchr(content->name, ':');
69207ff6
N
650 if (name)
651 name++;
3d2c4fc7 652 else
98dbd966 653 name = content->name;
69207ff6 654 break;
c30e5369 655 }
05833051 656 if (!auto_assem)
aa7c284c 657 /* If the array is listed in mdadm.conf or on
ac2ecf55
N
658 * command line, then we trust the name
659 * even if the array doesn't look local
660 */
661 trustworthy = LOCAL;
662
05833051 663 if (name[0] == 0 &&
98dbd966
DW
664 content->array.level == LEVEL_CONTAINER) {
665 name = content->text_version;
a4bc1720
N
666 trustworthy = METADATA;
667 }
0ac91628
N
668
669 if (name[0] && trustworthy != LOCAL &&
4977146a 670 ! c->require_homehost &&
0ac91628
N
671 conf_name_is_free(name))
672 trustworthy = LOCAL;
673
7cdc0872
N
674 if (trustworthy == LOCAL &&
675 strchr(name, ':'))
676 /* Ignore 'host:' prefix of name */
677 name = strchr(name, ':')+1;
678
a04d5763
N
679 mdfd = create_mddev(mddev, name, ident->autof, trustworthy,
680 chosen_name);
c30e5369
N
681 if (mdfd < 0) {
682 st->ss->free_super(st);
c30e5369 683 if (auto_assem)
60e1bc1a 684 goto try_again;
c30e5369
N
685 return 1;
686 }
a04d5763 687 mddev = chosen_name;
c30e5369
N
688 vers = md_get_version(mdfd);
689 if (vers < 9000) {
e7b84f9d 690 pr_err("Assemble requires driver version 0.90.0 or later.\n"
c30e5369
N
691 " Upgrade your kernel or try --build\n");
692 close(mdfd);
693 return 1;
694 }
66afdfa9 695 if (mddev_busy(fd2devnum(mdfd))) {
e7b84f9d 696 pr_err("%s already active, cannot restart it!\n",
c30e5369
N
697 mddev);
698 for (tmpdev = devlist ;
699 tmpdev && tmpdev->used != 1;
700 tmpdev = tmpdev->next)
701 ;
702 if (tmpdev && auto_assem)
e7b84f9d 703 pr_err("%s needed for %s...\n",
c30e5369
N
704 mddev, tmpdev->devname);
705 close(mdfd);
706 mdfd = -3;
707 st->ss->free_super(st);
c30e5369
N
708 if (auto_assem)
709 goto try_again;
710 return 1;
8a46fe84 711 }
c30e5369 712 ioctl(mdfd, STOP_ARRAY, NULL); /* just incase it was started but has no content */
8a46fe84 713
9008ed1c
N
714#ifndef MDASSEMBLE
715 if (content != &info) {
716 /* This is a member of a container. Try starting the array. */
588bebfc 717 int err;
4977146a
N
718 err = assemble_container_content(st, mdfd, content, c->runstop,
719 c->readonly,
720 chosen_name, c->verbose,
721 c->backup_file, c->freeze_reshape);
588bebfc 722 close(mdfd);
588bebfc 723 return err;
9008ed1c 724 }
a6482415 725 bitmap_done = 0;
9008ed1c 726#endif
811e6cbe 727 /* Ok, no bad inconsistancy, we can try updating etc */
503975b9
N
728 devices = xcalloc(num_devs, sizeof(*devices));
729 devmap = xcalloc(num_devs, content->array.raid_disks);
da6b5ca9 730 for (tmpdev = devlist; tmpdev; tmpdev=tmpdev->next) if (tmpdev->used == 1) {
811e6cbe
NB
731 char *devname = tmpdev->devname;
732 struct stat stb;
5787fa49 733 /* looks like a good enough match to update the super block if needed */
d1f1011b 734#ifndef MDASSEMBLE
4977146a 735 if (c->update) {
811e6cbe 736 int dfd;
4b1ac34b
NB
737 /* prepare useful information in info structures */
738 struct stat stb2;
3da92f27 739 struct supertype *tst;
1e2b2765 740 int err;
4b1ac34b 741 fstat(mdfd, &stb2);
7d99579f 742
4977146a 743 if (strcmp(c->update, "uuid")==0 &&
7d99579f
NB
744 !ident->uuid_set) {
745 int rfd;
746 if ((rfd = open("/dev/urandom", O_RDONLY)) < 0 ||
747 read(rfd, ident->uuid, 16) != 16) {
748 *(__u32*)(ident->uuid) = random();
749 *(__u32*)(ident->uuid+1) = random();
750 *(__u32*)(ident->uuid+2) = random();
751 *(__u32*)(ident->uuid+3) = random();
752 }
753 if (rfd >= 0) close(rfd);
7d99579f 754 }
811e6cbe
NB
755 dfd = dev_open(devname, O_RDWR|O_EXCL);
756
3da92f27 757 tst = dup_super(st);
9f22b13f 758 if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) {
e7b84f9d 759 pr_err("cannot re-read metadata from %s - aborting\n",
9f22b13f
N
760 devname);
761 if (dfd >= 0)
762 close(dfd);
763 close(mdfd);
d7f7ebb7 764 free(devices);
02e7c5b7 765 free(devmap);
9f22b13f
N
766 return 1;
767 }
02e7c5b7 768 tst->ss->getinfo_super(tst, content, devmap + devcnt * content->array.raid_disks);
811e6cbe 769
98dbd966
DW
770 memcpy(content->uuid, ident->uuid, 16);
771 strcpy(content->name, ident->name);
772 content->array.md_minor = minor(stb2.st_rdev);
811e6cbe 773
4977146a 774 if (strcmp(c->update, "byteorder") == 0)
1e2b2765
N
775 err = 0;
776 else
4977146a
N
777 err = tst->ss->update_super(tst, content, c->update,
778 devname, c->verbose,
1e2b2765 779 ident->uuid_set,
4977146a 780 c->homehost);
1e2b2765 781 if (err < 0) {
e7b84f9d
N
782 pr_err("--update=%s not understood"
783 " for %s metadata\n",
4977146a 784 c->update, tst->ss->name);
1e2b2765
N
785 tst->ss->free_super(tst);
786 free(tst);
787 close(mdfd);
788 close(dfd);
d7f7ebb7 789 free(devices);
02e7c5b7 790 free(devmap);
1e2b2765
N
791 return 1;
792 }
4977146a 793 if (strcmp(c->update, "uuid")==0 &&
e5eac01f
NB
794 !ident->uuid_set) {
795 ident->uuid_set = 1;
98dbd966 796 memcpy(ident->uuid, content->uuid, 16);
e5eac01f 797 }
1e2b2765 798 if (tst->ss->store_super(tst, dfd))
e7b84f9d 799 pr_err("Could not re-write superblock on %s.\n",
5787fa49 800 devname);
1e2b2765 801 close(dfd);
8131b493 802
4977146a 803 if (strcmp(c->update, "uuid")==0 &&
bf4fb153 804 ident->bitmap_fd >= 0 && !bitmap_done) {
3da92f27 805 if (bitmap_update_uuid(ident->bitmap_fd,
98dbd966 806 content->uuid,
3da92f27 807 tst->ss->swapuuid) != 0)
e7b84f9d 808 pr_err("Could not update uuid on external bitmap.\n");
bf4fb153
NB
809 else
810 bitmap_done = 1;
811 }
3da92f27 812 tst->ss->free_super(tst);
d1f1011b
NB
813 } else
814#endif
815 {
30e1b9a5 816 struct supertype *tst = dup_super(st);
da6b5ca9
NB
817 int dfd;
818 dfd = dev_open(devname, O_RDWR|O_EXCL);
819
9f22b13f 820 if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) {
e7b84f9d 821 pr_err("cannot re-read metadata from %s - aborting\n",
9f22b13f
N
822 devname);
823 if (dfd >= 0)
824 close(dfd);
825 close(mdfd);
d7f7ebb7 826 free(devices);
02e7c5b7 827 free(devmap);
9f22b13f
N
828 return 1;
829 }
02e7c5b7 830 tst->ss->getinfo_super(tst, content, devmap + devcnt * content->array.raid_disks);
3da92f27 831 tst->ss->free_super(tst);
da6b5ca9 832 close(dfd);
5787fa49
NB
833 }
834
811e6cbe
NB
835 stat(devname, &stb);
836
4977146a 837 if (c->verbose > 0)
e7b84f9d 838 pr_err("%s is identified as a member of %s, slot %d.\n",
98dbd966 839 devname, mddev, content->disk.raid_disk);
64c4757e 840 devices[devcnt].devname = devname;
64c4757e 841 devices[devcnt].uptodate = 0;
98dbd966 842 devices[devcnt].i = *content;
213ee40b
NB
843 devices[devcnt].i.disk.major = major(stb.st_rdev);
844 devices[devcnt].i.disk.minor = minor(stb.st_rdev);
64c4757e 845 if (most_recent < devcnt) {
213ee40b
NB
846 if (devices[devcnt].i.events
847 > devices[most_recent].i.events)
64c4757e
NB
848 most_recent = devcnt;
849 }
df0d4ea0 850 if (content->array.level == LEVEL_MULTIPATH)
5787fa49
NB
851 /* with multipath, the raid_disk from the superblock is meaningless */
852 i = devcnt;
853 else
213ee40b 854 i = devices[devcnt].i.disk.raid_disk;
308e1801 855 if (i+1 == 0) {
98dbd966
DW
856 if (nextspare < content->array.raid_disks)
857 nextspare = content->array.raid_disks;
308e1801 858 i = nextspare++;
08110d41 859 } else {
98dbd966 860 if (i >= content->array.raid_disks &&
08110d41
NB
861 i >= nextspare)
862 nextspare = i+1;
308e1801 863 }
98c6faba 864 if (i < 10000) {
56eedc1a 865 if (i >= bestcnt) {
f21e18ca 866 int newbestcnt = i+10;
503975b9 867 int *newbest = xmalloc(sizeof(int)*newbestcnt);
f21e18ca 868 int c;
56eedc1a
NB
869 for (c=0; c < newbestcnt; c++)
870 if (c < bestcnt)
871 newbest[c] = best[c];
872 else
873 newbest[c] = -1;
874 if (best)free(best);
875 best = newbest;
876 bestcnt = newbestcnt;
877 }
6a255b69 878 if (best[i] >=0 &&
213ee40b
NB
879 devices[best[i]].i.events
880 == devices[devcnt].i.events
881 && (devices[best[i]].i.disk.minor
882 != devices[devcnt].i.disk.minor)
b8ac1967 883 && st->ss == &super0
98dbd966 884 && content->array.level != LEVEL_MULTIPATH) {
6a255b69
NB
885 /* two different devices with identical superblock.
886 * Could be a mis-detection caused by overlapping
887 * partitions. fail-safe.
888 */
e7b84f9d 889 pr_err("WARNING %s and %s appear"
6a255b69
NB
890 " to have very similar superblocks.\n"
891 " If they are really different, "
892 "please --zero the superblock on one\n"
d2df86e0
NB
893 " If they are the same or overlap,"
894 " please remove one from %s.\n",
895 devices[best[i]].devname, devname,
896 inargv ? "the list" :
897 "the\n DEVICE list in mdadm.conf"
898 );
7f91af49 899 close(mdfd);
d7f7ebb7 900 free(devices);
02e7c5b7 901 free(devmap);
6a255b69
NB
902 return 1;
903 }
52826846 904 if (best[i] == -1
213ee40b
NB
905 || (devices[best[i]].i.events
906 < devices[devcnt].i.events))
52826846 907 best[i] = devcnt;
56eedc1a 908 }
64c4757e 909 devcnt++;
df37ffc0 910 }
4b1ac34b 911
64c4757e 912 if (devcnt == 0) {
e7b84f9d 913 pr_err("no devices found for %s\n",
64c4757e 914 mddev);
3d2b16e7
NB
915 if (st)
916 st->ss->free_super(st);
7f91af49 917 close(mdfd);
d7f7ebb7 918 free(devices);
02e7c5b7 919 free(devmap);
64c4757e
NB
920 return 1;
921 }
4b1ac34b 922
4977146a 923 if (c->update && strcmp(c->update, "byteorder")==0)
3d2b16e7
NB
924 st->minor_version = 90;
925
a5d85af7 926 st->ss->getinfo_super(st, content, NULL);
98dbd966 927 clean = content->array.state & 1;
4b1ac34b 928
64c4757e
NB
929 /* now we have some devices that might be suitable.
930 * I wonder how many
931 */
503975b9 932 avail = xcalloc(content->array.raid_disks, 1);
64c4757e 933 okcnt = 0;
52826846 934 sparecnt=0;
1ff98339 935 rebuilding_cnt=0;
f21e18ca 936 for (i=0; i< bestcnt; i++) {
64c4757e 937 int j = best[i];
ee04451c
NB
938 int event_margin = 1; /* always allow a difference of '1'
939 * like the kernel does
940 */
64c4757e 941 if (j < 0) continue;
d013a55e
NB
942 /* note: we ignore error flags in multipath arrays
943 * as they don't make sense
944 */
df0d4ea0 945 if (content->array.level != LEVEL_MULTIPATH)
f22385f9 946 if (!(devices[j].i.disk.state & (1<<MD_DISK_ACTIVE))) {
213ee40b 947 if (!(devices[j].i.disk.state
ed7fc6b4
AC
948 & (1<<MD_DISK_FAULTY))) {
949 devices[j].uptodate = 1;
aa88f531 950 sparecnt++;
ed7fc6b4 951 }
d013a55e 952 continue;
aa88f531 953 }
de5a472e 954 /* If this device thinks that 'most_recent' has failed, then
02e7c5b7
N
955 * we must reject this device.
956 */
957 if (j != most_recent &&
958 content->array.raid_disks > 0 &&
959 devices[most_recent].i.disk.raid_disk >= 0 &&
960 devmap[j * content->array.raid_disks + devices[most_recent].i.disk.raid_disk] == 0) {
4977146a 961 if (c->verbose > -1)
e7b84f9d 962 pr_err("ignoring %s as it reports %s as failed\n",
02e7c5b7
N
963 devices[j].devname, devices[most_recent].devname);
964 best[i] = -1;
965 continue;
966 }
213ee40b
NB
967 if (devices[j].i.events+event_margin >=
968 devices[most_recent].i.events) {
64c4757e 969 devices[j].uptodate = 1;
1ff98339 970 if (i < content->array.raid_disks) {
dcc4210f
DW
971 if (devices[j].i.recovery_start == MaxSector ||
972 (content->reshape_active &&
b720636a
N
973 ((i >= content->array.raid_disks - content->delta_disks) ||
974 (i >= content->array.raid_disks - content->delta_disks - 1
975 && content->array.level == 4)))) {
1ff98339
N
976 okcnt++;
977 avail[i]=1;
978 } else
979 rebuilding_cnt++;
265e0f17 980 } else
52826846 981 sparecnt++;
64c4757e
NB
982 }
983 }
02e7c5b7 984 free(devmap);
4977146a 985 while (c->force &&
da8fe5aa
N
986 (!enough(content->array.level, content->array.raid_disks,
987 content->array.layout, 1,
988 avail)
989 ||
990 (content->reshape_active && content->delta_disks > 0 &&
991 !enough(content->array.level, (content->array.raid_disks
992 - content->delta_disks),
993 content->new_layout, 1,
994 avail)
995 ))) {
64c4757e
NB
996 /* Choose the newest best drive which is
997 * not up-to-date, update the superblock
998 * and add it.
999 */
52826846 1000 int fd;
3da92f27 1001 struct supertype *tst;
f21e18ca 1002 unsigned long long current_events;
cd29a5c8 1003 chosen_drive = -1;
f21e18ca 1004 for (i = 0; i < content->array.raid_disks && i < bestcnt; i++) {
52826846
NB
1005 int j = best[i];
1006 if (j>=0 &&
1007 !devices[j].uptodate &&
921d9e16 1008 devices[j].i.recovery_start == MaxSector &&
52826846 1009 (chosen_drive < 0 ||
213ee40b
NB
1010 devices[j].i.events
1011 > devices[chosen_drive].i.events))
52826846
NB
1012 chosen_drive = j;
1013 }
1014 if (chosen_drive < 0)
1015 break;
213ee40b 1016 current_events = devices[chosen_drive].i.events;
c5a6f9a6 1017 add_another:
4977146a 1018 if (c->verbose >= 0)
e7b84f9d 1019 pr_err("forcing event count in %s(%d) from %d upto %d\n",
213ee40b
NB
1020 devices[chosen_drive].devname,
1021 devices[chosen_drive].i.disk.raid_disk,
1022 (int)(devices[chosen_drive].i.events),
1023 (int)(devices[most_recent].i.events));
8b0dabea 1024 fd = dev_open(devices[chosen_drive].devname, O_RDWR|O_EXCL);
52826846 1025 if (fd < 0) {
e7b84f9d 1026 pr_err("Couldn't open %s for write - not updating\n",
52826846 1027 devices[chosen_drive].devname);
213ee40b 1028 devices[chosen_drive].i.events = 0;
52826846
NB
1029 continue;
1030 }
3da92f27 1031 tst = dup_super(st);
60b435db 1032 if (tst->ss->load_super(tst,fd, NULL)) {
52826846 1033 close(fd);
e7b84f9d 1034 pr_err("RAID superblock disappeared from %s - not updating.\n",
52826846 1035 devices[chosen_drive].devname);
213ee40b 1036 devices[chosen_drive].i.events = 0;
52826846
NB
1037 continue;
1038 }
98dbd966
DW
1039 content->events = devices[most_recent].i.events;
1040 tst->ss->update_super(tst, content, "force-one",
4977146a 1041 devices[chosen_drive].devname, c->verbose,
67a8c82d 1042 0, NULL);
4b1ac34b 1043
3da92f27 1044 if (tst->ss->store_super(tst, fd)) {
52826846 1045 close(fd);
e7b84f9d 1046 pr_err("Could not re-write superblock on %s\n",
52826846 1047 devices[chosen_drive].devname);
213ee40b 1048 devices[chosen_drive].i.events = 0;
3da92f27 1049 tst->ss->free_super(tst);
52826846
NB
1050 continue;
1051 }
1052 close(fd);
213ee40b 1053 devices[chosen_drive].i.events = devices[most_recent].i.events;
52826846 1054 devices[chosen_drive].uptodate = 1;
265e0f17 1055 avail[chosen_drive] = 1;
52826846 1056 okcnt++;
3da92f27 1057 tst->ss->free_super(tst);
c5a6f9a6
NB
1058
1059 /* If there are any other drives of the same vintage,
1060 * add them in as well. We can't lose and we might gain
1061 */
f21e18ca 1062 for (i = 0; i < content->array.raid_disks && i < bestcnt ; i++) {
c5a6f9a6
NB
1063 int j = best[i];
1064 if (j >= 0 &&
1065 !devices[j].uptodate &&
135a31f5 1066 devices[j].i.recovery_start == MaxSector &&
213ee40b 1067 devices[j].i.events == current_events) {
c5a6f9a6
NB
1068 chosen_drive = j;
1069 goto add_another;
1070 }
1071 }
64c4757e 1072 }
52826846
NB
1073
1074 /* Now we want to look at the superblock which the kernel will base things on
1075 * and compare the devices that we think are working with the devices that the
1076 * superblock thinks are working.
1077 * If there are differences and --force is given, then update this chosen
1078 * superblock.
1079 */
cd29a5c8 1080 chosen_drive = -1;
3da92f27 1081 st->ss->free_super(st);
56eedc1a 1082 for (i=0; chosen_drive < 0 && i<bestcnt; i++) {
52826846
NB
1083 int j = best[i];
1084 int fd;
4b1ac34b 1085
52826846
NB
1086 if (j<0)
1087 continue;
1088 if (!devices[j].uptodate)
1089 continue;
a28232b8
N
1090 if (devices[j].i.events < devices[most_recent].i.events)
1091 continue;
52826846 1092 chosen_drive = j;
8b0dabea 1093 if ((fd=dev_open(devices[j].devname, O_RDONLY|O_EXCL))< 0) {
e7b84f9d 1094 pr_err("Cannot open %s: %s\n",
52826846 1095 devices[j].devname, strerror(errno));
7f91af49 1096 close(mdfd);
d7f7ebb7 1097 free(devices);
52826846
NB
1098 return 1;
1099 }
3da92f27 1100 if (st->ss->load_super(st,fd, NULL)) {
52826846 1101 close(fd);
e7b84f9d 1102 pr_err("RAID superblock has disappeared from %s\n",
52826846 1103 devices[j].devname);
7f91af49 1104 close(mdfd);
d7f7ebb7 1105 free(devices);
52826846
NB
1106 return 1;
1107 }
1108 close(fd);
1109 }
3da92f27 1110 if (st->sb == NULL) {
e7b84f9d 1111 pr_err("No suitable drives found for %s\n", mddev);
7f91af49 1112 close(mdfd);
d7f7ebb7 1113 free(devices);
4b1ac34b
NB
1114 return 1;
1115 }
a5d85af7 1116 st->ss->getinfo_super(st, content, NULL);
f35f2525 1117#ifndef MDASSEMBLE
98dbd966 1118 sysfs_init(content, mdfd, 0);
f35f2525 1119#endif
56eedc1a 1120 for (i=0; i<bestcnt; i++) {
52826846 1121 int j = best[i];
98c6faba 1122 unsigned int desired_state;
11a3e71d 1123
98dbd966 1124 if (i < content->array.raid_disks)
11a3e71d
NB
1125 desired_state = (1<<MD_DISK_ACTIVE) | (1<<MD_DISK_SYNC);
1126 else
1127 desired_state = 0;
1128
52826846
NB
1129 if (j<0)
1130 continue;
1131 if (!devices[j].uptodate)
1132 continue;
4b1ac34b 1133
213ee40b 1134 devices[j].i.disk.state = desired_state;
4e9a6ff7
N
1135 if (!(devices[j].i.array.state & 1))
1136 clean = 0;
213ee40b
NB
1137
1138 if (st->ss->update_super(st, &devices[j].i, "assemble", NULL,
4977146a
N
1139 c->verbose, 0, NULL)) {
1140 if (c->force) {
1141 if (c->verbose >= 0)
e7b84f9d 1142 pr_err("clearing FAULTY flag for device %d in %s for %s\n",
dab6685f 1143 j, mddev, devices[j].devname);
4b1ac34b 1144 change = 1;
52826846 1145 } else {
4977146a 1146 if (c->verbose >= -1)
e7b84f9d 1147 pr_err("device %d in %s has wrong state in superblock, but %s seems ok\n",
dab6685f 1148 i, mddev, devices[j].devname);
52826846
NB
1149 }
1150 }
4b1ac34b 1151#if 0
213ee40b 1152 if (!(super.disks[i].i.disk.state & (1 << MD_DISK_FAULTY))) {
e7b84f9d 1153 pr_err("devices %d of %s is not marked FAULTY in superblock, but cannot be found\n",
52826846
NB
1154 i, mddev);
1155 }
4b1ac34b 1156#endif
52826846 1157 }
4977146a 1158 if (c->force && !clean &&
98dbd966
DW
1159 !enough(content->array.level, content->array.raid_disks,
1160 content->array.layout, clean,
de5a472e 1161 avail)) {
98dbd966 1162 change += st->ss->update_super(st, content, "force-array",
4977146a 1163 devices[chosen_drive].devname, c->verbose,
67a8c82d 1164 0, NULL);
583315d9 1165 clean = 1;
d013a55e 1166 }
52826846 1167
4b1ac34b 1168 if (change) {
52826846 1169 int fd;
8b0dabea 1170 fd = dev_open(devices[chosen_drive].devname, O_RDWR|O_EXCL);
52826846 1171 if (fd < 0) {
e7b84f9d 1172 pr_err("Could not open %s for write - cannot Assemble array.\n",
52826846 1173 devices[chosen_drive].devname);
7f91af49 1174 close(mdfd);
d7f7ebb7 1175 free(devices);
52826846
NB
1176 return 1;
1177 }
3da92f27 1178 if (st->ss->store_super(st, fd)) {
52826846 1179 close(fd);
e7b84f9d 1180 pr_err("Could not re-write superblock on %s\n",
52826846 1181 devices[chosen_drive].devname);
7f91af49 1182 close(mdfd);
d7f7ebb7 1183 free(devices);
52826846
NB
1184 return 1;
1185 }
4977146a 1186 if (c->verbose >= 0)
e7b84f9d 1187 pr_err("Marking array %s as 'clean'\n",
a28232b8 1188 mddev);
52826846 1189 close(fd);
52826846
NB
1190 }
1191
353632d9
NB
1192 /* If we are in the middle of a reshape we may need to restore saved data
1193 * that was moved aside due to the reshape overwriting live data
1194 * The code of doing this lives in Grow.c
1195 */
39c5a909 1196#ifndef MDASSEMBLE
98dbd966 1197 if (content->reshape_active) {
353632d9 1198 int err = 0;
503975b9 1199 int *fdlist = xmalloc(sizeof(int)* bestcnt);
4977146a 1200 if (c->verbose > 0)
e7b84f9d 1201 pr_err(":%s has an active reshape - checking "
ea0ebe96
N
1202 "if critical section needs to be restored\n",
1203 chosen_name);
353632d9
NB
1204 for (i=0; i<bestcnt; i++) {
1205 int j = best[i];
1206 if (j >= 0) {
1207 fdlist[i] = dev_open(devices[j].devname, O_RDWR|O_EXCL);
1208 if (fdlist[i] < 0) {
e7b84f9d 1209 pr_err("Could not open %s for write - cannot Assemble array.\n",
353632d9
NB
1210 devices[j].devname);
1211 err = 1;
1212 break;
1213 }
1214 } else
1215 fdlist[i] = -1;
1216 }
87f26d14 1217 if (!err) {
ba53ea59
AK
1218 if (st->ss->external && st->ss->recover_backup)
1219 err = st->ss->recover_backup(st, content);
1220 else
1221 err = Grow_restart(st, content, fdlist, bestcnt,
4977146a
N
1222 c->backup_file, c->verbose > 0);
1223 if (err && c->invalid_backup) {
1224 if (c->verbose > 0)
e7b84f9d 1225 pr_err("continuing"
87f26d14
N
1226 " without restoring backup\n");
1227 err = 0;
1228 }
1229 }
353632d9
NB
1230 while (i>0) {
1231 i--;
1232 if (fdlist[i]>=0) close(fdlist[i]);
1233 }
1234 if (err) {
e7b84f9d 1235 pr_err("Failed to restore critical section for reshape, sorry.\n");
4977146a 1236 if (c->backup_file == NULL)
e7b84f9d 1237 cont_err("Possibly you needed to specify the --backup-file\n");
7f91af49 1238 close(mdfd);
d7f7ebb7 1239 free(devices);
353632d9
NB
1240 return err;
1241 }
1242 }
39c5a909 1243#endif
aa88f531
NB
1244 /* count number of in-sync devices according to the superblock.
1245 * We must have this number to start the array without -s or -R
1246 */
98dbd966 1247 req_cnt = content->array.working_disks;
aa88f531 1248
64c4757e
NB
1249 /* Almost ready to actually *do* something */
1250 if (!old_linux) {
fbf8a0b7 1251 int rv;
a19c88b8 1252
a04d5763
N
1253 /* First, fill in the map, so that udev can find our name
1254 * as soon as we become active.
1255 */
98dbd966
DW
1256 map_update(NULL, fd2devnum(mdfd), content->text_version,
1257 content->uuid, chosen_name);
a04d5763 1258
98dbd966 1259 rv = set_array_info(mdfd, st, content);
fbf8a0b7 1260 if (rv) {
e7b84f9d 1261 pr_err("failed to set array info for %s: %s\n",
64c4757e 1262 mddev, strerror(errno));
24af7a87 1263 ioctl(mdfd, STOP_ARRAY, NULL);
7f91af49 1264 close(mdfd);
d7f7ebb7 1265 free(devices);
64c4757e
NB
1266 return 1;
1267 }
11484a63 1268 if (ident->bitmap_fd >= 0) {
c82f047c 1269 if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) {
e7b84f9d 1270 pr_err("SET_BITMAP_FILE failed.\n");
24af7a87 1271 ioctl(mdfd, STOP_ARRAY, NULL);
7f91af49 1272 close(mdfd);
d7f7ebb7 1273 free(devices);
c82f047c
NB
1274 return 1;
1275 }
7ef02d01
NB
1276 } else if (ident->bitmap_file) {
1277 /* From config file */
1278 int bmfd = open(ident->bitmap_file, O_RDWR);
1279 if (bmfd < 0) {
e7b84f9d 1280 pr_err("Could not open bitmap file %s\n",
7ef02d01 1281 ident->bitmap_file);
24af7a87 1282 ioctl(mdfd, STOP_ARRAY, NULL);
7f91af49 1283 close(mdfd);
d7f7ebb7 1284 free(devices);
7ef02d01
NB
1285 return 1;
1286 }
1287 if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
e7b84f9d 1288 pr_err("Failed to set bitmapfile for %s\n", mddev);
7ef02d01 1289 close(bmfd);
24af7a87 1290 ioctl(mdfd, STOP_ARRAY, NULL);
7f91af49 1291 close(mdfd);
d7f7ebb7 1292 free(devices);
7ef02d01
NB
1293 return 1;
1294 }
1295 close(bmfd);
c82f047c 1296 }
7ef02d01 1297
52826846 1298 /* First, add the raid disks, but add the chosen one last */
56eedc1a 1299 for (i=0; i<= bestcnt; i++) {
52826846 1300 int j;
56eedc1a 1301 if (i < bestcnt) {
52826846
NB
1302 j = best[i];
1303 if (j == chosen_drive)
1304 continue;
1305 } else
1306 j = chosen_drive;
1307
56eedc1a 1308 if (j >= 0 /* && devices[j].uptodate */) {
484ae54d
N
1309 int dfd = dev_open(devices[j].devname,
1310 O_RDWR|O_EXCL);
1311 if (dfd >= 0) {
1312 remove_partitions(dfd);
1313 close(dfd);
1314 }
98dbd966 1315 rv = add_disk(mdfd, st, content, &devices[j].i);
7801ac20 1316
a19c88b8 1317 if (rv) {
e7b84f9d
N
1318 pr_err("failed to add "
1319 "%s to %s: %s\n",
1320 devices[j].devname,
1321 mddev,
1322 strerror(errno));
98dbd966 1323 if (i < content->array.raid_disks
213ee40b 1324 || i == bestcnt)
52826846
NB
1325 okcnt--;
1326 else
1327 sparecnt--;
4977146a 1328 } else if (c->verbose > 0)
e7b84f9d
N
1329 pr_err("added %s to %s as %d%s\n",
1330 devices[j].devname, mddev,
1331 devices[j].i.disk.raid_disk,
1332 devices[j].uptodate?"":
1333 " (possibly out of date)");
4977146a 1334 } else if (c->verbose > 0 && i < content->array.raid_disks)
e7b84f9d 1335 pr_err("no uptodate device for "
213ee40b 1336 "slot %d of %s\n",
64c4757e
NB
1337 i, mddev);
1338 }
aba69144 1339
98dbd966 1340 if (content->array.level == LEVEL_CONTAINER) {
4977146a 1341 if (c->verbose >= 0) {
e7b84f9d 1342 pr_err("Container %s has been "
598f0d58 1343 "assembled with %d drive%s",
57ed8c91 1344 mddev, okcnt+sparecnt, okcnt+sparecnt==1?"":"s");
f21e18ca 1345 if (okcnt < (unsigned)content->array.raid_disks)
598f0d58 1346 fprintf(stderr, " (out of %d)",
98dbd966 1347 content->array.raid_disks);
598f0d58
NB
1348 fprintf(stderr, "\n");
1349 }
ac597b1c 1350 st->ss->free_super(st);
98dbd966 1351 sysfs_uevent(content, "change");
a7c6e3fb 1352 wait_for(chosen_name, mdfd);
7f91af49 1353 close(mdfd);
d7f7ebb7 1354 free(devices);
598f0d58
NB
1355 return 0;
1356 }
1357
4977146a
N
1358 if (c->runstop == 1 ||
1359 (c->runstop <= 0 &&
98dbd966 1360 ( enough(content->array.level, content->array.raid_disks,
de5a472e 1361 content->array.layout, clean, avail) &&
1ff98339 1362 (okcnt + rebuilding_cnt >= req_cnt || start_partial_ok)
aa88f531 1363 ))) {
e9e43ec3
N
1364 /* This array is good-to-go.
1365 * If a reshape is in progress then we might need to
1366 * continue monitoring it. In that case we start
1367 * it read-only and let the grow code make it writable.
1368 */
1369 int rv;
eb3929a4 1370#ifndef MDASSEMBLE
e9e43ec3 1371 if (content->reshape_active &&
3bd58dc6
AK
1372 content->delta_disks <= 0) {
1373 rv = sysfs_set_str(content, NULL,
1374 "array_state", "readonly");
1375 if (rv == 0)
1376 rv = Grow_continue(mdfd, st, content,
4977146a
N
1377 c->backup_file,
1378 c->freeze_reshape);
1379 } else if (c->readonly &&
0ea8f5b1
N
1380 sysfs_attribute_available(
1381 content, NULL, "array_state")) {
1382 rv = sysfs_set_str(content, NULL,
1383 "array_state", "readonly");
3bd58dc6 1384 } else
eb3929a4 1385#endif
e9e43ec3
N
1386 rv = ioctl(mdfd, RUN_ARRAY, NULL);
1387 if (rv == 0) {
4977146a 1388 if (c->verbose >= 0) {
e7b84f9d 1389 pr_err("%s has been started with %d drive%s",
dab6685f 1390 mddev, okcnt, okcnt==1?"":"s");
f21e18ca 1391 if (okcnt < (unsigned)content->array.raid_disks)
98dbd966 1392 fprintf(stderr, " (out of %d)", content->array.raid_disks);
1ff98339
N
1393 if (rebuilding_cnt)
1394 fprintf(stderr, "%s %d rebuilding", sparecnt?",":" and", rebuilding_cnt);
dab6685f
NB
1395 if (sparecnt)
1396 fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
1397 fprintf(stderr, ".\n");
1398 }
8a659c33
N
1399 if (content->reshape_active &&
1400 content->array.level >= 4 &&
1401 content->array.level <= 6) {
acee8e89
N
1402 /* might need to increase the size
1403 * of the stripe cache - default is 256
1404 */
8a659c33 1405 if (256 < 4 * (content->array.chunk_size/4096)) {
acee8e89
N
1406 struct mdinfo *sra = sysfs_read(mdfd, 0, 0);
1407 if (sra)
1408 sysfs_set_num(sra, NULL,
1409 "stripe_cache_size",
8a659c33 1410 (4 * content->array.chunk_size / 4096) + 1);
83366b33 1411 sysfs_free(sra);
acee8e89
N
1412 }
1413 }
7e83544b
N
1414 if (okcnt < (unsigned)content->array.raid_disks) {
1415 /* If any devices did not get added
1416 * because the kernel rejected them based
1417 * on event count, try adding them
1418 * again providing the action policy is
1419 * 're-add' or greater. The bitmap
1420 * might allow them to be included, or
1421 * they will become spares.
1422 */
b787bec6 1423 for (i = 0; i < bestcnt; i++) {
7e83544b
N
1424 int j = best[i];
1425 if (j >= 0 && !devices[j].uptodate) {
1426 if (!disk_action_allows(&devices[j].i, st->ss->name, act_re_add))
1427 continue;
1428 rv = add_disk(mdfd, st, content,
1429 &devices[j].i);
4977146a 1430 if (rv == 0 && c->verbose >= 0)
e7b84f9d
N
1431 pr_err("%s has been re-added.\n",
1432 devices[j].devname);
7e83544b
N
1433 }
1434 }
1435 }
a7c6e3fb 1436 wait_for(mddev, mdfd);
7f91af49
N
1437 close(mdfd);
1438 if (auto_assem) {
589395d6 1439 int usecs = 1;
589395d6
NB
1440 /* There is a nasty race with 'mdadm --monitor'.
1441 * If it opens this device before we close it,
1442 * it gets an incomplete open on which IO
598f0d58
NB
1443 * doesn't work and the capacity is
1444 * wrong.
589395d6
NB
1445 * If we reopen (to check for layered devices)
1446 * before --monitor closes, we loose.
1447 *
1448 * So: wait upto 1 second for there to be
1449 * a non-zero capacity.
1450 */
1451 while (usecs < 1000) {
1452 mdfd = open(mddev, O_RDONLY);
1453 if (mdfd >= 0) {
beae1dfe
NB
1454 unsigned long long size;
1455 if (get_dev_size(mdfd, NULL, &size) &&
589395d6
NB
1456 size > 0)
1457 break;
1458 close(mdfd);
1459 }
1460 usleep(usecs);
1461 usecs <<= 1;
1462 }
1463 }
d7f7ebb7 1464 free(devices);
64c4757e 1465 return 0;
82b27616 1466 }
e7b84f9d 1467 pr_err("failed to RUN_ARRAY %s: %s\n",
64c4757e 1468 mddev, strerror(errno));
583315d9 1469
98dbd966 1470 if (!enough(content->array.level, content->array.raid_disks,
de5a472e 1471 content->array.layout, 1, avail))
e7b84f9d 1472 pr_err("Not enough devices to "
583315d9 1473 "start the array.\n");
98dbd966
DW
1474 else if (!enough(content->array.level,
1475 content->array.raid_disks,
1476 content->array.layout, clean,
de5a472e 1477 avail))
e7b84f9d 1478 pr_err("Not enough devices to "
583315d9
NB
1479 "start the array while not clean "
1480 "- consider --force.\n");
1481
7f91af49 1482 if (auto_assem)
1c203a4b 1483 ioctl(mdfd, STOP_ARRAY, NULL);
7f91af49 1484 close(mdfd);
d7f7ebb7 1485 free(devices);
64c4757e
NB
1486 return 1;
1487 }
4977146a 1488 if (c->runstop == -1) {
e7b84f9d
N
1489 pr_err("%s assembled from %d drive%s",
1490 mddev, okcnt, okcnt==1?"":"s");
f21e18ca 1491 if (okcnt != (unsigned)content->array.raid_disks)
98dbd966 1492 fprintf(stderr, " (out of %d)", content->array.raid_disks);
b8a8ccf9 1493 fprintf(stderr, ", but not started.\n");
7f91af49 1494 close(mdfd);
d7f7ebb7 1495 free(devices);
64c4757e 1496 return 0;
82b27616 1497 }
4977146a 1498 if (c->verbose >= -1) {
e7b84f9d 1499 pr_err("%s assembled from %d drive%s", mddev, okcnt, okcnt==1?"":"s");
1ff98339
N
1500 if (rebuilding_cnt)
1501 fprintf(stderr, "%s %d rebuilding", sparecnt?", ":" and ", rebuilding_cnt);
dab6685f
NB
1502 if (sparecnt)
1503 fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
98dbd966 1504 if (!enough(content->array.level, content->array.raid_disks,
de5a472e 1505 content->array.layout, 1, avail))
dab6685f 1506 fprintf(stderr, " - not enough to start the array.\n");
98dbd966
DW
1507 else if (!enough(content->array.level,
1508 content->array.raid_disks,
1509 content->array.layout, clean,
de5a472e 1510 avail))
583315d9
NB
1511 fprintf(stderr, " - not enough to start the "
1512 "array while not clean - consider "
1513 "--force.\n");
dab6685f 1514 else {
f21e18ca 1515 if (req_cnt == (unsigned)content->array.raid_disks)
dab6685f
NB
1516 fprintf(stderr, " - need all %d to start it", req_cnt);
1517 else
98dbd966 1518 fprintf(stderr, " - need %d of %d to start", req_cnt, content->array.raid_disks);
dab6685f
NB
1519 fprintf(stderr, " (use --run to insist).\n");
1520 }
aa88f531 1521 }
7f91af49 1522 if (auto_assem)
1c203a4b 1523 ioctl(mdfd, STOP_ARRAY, NULL);
56a8da69 1524 close(mdfd);
d7f7ebb7 1525 free(devices);
64c4757e 1526 return 1;
82b27616 1527 } else {
52826846
NB
1528 /* The "chosen_drive" is a good choice, and if necessary, the superblock has
1529 * been updated to point to the current locations of devices.
1530 * so we can just start the array
82b27616 1531 */
cd29a5c8 1532 unsigned long dev;
213ee40b
NB
1533 dev = makedev(devices[chosen_drive].i.disk.major,
1534 devices[chosen_drive].i.disk.minor);
82b27616 1535 if (ioctl(mdfd, START_ARRAY, dev)) {
e7b84f9d 1536 pr_err("Cannot start array: %s\n",
82b27616
NB
1537 strerror(errno));
1538 }
aba69144 1539
64c4757e 1540 }
7f91af49 1541 close(mdfd);
d7f7ebb7 1542 free(devices);
e0d19036 1543 return 0;
64c4757e 1544}
6234c63c
DW
1545
1546#ifndef MDASSEMBLE
1547int assemble_container_content(struct supertype *st, int mdfd,
1548 struct mdinfo *content, int runstop,
0ea8f5b1 1549 int readonly,
49680258 1550 char *chosen_name, int verbose,
b76b30e0 1551 char *backup_file, int freeze_reshape)
6234c63c
DW
1552{
1553 struct mdinfo *dev, *sra;
1554 int working = 0, preexist = 0;
882029c8 1555 int expansion = 0;
6234c63c 1556 struct map_ent *map = NULL;
7af03341 1557 int old_raid_disks;
4aecb54a 1558 int start_reshape;
6234c63c
DW
1559
1560 sysfs_init(content, mdfd, 0);
1561
1562 sra = sysfs_read(mdfd, 0, GET_VERSION);
0ea8f5b1
N
1563 if (sra == NULL || strcmp(sra->text_version, content->text_version) != 0) {
1564 if (content->array.major_version == -1 &&
1565 content->array.minor_version == -2 &&
1566 readonly &&
1567 content->text_version[0] == '/')
1568 content->text_version[0] = '-';
22472ee1
JS
1569 if (sysfs_set_array(content, md_get_version(mdfd)) != 0) {
1570 if (sra)
1571 sysfs_free(sra);
6234c63c 1572 return 1;
22472ee1 1573 }
0ea8f5b1 1574 }
588bebfc 1575
4aecb54a
AK
1576 /* There are two types of reshape: container wide or sub-array specific
1577 * Check if metadata requests blocking container wide reshapes
1578 */
1579 start_reshape = (content->reshape_active &&
1580 !((content->reshape_active == CONTAINER_RESHAPE) &&
1581 (content->array.state & (1<<MD_SB_BLOCK_CONTAINER_RESHAPE))));
1582
1583 /* Block subarray here if it is under reshape now
1584 * Do not allow for any changes in this array
1585 */
1586 if (st->ss->external && content->recovery_blocked && start_reshape)
b8063f07
AK
1587 block_subarray(content);
1588
6234c63c
DW
1589 if (sra)
1590 sysfs_free(sra);
7af03341 1591 old_raid_disks = content->array.raid_disks - content->delta_disks;
6234c63c 1592 for (dev = content->devs; dev; dev = dev->next)
14032016 1593 if (sysfs_add_disk(content, dev, 1) == 0) {
7af03341 1594 if (dev->disk.raid_disk >= old_raid_disks &&
14032016
AK
1595 content->reshape_active)
1596 expansion++;
1597 else
1598 working++;
1599 } else if (errno == EEXIST)
6234c63c 1600 preexist++;
111e9fda 1601 if (working + expansion == 0)
7cb2aa33 1602 return 1;/* Nothing new, don't try to start */
588bebfc 1603
8b4e5ea9
N
1604 map_update(&map, fd2devnum(mdfd),
1605 content->text_version,
1606 content->uuid, chosen_name);
1607
1608 if (runstop > 0 ||
882029c8
AK
1609 (working + preexist + expansion) >=
1610 content->array.working_disks) {
bb50e5d3 1611 int err;
a714580e 1612
81219e70 1613 if (start_reshape) {
49680258 1614 int spare = content->array.raid_disks + expansion;
3f54bd62
AK
1615 if (restore_backup(st, content,
1616 working,
1617 spare, backup_file, verbose) == 1)
49680258 1618 return 1;
49680258 1619
3bd58dc6
AK
1620 err = sysfs_set_str(content, NULL,
1621 "array_state", "readonly");
1622 if (err)
1623 return 1;
1624
a93ada3b
AK
1625 if (st->ss->external) {
1626 if (!mdmon_running(st->container_dev))
1627 start_mdmon(st->container_dev);
1628 ping_monitor_by_id(st->container_dev);
7728e1c6
LD
1629 if (mdmon_running(st->container_dev) &&
1630 st->update_tail == NULL)
1631 st->update_tail = &st->updates;
a93ada3b
AK
1632 }
1633
b76b30e0
AK
1634 err = Grow_continue(mdfd, st, content, backup_file,
1635 freeze_reshape);
49680258 1636 } else switch(content->array.level) {
6234c63c
DW
1637 case LEVEL_LINEAR:
1638 case LEVEL_MULTIPATH:
1639 case 0:
bb50e5d3 1640 err = sysfs_set_str(content, NULL, "array_state",
0ea8f5b1 1641 readonly ? "readonly" : "active");
6234c63c
DW
1642 break;
1643 default:
bb50e5d3 1644 err = sysfs_set_str(content, NULL, "array_state",
6234c63c
DW
1645 "readonly");
1646 /* start mdmon if needed. */
bb50e5d3
N
1647 if (!err) {
1648 if (!mdmon_running(st->container_dev))
1649 start_mdmon(st->container_dev);
983fff45 1650 ping_monitor_by_id(st->container_dev);
bb50e5d3 1651 }
6234c63c
DW
1652 break;
1653 }
bb50e5d3
N
1654 if (!err)
1655 sysfs_set_safemode(content, content->safe_mode_delay);
4aecb54a
AK
1656
1657 /* Block subarray here if it is not reshaped now
1658 * It has be blocked a little later to allow mdmon to switch in
1659 * in to R/W state
1660 */
1661 if (st->ss->external && content->recovery_blocked &&
1662 !start_reshape)
1663 block_subarray(content);
1664
6234c63c 1665 if (verbose >= 0) {
bb50e5d3 1666 if (err)
e7b84f9d
N
1667 pr_err("array %s now has %d device%s",
1668 chosen_name, working + preexist,
1669 working + preexist == 1 ? "":"s");
bb50e5d3 1670 else
e7b84f9d
N
1671 pr_err("Started %s with %d device%s",
1672 chosen_name, working + preexist,
1673 working + preexist == 1 ? "":"s");
6234c63c
DW
1674 if (preexist)
1675 fprintf(stderr, " (%d new)", working);
882029c8
AK
1676 if (expansion)
1677 fprintf(stderr, " ( + %d for expansion)",
1678 expansion);
6234c63c
DW
1679 fprintf(stderr, "\n");
1680 }
bb50e5d3 1681 if (!err)
a7c6e3fb 1682 wait_for(chosen_name, mdfd);
588bebfc 1683 return err;
6234c63c 1684 /* FIXME should have an O_EXCL and wait for read-auto */
7cb2aa33 1685 } else {
88716263 1686 if (verbose >= 0) {
e7b84f9d
N
1687 pr_err("%s assembled with %d device%s",
1688 chosen_name, preexist + working,
1689 preexist + working == 1 ? "":"s");
88716263
N
1690 if (preexist)
1691 fprintf(stderr, " (%d new)", working);
1692 fprintf(stderr, " but not started\n");
1693 }
7cb2aa33
N
1694 return 1;
1695 }
6234c63c
DW
1696}
1697#endif
1698