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