]>
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 int Manage_ro(char *devname
, int fd
, int readonly
)
36 /* switch to readonly or rw
39 * first check that array is runing
40 * use RESTART_ARRAY_RW or STOP_ARRAY_RO
43 mdu_array_info_t array
;
45 if (md_get_version(fd
) < 9000) {
46 fprintf(stderr
, Name
": need md driver version 0.90.0 or later\n");
49 if (ioctl(fd
, GET_ARRAY_INFO
, &array
)) {
50 fprintf(stderr
, Name
": %s does not appear to be active.\n",
56 if (ioctl(fd
, STOP_ARRAY_RO
, NULL
)) {
57 fprintf(stderr
, Name
": failed to set readonly for %s: %s\n",
58 devname
, strerror(errno
));
61 } else if (readonly
< 0) {
62 if (ioctl(fd
, RESTART_ARRAY_RW
, NULL
)) {
63 fprintf(stderr
, Name
": fail to re writable for %s: %s\n",
64 devname
, strerror(errno
));
71 int Manage_runstop(char *devname
, int fd
, int runstop
)
73 /* Run or stop the array. array must already be configured
76 mdu_array_info_t array
;
77 mdu_param_t param
; /* unused */
79 if (md_get_version(fd
) < 9000) {
80 fprintf(stderr
, Name
": need md driver version 0.90.0 or later\n");
83 if (ioctl(fd
, GET_ARRAY_INFO
, &array
)) {
84 fprintf(stderr
, Name
": %s does not appear to be active.\n",
90 if (ioctl(fd
, RUN_ARRAY
, ¶m
)) {
91 fprintf(stderr
, Name
": failed to run array %s: %s\n",
92 devname
, strerror(errno
));
95 } else if (runstop
< 0){
96 if (ioctl(fd
, STOP_ARRAY
, NULL
)) {
97 fprintf(stderr
, Name
": fail to re writable for %s: %s\n",
98 devname
, strerror(errno
));
105 int Manage_subdevs(char *devname
, int fd
,
106 int devcnt
, char *devnames
[], int devmodes
[])
108 /* do something to each dev.
110 * 'a' - add the device
112 * If that fails EINVAL, try ADD_NEW_DISK
113 * 'r' - remove the device HOT_REMOVE_DISK
114 * 'f' - set the device faulty SET_DISK_FAULTY
116 mdu_array_info_t array
;
117 mdu_disk_info_t disc
;
121 if (ioctl(fd
, GET_ARRAY_INFO
, &array
)) {
122 fprintf(stderr
, Name
": cannot get array info for %s\n",
126 for (i
=0 ; i
<devcnt
; i
++) {
127 if (stat(devnames
[i
], &stb
)) {
128 fprintf(stderr
, Name
": cannot find %s: %s\n",
129 devnames
[i
], strerror(errno
));
132 if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
133 fprintf(stderr
, Name
": %s is not a block device.\n",
139 fprintf(stderr
, Name
": internal error - devmode[%d]=%d\n",
143 /* add the device - hot or cold */
144 if (ioctl(fd
, HOT_ADD_DISK
, stb
.st_rdev
)==0) {
145 fprintf(stderr
, Name
": hot added %s\n",
150 * we might be creating, we might be assembling,
151 * it is hard to tell.
152 * set up number/raid_disk/state just
155 for (j
=0; j
<array
.nr_disks
; j
++) {
156 if (ioctl(fd
, GET_DISK_INFO
, &disc
))
158 if (disc
.major
==0 && disc
.minor
==0)
160 if (disc
.state
& 8) /* removed */
166 disc
.major
= MAJOR(stb
.st_rdev
);
167 disc
.minor
= MINOR(stb
.st_rdev
);
168 if (ioctl(fd
,ADD_NEW_DISK
, &disc
)) {
169 fprintf(stderr
, Name
": add new disk failed for %s: %s\n",
170 devnames
[i
], strerror(errno
));
173 fprintf(stderr
, Name
": added %s\n", devnames
[i
]);
178 /* FIXME check that is is a current member */
179 if (ioctl(fd
, HOT_REMOVE_DISK
, stb
.st_rdev
)) {
180 fprintf(stderr
, Name
": hot remove failed for %s: %s\n",
181 devnames
[i
], strerror(errno
));
184 fprintf(stderr
, Name
": hot removed %s\n", devnames
[i
]);
187 case 'f': /* set faulty */
188 /* FIXME check current member */
189 if (ioctl(fd
, SET_DISK_FAULTY
, stb
.st_rdev
)) {
190 fprintf(stderr
, Name
": set disk faulty failed for %s: %s\n",
191 devnames
[i
], strerror(errno
));
194 fprintf(stderr
, Name
": set %s faulty in %s\n",
195 devnames
[i
], devname
);