]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - Create.c
2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
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.
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.
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
22 * Email: <neilb@suse.de>
30 static int default_layout(struct supertype
*st
, int level
, int verbose
)
34 if (st
&& st
->ss
->default_geometry
)
35 st
->ss
->default_geometry(st
, &level
, &layout
, NULL
);
39 default: /* no layout */
43 layout
= 0x102; /* near=2, far=1 */
45 pr_err("layout defaults to n2\n");
49 layout
= map_name(r5layout
, "default");
51 pr_err("layout defaults to %s\n", map_num(r5layout
, layout
));
54 layout
= map_name(faultylayout
, "default");
57 pr_err("layout defaults to %s\n", map_num(faultylayout
, layout
));
65 int Create(struct supertype
*st
, char *mddev
,
66 int chunk
, int level
, int layout
, unsigned long long size
,
67 int raiddisks
, int sparedisks
,
68 char *name
, int *uuid
,
69 int subdevs
, struct mddev_dev
*devlist
,
71 char *bitmap_file
, int bitmap_chunk
, int write_behind
,
75 * Create a new raid array.
77 * First check that necessary details are available
78 * (i.e. level, raid-disks)
80 * Then check each disk to see what might be on it
81 * and report anything interesting.
83 * If anything looks odd, and runstop not set,
86 * SET_ARRAY_INFO and ADD_NEW_DISK, and
87 * if runstop==run, or raiddisks disks were used,
91 unsigned long long minsize
=0, maxsize
=0;
98 int first_missing
= subdevs
* 2;
99 int second_missing
= subdevs
* 2;
100 int missing_disks
= 0;
101 int insert_point
= subdevs
* 2; /* where to insert a missing drive */
107 int have_container
= 0;
108 int container_fd
= -1;
110 unsigned long long bitmapsize
;
111 struct mdinfo info
, *infos
;
113 int do_default_layout
= 0;
114 int do_default_chunk
= 0;
115 unsigned long safe_mode_delay
= 0;
116 char chosen_name
[1024];
117 struct map_ent
*map
= NULL
;
118 unsigned long long newsize
;
120 int major_num
= BITMAP_MAJOR_HI
;
122 memset(&info
, 0, sizeof(info
));
123 if (level
== UnSet
&& st
&& st
->ss
->default_geometry
)
124 st
->ss
->default_geometry(st
, &level
, NULL
, NULL
);
125 if (level
== UnSet
) {
126 pr_err("a RAID level is needed to create an array.\n");
129 if (raiddisks
< 4 && level
== 6) {
130 pr_err("at least 4 raid-devices needed for level 6\n");
133 if (raiddisks
> 256 && level
== 6) {
134 pr_err("no more than 256 raid-devices supported for level 6\n");
137 if (raiddisks
< 2 && level
>= 4) {
138 pr_err("at least 2 raid-devices needed for level 4 or 5\n");
141 if (level
<= 0 && sparedisks
) {
142 pr_err("This level does not support spare devices\n");
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
150 mdu_array_info_t inf
;
153 memset(&inf
, 0, sizeof(inf
));
154 fd
= open(devlist
->devname
, O_RDONLY
);
156 ioctl(fd
, GET_ARRAY_INFO
, &inf
) == 0 &&
157 inf
.raid_disks
== 0) {
158 /* yep, looks like a container */
160 rv
= st
->ss
->load_container(st
, fd
,
165 st
= super_by_fd(fd
, NULL
);
166 if (st
&& !(rv
= st
->ss
->
167 load_container(st
, fd
,
173 if (have_container
) {
175 first_missing
= subdevs
* 2;
176 second_missing
= subdevs
* 2;
177 insert_point
= subdevs
* 2;
183 if (st
&& st
->ss
->external
&& sparedisks
) {
184 pr_err("This metadata type does not support "
185 "spare disks at create time\n");
188 if (subdevs
> raiddisks
+sparedisks
) {
189 pr_err("You have listed more devices (%d) than are in the array(%d)!\n", subdevs
, raiddisks
+sparedisks
);
192 if (!have_container
&& subdevs
< raiddisks
+sparedisks
) {
193 pr_err("You haven't given enough devices (real or missing) to create this array\n");
196 if (bitmap_file
&& level
<= 0) {
197 pr_err("bitmaps not meaningful with level %s\n",
198 map_num(pers
, level
)?:"given");
202 /* now set some defaults */
205 if (layout
== UnSet
) {
206 do_default_layout
= 1;
207 layout
= default_layout(st
, level
, c
->verbose
);
211 /* check layout fits in array*/
212 if ((layout
&255) * ((layout
>>8)&255) > raiddisks
) {
213 pr_err("that layout requires at least %d devices\n",
214 (layout
&255) * ((layout
>>8)&255));
224 if (chunk
== 0 || chunk
== UnSet
) {
226 do_default_chunk
= 1;
227 /* chunk will be set later */
231 /* a chunksize of zero 0s perfectly valid (and preferred) since 2.6.16 */
232 if (get_linux_version() < 2006016 && chunk
== 0) {
235 pr_err("chunk size defaults to 64K\n");
240 case LEVEL_MULTIPATH
:
241 case LEVEL_CONTAINER
:
245 pr_err("chunk size ignored for this level\n");
249 pr_err("unknown level %d\n", level
);
253 if (size
&& chunk
&& chunk
!= UnSet
)
254 size
&= ~(unsigned long long)(chunk
- 1);
256 if (st
&& ! st
->ss
->validate_geometry(st
, level
, layout
, raiddisks
,
257 &chunk
, size
*2, NULL
, &newsize
, c
->verbose
>=0))
260 if (chunk
&& chunk
!= UnSet
) {
261 newsize
&= ~(unsigned long long)(chunk
*2 - 1);
262 if (do_default_chunk
) {
263 /* default chunk was just set */
266 "defaults to %dK\n", chunk
);
267 size
&= ~(unsigned long long)(chunk
- 1);
268 do_default_chunk
= 0;
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
281 if (size
&& c
->verbose
> 0)
282 pr_err("setting size to %lluK\n",
283 (unsigned long long)size
);
286 /* now look at the subdevs */
287 info
.array
.active_disks
= 0;
288 info
.array
.working_disks
= 0;
290 for (dv
=devlist
; dv
&& !have_container
; dv
=dv
->next
, dnum
++) {
291 char *dname
= dv
->devname
;
292 unsigned long long freesize
;
295 if (strcasecmp(dname
, "missing")==0) {
296 if (first_missing
> dnum
)
297 first_missing
= dnum
;
298 if (second_missing
> dnum
&& dnum
> first_missing
)
299 second_missing
= dnum
;
303 dfd
= open(dname
, O_RDONLY
);
305 pr_err("cannot open %s: %s\n",
306 dname
, strerror(errno
));
309 if (fstat(dfd
, &stb
) != 0 ||
310 (stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
312 pr_err("%s is not a block device\n",
317 info
.array
.working_disks
++;
318 if (dnum
< raiddisks
)
319 info
.array
.active_disks
++;
321 struct createinfo
*ci
= conf_get_create_info();
326 /* Need to choose a default metadata, which is different
327 * depending on geometry of array.
330 char *name
= "default";
331 for(i
=0; !st
&& superlist
[i
]; i
++) {
332 st
= superlist
[i
]->match_metadata_desc(name
);
335 if (do_default_layout
)
336 layout
= default_layout(st
, level
, c
->verbose
);
337 switch (st
->ss
->validate_geometry(
338 st
, level
, layout
, raiddisks
,
339 &chunk
, size
*2, dname
, &freesize
,
341 case -1: /* Not valid, message printed, and not
342 * worth checking any further */
345 case 0: /* Geometry not valid */
348 chunk
= do_default_chunk
? UnSet
: chunk
;
350 case 1: /* All happy */
356 int dfd
= open(dname
, O_RDONLY
|O_EXCL
);
358 pr_err("cannot open %s: %s\n",
359 dname
, strerror(errno
));
362 pr_err("device %s not suitable "
363 "for any style of array\n",
367 if (st
->ss
!= &super0
||
368 st
->minor_version
!= 90)
371 if (do_default_layout
)
372 layout
= default_layout(st
, level
, 0);
373 if (!st
->ss
->validate_geometry(st
, level
, layout
,
375 &chunk
, size
*2, dname
,
379 pr_err("%s is not suitable for "
387 freesize
/= 2; /* convert to K */
388 if (chunk
&& chunk
!= UnSet
) {
389 /* round to chunk size */
390 freesize
= freesize
& ~(chunk
-1);
391 if (do_default_chunk
) {
392 /* default chunk was just set */
395 "defaults to %dK\n", chunk
);
396 size
&= ~(unsigned long long)(chunk
- 1);
397 do_default_chunk
= 0;
401 if (size
&& freesize
< size
) {
402 pr_err("%s is smaller than given size."
403 " %lluK < %lluK + metadata\n",
404 dname
, freesize
, size
);
408 if (maxdisc
== NULL
|| (maxdisc
&& freesize
> maxsize
)) {
412 if (mindisc
==NULL
|| (mindisc
&& freesize
< minsize
)) {
416 if (c
->runstop
!= 1 || c
->verbose
>= 0) {
417 int fd
= open(dname
, O_RDONLY
);
419 pr_err("Cannot open %s: %s\n",
420 dname
, strerror(errno
));
424 warn
|= check_ext2(fd
, dname
);
425 warn
|= check_reiser(fd
, dname
);
426 warn
|= check_raid(fd
, dname
);
427 if (strcmp(st
->ss
->name
, "1.x") == 0 &&
428 st
->minor_version
>= 1)
429 /* metadata at front */
430 warn
|= check_partitions(fd
, dname
, 0, 0);
431 else if (level
== 1 || level
== LEVEL_CONTAINER
432 || (level
== 0 && raiddisks
== 1))
433 /* partitions could be meaningful */
434 warn
|= check_partitions(fd
, dname
, freesize
*2, size
*2);
436 /* partitions cannot be meaningful */
437 warn
|= check_partitions(fd
, dname
, 0, 0);
438 if (strcmp(st
->ss
->name
, "1.x") == 0 &&
439 st
->minor_version
>= 1 &&
442 (warn
& 1024) == 0) {
444 pr_err("Note: this array has metadata at the start and\n"
445 " may not be suitable as a boot device. If you plan to\n"
446 " store '/boot' on this device please ensure that\n"
447 " your boot-loader understands md/v1.x metadata, or use\n"
448 " --metadata=0.90\n");
453 if (raiddisks
+ sparedisks
> st
->max_devs
) {
454 pr_err("Too many devices:"
455 " %s metadata only supports %d\n",
456 st
->ss
->name
, st
->max_devs
);
460 info
.array
.working_disks
= raiddisks
;
462 pr_err("create aborted\n");
466 if (mindisc
== NULL
&& !have_container
) {
467 pr_err("no size and no drives given - aborting create.\n");
470 if (level
> 0 || level
== LEVEL_MULTIPATH
471 || level
== LEVEL_FAULTY
472 || st
->ss
->external
) {
473 /* size is meaningful */
474 if (!st
->ss
->validate_geometry(st
, level
, layout
,
478 pr_err("devices too large for RAID level %d\n", level
);
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
489 pr_err("size set to %lluK\n", size
);
492 if (!have_container
&& level
> 0 && ((maxsize
-size
)*100 > maxsize
)) {
493 if (c
->runstop
!= 1 || c
->verbose
>= 0)
494 pr_err("largest drive (%s) exceeds size (%lluK) by more than 1%%\n",
499 if (st
->ss
->detail_platform
&& st
->ss
->detail_platform(0, 1) != 0) {
500 if (c
->runstop
!= 1 || c
->verbose
>= 0)
501 pr_err("%s unable to enumerate platform support\n"
502 " array may not be compatible with hardware/firmware\n",
508 if (c
->runstop
!= 1) {
509 if (!ask("Continue creating array? ")) {
510 pr_err("create aborted.\n");
515 pr_err("creation continuing despite oddities due to --run\n");
519 /* If this is raid4/5, we want to configure the last active slot
520 * as missing, so that a reconstruct happens (faster than re-parity)
521 * FIX: Can we do this for raid6 as well?
523 if (st
->ss
->external
== 0 &&
524 assume_clean
==0 && c
->force
== 0 && first_missing
>= raiddisks
) {
528 insert_point
= raiddisks
-1;
530 info
.array
.active_disks
--;
537 /* For raid6, if creating with 1 missing drive, make a good drive
538 * into a spare, else the create will fail
540 if (assume_clean
== 0 && c
->force
== 0 && first_missing
< raiddisks
&&
541 st
->ss
->external
== 0 &&
542 second_missing
>= raiddisks
&& level
== 6) {
543 insert_point
= raiddisks
- 1;
544 if (insert_point
== first_missing
)
547 info
.array
.active_disks
--;
551 if (level
<= 0 && first_missing
< subdevs
* 2) {
552 pr_err("This level does not support missing devices\n");
556 /* We need to create the device */
558 mdfd
= create_mddev(mddev
, name
, c
->autof
, LOCAL
, chosen_name
);
563 /* verify if chosen_name is not in use,
564 * it could be in conflict with already existing device
565 * e.g. container, array
567 if (strncmp(chosen_name
, "/dev/md/", 8) == 0
568 && map_by_name(&map
, chosen_name
+8) != NULL
) {
569 pr_err("Array name %s is in use already.\n",
577 vers
= md_get_version(mdfd
);
579 pr_err("Create requires md driver version 0.90.0 or later\n");
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) {
586 pr_err("another array by this name"
587 " is already running.\n");
592 /* Ok, lets try some ioctls */
594 info
.array
.level
= level
;
595 info
.array
.size
= size
;
596 info
.array
.raid_disks
= raiddisks
;
597 /* The kernel should *know* what md_minor we are dealing
598 * with, but it chooses to trust me instead. Sigh
600 info
.array
.md_minor
= 0;
601 if (fstat(mdfd
, &stb
)==0)
602 info
.array
.md_minor
= minor(stb
.st_rdev
);
603 info
.array
.not_persistent
= 0;
605 if ( ( (level
== 4 || level
== 5) &&
606 (insert_point
< raiddisks
|| first_missing
< raiddisks
) )
608 ( level
== 6 && (insert_point
< raiddisks
609 || second_missing
< raiddisks
))
615 info
.array
.state
= 1; /* clean, but one+ drive will be missing*/
616 info
.resync_start
= MaxSector
;
618 info
.array
.state
= 0; /* not clean, but no errors */
619 info
.resync_start
= 0;
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.
626 int ncopies
= ((layout
>>8) & 255) * (layout
& 255);
627 bitmapsize
= (unsigned long long)size
* raiddisks
/ ncopies
* 2;
628 /* printf("bms=%llu as=%d rd=%d nc=%d\n", bitmapsize, size, raiddisks, ncopies);*/
630 bitmapsize
= (unsigned long long)size
* 2;
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
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
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,
644 * failed_disks is the number of disks marked failed
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.
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;
658 if (name
== NULL
|| *name
== 0) {
659 /* base name on mddev */
664 * /dev/md/home -> home
665 * /dev/mdhome -> home
667 /* FIXME compare this with rules in create_mddev */
668 name
= strrchr(mddev
, '/');
671 if (strncmp(name
, "md_d", 4)==0 &&
674 (name
-mddev
) == 5 /* /dev/ */)
676 else if (strncmp(name
, "md", 2)==0 &&
679 (name
-mddev
) == 5 /* /dev/ */)
683 if (!st
->ss
->init_super(st
, &info
.array
, size
, name
, c
->homehost
, uuid
))
686 total_slots
= info
.array
.nr_disks
;
687 st
->ss
->getinfo_super(st
, &info
, NULL
);
688 sysfs_init(&info
, mdfd
, 0);
690 if (did_default
&& c
->verbose
>= 0) {
691 if (is_subarray(info
.text_version
)) {
692 int dnum
= devname2devnum(info
.text_version
+1);
694 int mdp
= get_mdp_major();
697 path
= map_dev(MD_MAJOR
, dnum
, 1);
699 path
= map_dev(mdp
, (-1-dnum
)<< 6, 1);
701 mdi
= sysfs_read(-1, dnum
, GET_VERSION
);
703 pr_err("Creating array inside "
705 mdi
?mdi
->text_version
:"managed", path
);
708 pr_err("Defaulting to version"
709 " %s metadata\n", info
.text_version
);
712 map_update(&map
, fd2devnum(mdfd
), info
.text_version
,
713 info
.uuid
, chosen_name
);
716 if (bitmap_file
&& vers
< 9003) {
717 major_num
= BITMAP_MAJOR_HOSTENDIAN
;
719 pr_err("Warning - bitmaps created on this kernel are not portable\n"
720 " between different architectured. Consider upgrading the Linux kernel.\n");
724 if (bitmap_file
&& strcmp(bitmap_file
, "internal")==0) {
725 if ((vers
%100) < 2) {
726 pr_err("internal bitmaps not supported by this kernel.\n");
729 if (!st
->ss
->add_internal_bitmap
) {
730 pr_err("internal bitmaps not supported with %s metadata\n",
734 if (!st
->ss
->add_internal_bitmap(st
, &bitmap_chunk
,
735 c
->delay
, write_behind
,
736 bitmapsize
, 1, major_num
)) {
737 pr_err("Given bitmap chunk size not supported.\n");
744 sysfs_init(&info
, mdfd
, 0);
746 if (st
->ss
->external
&& st
->container_dev
!= NoMdDev
) {
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,
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.
759 * For now, fail if it is already running.
761 container_fd
= open_dev_excl(st
->container_dev
);
762 if (container_fd
< 0) {
763 pr_err("Cannot get exclusive "
764 "open on container - weird.\n");
767 if (mdmon_running(st
->container_dev
)) {
769 pr_err("reusing mdmon "
771 devnum2devname(st
->container_dev
));
772 st
->update_tail
= &st
->updates
;
776 rv
= set_array_info(mdfd
, st
, &info
);
778 pr_err("failed to set array info for %s: %s\n",
779 mddev
, strerror(errno
));
786 st
->ss
->uuid_from_super(st
, uuid
);
787 if (CreateBitmap(bitmap_file
, c
->force
, (char*)uuid
, bitmap_chunk
,
788 c
->delay
, write_behind
,
793 bitmap_fd
= open(bitmap_file
, O_RDWR
);
795 pr_err("weird: %s cannot be openned\n",
799 if (ioctl(mdfd
, SET_BITMAP_FILE
, bitmap_fd
) < 0) {
800 pr_err("Cannot set bitmap file for %s: %s\n",
801 mddev
, strerror(errno
));
806 infos
= xmalloc(sizeof(*infos
) * total_slots
);
808 for (pass
=1; pass
<=2 ; pass
++) {
809 struct mddev_dev
*moved_disk
= NULL
; /* the disk that was moved out of the insert point */
811 for (dnum
=0, dv
= devlist
; dv
;
812 dv
=(dv
->next
)?(dv
->next
):moved_disk
, dnum
++) {
815 struct mdinfo
*inf
= &infos
[dnum
];
817 if (dnum
>= total_slots
)
819 if (dnum
== insert_point
) {
823 if (strcasecmp(dv
->devname
, "missing")==0)
827 if (have_container
&& dnum
< info
.array
.raid_disks
- 1)
828 /* repeatedly use the container */
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
) |
843 if (dv
->writemostly
== 1)
844 inf
->disk
.state
|= (1<<MD_DISK_WRITEMOSTLY
);
849 if (st
->ss
->external
&&
850 st
->container_dev
!= NoMdDev
)
851 fd
= open(dv
->devname
, O_RDWR
);
853 fd
= open(dv
->devname
, O_RDWR
|O_EXCL
);
856 pr_err("failed to open %s "
857 "after earlier success - aborting\n",
862 inf
->disk
.major
= major(stb
.st_rdev
);
863 inf
->disk
.minor
= minor(stb
.st_rdev
);
866 remove_partitions(fd
);
867 if (st
->ss
->add_to_super(st
, &inf
->disk
,
869 ioctl(mdfd
, STOP_ARRAY
, NULL
);
872 st
->ss
->getinfo_super(st
, inf
, NULL
);
873 safe_mode_delay
= inf
->safe_mode_delay
;
875 if (have_container
&& c
->verbose
> 0)
876 pr_err("Using %s for device %d\n",
877 map_dev(inf
->disk
.major
,
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
);
890 rv
= add_disk(mdfd
, st
, &info
, inf
);
893 pr_err("ADD_NEW_DISK for %s "
895 dv
->devname
, strerror(errno
));
900 if (!have_container
&&
901 dv
== moved_disk
&& dnum
!= insert_point
) break;
904 struct mdinfo info_new
;
905 struct map_ent
*me
= NULL
;
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.
914 st
->ss
->getinfo_super(st
, &info_new
, NULL
);
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
);
923 if (st
->ss
->write_init_super(st
)) {
924 st
->ss
->free_super(st
);
928 /* update parent container uuid */
930 char *path
= xstrdup(me
->path
);
932 st
->ss
->getinfo_super(st
, &info_new
, NULL
);
933 map_update(&map
, st
->container_dev
,
934 info_new
.text_version
,
935 info_new
.uuid
, path
);
940 flush_metadata_updates(st
);
941 st
->ss
->free_super(st
);
946 if (level
== LEVEL_CONTAINER
) {
947 /* No need to start. But we should signal udev to
949 sysfs_uevent(&info
, "change");
951 pr_err("container %s prepared.\n", mddev
);
952 wait_for(chosen_name
, mdfd
);
953 } else if (c
->runstop
== 1 || subdevs
>= raiddisks
) {
954 if (st
->ss
->external
) {
958 case LEVEL_MULTIPATH
:
960 err
= sysfs_set_str(&info
, NULL
, "array_state",
967 err
= sysfs_set_str(&info
, NULL
, "array_state",
971 sysfs_set_safemode(&info
, safe_mode_delay
);
974 " activate array.\n");
975 ioctl(mdfd
, STOP_ARRAY
, NULL
);
978 } else if (c
->readonly
&&
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",
985 ioctl(mdfd
, STOP_ARRAY
, NULL
);
989 /* param is not actually used */
991 if (ioctl(mdfd
, RUN_ARRAY
, ¶m
)) {
992 pr_err("RUN_ARRAY failed: %s\n",
994 if (info
.array
.chunk_size
& (info
.array
.chunk_size
-1)) {
995 cont_err("Problem may be that "
996 "chunk size is not a power of 2\n");
998 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1002 if (c
->verbose
>= 0)
1003 pr_err("array %s started.\n", mddev
);
1004 if (st
->ss
->external
&& st
->container_dev
!= NoMdDev
) {
1006 start_mdmon(st
->container_dev
);
1008 ping_monitor_by_id(st
->container_dev
);
1009 close(container_fd
);
1011 wait_for(chosen_name
, mdfd
);
1013 pr_err("not starting array - not enough devices.\n");
1021 map_remove(&map
, fd2devnum(mdfd
));