]> git.ipfire.org Git - thirdparty/mdadm.git/blame - Create.c
Initial DDF support code.
[thirdparty/mdadm.git] / Create.c
CommitLineData
64c4757e 1/*
9a9dab36 2 * mdadm - manage Linux "md" devices aka RAID arrays.
64c4757e 3 *
4f589ad0 4 * Copyright (C) 2001-2006 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
22 * Email: <neilb@cse.unsw.edu.au>
23 * Paper: Neil Brown
24 * School of Computer Science and Engineering
25 * The University of New South Wales
26 * Sydney, 2052
27 * Australia
28 */
29
9a9dab36 30#include "mdadm.h"
682c7051
NB
31#include "md_u.h"
32#include "md_p.h"
60248f74 33#include <ctype.h>
64c4757e 34
82d9eba6 35int Create(struct supertype *st, char *mddev, int mdfd,
5dd497ee 36 int chunk, int level, int layout, unsigned long long size, int raiddisks, int sparedisks,
3d3dd91e 37 char *name, char *homehost, int *uuid,
cd29a5c8 38 int subdevs, mddev_dev_t devlist,
47d79ef8 39 int runstop, int verbose, int force, int assume_clean,
dfd4d8ee 40 char *bitmap_file, int bitmap_chunk, int write_behind, int delay)
64c4757e 41{
682c7051
NB
42 /*
43 * Create a new raid array.
44 *
45 * First check that necessary details are available
46 * (i.e. level, raid-disks)
47 *
48 * Then check each disk to see what might be on it
49 * and report anything interesting.
50 *
51 * If anything looks odd, and runstop not set,
52 * abort.
53 *
54 * SET_ARRAY_INFO and ADD_NEW_DISK, and
82d9eba6 55 * if runstop==run, or raiddisks disks were used,
682c7051
NB
56 * RUN_ARRAY
57 */
b5e64645 58 unsigned long long minsize=0, maxsize=0;
cd29a5c8
NB
59 char *mindisc = NULL;
60 char *maxdisc = NULL;
c913b90e 61 int dnum;
cd29a5c8 62 mddev_dev_t dv;
682c7051 63 int fail=0, warn=0;
82b27616 64 struct stat stb;
82d9eba6 65 int first_missing = subdevs * 2;
6fb79233 66 int second_missing = subdevs * 2;
52826846 67 int missing_disks = 0;
82d9eba6 68 int insert_point = subdevs * 2; /* where to insert a missing drive */
4b1ac34b 69 int pass;
82d9eba6
NB
70 int vers;
71 int rv;
c82f047c 72 int bitmap_fd;
f9c25f1d 73 unsigned long long bitmapsize;
d03373f1 74 struct mdinfo *sra;
06c7f68e 75 struct mdinfo info;
682c7051 76
943eafef 77 int major_num = BITMAP_MAJOR_HI;
dcec9ee5 78
06c7f68e 79 memset(&info, 0, sizeof(info));
29e766a5 80
82d9eba6
NB
81 vers = md_get_version(mdfd);
82 if (vers < 9000) {
dd0781e5 83 fprintf(stderr, Name ": Create requires md driver version 0.90.0 or later\n");
52826846 84 return 1;
32e5a4ee
DL
85 } else {
86 mdu_array_info_t inf;
87 memset(&inf, 0, sizeof(inf));
88 ioctl(mdfd, GET_ARRAY_INFO, &inf);
89 if (inf.working_disks != 0) {
90 fprintf(stderr, Name ": another array by this name"
91 " is already running.\n");
92 return 1;
93 }
682c7051 94 }
a322f70c
DW
95 if (level == UnSet) {
96 /* "ddf" metadata only supports one level - should possibly
97 * push this into metadata handler??
98 */
99 if (st && st->ss == &super_ddf)
100 level = LEVEL_CONTAINER;
101 }
102
98c6faba 103 if (level == UnSet) {
682c7051
NB
104 fprintf(stderr,
105 Name ": a RAID level is needed to create an array.\n");
106 return 1;
107 }
98c6faba
NB
108 if (raiddisks < 4 && level == 6) {
109 fprintf(stderr,
110 Name ": at least 4 raid-devices needed for level 6\n");
111 return 1;
112 }
113 if (raiddisks > 256 && level == 6) {
114 fprintf(stderr,
115 Name ": no more than 256 raid-devices supported for level 6\n");
116 return 1;
117 }
52826846
NB
118 if (raiddisks < 2 && level >= 4) {
119 fprintf(stderr,
98c6faba 120 Name ": at least 2 raid-devices needed for level 4 or 5\n");
52826846
NB
121 return 1;
122 }
570510ba
NB
123 if (level <= 0 && sparedisks) {
124 fprintf(stderr,
125 Name ": This level does not support spare devices\n");
126 return 1;
127 }
682c7051 128 if (subdevs > raiddisks+sparedisks) {
b83d95f3 129 fprintf(stderr, Name ": You have listed more devices (%d) than are in the array(%d)!\n", subdevs, raiddisks+sparedisks);
52826846 130 return 1;
682c7051 131 }
cd29a5c8 132 if (subdevs < raiddisks+sparedisks) {
52826846
NB
133 fprintf(stderr, Name ": You haven't given enough devices (real or missing) to create this array\n");
134 return 1;
135 }
5b28bd56
NB
136 if (bitmap_file && level <= 0) {
137 fprintf(stderr, Name ": bitmaps not meaningful with level %s\n",
138 map_num(pers, level)?:"given");
139 return 1;
140 }
52826846 141
682c7051 142 /* now set some defaults */
98c6faba 143 if (layout == UnSet)
682c7051
NB
144 switch(level) {
145 default: /* no layout */
146 layout = 0;
147 break;
e5329c37
NB
148 case 10:
149 layout = 0x102; /* near=2, far=1 */
dab6685f 150 if (verbose > 0)
e5329c37
NB
151 fprintf(stderr,
152 Name ": layout defaults to n1\n");
153 break;
682c7051 154 case 5:
98c6faba 155 case 6:
682c7051 156 layout = map_name(r5layout, "default");
dab6685f 157 if (verbose > 0)
682c7051
NB
158 fprintf(stderr,
159 Name ": layout defaults to %s\n", map_num(r5layout, layout));
160 break;
b5e64645
NB
161 case LEVEL_FAULTY:
162 layout = map_name(faultylayout, "default");
163
dab6685f 164 if (verbose > 0)
b5e64645
NB
165 fprintf(stderr,
166 Name ": layout defaults to %s\n", map_num(faultylayout, layout));
167 break;
682c7051
NB
168 }
169
e5329c37
NB
170 if (level == 10)
171 /* check layout fits in array*/
172 if ((layout&255) * ((layout>>8)&255) > raiddisks) {
173 fprintf(stderr, Name ": that layout requires at least %d devices\n",
174 (layout&255) * ((layout>>8)&255));
175 return 1;
176 }
177
aa88f531
NB
178 switch(level) {
179 case 4:
180 case 5:
e5329c37 181 case 10:
98c6faba 182 case 6:
aa88f531 183 case 0:
570510ba 184 case LEVEL_LINEAR: /* linear */
aa88f531
NB
185 if (chunk == 0) {
186 chunk = 64;
dab6685f 187 if (verbose > 0)
aa88f531
NB
188 fprintf(stderr, Name ": chunk size defaults to 64K\n");
189 }
190 break;
570510ba 191 case 1:
08e43379 192 case LEVEL_FAULTY:
570510ba 193 case LEVEL_MULTIPATH:
17f25ca6 194 case LEVEL_CONTAINER:
aa88f531
NB
195 if (chunk) {
196 chunk = 0;
dab6685f 197 if (verbose > 0)
aa88f531
NB
198 fprintf(stderr, Name ": chunk size ignored for this level\n");
199 }
200 break;
570510ba
NB
201 default:
202 fprintf(stderr, Name ": unknown level %d\n", level);
203 return 1;
682c7051
NB
204 }
205
17f25ca6
NB
206 if (st && ! st->ss->validate_geometry(st, level, layout, raiddisks,
207 chunk, size, NULL, NULL))
208 return 1;
209
682c7051 210 /* now look at the subdevs */
06c7f68e
NB
211 info.array.active_disks = 0;
212 info.array.working_disks = 0;
c913b90e
NB
213 dnum = 0;
214 for (dv=devlist; dv; dv=dv->next, dnum++) {
cd29a5c8 215 char *dname = dv->devname;
17f25ca6 216 unsigned long long freesize;
cd29a5c8 217 if (strcasecmp(dname, "missing")==0) {
c913b90e
NB
218 if (first_missing > dnum)
219 first_missing = dnum;
6fb79233
NB
220 if (second_missing > dnum && dnum > first_missing)
221 second_missing = dnum;
52826846
NB
222 missing_disks ++;
223 continue;
224 }
06c7f68e 225 info.array.working_disks++;
c913b90e 226 if (dnum < raiddisks)
06c7f68e 227 info.array.active_disks++;
058574b1 228 if (st == NULL) {
8aec876d 229 struct createinfo *ci = conf_get_create_info();
058574b1
NB
230 if (ci)
231 st = ci->supertype;
232 }
576d6d83
NB
233 if (st == NULL) {
234 /* Need to choose a default metadata, which is different
17f25ca6 235 * depending on geometry of array.
576d6d83
NB
236 */
237 int i;
238 char *name = "default";
17f25ca6 239 for(i=0; !st && superlist[i]; i++) {
576d6d83 240 st = superlist[i]->match_metadata_desc(name);
17f25ca6
NB
241 if (st && !st->ss->validate_geometry
242 (st, level, layout, raiddisks,
243 chunk, size, dname, &freesize))
244 st = NULL;
245 }
576d6d83
NB
246
247 if (!st) {
17f25ca6
NB
248 fprintf(stderr, Name ": device %s not suitable "
249 "for any style of array\n",
250 dname);
576d6d83
NB
251 exit(2);
252 }
253 if (st->ss->major != 0 ||
254 st->minor_version != 90)
32e5a4ee
DL
255 fprintf(stderr, Name ": Defaulting to version"
256 " %d.%d metadata\n",
576d6d83
NB
257 st->ss->major,
258 st->minor_version);
17f25ca6
NB
259 } else {
260 if (!st->ss->validate_geometry(st, level, layout,
261 raiddisks,
262 chunk, size, dname,
263 &freesize)) {
264
265 fprintf(stderr,
266 Name ": %s is not suitable for "
267 "this array.\n",
268 dname);
269 fail = 1;
270 continue;
271 }
682c7051 272 }
82d9eba6
NB
273
274 freesize /= 2; /* convert to K */
d2cd3ffc
NB
275 if (chunk) {
276 /* round to chunk size */
277 freesize = freesize & ~(chunk-1);
278 }
682c7051
NB
279
280 if (size && freesize < size) {
52826846 281 fprintf(stderr, Name ": %s is smaller that given size."
17f25ca6
NB
282 " %lluK < %lluK + metadata\n",
283 dname, freesize, size);
52826846 284 fail = 1;
52826846 285 continue;
682c7051 286 }
cd29a5c8
NB
287 if (maxdisc == NULL || (maxdisc && freesize > maxsize)) {
288 maxdisc = dname;
52826846 289 maxsize = freesize;
682c7051 290 }
cd29a5c8
NB
291 if (mindisc ==NULL || (mindisc && freesize < minsize)) {
292 mindisc = dname;
52826846 293 minsize = freesize;
682c7051 294 }
dab6685f 295 if (runstop != 1 || verbose >= 0) {
b6e63da4
NB
296 int fd = open(dname, O_RDONLY, 0);
297 if (fd <0 ) {
298 fprintf(stderr, Name ": Cannot open %s: %s\n",
299 dname, strerror(errno));
300 fail=1;
301 continue;
302 }
dab6685f
NB
303 warn |= check_ext2(fd, dname);
304 warn |= check_reiser(fd, dname);
305 warn |= check_raid(fd, dname);
b6e63da4 306 close(fd);
dab6685f 307 }
682c7051
NB
308 }
309 if (fail) {
52826846
NB
310 fprintf(stderr, Name ": create aborted\n");
311 return 1;
682c7051
NB
312 }
313 if (size == 0) {
cd29a5c8 314 if (mindisc == NULL) {
52826846
NB
315 fprintf(stderr, Name ": no size and no drives given - aborting create.\n");
316 return 1;
317 }
c13c45e9 318 if (level > 0 || level == LEVEL_MULTIPATH || level == LEVEL_FAULTY) {
b5e64645 319 /* size is meaningful */
5dd497ee 320 if (minsize > 0x100000000ULL && st->ss->major == 0) {
aba69144 321 fprintf(stderr, Name ": devices too large for RAID level %d\n", level);
b5e64645
NB
322 return 1;
323 }
324 size = minsize;
dab6685f 325 if (verbose > 0)
5dd497ee 326 fprintf(stderr, Name ": size set to %lluK\n", size);
b5e64645 327 }
682c7051 328 }
b5e64645 329 if (level > 0 && ((maxsize-size)*100 > maxsize)) {
dab6685f 330 if (runstop != 1 || verbose >= 0)
5dd497ee 331 fprintf(stderr, Name ": largest drive (%s) exceed size (%lluK) by more than 1%%\n",
dab6685f 332 maxdisc, size);
52826846 333 warn = 1;
682c7051
NB
334 }
335
336 if (warn) {
52826846
NB
337 if (runstop!= 1) {
338 if (!ask("Continue creating array? ")) {
339 fprintf(stderr, Name ": create aborted.\n");
340 return 1;
341 }
342 } else {
dab6685f 343 if (verbose > 0)
52826846 344 fprintf(stderr, Name ": creation continuing despite oddities due to --run\n");
682c7051 345 }
682c7051
NB
346 }
347
66f8bbbe 348 /* If this is raid4/5, we want to configure the last active slot
52826846 349 * as missing, so that a reconstruct happens (faster than re-parity)
98c6faba 350 * FIX: Can we do this for raid6 as well?
52826846 351 */
47d79ef8 352 if (assume_clean==0 && force == 0 && first_missing >= raiddisks) {
98c6faba 353 switch ( level ) {
66f8bbbe 354 case 4:
98c6faba
NB
355 case 5:
356 insert_point = raiddisks-1;
357 sparedisks++;
06c7f68e 358 info.array.active_disks--;
98c6faba
NB
359 missing_disks++;
360 break;
361 default:
362 break;
363 }
52826846 364 }
6fb79233
NB
365 /* For raid6, if creating with 1 missing drive, make a good drive
366 * into a spare, else the create will fail
367 */
368 if (assume_clean == 0 && force == 0 && first_missing < raiddisks &&
369 second_missing >= raiddisks && level == 6) {
370 insert_point = raiddisks - 1;
371 if (insert_point == first_missing)
372 insert_point--;
373 sparedisks ++;
374 info.array.active_disks--;
375 missing_disks++;
376 }
570510ba
NB
377
378 if (level <= 0 && first_missing != subdevs * 2) {
379 fprintf(stderr,
380 Name ": This level does not support missing devices\n");
381 return 1;
382 }
aba69144 383
682c7051
NB
384 /* Ok, lets try some ioctls */
385
06c7f68e
NB
386 info.array.level = level;
387 info.array.size = size;
388 info.array.raid_disks = raiddisks;
82b27616
NB
389 /* The kernel should *know* what md_minor we are dealing
390 * with, but it chooses to trust me instead. Sigh
391 */
06c7f68e 392 info.array.md_minor = 0;
82b27616 393 if (fstat(mdfd, &stb)==0)
06c7f68e
NB
394 info.array.md_minor = minor(stb.st_rdev);
395 info.array.not_persistent = 0;
6fb79233 396
66f8bbbe 397 if ( ( (level == 4 || level == 5) &&
b5e64645
NB
398 (insert_point < raiddisks || first_missing < raiddisks) )
399 ||
6fb79233
NB
400 ( level == 6 && (insert_point < raiddisks
401 || second_missing < raiddisks))
47d79ef8
NB
402 ||
403 assume_clean
b5e64645 404 )
06c7f68e 405 info.array.state = 1; /* clean, but one+ drive will be missing*/
82b27616 406 else
06c7f68e 407 info.array.state = 0; /* not clean, but no errors */
82b27616 408
f9c25f1d
NB
409 if (level == 10) {
410 /* for raid10, the bitmap size is the capacity of the array,
411 * which is array.size * raid_disks / ncopies;
412 * .. but convert to sectors.
413 */
702b557b 414 int ncopies = ((layout>>8) & 255) * (layout & 255);
5dd497ee
NB
415 bitmapsize = (unsigned long long)size * raiddisks / ncopies * 2;
416/* printf("bms=%llu as=%d rd=%d nc=%d\n", bitmapsize, size, raiddisks, ncopies);*/
f9c25f1d 417 } else
5dd497ee 418 bitmapsize = (unsigned long long)size * 2;
f9c25f1d 419
82b27616
NB
420 /* There is lots of redundancy in these disk counts,
421 * raid_disks is the most meaningful value
422 * it describes the geometry of the array
423 * it is constant
424 * nr_disks is total number of used slots.
425 * it should be raid_disks+spare_disks
426 * spare_disks is the number of extra disks present
427 * see above
428 * active_disks is the number of working disks in
429 * active slots. (With raid_disks)
430 * working_disks is the total number of working disks,
431 * including spares
432 * failed_disks is the number of disks marked failed
433 *
434 * Ideally, the kernel would keep these (except raid_disks)
435 * up-to-date as we ADD_NEW_DISK, but it doesn't (yet).
436 * So for now, we assume that all raid and spare
437 * devices will be given.
438 */
06c7f68e
NB
439 info.array.spare_disks=sparedisks;
440 info.array.failed_disks=missing_disks;
441 info.array.nr_disks = info.array.working_disks
442 + info.array.failed_disks;
443 info.array.layout = layout;
444 info.array.chunk_size = chunk*1024;
445 info.array.major_version = st->ss->major;
82d9eba6 446
b3b33eb5
NB
447 if (name == NULL || *name == 0) {
448 /* base name on mddev */
d1e80164
NB
449 /* /dev/md0 -> 0
450 * /dev/md_d0 -> d0
451 * /dev/md/1 -> 1
452 * /dev/md/d1 -> d1
453 * /dev/md/home -> home
454 * /dev/mdhome -> home
455 */
b3b33eb5
NB
456 name = strrchr(mddev, '/');
457 if (name) {
458 name++;
60248f74
NB
459 if (strncmp(name, "md_d", 4)==0 &&
460 strlen(name) > 4 &&
461 isdigit(name[4]) &&
b3b33eb5 462 (name-mddev) == 5 /* /dev/ */)
d1e80164 463 name += 3;
60248f74
NB
464 else if (strncmp(name, "md", 2)==0 &&
465 strlen(name) > 2 &&
466 isdigit(name[2]) &&
467 (name-mddev) == 5 /* /dev/ */)
b3b33eb5
NB
468 name += 2;
469 }
470 }
06c7f68e 471 if (!st->ss->init_super(st, &info.array, size, name, homehost, uuid))
82d9eba6 472 return 1;
682c7051 473
dcec9ee5 474 if (bitmap_file && vers < 9003) {
943eafef 475 major_num = BITMAP_MAJOR_HOSTENDIAN;
dcec9ee5
NB
476#ifdef __BIG_ENDIAN
477 fprintf(stderr, Name ": Warning - bitmaps created on this kernel are not portable\n"
478 " between different architectured. Consider upgrading the Linux kernel.\n");
479#endif
480 }
481
55935d51
NB
482 if (bitmap_file && strcmp(bitmap_file, "internal")==0) {
483 if ((vers%100) < 2) {
484 fprintf(stderr, Name ": internal bitmaps not supported by this kernel.\n");
485 return 1;
486 }
3da92f27 487 if (!st->ss->add_internal_bitmap(st, &bitmap_chunk,
199171a2 488 delay, write_behind,
943eafef 489 bitmapsize, 1, major_num)) {
55935d51
NB
490 fprintf(stderr, Name ": Given bitmap chunk size not supported.\n");
491 return 1;
492 }
493 bitmap_file = NULL;
494 }
495
496
d03373f1 497 sra = sysfs_read(mdfd, 0, 0);
55935d51 498
d03373f1
NB
499 if (st->ss->external) {
500 char ver[100];
501 strcat(strcpy(ver, "external:"), st->ss->text_version);
502 if ((vers % 100) < 2 ||
503 sra == NULL ||
504 sysfs_set_str(sra, NULL, "metadata_version",
505 ver) < 0) {
506 fprintf(stderr, Name ": This kernel does not "
507 "support external metadata.\n");
508 return 1;
509 }
510 rv = 0;
511 } else if ((vers % 100) >= 1) { /* can use different versions */
82d9eba6
NB
512 mdu_array_info_t inf;
513 memset(&inf, 0, sizeof(inf));
514 inf.major_version = st->ss->major;
515 inf.minor_version = st->minor_version;
516 rv = ioctl(mdfd, SET_ARRAY_INFO, &inf);
aba69144 517 } else
82d9eba6
NB
518 rv = ioctl(mdfd, SET_ARRAY_INFO, NULL);
519 if (rv) {
52826846
NB
520 fprintf(stderr, Name ": SET_ARRAY_INFO failed for %s: %s\n",
521 mddev, strerror(errno));
522 return 1;
682c7051 523 }
52826846 524
c82f047c
NB
525 if (bitmap_file) {
526 int uuid[4];
55935d51 527
3da92f27 528 st->ss->uuid_from_super(st, uuid);
dfd4d8ee 529 if (CreateBitmap(bitmap_file, force, (char*)uuid, bitmap_chunk,
dcec9ee5 530 delay, write_behind,
f9c25f1d 531 bitmapsize,
943eafef 532 major_num)) {
c82f047c
NB
533 return 1;
534 }
535 bitmap_fd = open(bitmap_file, O_RDWR);
536 if (bitmap_fd < 0) {
537 fprintf(stderr, Name ": weird: %s cannot be openned\n",
dcec9ee5 538 bitmap_file);
c82f047c
NB
539 return 1;
540 }
541 if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) {
542 fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n",
543 mddev, strerror(errno));
544 return 1;
545 }
546 }
547
4b1ac34b 548
4b1ac34b
NB
549 for (pass=1; pass <=2 ; pass++) {
550 mddev_dev_t moved_disk = NULL; /* the disk that was moved out of the insert point */
551
552 for (dnum=0, dv = devlist ; dv ;
553 dv=(dv->next)?(dv->next):moved_disk, dnum++) {
554 int fd;
555 struct stat stb;
4b1ac34b 556
06c7f68e 557 info.disk.number = dnum;
4b1ac34b
NB
558 if (dnum == insert_point) {
559 moved_disk = dv;
52826846 560 }
06c7f68e
NB
561 info.disk.raid_disk = info.disk.number;
562 if (info.disk.raid_disk < raiddisks)
563 info.disk.state = (1<<MD_DISK_ACTIVE) |
dfd4d8ee 564 (1<<MD_DISK_SYNC);
4b1ac34b 565 else
06c7f68e 566 info.disk.state = 0;
dfd4d8ee 567 if (dv->writemostly)
06c7f68e 568 info.disk.state |= (1<<MD_DISK_WRITEMOSTLY);
dfd4d8ee 569
4b1ac34b 570 if (dnum == insert_point ||
111d01fc
NB
571 strcasecmp(dv->devname, "missing")==0)
572 continue;
573
574 fd = open(dv->devname, O_RDWR|O_EXCL, 0);
575 if (fd < 0) {
576 fprintf(stderr, Name ": failed to open %s "
577 "after earlier success - aborting\n",
578 dv->devname);
579 return 1;
4b1ac34b 580 }
111d01fc
NB
581 fstat(fd, &stb);
582 info.disk.major = major(stb.st_rdev);
583 info.disk.minor = minor(stb.st_rdev);
584
4b1ac34b
NB
585 switch(pass){
586 case 1:
111d01fc
NB
587 remove_partitions(fd);
588 st->ss->add_to_super(st, &info.disk,
589 fd, dv->devname);
4b1ac34b
NB
590 break;
591 case 2:
111d01fc 592 close(fd);
4b1ac34b 593
d03373f1
NB
594 if (st->ss->external) {
595 char dv[100];
596 sprintf(dv, "%d:%d\n",
597 info.disk.major,
598 info.disk.minor);
599 sysfs_set_str(sra, NULL, "new_dev", dv);
600 /* FIXME check error */
601 /*FIXME find that device and set it up*/
602 } else if (ioctl(mdfd, ADD_NEW_DISK,
603 &info.disk)) {
604 fprintf(stderr,
605 Name ": ADD_NEW_DISK for %s "
606 "failed: %s\n",
4b1ac34b 607 dv->devname, strerror(errno));
3da92f27 608 st->ss->free_super(st);
4b1ac34b
NB
609 return 1;
610 }
4b1ac34b
NB
611 break;
612 }
613 if (dv == moved_disk && dnum != insert_point) break;
52826846 614 }
111d01fc
NB
615 if (pass == 1)
616 st->ss->write_init_super(st);
5e52ae9e 617 }
3da92f27 618 st->ss->free_super(st);
5e52ae9e 619
682c7051 620 /* param is not actually used */
17f25ca6
NB
621 if (level == LEVEL_CONTAINER)
622 /* No need to start */
623 ;
624 else if (runstop == 1 || subdevs >= raiddisks) {
82b27616 625 mdu_param_t param;
682c7051
NB
626 if (ioctl(mdfd, RUN_ARRAY, &param)) {
627 fprintf(stderr, Name ": RUN_ARRAY failed: %s\n",
628 strerror(errno));
91f068bf 629 Manage_runstop(mddev, mdfd, -1, 0);
682c7051
NB
630 return 1;
631 }
dab6685f
NB
632 if (verbose >= 0)
633 fprintf(stderr, Name ": array %s started.\n", mddev);
682c7051 634 } else {
b83d95f3 635 fprintf(stderr, Name ": not starting array - not enough devices.\n");
682c7051
NB
636 }
637 return 0;
64c4757e 638}