]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - Build.c
2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
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@cse.unsw.edu.au>
24 * School of Computer Science and Engineering
25 * The University of New South Wales
32 #define REGISTER_DEV _IO (MD_MAJOR, 1)
33 #define START_MD _IO (MD_MAJOR, 2)
34 #define STOP_MD _IO (MD_MAJOR, 3)
36 int Build(char *mddev
, int mdfd
, int chunk
, int level
,
40 /* Build a linear or raid0 arrays without superblocks
41 * We cannot really do any checks, we just do it.
42 * For md_version < 0.90.0, we call REGISTER_DEV
43 * with the device numbers, and then
44 * START_MD giving the "geometry"
45 * geometry is 0xpp00cc
46 * where pp is personality: 1==linear, 2=raid0
47 * cc = chunk size factor: 0==4k, 1==8k etc.
49 * For md_version >= 0.90.0 we call
50 * SET_ARRAY_INFO, ADD_NEW_DISK, RUN_ARRAY
59 /* scan all devices, make sure they really are block devices */
60 for (dv
= devlist
; dv
; dv
=dv
->next
) {
61 if (stat(dv
->devname
, &stb
)) {
62 fprintf(stderr
, Name
": Cannot find %s: %s\n",
63 dv
->devname
, strerror(errno
));
66 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
67 fprintf(stderr
, Name
": %s is not a block device.\n",
74 if (raiddisks
!= subdevs
) {
75 fprintf(stderr
, Name
": requested %d devices in array but listed %d\n",
80 vers
= md_get_version(mdfd
);
82 /* looks Ok, go for it */
84 mdu_array_info_t array
;
87 array
.nr_disks
= raiddisks
;
88 array
.raid_disks
= raiddisks
;
90 if (fstat(mdfd
, &stb
)==0)
91 array
.md_minor
= MINOR(stb
.st_rdev
);
92 array
.not_persistent
= 1;
93 array
.state
= 0; /* not clean, but no errors */
94 array
.active_disks
= raiddisks
;
95 array
.working_disks
= raiddisks
;
96 array
.spare_disks
= 0;
97 array
.failed_disks
= 0;
100 array
.chunk_size
= chunk
*1024;
101 if (ioctl(mdfd
, SET_ARRAY_INFO
, &array
)) {
102 fprintf(stderr
, Name
": SET_ARRAY_INFO failed for %s: %s\n",
103 mddev
, strerror(errno
));
107 /* now add the devices */
108 for ((i
=0), (dv
= devlist
) ; dv
; i
++, dv
=dv
->next
) {
109 if (stat(dv
->devname
, &stb
)) {
110 fprintf(stderr
, Name
": Wierd: %s has disappeared.\n",
114 if ((stb
.st_mode
& S_IFMT
)!= S_IFBLK
) {
115 fprintf(stderr
, Name
": Wierd: %s is no longer a block device.\n",
120 mdu_disk_info_t disk
;
124 disk
.major
= MAJOR(stb
.st_rdev
);
125 disk
.minor
= MINOR(stb
.st_rdev
);
126 if (ioctl(mdfd
, ADD_NEW_DISK
, &disk
)) {
127 fprintf(stderr
, Name
": ADD_NEW_DISK failed for %s: %s\n",
128 dv
->devname
, strerror(errno
));
132 if (ioctl(mdfd
, REGISTER_DEV
, &stb
.st_rdev
)) {
133 fprintf(stderr
, Name
": REGISTER_DEV failed for %s: %s.\n",
134 dv
->devname
, strerror(errno
));
139 /* now to start it */
141 mdu_param_t param
; /* not used by syscall */
142 if (ioctl(mdfd
, RUN_ARRAY
, ¶m
)) {
143 fprintf(stderr
, Name
": RUN_ARRAY failed: %s\n",
150 while (chunk
> 4096) {
156 else chunk
|= 0x10000;
157 if (ioctl(mdfd
, START_MD
, arg
)) {
158 fprintf(stderr
, Name
": START_MD failed: %s\n",
163 fprintf(stderr
, Name
": array %s built and started.\n",
169 ioctl(mdfd
, STOP_ARRAY
, 0);
171 ioctl(mdfd
, STOP_MD
, 0);