]>
Commit | Line | Data |
---|---|---|
64c4757e | 1 | /* |
9a9dab36 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. |
64c4757e | 3 | * |
e736b623 | 4 | * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de> |
64c4757e NB |
5 | * |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | * | |
21 | * Author: Neil Brown | |
e736b623 | 22 | * Email: <neilb@suse.de> |
64c4757e NB |
23 | */ |
24 | ||
9a9dab36 | 25 | #include "mdadm.h" |
682c7051 NB |
26 | #include "md_u.h" |
27 | #include "md_p.h" | |
60248f74 | 28 | #include <ctype.h> |
64c4757e | 29 | |
a18a888e DW |
30 | static int default_layout(struct supertype *st, int level, int verbose) |
31 | { | |
32 | int layout = UnSet; | |
33 | ||
30f58b22 DW |
34 | if (st && st->ss->default_geometry) |
35 | st->ss->default_geometry(st, &level, &layout, NULL); | |
a18a888e DW |
36 | |
37 | if (layout == UnSet) | |
38 | switch(level) { | |
39 | default: /* no layout */ | |
40 | layout = 0; | |
41 | break; | |
42 | case 10: | |
43 | layout = 0x102; /* near=2, far=1 */ | |
44 | if (verbose > 0) | |
e7b84f9d | 45 | pr_err("layout defaults to n2\n"); |
a18a888e DW |
46 | break; |
47 | case 5: | |
48 | case 6: | |
49 | layout = map_name(r5layout, "default"); | |
50 | if (verbose > 0) | |
e7b84f9d | 51 | pr_err("layout defaults to %s\n", map_num(r5layout, layout)); |
a18a888e DW |
52 | break; |
53 | case LEVEL_FAULTY: | |
54 | layout = map_name(faultylayout, "default"); | |
55 | ||
56 | if (verbose > 0) | |
e7b84f9d | 57 | pr_err("layout defaults to %s\n", map_num(faultylayout, layout)); |
a18a888e DW |
58 | break; |
59 | } | |
60 | ||
61 | return layout; | |
62 | } | |
63 | ||
64 | ||
7f91af49 | 65 | int Create(struct supertype *st, char *mddev, |
acab7bb1 N |
66 | int chunk, int level, int layout, unsigned long long size, |
67 | int raiddisks, int sparedisks, | |
171dccc8 | 68 | char *name, int *uuid, |
a655e550 | 69 | int subdevs, struct mddev_dev *devlist, |
171dccc8 | 70 | int assume_clean, |
acab7bb1 | 71 | char *bitmap_file, int bitmap_chunk, int write_behind, |
171dccc8 | 72 | struct context *c) |
64c4757e | 73 | { |
682c7051 NB |
74 | /* |
75 | * Create a new raid array. | |
76 | * | |
77 | * First check that necessary details are available | |
78 | * (i.e. level, raid-disks) | |
79 | * | |
80 | * Then check each disk to see what might be on it | |
81 | * and report anything interesting. | |
82 | * | |
83 | * If anything looks odd, and runstop not set, | |
84 | * abort. | |
85 | * | |
86 | * SET_ARRAY_INFO and ADD_NEW_DISK, and | |
82d9eba6 | 87 | * if runstop==run, or raiddisks disks were used, |
682c7051 NB |
88 | * RUN_ARRAY |
89 | */ | |
7f91af49 | 90 | int mdfd; |
b5e64645 | 91 | unsigned long long minsize=0, maxsize=0; |
cd29a5c8 NB |
92 | char *mindisc = NULL; |
93 | char *maxdisc = NULL; | |
c913b90e | 94 | int dnum; |
a655e550 | 95 | struct mddev_dev *dv; |
682c7051 | 96 | int fail=0, warn=0; |
82b27616 | 97 | struct stat stb; |
82d9eba6 | 98 | int first_missing = subdevs * 2; |
6fb79233 | 99 | int second_missing = subdevs * 2; |
52826846 | 100 | int missing_disks = 0; |
82d9eba6 | 101 | int insert_point = subdevs * 2; /* where to insert a missing drive */ |
d2ca6449 | 102 | int total_slots; |
4b1ac34b | 103 | int pass; |
82d9eba6 NB |
104 | int vers; |
105 | int rv; | |
c82f047c | 106 | int bitmap_fd; |
5f8097be | 107 | int have_container = 0; |
0e600426 | 108 | int container_fd = -1; |
a931db9e | 109 | int need_mdmon = 0; |
f9c25f1d | 110 | unsigned long long bitmapsize; |
d2ca6449 | 111 | struct mdinfo info, *infos; |
b8ac1967 | 112 | int did_default = 0; |
a18a888e | 113 | int do_default_layout = 0; |
c21e737b | 114 | int do_default_chunk = 0; |
8ed3e5e1 | 115 | unsigned long safe_mode_delay = 0; |
a04d5763 | 116 | char chosen_name[1024]; |
ad5bc697 | 117 | struct map_ent *map = NULL; |
8592f29d | 118 | unsigned long long newsize; |
682c7051 | 119 | |
943eafef | 120 | int major_num = BITMAP_MAJOR_HI; |
dcec9ee5 | 121 | |
06c7f68e | 122 | memset(&info, 0, sizeof(info)); |
30f58b22 DW |
123 | if (level == UnSet && st && st->ss->default_geometry) |
124 | st->ss->default_geometry(st, &level, NULL, NULL); | |
98c6faba | 125 | if (level == UnSet) { |
e7b84f9d | 126 | pr_err("a RAID level is needed to create an array.\n"); |
682c7051 NB |
127 | return 1; |
128 | } | |
98c6faba | 129 | if (raiddisks < 4 && level == 6) { |
e7b84f9d | 130 | pr_err("at least 4 raid-devices needed for level 6\n"); |
98c6faba NB |
131 | return 1; |
132 | } | |
133 | if (raiddisks > 256 && level == 6) { | |
e7b84f9d | 134 | pr_err("no more than 256 raid-devices supported for level 6\n"); |
98c6faba NB |
135 | return 1; |
136 | } | |
52826846 | 137 | if (raiddisks < 2 && level >= 4) { |
e7b84f9d | 138 | pr_err("at least 2 raid-devices needed for level 4 or 5\n"); |
52826846 NB |
139 | return 1; |
140 | } | |
570510ba | 141 | if (level <= 0 && sparedisks) { |
e7b84f9d | 142 | pr_err("This level does not support spare devices\n"); |
570510ba NB |
143 | return 1; |
144 | } | |
5f8097be NB |
145 | |
146 | if (subdevs == 1 && strcmp(devlist->devname, "missing") != 0) { | |
147 | /* If given a single device, it might be a container, and we can | |
148 | * extract a device list from there | |
149 | */ | |
150 | mdu_array_info_t inf; | |
151 | int fd; | |
152 | ||
153 | memset(&inf, 0, sizeof(inf)); | |
37ea3936 | 154 | fd = open(devlist->devname, O_RDONLY); |
5f8097be NB |
155 | if (fd >= 0 && |
156 | ioctl(fd, GET_ARRAY_INFO, &inf) == 0 && | |
157 | inf.raid_disks == 0) { | |
158 | /* yep, looks like a container */ | |
159 | if (st) { | |
0fb69d1d N |
160 | rv = st->ss->load_container(st, fd, |
161 | devlist->devname); | |
5f8097be NB |
162 | if (rv == 0) |
163 | have_container = 1; | |
164 | } else { | |
0fb69d1d | 165 | st = super_by_fd(fd, NULL); |
5f8097be | 166 | if (st && !(rv = st->ss-> |
0fb69d1d N |
167 | load_container(st, fd, |
168 | devlist->devname))) | |
5f8097be NB |
169 | have_container = 1; |
170 | else | |
171 | st = NULL; | |
172 | } | |
18fde300 | 173 | if (have_container) { |
8592f29d | 174 | subdevs = raiddisks; |
18fde300 DW |
175 | first_missing = subdevs * 2; |
176 | second_missing = subdevs * 2; | |
177 | insert_point = subdevs * 2; | |
178 | } | |
5f8097be NB |
179 | } |
180 | if (fd >= 0) | |
181 | close(fd); | |
5f8097be | 182 | } |
ffcfc735 | 183 | if (st && st->ss->external && sparedisks) { |
e7b84f9d N |
184 | pr_err("This metadata type does not support " |
185 | "spare disks at create time\n"); | |
ffcfc735 N |
186 | return 1; |
187 | } | |
682c7051 | 188 | if (subdevs > raiddisks+sparedisks) { |
e7b84f9d | 189 | pr_err("You have listed more devices (%d) than are in the array(%d)!\n", subdevs, raiddisks+sparedisks); |
52826846 | 190 | return 1; |
682c7051 | 191 | } |
5f8097be | 192 | if (!have_container && subdevs < raiddisks+sparedisks) { |
e7b84f9d | 193 | pr_err("You haven't given enough devices (real or missing) to create this array\n"); |
52826846 NB |
194 | return 1; |
195 | } | |
5b28bd56 | 196 | if (bitmap_file && level <= 0) { |
e7b84f9d | 197 | pr_err("bitmaps not meaningful with level %s\n", |
5b28bd56 NB |
198 | map_num(pers, level)?:"given"); |
199 | return 1; | |
200 | } | |
52826846 | 201 | |
682c7051 | 202 | /* now set some defaults */ |
b5e64645 | 203 | |
a18a888e DW |
204 | |
205 | if (layout == UnSet) { | |
206 | do_default_layout = 1; | |
171dccc8 | 207 | layout = default_layout(st, level, c->verbose); |
a18a888e | 208 | } |
682c7051 | 209 | |
e5329c37 NB |
210 | if (level == 10) |
211 | /* check layout fits in array*/ | |
212 | if ((layout&255) * ((layout>>8)&255) > raiddisks) { | |
e7b84f9d | 213 | pr_err("that layout requires at least %d devices\n", |
e5329c37 NB |
214 | (layout&255) * ((layout>>8)&255)); |
215 | return 1; | |
216 | } | |
217 | ||
aa88f531 NB |
218 | switch(level) { |
219 | case 4: | |
220 | case 5: | |
e5329c37 | 221 | case 10: |
98c6faba | 222 | case 6: |
aa88f531 | 223 | case 0: |
bb7295f1 N |
224 | if (chunk == 0 || chunk == UnSet) { |
225 | chunk = UnSet; | |
c21e737b CA |
226 | do_default_chunk = 1; |
227 | /* chunk will be set later */ | |
bb7295f1 | 228 | } |
5f175898 N |
229 | break; |
230 | case LEVEL_LINEAR: | |
231 | /* a chunksize of zero 0s perfectly valid (and preferred) since 2.6.16 */ | |
232 | if (get_linux_version() < 2006016 && chunk == 0) { | |
aa88f531 | 233 | chunk = 64; |
171dccc8 | 234 | if (c->verbose > 0) |
e7b84f9d | 235 | pr_err("chunk size defaults to 64K\n"); |
aa88f531 NB |
236 | } |
237 | break; | |
570510ba | 238 | case 1: |
08e43379 | 239 | case LEVEL_FAULTY: |
570510ba | 240 | case LEVEL_MULTIPATH: |
17f25ca6 | 241 | case LEVEL_CONTAINER: |
aa88f531 NB |
242 | if (chunk) { |
243 | chunk = 0; | |
171dccc8 | 244 | if (c->verbose > 0) |
e7b84f9d | 245 | pr_err("chunk size ignored for this level\n"); |
aa88f531 NB |
246 | } |
247 | break; | |
570510ba | 248 | default: |
e7b84f9d | 249 | pr_err("unknown level %d\n", level); |
570510ba | 250 | return 1; |
682c7051 | 251 | } |
8592f29d | 252 | |
bb7295f1 | 253 | if (size && chunk && chunk != UnSet) |
9f3bd60c | 254 | size &= ~(unsigned long long)(chunk - 1); |
8592f29d | 255 | newsize = size * 2; |
17f25ca6 | 256 | if (st && ! st->ss->validate_geometry(st, level, layout, raiddisks, |
171dccc8 | 257 | &chunk, size*2, NULL, &newsize, c->verbose>=0)) |
17f25ca6 | 258 | return 1; |
bb7295f1 | 259 | |
db975ab5 | 260 | if (chunk && chunk != UnSet) { |
bb7295f1 | 261 | newsize &= ~(unsigned long long)(chunk*2 - 1); |
64385908 CA |
262 | if (do_default_chunk) { |
263 | /* default chunk was just set */ | |
171dccc8 | 264 | if (c->verbose > 0) |
e7b84f9d | 265 | pr_err("chunk size " |
64385908 CA |
266 | "defaults to %dK\n", chunk); |
267 | size &= ~(unsigned long long)(chunk - 1); | |
268 | do_default_chunk = 0; | |
269 | } | |
bb7295f1 | 270 | } |
64385908 | 271 | |
8592f29d N |
272 | if (size == 0) { |
273 | size = newsize / 2; | |
ae6c05ad N |
274 | if (level == 1) |
275 | /* If this is ever reshaped to RAID5, we will | |
276 | * need a chunksize. So round it off a bit | |
277 | * now just to be safe | |
278 | */ | |
279 | size &= ~(64ULL-1); | |
280 | ||
171dccc8 | 281 | if (size && c->verbose > 0) |
e7b84f9d | 282 | pr_err("setting size to %lluK\n", |
8592f29d N |
283 | (unsigned long long)size); |
284 | } | |
17f25ca6 | 285 | |
682c7051 | 286 | /* now look at the subdevs */ |
06c7f68e NB |
287 | info.array.active_disks = 0; |
288 | info.array.working_disks = 0; | |
c913b90e | 289 | dnum = 0; |
8592f29d | 290 | for (dv=devlist; dv && !have_container; dv=dv->next, dnum++) { |
cd29a5c8 | 291 | char *dname = dv->devname; |
17f25ca6 | 292 | unsigned long long freesize; |
e9b11fee N |
293 | int dfd; |
294 | ||
cd29a5c8 | 295 | if (strcasecmp(dname, "missing")==0) { |
c913b90e NB |
296 | if (first_missing > dnum) |
297 | first_missing = dnum; | |
6fb79233 NB |
298 | if (second_missing > dnum && dnum > first_missing) |
299 | second_missing = dnum; | |
52826846 NB |
300 | missing_disks ++; |
301 | continue; | |
302 | } | |
58b3c697 | 303 | dfd = open(dname, O_RDONLY); |
e9b11fee | 304 | if (dfd < 0) { |
e7b84f9d | 305 | pr_err("cannot open %s: %s\n", |
e9b11fee N |
306 | dname, strerror(errno)); |
307 | exit(2); | |
308 | } | |
309 | if (fstat(dfd, &stb) != 0 || | |
310 | (stb.st_mode & S_IFMT) != S_IFBLK) { | |
311 | close(dfd); | |
e7b84f9d | 312 | pr_err("%s is not a block device\n", |
e9b11fee N |
313 | dname); |
314 | exit(2); | |
315 | } | |
316 | close(dfd); | |
06c7f68e | 317 | info.array.working_disks++; |
c913b90e | 318 | if (dnum < raiddisks) |
06c7f68e | 319 | info.array.active_disks++; |
058574b1 | 320 | if (st == NULL) { |
8aec876d | 321 | struct createinfo *ci = conf_get_create_info(); |
058574b1 NB |
322 | if (ci) |
323 | st = ci->supertype; | |
324 | } | |
576d6d83 NB |
325 | if (st == NULL) { |
326 | /* Need to choose a default metadata, which is different | |
17f25ca6 | 327 | * depending on geometry of array. |
576d6d83 NB |
328 | */ |
329 | int i; | |
330 | char *name = "default"; | |
17f25ca6 | 331 | for(i=0; !st && superlist[i]; i++) { |
576d6d83 | 332 | st = superlist[i]->match_metadata_desc(name); |
ecbd9e81 N |
333 | if (!st) |
334 | continue; | |
a18a888e | 335 | if (do_default_layout) |
171dccc8 | 336 | layout = default_layout(st, level, c->verbose); |
ecbd9e81 N |
337 | switch (st->ss->validate_geometry( |
338 | st, level, layout, raiddisks, | |
339 | &chunk, size*2, dname, &freesize, | |
171dccc8 | 340 | c->verbose > 0)) { |
ecbd9e81 N |
341 | case -1: /* Not valid, message printed, and not |
342 | * worth checking any further */ | |
343 | exit(2); | |
344 | break; | |
345 | case 0: /* Geometry not valid */ | |
55425f27 | 346 | free(st); |
17f25ca6 | 347 | st = NULL; |
64385908 | 348 | chunk = do_default_chunk ? UnSet : chunk; |
ecbd9e81 N |
349 | break; |
350 | case 1: /* All happy */ | |
351 | break; | |
55425f27 | 352 | } |
17f25ca6 | 353 | } |
576d6d83 NB |
354 | |
355 | if (!st) { | |
58b3c697 N |
356 | int dfd = open(dname, O_RDONLY|O_EXCL); |
357 | if (dfd < 0) { | |
e7b84f9d | 358 | pr_err("cannot open %s: %s\n", |
58b3c697 N |
359 | dname, strerror(errno)); |
360 | exit(2); | |
361 | } | |
e7b84f9d | 362 | pr_err("device %s not suitable " |
17f25ca6 NB |
363 | "for any style of array\n", |
364 | dname); | |
576d6d83 NB |
365 | exit(2); |
366 | } | |
b8ac1967 | 367 | if (st->ss != &super0 || |
576d6d83 | 368 | st->minor_version != 90) |
b8ac1967 | 369 | did_default = 1; |
17f25ca6 | 370 | } else { |
a18a888e | 371 | if (do_default_layout) |
ad6db3cb | 372 | layout = default_layout(st, level, 0); |
17f25ca6 NB |
373 | if (!st->ss->validate_geometry(st, level, layout, |
374 | raiddisks, | |
c21e737b | 375 | &chunk, size*2, dname, |
2c514b71 | 376 | &freesize, |
171dccc8 | 377 | c->verbose >= 0)) { |
17f25ca6 | 378 | |
e7b84f9d N |
379 | pr_err("%s is not suitable for " |
380 | "this array.\n", | |
381 | dname); | |
17f25ca6 NB |
382 | fail = 1; |
383 | continue; | |
384 | } | |
682c7051 | 385 | } |
82d9eba6 NB |
386 | |
387 | freesize /= 2; /* convert to K */ | |
db975ab5 | 388 | if (chunk && chunk != UnSet) { |
d2cd3ffc NB |
389 | /* round to chunk size */ |
390 | freesize = freesize & ~(chunk-1); | |
64385908 CA |
391 | if (do_default_chunk) { |
392 | /* default chunk was just set */ | |
171dccc8 | 393 | if (c->verbose > 0) |
e7b84f9d | 394 | pr_err("chunk size " |
64385908 CA |
395 | "defaults to %dK\n", chunk); |
396 | size &= ~(unsigned long long)(chunk - 1); | |
397 | do_default_chunk = 0; | |
398 | } | |
d2cd3ffc | 399 | } |
682c7051 NB |
400 | |
401 | if (size && freesize < size) { | |
e7b84f9d | 402 | pr_err("%s is smaller than given size." |
17f25ca6 NB |
403 | " %lluK < %lluK + metadata\n", |
404 | dname, freesize, size); | |
52826846 | 405 | fail = 1; |
52826846 | 406 | continue; |
682c7051 | 407 | } |
cd29a5c8 NB |
408 | if (maxdisc == NULL || (maxdisc && freesize > maxsize)) { |
409 | maxdisc = dname; | |
52826846 | 410 | maxsize = freesize; |
682c7051 | 411 | } |
cd29a5c8 NB |
412 | if (mindisc ==NULL || (mindisc && freesize < minsize)) { |
413 | mindisc = dname; | |
52826846 | 414 | minsize = freesize; |
682c7051 | 415 | } |
171dccc8 | 416 | if (c->runstop != 1 || c->verbose >= 0) { |
37ea3936 | 417 | int fd = open(dname, O_RDONLY); |
b6e63da4 | 418 | if (fd <0 ) { |
e7b84f9d | 419 | pr_err("Cannot open %s: %s\n", |
b6e63da4 NB |
420 | dname, strerror(errno)); |
421 | fail=1; | |
422 | continue; | |
423 | } | |
dab6685f NB |
424 | warn |= check_ext2(fd, dname); |
425 | warn |= check_reiser(fd, dname); | |
426 | warn |= check_raid(fd, dname); | |
034b203a TM |
427 | if (strcmp(st->ss->name, "1.x") == 0 && |
428 | st->minor_version >= 1) | |
429 | /* metadata at front */ | |
53ed6ac3 | 430 | warn |= check_partitions(fd, dname, 0, 0); |
0ac3f649 KW |
431 | else if (level == 1 || level == LEVEL_CONTAINER |
432 | || (level == 0 && raiddisks == 1)) | |
034b203a | 433 | /* partitions could be meaningful */ |
53ed6ac3 | 434 | warn |= check_partitions(fd, dname, freesize*2, size*2); |
034b203a TM |
435 | else |
436 | /* partitions cannot be meaningful */ | |
53ed6ac3 | 437 | warn |= check_partitions(fd, dname, 0, 0); |
034b203a | 438 | if (strcmp(st->ss->name, "1.x") == 0 && |
a0962fe9 N |
439 | st->minor_version >= 1 && |
440 | did_default && | |
034b203a TM |
441 | level == 1 && |
442 | (warn & 1024) == 0) { | |
443 | warn |= 1024; | |
e7b84f9d | 444 | pr_err("Note: this array has metadata at the start and\n" |
a0962fe9 | 445 | " may not be suitable as a boot device. If you plan to\n" |
cc86f89c | 446 | " store '/boot' on this device please ensure that\n" |
a0962fe9 | 447 | " your boot-loader understands md/v1.x metadata, or use\n" |
cc86f89c | 448 | " --metadata=0.90\n"); |
a0962fe9 | 449 | } |
b6e63da4 | 450 | close(fd); |
dab6685f | 451 | } |
682c7051 | 452 | } |
acab7bb1 | 453 | if (raiddisks + sparedisks > st->max_devs) { |
e7b84f9d | 454 | pr_err("Too many devices:" |
acab7bb1 N |
455 | " %s metadata only supports %d\n", |
456 | st->ss->name, st->max_devs); | |
457 | return 1; | |
458 | } | |
8592f29d N |
459 | if (have_container) |
460 | info.array.working_disks = raiddisks; | |
682c7051 | 461 | if (fail) { |
e7b84f9d | 462 | pr_err("create aborted\n"); |
52826846 | 463 | return 1; |
682c7051 NB |
464 | } |
465 | if (size == 0) { | |
5f8097be | 466 | if (mindisc == NULL && !have_container) { |
e7b84f9d | 467 | pr_err("no size and no drives given - aborting create.\n"); |
52826846 NB |
468 | return 1; |
469 | } | |
5f8097be NB |
470 | if (level > 0 || level == LEVEL_MULTIPATH |
471 | || level == LEVEL_FAULTY | |
b8ac1967 | 472 | || st->ss->external ) { |
b5e64645 | 473 | /* size is meaningful */ |
b8ac1967 NB |
474 | if (!st->ss->validate_geometry(st, level, layout, |
475 | raiddisks, | |
c21e737b | 476 | &chunk, minsize*2, |
2c514b71 | 477 | NULL, NULL, 0)) { |
e7b84f9d | 478 | pr_err("devices too large for RAID level %d\n", level); |
b5e64645 NB |
479 | return 1; |
480 | } | |
481 | size = minsize; | |
ae6c05ad N |
482 | if (level == 1) |
483 | /* If this is ever reshaped to RAID5, we will | |
484 | * need a chunksize. So round it off a bit | |
485 | * now just to be safe | |
486 | */ | |
487 | size &= ~(64ULL-1); | |
171dccc8 | 488 | if (c->verbose > 0) |
e7b84f9d | 489 | pr_err("size set to %lluK\n", size); |
b5e64645 | 490 | } |
682c7051 | 491 | } |
8592f29d | 492 | if (!have_container && level > 0 && ((maxsize-size)*100 > maxsize)) { |
171dccc8 | 493 | if (c->runstop != 1 || c->verbose >= 0) |
e7b84f9d | 494 | pr_err("largest drive (%s) exceeds size (%lluK) by more than 1%%\n", |
dab6685f | 495 | maxdisc, size); |
52826846 | 496 | warn = 1; |
682c7051 NB |
497 | } |
498 | ||
5615172f | 499 | if (st->ss->detail_platform && st->ss->detail_platform(0, 1) != 0) { |
171dccc8 | 500 | if (c->runstop != 1 || c->verbose >= 0) |
e7b84f9d | 501 | pr_err("%s unable to enumerate platform support\n" |
5615172f DW |
502 | " array may not be compatible with hardware/firmware\n", |
503 | st->ss->name); | |
504 | warn = 1; | |
505 | } | |
506 | ||
682c7051 | 507 | if (warn) { |
171dccc8 | 508 | if (c->runstop!= 1) { |
52826846 | 509 | if (!ask("Continue creating array? ")) { |
e7b84f9d | 510 | pr_err("create aborted.\n"); |
52826846 NB |
511 | return 1; |
512 | } | |
513 | } else { | |
171dccc8 | 514 | if (c->verbose > 0) |
e7b84f9d | 515 | pr_err("creation continuing despite oddities due to --run\n"); |
682c7051 | 516 | } |
682c7051 NB |
517 | } |
518 | ||
66f8bbbe | 519 | /* If this is raid4/5, we want to configure the last active slot |
52826846 | 520 | * as missing, so that a reconstruct happens (faster than re-parity) |
98c6faba | 521 | * FIX: Can we do this for raid6 as well? |
52826846 | 522 | */ |
87b47257 | 523 | if (st->ss->external == 0 && |
171dccc8 | 524 | assume_clean==0 && c->force == 0 && first_missing >= raiddisks) { |
98c6faba | 525 | switch ( level ) { |
66f8bbbe | 526 | case 4: |
98c6faba NB |
527 | case 5: |
528 | insert_point = raiddisks-1; | |
529 | sparedisks++; | |
06c7f68e | 530 | info.array.active_disks--; |
98c6faba NB |
531 | missing_disks++; |
532 | break; | |
533 | default: | |
534 | break; | |
535 | } | |
52826846 | 536 | } |
6fb79233 NB |
537 | /* For raid6, if creating with 1 missing drive, make a good drive |
538 | * into a spare, else the create will fail | |
539 | */ | |
171dccc8 | 540 | if (assume_clean == 0 && c->force == 0 && first_missing < raiddisks && |
ffcfc735 | 541 | st->ss->external == 0 && |
6fb79233 NB |
542 | second_missing >= raiddisks && level == 6) { |
543 | insert_point = raiddisks - 1; | |
544 | if (insert_point == first_missing) | |
545 | insert_point--; | |
546 | sparedisks ++; | |
547 | info.array.active_disks--; | |
548 | missing_disks++; | |
549 | } | |
570510ba | 550 | |
5f8097be | 551 | if (level <= 0 && first_missing < subdevs * 2) { |
e7b84f9d | 552 | pr_err("This level does not support missing devices\n"); |
570510ba NB |
553 | return 1; |
554 | } | |
aba69144 | 555 | |
7f91af49 | 556 | /* We need to create the device */ |
ad5bc697 | 557 | map_lock(&map); |
171dccc8 | 558 | mdfd = create_mddev(mddev, name, c->autof, LOCAL, chosen_name); |
e06af9dd JS |
559 | if (mdfd < 0) { |
560 | map_unlock(&map); | |
7f91af49 | 561 | return 1; |
e06af9dd | 562 | } |
3e9df86a AK |
563 | /* verify if chosen_name is not in use, |
564 | * it could be in conflict with already existing device | |
565 | * e.g. container, array | |
566 | */ | |
567 | if (strncmp(chosen_name, "/dev/md/", 8) == 0 | |
568 | && map_by_name(&map, chosen_name+8) != NULL) { | |
e7b84f9d | 569 | pr_err("Array name %s is in use already.\n", |
3e9df86a AK |
570 | chosen_name); |
571 | close(mdfd); | |
572 | map_unlock(&map); | |
573 | return 1; | |
574 | } | |
f2be09f1 | 575 | mddev = chosen_name; |
7f91af49 N |
576 | |
577 | vers = md_get_version(mdfd); | |
578 | if (vers < 9000) { | |
e7b84f9d | 579 | pr_err("Create requires md driver version 0.90.0 or later\n"); |
e06af9dd | 580 | goto abort_locked; |
7f91af49 N |
581 | } else { |
582 | mdu_array_info_t inf; | |
583 | memset(&inf, 0, sizeof(inf)); | |
584 | ioctl(mdfd, GET_ARRAY_INFO, &inf); | |
585 | if (inf.working_disks != 0) { | |
e7b84f9d | 586 | pr_err("another array by this name" |
7f91af49 | 587 | " is already running.\n"); |
e06af9dd | 588 | goto abort_locked; |
7f91af49 N |
589 | } |
590 | } | |
a04d5763 | 591 | |
682c7051 NB |
592 | /* Ok, lets try some ioctls */ |
593 | ||
06c7f68e NB |
594 | info.array.level = level; |
595 | info.array.size = size; | |
596 | info.array.raid_disks = raiddisks; | |
82b27616 NB |
597 | /* The kernel should *know* what md_minor we are dealing |
598 | * with, but it chooses to trust me instead. Sigh | |
599 | */ | |
06c7f68e | 600 | info.array.md_minor = 0; |
82b27616 | 601 | if (fstat(mdfd, &stb)==0) |
06c7f68e NB |
602 | info.array.md_minor = minor(stb.st_rdev); |
603 | info.array.not_persistent = 0; | |
6fb79233 | 604 | |
66f8bbbe | 605 | if ( ( (level == 4 || level == 5) && |
b5e64645 NB |
606 | (insert_point < raiddisks || first_missing < raiddisks) ) |
607 | || | |
6fb79233 NB |
608 | ( level == 6 && (insert_point < raiddisks |
609 | || second_missing < raiddisks)) | |
47d79ef8 | 610 | || |
d024b0a7 NB |
611 | ( level <= 0 ) |
612 | || | |
47d79ef8 | 613 | assume_clean |
103f2410 | 614 | ) { |
06c7f68e | 615 | info.array.state = 1; /* clean, but one+ drive will be missing*/ |
b7528a20 | 616 | info.resync_start = MaxSector; |
103f2410 | 617 | } else { |
06c7f68e | 618 | info.array.state = 0; /* not clean, but no errors */ |
103f2410 NB |
619 | info.resync_start = 0; |
620 | } | |
f9c25f1d NB |
621 | if (level == 10) { |
622 | /* for raid10, the bitmap size is the capacity of the array, | |
623 | * which is array.size * raid_disks / ncopies; | |
624 | * .. but convert to sectors. | |
625 | */ | |
702b557b | 626 | int ncopies = ((layout>>8) & 255) * (layout & 255); |
5dd497ee NB |
627 | bitmapsize = (unsigned long long)size * raiddisks / ncopies * 2; |
628 | /* printf("bms=%llu as=%d rd=%d nc=%d\n", bitmapsize, size, raiddisks, ncopies);*/ | |
f9c25f1d | 629 | } else |
5dd497ee | 630 | bitmapsize = (unsigned long long)size * 2; |
f9c25f1d | 631 | |
82b27616 NB |
632 | /* There is lots of redundancy in these disk counts, |
633 | * raid_disks is the most meaningful value | |
634 | * it describes the geometry of the array | |
635 | * it is constant | |
636 | * nr_disks is total number of used slots. | |
637 | * it should be raid_disks+spare_disks | |
638 | * spare_disks is the number of extra disks present | |
639 | * see above | |
640 | * active_disks is the number of working disks in | |
641 | * active slots. (With raid_disks) | |
642 | * working_disks is the total number of working disks, | |
643 | * including spares | |
644 | * failed_disks is the number of disks marked failed | |
645 | * | |
646 | * Ideally, the kernel would keep these (except raid_disks) | |
647 | * up-to-date as we ADD_NEW_DISK, but it doesn't (yet). | |
648 | * So for now, we assume that all raid and spare | |
649 | * devices will be given. | |
650 | */ | |
06c7f68e NB |
651 | info.array.spare_disks=sparedisks; |
652 | info.array.failed_disks=missing_disks; | |
653 | info.array.nr_disks = info.array.working_disks | |
654 | + info.array.failed_disks; | |
655 | info.array.layout = layout; | |
656 | info.array.chunk_size = chunk*1024; | |
82d9eba6 | 657 | |
b3b33eb5 NB |
658 | if (name == NULL || *name == 0) { |
659 | /* base name on mddev */ | |
d1e80164 NB |
660 | /* /dev/md0 -> 0 |
661 | * /dev/md_d0 -> d0 | |
662 | * /dev/md/1 -> 1 | |
663 | * /dev/md/d1 -> d1 | |
664 | * /dev/md/home -> home | |
665 | * /dev/mdhome -> home | |
666 | */ | |
69207ff6 | 667 | /* FIXME compare this with rules in create_mddev */ |
b3b33eb5 NB |
668 | name = strrchr(mddev, '/'); |
669 | if (name) { | |
670 | name++; | |
60248f74 NB |
671 | if (strncmp(name, "md_d", 4)==0 && |
672 | strlen(name) > 4 && | |
673 | isdigit(name[4]) && | |
b3b33eb5 | 674 | (name-mddev) == 5 /* /dev/ */) |
d1e80164 | 675 | name += 3; |
60248f74 NB |
676 | else if (strncmp(name, "md", 2)==0 && |
677 | strlen(name) > 2 && | |
678 | isdigit(name[2]) && | |
679 | (name-mddev) == 5 /* /dev/ */) | |
b3b33eb5 NB |
680 | name += 2; |
681 | } | |
682 | } | |
171dccc8 | 683 | if (!st->ss->init_super(st, &info.array, size, name, c->homehost, uuid)) |
e06af9dd | 684 | goto abort_locked; |
682c7051 | 685 | |
d2ca6449 | 686 | total_slots = info.array.nr_disks; |
a5d85af7 | 687 | st->ss->getinfo_super(st, &info, NULL); |
95eeceeb | 688 | sysfs_init(&info, mdfd, 0); |
159c3a1a | 689 | |
171dccc8 | 690 | if (did_default && c->verbose >= 0) { |
3c558363 | 691 | if (is_subarray(info.text_version)) { |
f7f1b6a1 NB |
692 | int dnum = devname2devnum(info.text_version+1); |
693 | char *path; | |
694 | int mdp = get_mdp_major(); | |
695 | struct mdinfo *mdi; | |
696 | if (dnum > 0) | |
697 | path = map_dev(MD_MAJOR, dnum, 1); | |
698 | else | |
699 | path = map_dev(mdp, (-1-dnum)<< 6, 1); | |
700 | ||
701 | mdi = sysfs_read(-1, dnum, GET_VERSION); | |
702 | ||
e7b84f9d | 703 | pr_err("Creating array inside " |
f7f1b6a1 NB |
704 | "%s container %s\n", |
705 | mdi?mdi->text_version:"managed", path); | |
706 | sysfs_free(mdi); | |
707 | } else | |
e7b84f9d | 708 | pr_err("Defaulting to version" |
f7f1b6a1 NB |
709 | " %s metadata\n", info.text_version); |
710 | } | |
b8ac1967 | 711 | |
ad5bc697 | 712 | map_update(&map, fd2devnum(mdfd), info.text_version, |
a04d5763 | 713 | info.uuid, chosen_name); |
ad5bc697 | 714 | map_unlock(&map); |
a04d5763 | 715 | |
dcec9ee5 | 716 | if (bitmap_file && vers < 9003) { |
943eafef | 717 | major_num = BITMAP_MAJOR_HOSTENDIAN; |
dcec9ee5 | 718 | #ifdef __BIG_ENDIAN |
e7b84f9d | 719 | pr_err("Warning - bitmaps created on this kernel are not portable\n" |
dcec9ee5 NB |
720 | " between different architectured. Consider upgrading the Linux kernel.\n"); |
721 | #endif | |
722 | } | |
723 | ||
55935d51 NB |
724 | if (bitmap_file && strcmp(bitmap_file, "internal")==0) { |
725 | if ((vers%100) < 2) { | |
e7b84f9d | 726 | pr_err("internal bitmaps not supported by this kernel.\n"); |
7f91af49 | 727 | goto abort; |
55935d51 | 728 | } |
ebeb3663 | 729 | if (!st->ss->add_internal_bitmap) { |
e7b84f9d | 730 | pr_err("internal bitmaps not supported with %s metadata\n", |
ebeb3663 N |
731 | st->ss->name); |
732 | goto abort; | |
733 | } | |
3da92f27 | 734 | if (!st->ss->add_internal_bitmap(st, &bitmap_chunk, |
171dccc8 | 735 | c->delay, write_behind, |
943eafef | 736 | bitmapsize, 1, major_num)) { |
e7b84f9d | 737 | pr_err("Given bitmap chunk size not supported.\n"); |
7f91af49 | 738 | goto abort; |
55935d51 NB |
739 | } |
740 | bitmap_file = NULL; | |
741 | } | |
742 | ||
743 | ||
f35f2525 | 744 | sysfs_init(&info, mdfd, 0); |
55935d51 | 745 | |
d1d599ea | 746 | if (st->ss->external && st->container_dev != NoMdDev) { |
f35f2525 N |
747 | /* member */ |
748 | ||
749 | /* When creating a member, we need to be careful | |
750 | * to negotiate with mdmon properly. | |
751 | * If it is already running, we cannot write to | |
752 | * the devices and must ask it to do that part. | |
753 | * If it isn't running, we write to the devices, | |
754 | * and then start it. | |
755 | * We hold an exclusive open on the container | |
756 | * device to make sure mdmon doesn't exit after | |
757 | * we checked that it is running. | |
758 | * | |
759 | * For now, fail if it is already running. | |
760 | */ | |
761 | container_fd = open_dev_excl(st->container_dev); | |
762 | if (container_fd < 0) { | |
e7b84f9d | 763 | pr_err("Cannot get exclusive " |
f35f2525 | 764 | "open on container - weird.\n"); |
7f91af49 | 765 | goto abort; |
d03373f1 | 766 | } |
f35f2525 | 767 | if (mdmon_running(st->container_dev)) { |
171dccc8 | 768 | if (c->verbose) |
e7b84f9d | 769 | pr_err("reusing mdmon " |
f35f2525 N |
770 | "for %s.\n", |
771 | devnum2devname(st->container_dev)); | |
772 | st->update_tail = &st->updates; | |
773 | } else | |
774 | need_mdmon = 1; | |
775 | } | |
776 | rv = set_array_info(mdfd, st, &info); | |
82d9eba6 | 777 | if (rv) { |
e7b84f9d | 778 | pr_err("failed to set array info for %s: %s\n", |
52826846 | 779 | mddev, strerror(errno)); |
7f91af49 | 780 | goto abort; |
682c7051 | 781 | } |
52826846 | 782 | |
c82f047c NB |
783 | if (bitmap_file) { |
784 | int uuid[4]; | |
55935d51 | 785 | |
3da92f27 | 786 | st->ss->uuid_from_super(st, uuid); |
171dccc8 N |
787 | if (CreateBitmap(bitmap_file, c->force, (char*)uuid, bitmap_chunk, |
788 | c->delay, write_behind, | |
f9c25f1d | 789 | bitmapsize, |
943eafef | 790 | major_num)) { |
7f91af49 | 791 | goto abort; |
c82f047c NB |
792 | } |
793 | bitmap_fd = open(bitmap_file, O_RDWR); | |
794 | if (bitmap_fd < 0) { | |
e7b84f9d | 795 | pr_err("weird: %s cannot be openned\n", |
dcec9ee5 | 796 | bitmap_file); |
7f91af49 | 797 | goto abort; |
c82f047c NB |
798 | } |
799 | if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) { | |
e7b84f9d | 800 | pr_err("Cannot set bitmap file for %s: %s\n", |
c82f047c | 801 | mddev, strerror(errno)); |
7f91af49 | 802 | goto abort; |
c82f047c NB |
803 | } |
804 | } | |
805 | ||
503975b9 | 806 | infos = xmalloc(sizeof(*infos) * total_slots); |
4b1ac34b | 807 | |
4b1ac34b | 808 | for (pass=1; pass <=2 ; pass++) { |
a655e550 | 809 | struct mddev_dev *moved_disk = NULL; /* the disk that was moved out of the insert point */ |
4b1ac34b NB |
810 | |
811 | for (dnum=0, dv = devlist ; dv ; | |
812 | dv=(dv->next)?(dv->next):moved_disk, dnum++) { | |
813 | int fd; | |
814 | struct stat stb; | |
d2ca6449 | 815 | struct mdinfo *inf = &infos[dnum]; |
4b1ac34b | 816 | |
d2ca6449 NB |
817 | if (dnum >= total_slots) |
818 | abort(); | |
4b1ac34b NB |
819 | if (dnum == insert_point) { |
820 | moved_disk = dv; | |
8592f29d | 821 | continue; |
52826846 | 822 | } |
8592f29d | 823 | if (strcasecmp(dv->devname, "missing")==0) |
111d01fc | 824 | continue; |
8592f29d N |
825 | if (have_container) |
826 | moved_disk = NULL; | |
827 | if (have_container && dnum < info.array.raid_disks - 1) | |
828 | /* repeatedly use the container */ | |
829 | moved_disk = dv; | |
111d01fc | 830 | |
d2ca6449 NB |
831 | switch(pass) { |
832 | case 1: | |
833 | *inf = info; | |
5f8097be | 834 | |
d2ca6449 NB |
835 | inf->disk.number = dnum; |
836 | inf->disk.raid_disk = dnum; | |
837 | if (inf->disk.raid_disk < raiddisks) | |
838 | inf->disk.state = (1<<MD_DISK_ACTIVE) | | |
839 | (1<<MD_DISK_SYNC); | |
840 | else | |
841 | inf->disk.state = 0; | |
842 | ||
b01b06bd | 843 | if (dv->writemostly == 1) |
d2ca6449 NB |
844 | inf->disk.state |= (1<<MD_DISK_WRITEMOSTLY); |
845 | ||
8592f29d N |
846 | if (have_container) |
847 | fd = -1; | |
848 | else { | |
d1d599ea N |
849 | if (st->ss->external && |
850 | st->container_dev != NoMdDev) | |
8592f29d N |
851 | fd = open(dv->devname, O_RDWR); |
852 | else | |
853 | fd = open(dv->devname, O_RDWR|O_EXCL); | |
854 | ||
855 | if (fd < 0) { | |
e7b84f9d | 856 | pr_err("failed to open %s " |
8592f29d N |
857 | "after earlier success - aborting\n", |
858 | dv->devname); | |
859 | goto abort; | |
860 | } | |
861 | fstat(fd, &stb); | |
862 | inf->disk.major = major(stb.st_rdev); | |
863 | inf->disk.minor = minor(stb.st_rdev); | |
d2ca6449 | 864 | } |
8592f29d N |
865 | if (fd >= 0) |
866 | remove_partitions(fd); | |
f20c3968 | 867 | if (st->ss->add_to_super(st, &inf->disk, |
4eb26970 DW |
868 | fd, dv->devname)) { |
869 | ioctl(mdfd, STOP_ARRAY, NULL); | |
f20c3968 | 870 | goto abort; |
4eb26970 | 871 | } |
a5d85af7 | 872 | st->ss->getinfo_super(st, inf, NULL); |
8ed3e5e1 | 873 | safe_mode_delay = inf->safe_mode_delay; |
d2ca6449 | 874 | |
171dccc8 | 875 | if (have_container && c->verbose > 0) |
e7b84f9d | 876 | pr_err("Using %s for device %d\n", |
8592f29d N |
877 | map_dev(inf->disk.major, |
878 | inf->disk.minor, | |
879 | 0), dnum); | |
880 | ||
881 | if (!have_container) { | |
882 | /* getinfo_super might have lost these ... */ | |
883 | inf->disk.major = major(stb.st_rdev); | |
884 | inf->disk.minor = minor(stb.st_rdev); | |
885 | } | |
4b1ac34b NB |
886 | break; |
887 | case 2: | |
d2ca6449 | 888 | inf->errors = 0; |
4b1ac34b | 889 | |
f35f2525 | 890 | rv = add_disk(mdfd, st, &info, inf); |
d2ca6449 | 891 | |
2503d23b | 892 | if (rv) { |
e7b84f9d N |
893 | pr_err("ADD_NEW_DISK for %s " |
894 | "failed: %s\n", | |
895 | dv->devname, strerror(errno)); | |
7f91af49 | 896 | goto abort; |
4b1ac34b | 897 | } |
4b1ac34b NB |
898 | break; |
899 | } | |
8592f29d N |
900 | if (!have_container && |
901 | dv == moved_disk && dnum != insert_point) break; | |
52826846 | 902 | } |
edd8d13c | 903 | if (pass == 1) { |
9b1fb677 DW |
904 | struct mdinfo info_new; |
905 | struct map_ent *me = NULL; | |
906 | ||
907 | /* check to see if the uuid has changed due to these | |
908 | * metadata changes, and if so update the member array | |
909 | * and container uuid. Note ->write_init_super clears | |
910 | * the subarray cursor such that ->getinfo_super once | |
911 | * again returns container info. | |
912 | */ | |
913 | map_lock(&map); | |
a5d85af7 | 914 | st->ss->getinfo_super(st, &info_new, NULL); |
9b1fb677 DW |
915 | if (st->ss->external && level != LEVEL_CONTAINER && |
916 | !same_uuid(info_new.uuid, info.uuid, 0)) { | |
917 | map_update(&map, fd2devnum(mdfd), | |
918 | info_new.text_version, | |
919 | info_new.uuid, chosen_name); | |
920 | me = map_by_devnum(&map, st->container_dev); | |
921 | } | |
922 | ||
ab80e597 | 923 | if (st->ss->write_init_super(st)) { |
ab80e597 | 924 | st->ss->free_super(st); |
e06af9dd | 925 | goto abort_locked; |
ab80e597 | 926 | } |
9b1fb677 DW |
927 | |
928 | /* update parent container uuid */ | |
929 | if (me) { | |
503975b9 | 930 | char *path = xstrdup(me->path); |
9b1fb677 | 931 | |
a5d85af7 | 932 | st->ss->getinfo_super(st, &info_new, NULL); |
9b1fb677 DW |
933 | map_update(&map, st->container_dev, |
934 | info_new.text_version, | |
935 | info_new.uuid, path); | |
936 | free(path); | |
937 | } | |
938 | map_unlock(&map); | |
939 | ||
edd8d13c | 940 | flush_metadata_updates(st); |
6946681d | 941 | st->ss->free_super(st); |
edd8d13c | 942 | } |
5e52ae9e | 943 | } |
d2ca6449 | 944 | free(infos); |
5e52ae9e | 945 | |
97590376 N |
946 | if (level == LEVEL_CONTAINER) { |
947 | /* No need to start. But we should signal udev to | |
948 | * create links */ | |
949 | sysfs_uevent(&info, "change"); | |
171dccc8 | 950 | if (c->verbose >= 0) |
e7b84f9d | 951 | pr_err("container %s prepared.\n", mddev); |
a7c6e3fb | 952 | wait_for(chosen_name, mdfd); |
171dccc8 | 953 | } else if (c->runstop == 1 || subdevs >= raiddisks) { |
598f0d58 | 954 | if (st->ss->external) { |
4c821454 | 955 | int err; |
598f0d58 NB |
956 | switch(level) { |
957 | case LEVEL_LINEAR: | |
958 | case LEVEL_MULTIPATH: | |
959 | case 0: | |
4c821454 | 960 | err = sysfs_set_str(&info, NULL, "array_state", |
171dccc8 | 961 | c->readonly |
72d566f6 N |
962 | ? "readonly" |
963 | : "active"); | |
a931db9e | 964 | need_mdmon = 0; |
598f0d58 NB |
965 | break; |
966 | default: | |
4c821454 N |
967 | err = sysfs_set_str(&info, NULL, "array_state", |
968 | "readonly"); | |
598f0d58 NB |
969 | break; |
970 | } | |
f35f2525 | 971 | sysfs_set_safemode(&info, safe_mode_delay); |
4c821454 | 972 | if (err) { |
e7b84f9d N |
973 | pr_err("failed to" |
974 | " activate array.\n"); | |
4c821454 N |
975 | ioctl(mdfd, STOP_ARRAY, NULL); |
976 | goto abort; | |
977 | } | |
171dccc8 | 978 | } else if (c->readonly && |
72d566f6 N |
979 | sysfs_attribute_available( |
980 | &info, NULL, "array_state")) { | |
981 | if (sysfs_set_str(&info, NULL, | |
982 | "array_state", "readonly") < 0) { | |
983 | pr_err("Failed to start array: %s\n", | |
984 | strerror(errno)); | |
985 | ioctl(mdfd, STOP_ARRAY, NULL); | |
986 | goto abort; | |
987 | } | |
598f0d58 | 988 | } else { |
97590376 | 989 | /* param is not actually used */ |
598f0d58 NB |
990 | mdu_param_t param; |
991 | if (ioctl(mdfd, RUN_ARRAY, ¶m)) { | |
e7b84f9d | 992 | pr_err("RUN_ARRAY failed: %s\n", |
72d566f6 | 993 | strerror(errno)); |
a252c078 | 994 | if (info.array.chunk_size & (info.array.chunk_size-1)) { |
e7b84f9d N |
995 | cont_err("Problem may be that " |
996 | "chunk size is not a power of 2\n"); | |
a252c078 | 997 | } |
4eb26970 | 998 | ioctl(mdfd, STOP_ARRAY, NULL); |
7f91af49 | 999 | goto abort; |
598f0d58 | 1000 | } |
682c7051 | 1001 | } |
171dccc8 | 1002 | if (c->verbose >= 0) |
e7b84f9d | 1003 | pr_err("array %s started.\n", mddev); |
d1d599ea | 1004 | if (st->ss->external && st->container_dev != NoMdDev) { |
8850ee3e N |
1005 | if (need_mdmon) |
1006 | start_mdmon(st->container_dev); | |
1007 | ||
983fff45 | 1008 | ping_monitor_by_id(st->container_dev); |
a931db9e NB |
1009 | close(container_fd); |
1010 | } | |
a7c6e3fb | 1011 | wait_for(chosen_name, mdfd); |
682c7051 | 1012 | } else { |
e7b84f9d | 1013 | pr_err("not starting array - not enough devices.\n"); |
682c7051 | 1014 | } |
7f91af49 | 1015 | close(mdfd); |
682c7051 | 1016 | return 0; |
7f91af49 N |
1017 | |
1018 | abort: | |
4eb26970 | 1019 | map_lock(&map); |
e06af9dd | 1020 | abort_locked: |
4eb26970 DW |
1021 | map_remove(&map, fd2devnum(mdfd)); |
1022 | map_unlock(&map); | |
1023 | ||
7f91af49 N |
1024 | if (mdfd >= 0) |
1025 | close(mdfd); | |
1026 | return 1; | |
64c4757e | 1027 | } |