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