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