]>
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
);
252 if (size
== MAX_SIZE
)
253 /* use '0' to mean 'max' now... */
255 if (size
&& chunk
&& chunk
!= UnSet
)
256 size
&= ~(unsigned long long)(chunk
- 1);
258 if (st
&& ! st
->ss
->validate_geometry(st
, level
, layout
, raiddisks
,
259 &chunk
, size
*2, NULL
, &newsize
, c
->verbose
>=0))
262 if (chunk
&& chunk
!= UnSet
) {
263 newsize
&= ~(unsigned long long)(chunk
*2 - 1);
264 if (do_default_chunk
) {
265 /* default chunk was just set */
268 "defaults to %dK\n", chunk
);
269 size
&= ~(unsigned long long)(chunk
- 1);
270 do_default_chunk
= 0;
277 /* If this is ever reshaped to RAID5, we will
278 * need a chunksize. So round it off a bit
279 * now just to be safe
283 if (size
&& c
->verbose
> 0)
284 pr_err("setting size to %lluK\n",
285 (unsigned long long)size
);
288 /* now look at the subdevs */
289 info
.array
.active_disks
= 0;
290 info
.array
.working_disks
= 0;
292 for (dv
=devlist
; dv
&& !have_container
; dv
=dv
->next
, dnum
++) {
293 char *dname
= dv
->devname
;
294 unsigned long long freesize
;
297 if (strcasecmp(dname
, "missing")==0) {
298 if (first_missing
> dnum
)
299 first_missing
= dnum
;
300 if (second_missing
> dnum
&& dnum
> first_missing
)
301 second_missing
= dnum
;
305 dfd
= open(dname
, O_RDONLY
);
307 pr_err("cannot open %s: %s\n",
308 dname
, strerror(errno
));
311 if (fstat(dfd
, &stb
) != 0 ||
312 (stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
314 pr_err("%s is not a block device\n",
319 info
.array
.working_disks
++;
320 if (dnum
< raiddisks
)
321 info
.array
.active_disks
++;
323 struct createinfo
*ci
= conf_get_create_info();
328 /* Need to choose a default metadata, which is different
329 * depending on geometry of array.
332 char *name
= "default";
333 for(i
=0; !st
&& superlist
[i
]; i
++) {
334 st
= superlist
[i
]->match_metadata_desc(name
);
337 if (do_default_layout
)
338 layout
= default_layout(st
, level
, c
->verbose
);
339 switch (st
->ss
->validate_geometry(
340 st
, level
, layout
, raiddisks
,
341 &chunk
, size
*2, dname
, &freesize
,
343 case -1: /* Not valid, message printed, and not
344 * worth checking any further */
347 case 0: /* Geometry not valid */
350 chunk
= do_default_chunk
? UnSet
: chunk
;
352 case 1: /* All happy */
358 int dfd
= open(dname
, O_RDONLY
|O_EXCL
);
360 pr_err("cannot open %s: %s\n",
361 dname
, strerror(errno
));
364 pr_err("device %s not suitable "
365 "for any style of array\n",
369 if (st
->ss
!= &super0
||
370 st
->minor_version
!= 90)
373 if (do_default_layout
)
374 layout
= default_layout(st
, level
, 0);
375 if (!st
->ss
->validate_geometry(st
, level
, layout
,
377 &chunk
, size
*2, dname
,
381 pr_err("%s is not suitable for "
389 freesize
/= 2; /* convert to K */
390 if (chunk
&& chunk
!= UnSet
) {
391 /* round to chunk size */
392 freesize
= freesize
& ~(chunk
-1);
393 if (do_default_chunk
) {
394 /* default chunk was just set */
397 "defaults to %dK\n", chunk
);
398 size
&= ~(unsigned long long)(chunk
- 1);
399 do_default_chunk
= 0;
403 if (size
&& freesize
< size
) {
404 pr_err("%s is smaller than given size."
405 " %lluK < %lluK + metadata\n",
406 dname
, freesize
, size
);
410 if (maxdisc
== NULL
|| (maxdisc
&& freesize
> maxsize
)) {
414 if (mindisc
==NULL
|| (mindisc
&& freesize
< minsize
)) {
418 if (c
->runstop
!= 1 || c
->verbose
>= 0) {
419 int fd
= open(dname
, O_RDONLY
);
421 pr_err("Cannot open %s: %s\n",
422 dname
, strerror(errno
));
426 warn
|= check_ext2(fd
, dname
);
427 warn
|= check_reiser(fd
, dname
);
428 warn
|= check_raid(fd
, dname
);
429 if (strcmp(st
->ss
->name
, "1.x") == 0 &&
430 st
->minor_version
>= 1)
431 /* metadata at front */
432 warn
|= check_partitions(fd
, dname
, 0, 0);
433 else if (level
== 1 || level
== LEVEL_CONTAINER
434 || (level
== 0 && raiddisks
== 1))
435 /* partitions could be meaningful */
436 warn
|= check_partitions(fd
, dname
, freesize
*2, size
*2);
438 /* partitions cannot be meaningful */
439 warn
|= check_partitions(fd
, dname
, 0, 0);
440 if (strcmp(st
->ss
->name
, "1.x") == 0 &&
441 st
->minor_version
>= 1 &&
444 (warn
& 1024) == 0) {
446 pr_err("Note: this array has metadata at the start and\n"
447 " may not be suitable as a boot device. If you plan to\n"
448 " store '/boot' on this device please ensure that\n"
449 " your boot-loader understands md/v1.x metadata, or use\n"
450 " --metadata=0.90\n");
455 if (raiddisks
+ sparedisks
> st
->max_devs
) {
456 pr_err("Too many devices:"
457 " %s metadata only supports %d\n",
458 st
->ss
->name
, st
->max_devs
);
462 info
.array
.working_disks
= raiddisks
;
464 pr_err("create aborted\n");
468 if (mindisc
== NULL
&& !have_container
) {
469 pr_err("no size and no drives given - aborting create.\n");
472 if (level
> 0 || level
== LEVEL_MULTIPATH
473 || level
== LEVEL_FAULTY
474 || st
->ss
->external
) {
475 /* size is meaningful */
476 if (!st
->ss
->validate_geometry(st
, level
, layout
,
480 pr_err("devices too large for RAID level %d\n", level
);
485 /* If this is ever reshaped to RAID5, we will
486 * need a chunksize. So round it off a bit
487 * now just to be safe
491 pr_err("size set to %lluK\n", size
);
494 if (!have_container
&& level
> 0 && ((maxsize
-size
)*100 > maxsize
)) {
495 if (c
->runstop
!= 1 || c
->verbose
>= 0)
496 pr_err("largest drive (%s) exceeds size (%lluK) by more than 1%%\n",
501 if (st
->ss
->detail_platform
&& st
->ss
->detail_platform(0, 1) != 0) {
502 if (c
->runstop
!= 1 || c
->verbose
>= 0)
503 pr_err("%s unable to enumerate platform support\n"
504 " array may not be compatible with hardware/firmware\n",
510 if (c
->runstop
!= 1) {
511 if (!ask("Continue creating array? ")) {
512 pr_err("create aborted.\n");
517 pr_err("creation continuing despite oddities due to --run\n");
521 /* If this is raid4/5, we want to configure the last active slot
522 * as missing, so that a reconstruct happens (faster than re-parity)
523 * FIX: Can we do this for raid6 as well?
525 if (st
->ss
->external
== 0 &&
526 assume_clean
==0 && c
->force
== 0 && first_missing
>= raiddisks
) {
530 insert_point
= raiddisks
-1;
532 info
.array
.active_disks
--;
539 /* For raid6, if creating with 1 missing drive, make a good drive
540 * into a spare, else the create will fail
542 if (assume_clean
== 0 && c
->force
== 0 && first_missing
< raiddisks
&&
543 st
->ss
->external
== 0 &&
544 second_missing
>= raiddisks
&& level
== 6) {
545 insert_point
= raiddisks
- 1;
546 if (insert_point
== first_missing
)
549 info
.array
.active_disks
--;
553 if (level
<= 0 && first_missing
< subdevs
* 2) {
554 pr_err("This level does not support missing devices\n");
558 /* We need to create the device */
560 mdfd
= create_mddev(mddev
, name
, c
->autof
, LOCAL
, chosen_name
);
565 /* verify if chosen_name is not in use,
566 * it could be in conflict with already existing device
567 * e.g. container, array
569 if (strncmp(chosen_name
, "/dev/md/", 8) == 0
570 && map_by_name(&map
, chosen_name
+8) != NULL
) {
571 pr_err("Array name %s is in use already.\n",
579 vers
= md_get_version(mdfd
);
581 pr_err("Create requires md driver version 0.90.0 or later\n");
584 mdu_array_info_t inf
;
585 memset(&inf
, 0, sizeof(inf
));
586 ioctl(mdfd
, GET_ARRAY_INFO
, &inf
);
587 if (inf
.working_disks
!= 0) {
588 pr_err("another array by this name"
589 " is already running.\n");
594 /* Ok, lets try some ioctls */
596 info
.array
.level
= level
;
597 info
.array
.size
= size
;
598 info
.array
.raid_disks
= raiddisks
;
599 /* The kernel should *know* what md_minor we are dealing
600 * with, but it chooses to trust me instead. Sigh
602 info
.array
.md_minor
= 0;
603 if (fstat(mdfd
, &stb
)==0)
604 info
.array
.md_minor
= minor(stb
.st_rdev
);
605 info
.array
.not_persistent
= 0;
607 if ( ( (level
== 4 || level
== 5) &&
608 (insert_point
< raiddisks
|| first_missing
< raiddisks
) )
610 ( level
== 6 && (insert_point
< raiddisks
611 || second_missing
< raiddisks
))
617 info
.array
.state
= 1; /* clean, but one+ drive will be missing*/
618 info
.resync_start
= MaxSector
;
620 info
.array
.state
= 0; /* not clean, but no errors */
621 info
.resync_start
= 0;
624 /* for raid10, the bitmap size is the capacity of the array,
625 * which is array.size * raid_disks / ncopies;
626 * .. but convert to sectors.
628 int ncopies
= ((layout
>>8) & 255) * (layout
& 255);
629 bitmapsize
= (unsigned long long)size
* raiddisks
/ ncopies
* 2;
630 /* printf("bms=%llu as=%d rd=%d nc=%d\n", bitmapsize, size, raiddisks, ncopies);*/
632 bitmapsize
= (unsigned long long)size
* 2;
634 /* There is lots of redundancy in these disk counts,
635 * raid_disks is the most meaningful value
636 * it describes the geometry of the array
638 * nr_disks is total number of used slots.
639 * it should be raid_disks+spare_disks
640 * spare_disks is the number of extra disks present
642 * active_disks is the number of working disks in
643 * active slots. (With raid_disks)
644 * working_disks is the total number of working disks,
646 * failed_disks is the number of disks marked failed
648 * Ideally, the kernel would keep these (except raid_disks)
649 * up-to-date as we ADD_NEW_DISK, but it doesn't (yet).
650 * So for now, we assume that all raid and spare
651 * devices will be given.
653 info
.array
.spare_disks
=sparedisks
;
654 info
.array
.failed_disks
=missing_disks
;
655 info
.array
.nr_disks
= info
.array
.working_disks
656 + info
.array
.failed_disks
;
657 info
.array
.layout
= layout
;
658 info
.array
.chunk_size
= chunk
*1024;
660 if (name
== NULL
|| *name
== 0) {
661 /* base name on mddev */
666 * /dev/md/home -> home
667 * /dev/mdhome -> home
669 /* FIXME compare this with rules in create_mddev */
670 name
= strrchr(mddev
, '/');
673 if (strncmp(name
, "md_d", 4)==0 &&
676 (name
-mddev
) == 5 /* /dev/ */)
678 else if (strncmp(name
, "md", 2)==0 &&
681 (name
-mddev
) == 5 /* /dev/ */)
685 if (!st
->ss
->init_super(st
, &info
.array
, size
, name
, c
->homehost
, uuid
))
688 total_slots
= info
.array
.nr_disks
;
689 st
->ss
->getinfo_super(st
, &info
, NULL
);
690 sysfs_init(&info
, mdfd
, 0);
692 if (did_default
&& c
->verbose
>= 0) {
693 if (is_subarray(info
.text_version
)) {
694 int dnum
= devname2devnum(info
.text_version
+1);
696 int mdp
= get_mdp_major();
699 path
= map_dev(MD_MAJOR
, dnum
, 1);
701 path
= map_dev(mdp
, (-1-dnum
)<< 6, 1);
703 mdi
= sysfs_read(-1, dnum
, GET_VERSION
);
705 pr_err("Creating array inside "
707 mdi
?mdi
->text_version
:"managed", path
);
710 pr_err("Defaulting to version"
711 " %s metadata\n", info
.text_version
);
714 map_update(&map
, fd2devnum(mdfd
), info
.text_version
,
715 info
.uuid
, chosen_name
);
718 if (bitmap_file
&& vers
< 9003) {
719 major_num
= BITMAP_MAJOR_HOSTENDIAN
;
721 pr_err("Warning - bitmaps created on this kernel are not portable\n"
722 " between different architectured. Consider upgrading the Linux kernel.\n");
726 if (bitmap_file
&& strcmp(bitmap_file
, "internal")==0) {
727 if ((vers
%100) < 2) {
728 pr_err("internal bitmaps not supported by this kernel.\n");
731 if (!st
->ss
->add_internal_bitmap
) {
732 pr_err("internal bitmaps not supported with %s metadata\n",
736 if (!st
->ss
->add_internal_bitmap(st
, &bitmap_chunk
,
737 c
->delay
, write_behind
,
738 bitmapsize
, 1, major_num
)) {
739 pr_err("Given bitmap chunk size not supported.\n");
746 sysfs_init(&info
, mdfd
, 0);
748 if (st
->ss
->external
&& st
->container_dev
!= NoMdDev
) {
751 /* When creating a member, we need to be careful
752 * to negotiate with mdmon properly.
753 * If it is already running, we cannot write to
754 * the devices and must ask it to do that part.
755 * If it isn't running, we write to the devices,
757 * We hold an exclusive open on the container
758 * device to make sure mdmon doesn't exit after
759 * we checked that it is running.
761 * For now, fail if it is already running.
763 container_fd
= open_dev_excl(st
->container_dev
);
764 if (container_fd
< 0) {
765 pr_err("Cannot get exclusive "
766 "open on container - weird.\n");
769 if (mdmon_running(st
->container_dev
)) {
771 pr_err("reusing mdmon "
773 devnum2devname(st
->container_dev
));
774 st
->update_tail
= &st
->updates
;
778 rv
= set_array_info(mdfd
, st
, &info
);
780 pr_err("failed to set array info for %s: %s\n",
781 mddev
, strerror(errno
));
788 st
->ss
->uuid_from_super(st
, uuid
);
789 if (CreateBitmap(bitmap_file
, c
->force
, (char*)uuid
, bitmap_chunk
,
790 c
->delay
, write_behind
,
795 bitmap_fd
= open(bitmap_file
, O_RDWR
);
797 pr_err("weird: %s cannot be openned\n",
801 if (ioctl(mdfd
, SET_BITMAP_FILE
, bitmap_fd
) < 0) {
802 pr_err("Cannot set bitmap file for %s: %s\n",
803 mddev
, strerror(errno
));
808 infos
= xmalloc(sizeof(*infos
) * total_slots
);
810 for (pass
=1; pass
<=2 ; pass
++) {
811 struct mddev_dev
*moved_disk
= NULL
; /* the disk that was moved out of the insert point */
813 for (dnum
=0, dv
= devlist
; dv
;
814 dv
=(dv
->next
)?(dv
->next
):moved_disk
, dnum
++) {
817 struct mdinfo
*inf
= &infos
[dnum
];
819 if (dnum
>= total_slots
)
821 if (dnum
== insert_point
) {
825 if (strcasecmp(dv
->devname
, "missing")==0)
829 if (have_container
&& dnum
< info
.array
.raid_disks
- 1)
830 /* repeatedly use the container */
837 inf
->disk
.number
= dnum
;
838 inf
->disk
.raid_disk
= dnum
;
839 if (inf
->disk
.raid_disk
< raiddisks
)
840 inf
->disk
.state
= (1<<MD_DISK_ACTIVE
) |
845 if (dv
->writemostly
== 1)
846 inf
->disk
.state
|= (1<<MD_DISK_WRITEMOSTLY
);
851 if (st
->ss
->external
&&
852 st
->container_dev
!= NoMdDev
)
853 fd
= open(dv
->devname
, O_RDWR
);
855 fd
= open(dv
->devname
, O_RDWR
|O_EXCL
);
858 pr_err("failed to open %s "
859 "after earlier success - aborting\n",
864 inf
->disk
.major
= major(stb
.st_rdev
);
865 inf
->disk
.minor
= minor(stb
.st_rdev
);
868 remove_partitions(fd
);
869 if (st
->ss
->add_to_super(st
, &inf
->disk
,
871 ioctl(mdfd
, STOP_ARRAY
, NULL
);
874 st
->ss
->getinfo_super(st
, inf
, NULL
);
875 safe_mode_delay
= inf
->safe_mode_delay
;
877 if (have_container
&& c
->verbose
> 0)
878 pr_err("Using %s for device %d\n",
879 map_dev(inf
->disk
.major
,
883 if (!have_container
) {
884 /* getinfo_super might have lost these ... */
885 inf
->disk
.major
= major(stb
.st_rdev
);
886 inf
->disk
.minor
= minor(stb
.st_rdev
);
892 rv
= add_disk(mdfd
, st
, &info
, inf
);
895 pr_err("ADD_NEW_DISK for %s "
897 dv
->devname
, strerror(errno
));
902 if (!have_container
&&
903 dv
== moved_disk
&& dnum
!= insert_point
) break;
906 struct mdinfo info_new
;
907 struct map_ent
*me
= NULL
;
909 /* check to see if the uuid has changed due to these
910 * metadata changes, and if so update the member array
911 * and container uuid. Note ->write_init_super clears
912 * the subarray cursor such that ->getinfo_super once
913 * again returns container info.
916 st
->ss
->getinfo_super(st
, &info_new
, NULL
);
917 if (st
->ss
->external
&& level
!= LEVEL_CONTAINER
&&
918 !same_uuid(info_new
.uuid
, info
.uuid
, 0)) {
919 map_update(&map
, fd2devnum(mdfd
),
920 info_new
.text_version
,
921 info_new
.uuid
, chosen_name
);
922 me
= map_by_devnum(&map
, st
->container_dev
);
925 if (st
->ss
->write_init_super(st
)) {
926 st
->ss
->free_super(st
);
930 /* update parent container uuid */
932 char *path
= xstrdup(me
->path
);
934 st
->ss
->getinfo_super(st
, &info_new
, NULL
);
935 map_update(&map
, st
->container_dev
,
936 info_new
.text_version
,
937 info_new
.uuid
, path
);
942 flush_metadata_updates(st
);
943 st
->ss
->free_super(st
);
948 if (level
== LEVEL_CONTAINER
) {
949 /* No need to start. But we should signal udev to
951 sysfs_uevent(&info
, "change");
953 pr_err("container %s prepared.\n", mddev
);
954 wait_for(chosen_name
, mdfd
);
955 } else if (c
->runstop
== 1 || subdevs
>= raiddisks
) {
956 if (st
->ss
->external
) {
960 case LEVEL_MULTIPATH
:
962 err
= sysfs_set_str(&info
, NULL
, "array_state",
969 err
= sysfs_set_str(&info
, NULL
, "array_state",
973 sysfs_set_safemode(&info
, safe_mode_delay
);
976 " activate array.\n");
977 ioctl(mdfd
, STOP_ARRAY
, NULL
);
980 } else if (c
->readonly
&&
981 sysfs_attribute_available(
982 &info
, NULL
, "array_state")) {
983 if (sysfs_set_str(&info
, NULL
,
984 "array_state", "readonly") < 0) {
985 pr_err("Failed to start array: %s\n",
987 ioctl(mdfd
, STOP_ARRAY
, NULL
);
991 /* param is not actually used */
993 if (ioctl(mdfd
, RUN_ARRAY
, ¶m
)) {
994 pr_err("RUN_ARRAY failed: %s\n",
996 if (info
.array
.chunk_size
& (info
.array
.chunk_size
-1)) {
997 cont_err("Problem may be that "
998 "chunk size is not a power of 2\n");
1000 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1004 if (c
->verbose
>= 0)
1005 pr_err("array %s started.\n", mddev
);
1006 if (st
->ss
->external
&& st
->container_dev
!= NoMdDev
) {
1008 start_mdmon(st
->container_dev
);
1010 ping_monitor_by_id(st
->container_dev
);
1011 close(container_fd
);
1013 wait_for(chosen_name
, mdfd
);
1015 pr_err("not starting array - not enough devices.\n");
1023 map_remove(&map
, fd2devnum(mdfd
));