mdadm-1.0.9
[thirdparty/mdadm.git] / mdadm.c
CommitLineData
64c4757e 1/*
9a9dab36 2 * mdadm - manage Linux "md" devices aka RAID arrays.
64c4757e 3 *
cd29a5c8 4 * Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
64c4757e
NB
5 *
6 *
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.
11 *
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.
16 *
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
20 *
21 * Author: Neil Brown
22 * Email: <neilb@cse.unsw.edu.au>
23 * Paper: Neil Brown
24 * School of Computer Science and Engineering
25 * The University of New South Wales
26 * Sydney, 2052
27 * Australia
28 */
29
9a9dab36 30#include "mdadm.h"
64c4757e
NB
31#include "md_p.h"
32
52826846 33int open_mddev(char *dev)
64c4757e 34{
52826846
NB
35 int mdfd = open(dev, O_RDWR, 0);
36 if (mdfd < 0)
e0d19036 37 fprintf(stderr, Name ": error opening %s: %s\n",
52826846
NB
38 dev, strerror(errno));
39 else if (md_get_version(mdfd) <= 0) {
40 fprintf(stderr, Name ": %s does not appear to be an md device\n",
41 dev);
42 close(mdfd);
43 mdfd = -1;
64c4757e 44 }
52826846
NB
45 return mdfd;
46}
64c4757e 47
64c4757e 48
52826846
NB
49
50int main(int argc, char *argv[])
51{
e0d19036 52 int mode = 0;
52826846 53 int opt;
e0d19036 54 int option_index;
52826846
NB
55 char *help_text;
56 char *c;
57 int rv;
52826846
NB
58
59 int chunk = 0;
60 int size = 0;
61 int level = -10;
62 int layout = -1;
63 int raiddisks = 0;
64 int sparedisks = 0;
65 struct mddev_ident_s ident;
66 char *configfile = NULL;
cd29a5c8 67 char *cp;
5787fa49 68 char *update = NULL;
52826846
NB
69 int scan = 0;
70 char devmode = 0;
71 int runstop = 0;
72 int readonly = 0;
bd526cee 73 int SparcAdjust = 0;
cd29a5c8
NB
74 mddev_dev_t devlist = NULL;
75 mddev_dev_t *devlistend = & devlist;
76 mddev_dev_t dv;
52826846
NB
77 int devs_found = 0;
78 int verbose = 0;
cd29a5c8 79 int brief = 0;
52826846
NB
80 int force = 0;
81
82 char *mailaddr = NULL;
83 char *program = NULL;
84 int delay = 0;
85
86 int mdfd = -1;
87
88 ident.uuid_set=0;
cd29a5c8
NB
89 ident.level = -10;
90 ident.raid_disks = -1;
52826846
NB
91 ident.super_minor= -1;
92 ident.devices=0;
93
e0d19036
NB
94 while ((option_index = -1) ,
95 (opt=getopt_long(argc, argv,
52826846 96 short_options, long_options,
e0d19036
NB
97 &option_index)) != -1) {
98 int newmode = mode;
99 /* firstly, so mode-independant options */
52826846 100 switch(opt) {
52826846
NB
101 case 'h':
102 help_text = Help;
103 switch (mode) {
e0d19036
NB
104 case ASSEMBLE : help_text = Help_assemble; break;
105 case BUILD : help_text = Help_build; break;
106 case CREATE : help_text = Help_create; break;
107 case MANAGE : help_text = Help_manage; break;
108 case MISC : help_text = Help_misc; break;
109 case MONITOR : help_text = Help_monitor; break;
52826846
NB
110 }
111 fputs(help_text,stderr);
112 exit(0);
113
114 case 'V':
115 fputs(Version, stderr);
116 exit(0);
117
118 case 'v': verbose = 1;
119 continue;
120
cd29a5c8
NB
121 case 'b': brief = 1;
122 continue;
123
e0d19036
NB
124 case ':':
125 case '?':
126 fputs(Usage, stderr);
127 exit(2);
128 }
129 /* second, figure out the mode.
130 * Some options force the mode. Others
131 * set the mode if it isn't already
132 */
133
134 switch(opt) {
135 case '@': /* just incase they say --manage */
136 newmode = MANAGE; break;
137 case 'a':
138 case 'r':
139 case 'f':
140 case 1 : if (!mode) newmode = MANAGE; break;
141
142 case 'A': newmode = ASSEMBLE; break;
143 case 'B': newmode = BUILD; break;
144 case 'C': newmode = CREATE; break;
145 case 'F': newmode = MONITOR;break;
146
147 case '#':
148 case 'D':
149 case 'E':
150 case 'Q': newmode = MISC; break;
151 case 'R':
152 case 'S':
153 case 'o':
154 case 'w':
155 case 'K': if (!mode) newmode = MISC; break;
156 }
157 if (mode && newmode == mode) {
158 /* everybody happy ! */
159 } else if (mode && newmode != mode) {
160 /* not allowed.. */
161 fprintf(stderr, Name ": ");
162 if (option_index >= 0)
163 fprintf(stderr, "--%s", long_options[option_index].name);
164 else
165 fprintf(stderr, "-%c", opt);
166 fprintf(stderr, " would set mode to %s, but it is already %s.\n",
167 map_num(modes, newmode),
168 map_num(modes, mode));
169 exit(2);
170 } else if (!mode && newmode) {
171 mode = newmode;
172 } else {
173 /* special case of -c --help */
174 if (opt == 'c' &&
175 ( strncmp(optarg, "--h", 3)==0 ||
176 strncmp(optarg, "-h", 2)==0)) {
177 fputs(Help_config, stderr);
178 exit(0);
cd29a5c8 179 }
e0d19036
NB
180 if (option_index >= 0)
181 fprintf(stderr, "--%s", long_options[option_index].name);
182 else
183 fprintf(stderr, "-%c", opt);
184 fprintf(stderr, " does not set the mode, and so cannot be first.\n");
185 exit(2);
186 }
187
188 /* if we just set the mode, then done */
189 switch(opt) {
190 case '@':
191 case '#':
192 case 'A':
193 case 'B':
194 case 'C':
195 case 'F':
196 continue;
197 }
198 if (opt == 1) {
199 /* an undecorated option - must be a device name.
200 */
cd29a5c8
NB
201 if (devs_found > 0 && mode == '@' && !devmode) {
202 fprintf(stderr, Name ": Must give on of -a/-r/-f for subsequent devices at %s\n", optarg);
52826846
NB
203 exit(2);
204 }
cd29a5c8
NB
205 dv = malloc(sizeof(*dv));
206 if (dv == NULL) {
207 fprintf(stderr, Name ": malloc failed\n");
208 exit(3);
209 }
210 dv->devname = optarg;
211 dv->disposition = devmode;
212 dv->next = NULL;
213 *devlistend = dv;
214 devlistend = &dv->next;
215
52826846
NB
216 devs_found++;
217 continue;
682c7051 218 }
682c7051 219
52826846
NB
220 /* We've got a mode, and opt is now something else which
221 * could depend on the mode */
222#define O(a,b) ((a<<8)|b)
223 switch (O(mode,opt)) {
e0d19036
NB
224 case O(CREATE,'c'):
225 case O(BUILD,'c'): /* chunk or rounding */
52826846
NB
226 if (chunk) {
227 fprintf(stderr, Name ": chunk/rounding may only be specified once. "
228 "Second value is %s.\n", optarg);
229 exit(2);
230 }
231 chunk = strtol(optarg, &c, 10);
232 if (!optarg[0] || *c || chunk<4 || ((chunk-1)&chunk)) {
233 fprintf(stderr, Name ": invalid chunk/rounding value: %s\n",
234 optarg);
235 exit(2);
236 }
237 continue;
64c4757e 238
e0d19036 239 case O(CREATE,'z'): /* size */
52826846
NB
240 if (size) {
241 fprintf(stderr, Name ": size may only be specified once. "
242 "Second value is %s.\n", optarg);
243 exit(2);
244 }
245 size = strtol(optarg, &c, 10);
246 if (!optarg[0] || *c || size < 4) {
247 fprintf(stderr, Name ": invalid size: %s\n",
248 optarg);
249 exit(2);
250 }
251 continue;
64c4757e 252
e0d19036
NB
253 case O(CREATE,'l'):
254 case O(BUILD,'l'): /* set raid level*/
52826846
NB
255 if (level != -10) {
256 fprintf(stderr, Name ": raid level may only be set once. "
257 "Second value is %s.\n", optarg);
258 exit(2);
259 }
260 level = map_name(pers, optarg);
261 if (level == -10) {
262 fprintf(stderr, Name ": invalid raid level: %s\n",
263 optarg);
264 exit(2);
265 }
e0d19036 266 if (level != 0 && level != -1 && mode == BUILD) {
52826846
NB
267 fprintf(stderr, Name ": Raid level %s not permitted with --build.\n",
268 optarg);
269 exit(2);
270 }
e0d19036 271 if (sparedisks > 0 && level < 1 && level >= -1) {
b83d95f3 272 fprintf(stderr, Name ": raid level %s is incompatible with spare-devices setting.\n",
52826846
NB
273 optarg);
274 exit(2);
275 }
cd29a5c8 276 ident.level = level;
52826846 277 continue;
64c4757e 278
e0d19036 279 case O(CREATE,'p'): /* raid5 layout */
52826846
NB
280 if (layout >= 0) {
281 fprintf(stderr,Name ": layout may only be sent once. "
282 "Second value was %s\n", optarg);
283 exit(2);
284 }
285 switch(level) {
286 default:
56eb10c0 287 fprintf(stderr, Name ": layout not meaningful for %s arrays.\n",
52826846
NB
288 map_num(pers, level));
289 exit(2);
290 case -10:
291 fprintf(stderr, Name ": raid level must be given before layout.\n");
292 exit(2);
293
294 case 5:
295 layout = map_name(r5layout, optarg);
296 if (layout==-10) {
297 fprintf(stderr, Name ": layout %s not understood for raid5.\n",
298 optarg);
299 exit(2);
300 }
301 break;
302 }
303 continue;
304
e0d19036
NB
305 case O(CREATE,'n'):
306 case O(BUILD,'n'): /* number of raid disks */
52826846 307 if (raiddisks) {
b83d95f3 308 fprintf(stderr, Name ": raid-devices set twice: %d and %s\n",
52826846
NB
309 raiddisks, optarg);
310 exit(2);
311 }
312 raiddisks = strtol(optarg, &c, 10);
313 if (!optarg[0] || *c || raiddisks<=0 || raiddisks > MD_SB_DISKS) {
b83d95f3 314 fprintf(stderr, Name ": invalid number of raid devices: %s\n",
52826846
NB
315 optarg);
316 exit(2);
317 }
cd29a5c8 318 ident.raid_disks = raiddisks;
52826846
NB
319 continue;
320
e0d19036 321 case O(CREATE,'x'): /* number of spare (eXtra) discs */
52826846 322 if (sparedisks) {
b83d95f3 323 fprintf(stderr,Name ": spare-devices set twice: %d and %s\n",
52826846
NB
324 sparedisks, optarg);
325 exit(2);
326 }
e0d19036 327 if (level > -10 && level <= 0 && level >= -1) {
b83d95f3 328 fprintf(stderr, Name ": spare-devices setting is incompatible with raid level %d\n",
52826846
NB
329 level);
330 exit(2);
331 }
332 sparedisks = strtol(optarg, &c, 10);
333 if (!optarg[0] || *c || sparedisks < 0 || sparedisks > MD_SB_DISKS - raiddisks) {
b83d95f3 334 fprintf(stderr, Name ": invalid number of spare-devices: %s\n",
52826846
NB
335 optarg);
336 exit(2);
337 }
338 continue;
e0d19036
NB
339 case O(CREATE,'f'): /* force honouring of device list */
340 case O(ASSEMBLE,'f'): /* force assembly */
341 case O(MISC,'f'): /* force zero */
52826846
NB
342 force=1;
343 continue;
344
345 /* now for the Assemble options */
e0d19036 346 case O(ASSEMBLE,'u'): /* uuid of array */
52826846 347 if (ident.uuid_set) {
cd29a5c8 348 fprintf(stderr, Name ": uuid cannot be set twice. "
52826846
NB
349 "Second value %s.\n", optarg);
350 exit(2);
351 }
352 if (parse_uuid(optarg, ident.uuid))
353 ident.uuid_set = 1;
354 else {
355 fprintf(stderr,Name ": Bad uuid: %s\n", optarg);
356 exit(2);
357 }
358 continue;
359
e0d19036 360 case O(ASSEMBLE,'m'): /* super-minor for array */
cd29a5c8
NB
361 if (ident.super_minor >= 0) {
362 fprintf(stderr, Name ": super-minor cannot be set twice. "
363 "Second value: %s.\n", optarg);
364 exit(2);
365 }
366 ident.super_minor = strtoul(optarg, &cp, 10);
367 if (!optarg[0] || *cp) {
368 fprintf(stderr, Name ": Bad super-minor number: %s.\n", optarg);
369 exit(2);
370 }
371 continue;
372
5787fa49
NB
373 case O(ASSEMBLE,'U'): /* update the superblock */
374 if (update) {
375 fprintf(stderr, Name ": Can only update one aspect of superblock, both %s and %s given.\n",
376 update, optarg);
377 exit(2);
378 }
379 update = optarg;
380 if (strcmp(update, "sparc2.2")==0) continue;
381 if (strcmp(update, "super-minor") == 0)
382 continue;
383 fprintf(stderr, Name ": '--update %s' invalid. Only 'sparc2.2' or 'super-minor' supported\n",update);
384 exit(2);
385
e0d19036 386 case O(ASSEMBLE,'c'): /* config file */
2d465520 387 case O(MISC, 'c'):
e0d19036 388 case O(MONITOR,'c'):
52826846
NB
389 if (configfile) {
390 fprintf(stderr, Name ": configfile cannot be set twice. "
391 "Second value is %s.\n", optarg);
392 exit(2);
393 }
394 configfile = optarg;
395 /* FIXME possibly check that config file exists. Even parse it */
396 continue;
e0d19036
NB
397 case O(ASSEMBLE,'s'): /* scan */
398 case O(MISC,'s'):
399 case O(MONITOR,'s'):
52826846
NB
400 scan = 1;
401 continue;
402
e0d19036 403 case O(MONITOR,'m'): /* mail address */
52826846
NB
404 if (mailaddr)
405 fprintf(stderr, Name ": only specify one mailaddress. %s ignored.\n",
406 optarg);
407 else
408 mailaddr = optarg;
409 continue;
410
e0d19036 411 case O(MONITOR,'p'): /* alert program */
52826846
NB
412 if (program)
413 fprintf(stderr, Name ": only specify one alter program. %s ignored.\n",
414 optarg);
415 else
416 program = optarg;
417 continue;
64c4757e 418
e0d19036 419 case O(MONITOR,'d'): /* delay in seconds */
52826846
NB
420 if (delay)
421 fprintf(stderr, Name ": only specify delay once. %s ignored.\n",
422 optarg);
423 else {
424 delay = strtol(optarg, &c, 10);
425 if (!optarg[0] || *c || delay<1) {
426 fprintf(stderr, Name ": invalid delay: %s\n",
427 optarg);
428 exit(2);
429 }
430 }
431 continue;
432
433
434 /* now the general management options. Some are applicable
435 * to other modes. None have arguments.
436 */
e0d19036
NB
437 case O(MANAGE,'a'):
438 case O(CREATE,'a'):
439 case O(BUILD,'a'):
440 case O(ASSEMBLE,'a'): /* add a drive */
52826846
NB
441 devmode = 'a';
442 continue;
e0d19036 443 case O(MANAGE,'r'): /* remove a drive */
52826846
NB
444 devmode = 'r';
445 continue;
e0d19036 446 case O(MANAGE,'f'): /* set faulty */
52826846
NB
447 devmode = 'f';
448 continue;
e0d19036
NB
449 case O(MANAGE,'R'):
450 case O(ASSEMBLE,'R'):
451 case O(BUILD,'R'):
452 case O(CREATE,'R'): /* Run the array */
52826846
NB
453 if (runstop < 0) {
454 fprintf(stderr, Name ": Cannot both Stop and Run an array\n");
455 exit(2);
456 }
457 runstop = 1;
458 continue;
e0d19036 459 case O(MANAGE,'S'):
52826846
NB
460 if (runstop > 0) {
461 fprintf(stderr, Name ": Cannot both Run and Stop an array\n");
462 exit(2);
463 }
464 runstop = -1;
465 continue;
466
e0d19036 467 case O(MANAGE,'o'):
52826846
NB
468 if (readonly < 0) {
469 fprintf(stderr, Name ": Cannot have both readonly and readwrite\n");
470 exit(2);
471 }
472 readonly = 1;
473 continue;
e0d19036 474 case O(MANAGE,'w'):
52826846 475 if (readonly > 0) {
e0d19036 476 fprintf(stderr, Name ": Cannot have both readwrite and readonly.\n");
52826846
NB
477 exit(2);
478 }
479 readonly = -1;
480 continue;
e0d19036
NB
481
482 case O(MISC,'Q'):
483 case O(MISC,'D'):
484 case O(MISC,'E'):
485 case O(MISC,'K'):
486 case O(MISC,'R'):
487 case O(MISC,'S'):
488 case O(MISC,'o'):
489 case O(MISC,'w'):
490 if (devmode && devmode != opt &&
491 (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) {
492 fprintf(stderr, Name ": --examine/-E cannot be given with -%c\n",
493 devmode =='E'?opt:devmode);
494 exit(2);
495 }
496 devmode = opt;
497 continue;
498
bd526cee
NB
499 case O(MISC, 22):
500 if (devmode != 'E') {
501 fprintf(stderr, Name ": --sparc2.2 only allowed with --examine\n");
502 exit(2);
503 }
504 SparcAdjust = 1;
505 continue;
52826846
NB
506 }
507 /* We have now processed all the valid options. Anything else is
508 * an error
509 */
e0d19036
NB
510 fprintf(stderr, Name ": option %c not valid in %s mode\n",
511 opt, map_num(modes, mode));
64c4757e 512 exit(2);
52826846
NB
513
514 }
515
516 if (!mode) {
517 fputs(Usage, stderr);
64c4757e 518 exit(2);
64c4757e 519 }
52826846
NB
520 /* Ok, got the option parsing out of the way
521 * hopefully it's mostly right but there might be some stuff
522 * missing
523 *
e0d19036 524 * That is mosty checked in the per-mode stuff but...
52826846
NB
525 *
526 * For @,B,C and A without -s, the first device listed must be an md device
527 * we check that here and open it.
64c4757e 528 */
52826846 529
e0d19036 530 if (mode==MANAGE || mode == BUILD || mode == CREATE || (mode == ASSEMBLE && ! scan)) {
52826846
NB
531 if (devs_found < 1) {
532 fprintf(stderr, Name ": an md device must be given in this mode\n");
533 exit(2);
534 }
cd29a5c8 535 mdfd = open_mddev(devlist->devname);
52826846
NB
536 if (mdfd < 0)
537 exit(1);
64c4757e 538 }
52826846 539
52826846
NB
540 rv = 0;
541 switch(mode) {
e0d19036 542 case MANAGE:
52826846
NB
543 /* readonly, add/remove, readwrite, runstop */
544 if (readonly>0)
cd29a5c8 545 rv = Manage_ro(devlist->devname, mdfd, readonly);
52826846 546 if (!rv && devs_found>1)
cd29a5c8
NB
547 rv = Manage_subdevs(devlist->devname, mdfd,
548 devlist->next);
52826846 549 if (!rv && readonly < 0)
cd29a5c8 550 rv = Manage_ro(devlist->devname, mdfd, readonly);
52826846 551 if (!rv && runstop)
cd29a5c8 552 rv = Manage_runstop(devlist->devname, mdfd, runstop);
52826846 553 break;
e0d19036 554 case ASSEMBLE:
52826846 555 if (!scan)
cd29a5c8
NB
556 rv = Assemble(devlist->devname, mdfd, &ident, configfile,
557 devlist->next,
5787fa49
NB
558 readonly, runstop, update, verbose, force);
559 else if (devs_found>0) {
560 if (update && devs_found > 1) {
561 fprintf(stderr, Name ": can only update a single array at a time\n");
562 exit(1);
563 }
cd29a5c8
NB
564 for (dv = devlist ; dv ; dv=dv->next) {
565 mddev_ident_t array_ident = conf_get_ident(configfile, dv->devname);
566 mdfd = open_mddev(dv->devname);
52826846
NB
567 if (mdfd < 0) {
568 rv |= 1;
569 continue;
570 }
571 if (array_ident == NULL) {
572 fprintf(stderr, Name ": %s not identified in config file.\n",
cd29a5c8 573 dv->devname);
52826846
NB
574 rv |= 1;
575 continue;
576 }
cd29a5c8
NB
577 rv |= Assemble(dv->devname, mdfd, array_ident, configfile,
578 NULL,
5787fa49 579 readonly, runstop, update, verbose, force);
52826846 580 }
5787fa49 581 } else {
52826846
NB
582 mddev_ident_t array_list = conf_get_ident(configfile, NULL);
583 if (!array_list) {
584 fprintf(stderr, Name ": No arrays found in config file\n");
585 rv = 1;
586 } else
587 for (; array_list; array_list = array_list->next) {
cd29a5c8 588 mdu_array_info_t array;
52826846
NB
589 mdfd = open_mddev(array_list->devname);
590 if (mdfd < 0) {
591 rv |= 1;
592 continue;
593 }
cd29a5c8
NB
594 if (ioctl(mdfd, GET_ARRAY_INFO, &array)>=0)
595 /* already assembled, skip */
596 continue;
52826846
NB
597 rv |= Assemble(array_list->devname, mdfd,
598 array_list, configfile,
cd29a5c8 599 NULL,
5787fa49 600 readonly, runstop, NULL, verbose, force);
52826846
NB
601 }
602 }
603 break;
e0d19036 604 case BUILD:
cd29a5c8 605 rv = Build(devlist->devname, mdfd, chunk, level, raiddisks, devlist->next);
52826846 606 break;
e0d19036 607 case CREATE:
cd29a5c8 608 rv = Create(devlist->devname, mdfd, chunk, level, layout, size,
52826846 609 raiddisks, sparedisks,
cd29a5c8 610 devs_found-1, devlist->next, runstop, verbose, force);
52826846 611 break;
e0d19036
NB
612 case MISC:
613
614 if (devmode == 'E') {
615 if (devlist == NULL && !scan) {
616 fprintf(stderr, Name ": No devices to examine\n");
617 exit(2);
618 }
619 if (devlist == NULL)
620 devlist = conf_get_devs(configfile);
621 if (devlist == NULL) {
c913b90e 622 fprintf(stderr, Name ": No devices listed in %s\n", configfile?configfile:DefaultConfFile);
e0d19036
NB
623 exit(1);
624 }
bd526cee 625 rv = Examine(devlist, scan?!verbose:brief, scan, SparcAdjust);
e0d19036
NB
626 } else {
627 if (devlist == NULL) {
628 if ((devmode == 'S' ||devmode=='D') && scan) {
629 /* apply to all devices in /proc/mdstat */
630 struct mdstat_ent *ms = mdstat_read();
631 struct mdstat_ent *e;
632 for (e=ms ; e ; e=e->next) {
633 char *name = get_md_name(e->devnum);
634
635 if (!name) {
636 fprintf(stderr, Name ": cannot find device file for %s\n",
637 e->dev);
638 continue;
639 }
640 if (devmode == 'D')
641 rv |= Detail(name, !verbose);
642 else if (devmode=='S') {
643 mdfd = open_mddev(name);
644 if (mdfd >= 0)
645 rv |= Manage_runstop(name, mdfd, -1);
646 }
647 put_md_name(name);
648 }
649 } else {
650 fprintf(stderr, Name ": No devices given.\n");
651 exit(2);
652 }
653 }
654 for (dv=devlist ; dv; dv=dv->next) {
655 switch(dv->disposition) {
656 case 'D':
657 rv |= Detail(dv->devname, brief); continue;
658 case 'K': /* Zero superblock */
659 rv |= Kill(dv->devname, force); continue;
660 case 'Q':
661 rv |= Query(dv->devname); continue;
662 }
663 mdfd = open_mddev(dv->devname);
664 if (mdfd>=0)
665 switch(dv->disposition) {
666 case 'R':
667 rv |= Manage_runstop(dv->devname, mdfd, 1); break;
668 case 'S':
669 rv |= Manage_runstop(dv->devname, mdfd, -1); break;
670 case 'o':
671 rv |= Manage_ro(dv->devname, mdfd, 1); break;
672 case 'w':
673 rv |= Manage_ro(dv->devname, mdfd, -1); break;
674 }
675 }
cd29a5c8 676 }
9a9dab36 677 break;
e0d19036
NB
678 case MONITOR:
679/*
680 if (!devlist && !scan) {
681 fprintf(stderr, Name ": Cannot monitor: need --scan or at least one device\n");
682 rv = 1;
683 break;
684 }
685*/ rv= Monitor(devlist, mailaddr, program,
686 delay?delay:60, scan, configfile);
9a9dab36 687 break;
64c4757e 688 }
52826846 689 exit(rv);
64c4757e 690}