]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - Manage.c
2 * mdctl - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001 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
34 #define REGISTER_DEV _IO (MD_MAJOR, 1)
35 #define START_MD _IO (MD_MAJOR, 2)
36 #define STOP_MD _IO (MD_MAJOR, 3)
38 int Manage_ro(char *devname
, int fd
, int readonly
)
40 /* switch to readonly or rw
43 * first check that array is runing
44 * use RESTART_ARRAY_RW or STOP_ARRAY_RO
47 mdu_array_info_t array
;
49 if (md_get_version(fd
) < 9000) {
50 fprintf(stderr
, Name
": need md driver version 0.90.0 or later\n");
53 if (ioctl(fd
, GET_ARRAY_INFO
, &array
)) {
54 fprintf(stderr
, Name
": %s does not appear to be active.\n",
60 if (ioctl(fd
, STOP_ARRAY_RO
, NULL
)) {
61 fprintf(stderr
, Name
": failed to set readonly for %s: %s\n",
62 devname
, strerror(errno
));
65 } else if (readonly
< 0) {
66 if (ioctl(fd
, RESTART_ARRAY_RW
, NULL
)) {
67 fprintf(stderr
, Name
": failed to set writable for %s: %s\n",
68 devname
, strerror(errno
));
75 int Manage_runstop(char *devname
, int fd
, int runstop
)
77 /* Run or stop the array. array must already be configured
80 mdu_array_info_t array
;
81 mdu_param_t param
; /* unused */
83 if (runstop
== -1 && md_get_version(fd
) < 9000) {
84 if (ioctl(fd
, STOP_MD
, 0)) {
85 fprintf(stderr
, Name
": stopping device %s failed: %s\n",
86 devname
, strerror(errno
));
91 if (md_get_version(fd
) < 9000) {
92 fprintf(stderr
, Name
": need md driver version 0.90.0 or later\n");
96 if (ioctl(fd, GET_ARRAY_INFO, &array)) {
97 fprintf(stderr, Name ": %s does not appear to be active.\n",
103 if (ioctl(fd
, RUN_ARRAY
, ¶m
)) {
104 fprintf(stderr
, Name
": failed to run array %s: %s\n",
105 devname
, strerror(errno
));
108 } else if (runstop
< 0){
109 if (ioctl(fd
, STOP_ARRAY
, NULL
)) {
110 fprintf(stderr
, Name
": fail to re writable for %s: %s\n",
111 devname
, strerror(errno
));
118 int Manage_subdevs(char *devname
, int fd
,
119 int devcnt
, char *devnames
[], int devmodes
[])
121 /* do something to each dev.
123 * 'a' - add the device
125 * If that fails EINVAL, try ADD_NEW_DISK
126 * 'r' - remove the device HOT_REMOVE_DISK
127 * 'f' - set the device faulty SET_DISK_FAULTY
129 mdu_array_info_t array
;
130 mdu_disk_info_t disc
;
134 if (ioctl(fd
, GET_ARRAY_INFO
, &array
)) {
135 fprintf(stderr
, Name
": cannot get array info for %s\n",
139 for (i
=0 ; i
<devcnt
; i
++) {
140 if (stat(devnames
[i
], &stb
)) {
141 fprintf(stderr
, Name
": cannot find %s: %s\n",
142 devnames
[i
], strerror(errno
));
145 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
146 fprintf(stderr
, Name
": %s is not a block device.\n",
152 fprintf(stderr
, Name
": internal error - devmode[%d]=%d\n",
156 /* add the device - hot or cold */
157 if (ioctl(fd
, HOT_ADD_DISK
, stb
.st_rdev
)==0) {
158 fprintf(stderr
, Name
": hot added %s\n",
163 * we might be creating, we might be assembling,
164 * it is hard to tell.
165 * set up number/raid_disk/state just
168 for (j
=0; j
<array
.nr_disks
; j
++) {
169 if (ioctl(fd
, GET_DISK_INFO
, &disc
))
171 if (disc
.major
==0 && disc
.minor
==0)
173 if (disc
.state
& 8) /* removed */
179 disc
.major
= MAJOR(stb
.st_rdev
);
180 disc
.minor
= MINOR(stb
.st_rdev
);
181 if (ioctl(fd
,ADD_NEW_DISK
, &disc
)) {
182 fprintf(stderr
, Name
": add new disk failed for %s: %s\n",
183 devnames
[i
], strerror(errno
));
186 fprintf(stderr
, Name
": added %s\n", devnames
[i
]);
191 /* FIXME check that it is a current member */
192 if (ioctl(fd
, HOT_REMOVE_DISK
, stb
.st_rdev
)) {
193 fprintf(stderr
, Name
": hot remove failed for %s: %s\n",
194 devnames
[i
], strerror(errno
));
197 fprintf(stderr
, Name
": hot removed %s\n", devnames
[i
]);
200 case 'f': /* set faulty */
201 /* FIXME check current member */
202 if (ioctl(fd
, SET_DISK_FAULTY
, stb
.st_rdev
)) {
203 fprintf(stderr
, Name
": set disk faulty failed for %s: %s\n",
204 devnames
[i
], strerror(errno
));
207 fprintf(stderr
, Name
": set %s faulty in %s\n",
208 devnames
[i
], devname
);