forked from neilbrown/mdadm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdadm.c
1842 lines (1739 loc) · 45.6 KB
/
mdadm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* mdadm - manage Linux "md" devices aka RAID arrays.
*
* Copyright (C) 2001-2013 Neil Brown <neilb@suse.de>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Neil Brown
* Email: <neilb@suse.de>
*
* Additions for bitmap and write-behind RAID options, Copyright (C) 2003-2004,
* Paul Clements, SteelEye Technology, Inc.
*/
#include "mdadm.h"
#include "md_p.h"
#include <ctype.h>
static int scan_assemble(struct supertype *ss,
struct context *c,
struct mddev_ident *ident);
static int misc_scan(char devmode, struct context *c);
static int stop_scan(int verbose);
static int misc_list(struct mddev_dev *devlist,
struct mddev_ident *ident,
char *dump_directory,
struct supertype *ss, struct context *c);
const char Name[] = "mdadm";
int main(int argc, char *argv[])
{
int mode = 0;
int opt;
int option_index;
int rv;
int i;
unsigned long long array_size = 0;
unsigned long long data_offset = INVALID_SECTORS;
struct mddev_ident ident;
char *configfile = NULL;
int devmode = 0;
int bitmap_fd = -1;
struct mddev_dev *devlist = NULL;
struct mddev_dev **devlistend = & devlist;
struct mddev_dev *dv;
int devs_found = 0;
char *symlinks = NULL;
int grow_continue = 0;
/* autof indicates whether and how to create device node.
* bottom 3 bits are style. Rest (when shifted) are number of parts
* 0 - unset
* 1 - don't create (no)
* 2 - if is_standard, then create (yes)
* 3 - create as 'md' - reject is_standard mdp (md)
* 4 - create as 'mdp' - reject is_standard md (mdp)
* 5 - default to md if not is_standard (md in config file)
* 6 - default to mdp if not is_standard (part, or mdp in config file)
*/
struct context c = {
.require_homehost = 1,
};
struct shape s = {
.level = UnSet,
.layout = UnSet,
.bitmap_chunk = UnSet,
};
char sys_hostname[256];
char *mailaddr = NULL;
char *program = NULL;
int increments = 20;
int daemonise = 0;
char *pidfile = NULL;
int oneshot = 0;
int spare_sharing = 1;
struct supertype *ss = NULL;
int writemostly = 0;
char *shortopt = short_options;
int dosyslog = 0;
int rebuild_map = 0;
char *remove_path = NULL;
char *udev_filename = NULL;
char *dump_directory = NULL;
int print_help = 0;
FILE *outf;
int mdfd = -1;
srandom(time(0) ^ getpid());
ident.uuid_set=0;
ident.level = UnSet;
ident.raid_disks = UnSet;
ident.super_minor= UnSet;
ident.devices=0;
ident.spare_group = NULL;
ident.autof = 0;
ident.st = NULL;
ident.bitmap_fd = -1;
ident.bitmap_file = NULL;
ident.name[0] = 0;
ident.container = NULL;
ident.member = NULL;
while ((option_index = -1) ,
(opt=getopt_long(argc, argv,
shortopt, long_options,
&option_index)) != -1) {
int newmode = mode;
/* firstly, some mode-independent options */
switch(opt) {
case HelpOptions:
print_help = 2;
continue;
case 'h':
print_help = 1;
continue;
case 'V':
fputs(Version, stderr);
exit(0);
case 'v': c.verbose++;
continue;
case 'q': c.verbose--;
continue;
case 'b':
if (mode == ASSEMBLE || mode == BUILD || mode == CREATE
|| mode == GROW || mode == INCREMENTAL
|| mode == MANAGE)
break; /* b means bitmap */
case Brief:
c.brief = 1;
continue;
case 'Y': c.export++;
continue;
case HomeHost:
if (strcasecmp(optarg, "<ignore>") == 0)
c.require_homehost = 0;
else
c.homehost = optarg;
continue;
case OffRootOpt:
/* Silently ignore old option */
continue;
case Prefer:
if (c.prefer)
free(c.prefer);
if (asprintf(&c.prefer, "/%s/", optarg) <= 0)
c.prefer = NULL;
continue;
case ':':
case '?':
fputs(Usage, stderr);
exit(2);
}
/* second, figure out the mode.
* Some options force the mode. Others
* set the mode if it isn't already
*/
switch(opt) {
case ManageOpt:
newmode = MANAGE;
shortopt = short_bitmap_options;
break;
case 'a':
case Add:
case AddSpare:
case 'r':
case Remove:
case Replace:
case With:
case 'f':
case Fail:
case ReAdd: /* re-add */
if (!mode) {
newmode = MANAGE;
shortopt = short_bitmap_options;
}
break;
case 'A': newmode = ASSEMBLE;
shortopt = short_bitmap_auto_options;
break;
case 'B': newmode = BUILD;
shortopt = short_bitmap_auto_options;
break;
case 'C': newmode = CREATE;
shortopt = short_bitmap_auto_options;
break;
case 'F': newmode = MONITOR;
break;
case 'G': newmode = GROW;
shortopt = short_bitmap_options;
break;
case 'I': newmode = INCREMENTAL;
shortopt = short_bitmap_auto_options;
break;
case AutoDetect:
newmode = AUTODETECT;
break;
case MiscOpt:
case 'D':
case 'E':
case 'X':
case 'Q':
case ExamineBB:
case Dump:
case Restore:
case Action:
newmode = MISC;
break;
case 'R':
case 'S':
case 'o':
case 'w':
case 'W':
case WaitOpt:
case Waitclean:
case DetailPlatform:
case KillSubarray:
case UpdateSubarray:
case UdevRules:
case KillOpt:
if (!mode)
newmode = MISC;
break;
case NoSharing:
newmode = MONITOR;
break;
}
if (mode && newmode == mode) {
/* everybody happy ! */
} else if (mode && newmode != mode) {
/* not allowed.. */
pr_err("");
if (option_index >= 0)
fprintf(stderr, "--%s", long_options[option_index].name);
else
fprintf(stderr, "-%c", opt);
fprintf(stderr, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
map_num(modes, newmode),
map_num(modes, mode));
exit(2);
} else if (!mode && newmode) {
mode = newmode;
if (mode == MISC && devs_found) {
pr_err("No action given for %s in --misc mode\n",
devlist->devname);
cont_err("Action options must come before device names\n");
exit(2);
}
} else {
/* special case of -c --help */
if ((opt == 'c' || opt == ConfigFile) &&
( strncmp(optarg, "--h", 3)==0 ||
strncmp(optarg, "-h", 2)==0)) {
fputs(Help_config, stdout);
exit(0);
}
/* If first option is a device, don't force the mode yet */
if (opt == 1) {
if (devs_found == 0) {
dv = xmalloc(sizeof(*dv));
dv->devname = optarg;
dv->disposition = devmode;
dv->writemostly = writemostly;
dv->used = 0;
dv->next = NULL;
*devlistend = dv;
devlistend = &dv->next;
devs_found++;
continue;
}
/* No mode yet, and this is the second device ... */
pr_err("An option must be given to set the mode before a second device\n"
" (%s) is listed\n", optarg);
exit(2);
}
if (option_index >= 0)
pr_err("--%s", long_options[option_index].name);
else
pr_err("-%c", opt);
fprintf(stderr, " does not set the mode, and so cannot be the first option.\n");
exit(2);
}
/* if we just set the mode, then done */
switch(opt) {
case ManageOpt:
case MiscOpt:
case 'A':
case 'B':
case 'C':
case 'F':
case 'G':
case 'I':
case AutoDetect:
continue;
}
if (opt == 1) {
/* an undecorated option - must be a device name.
*/
if (devs_found > 0 && devmode == DetailPlatform) {
pr_err("controller may only be specified once. %s ignored\n",
optarg);
continue;
}
if (devs_found > 0 && mode == MANAGE && !devmode) {
pr_err("Must give one of -a/-r/-f for subsequent devices at %s\n", optarg);
exit(2);
}
if (devs_found > 0 && mode == GROW && !devmode) {
pr_err("Must give -a/--add for devices to add: %s\n", optarg);
exit(2);
}
dv = xmalloc(sizeof(*dv));
dv->devname = optarg;
dv->disposition = devmode;
dv->writemostly = writemostly;
dv->used = 0;
dv->next = NULL;
*devlistend = dv;
devlistend = &dv->next;
devs_found++;
continue;
}
/* We've got a mode, and opt is now something else which
* could depend on the mode */
#define O(a,b) ((a<<16)|b)
switch (O(mode,opt)) {
case O(GROW,'c'):
case O(GROW,ChunkSize):
case O(CREATE,'c'):
case O(CREATE,ChunkSize):
case O(BUILD,'c'): /* chunk or rounding */
case O(BUILD,ChunkSize): /* chunk or rounding */
if (s.chunk) {
pr_err("chunk/rounding may only be specified once. Second value is %s.\n", optarg);
exit(2);
}
s.chunk = parse_size(optarg);
if (s.chunk == INVALID_SECTORS ||
s.chunk < 8 || (s.chunk&1)) {
pr_err("invalid chunk/rounding value: %s\n",
optarg);
exit(2);
}
/* Convert sectors to K */
s.chunk /= 2;
continue;
case O(INCREMENTAL, 'e'):
case O(CREATE,'e'):
case O(ASSEMBLE,'e'):
case O(MISC,'e'): /* set metadata (superblock) information */
if (ss) {
pr_err("metadata information already given\n");
exit(2);
}
for(i=0; !ss && superlist[i]; i++)
ss = superlist[i]->match_metadata_desc(optarg);
if (!ss) {
pr_err("unrecognised metadata identifier: %s\n", optarg);
exit(2);
}
continue;
case O(MANAGE,'W'):
case O(MANAGE,WriteMostly):
case O(BUILD,'W'):
case O(BUILD,WriteMostly):
case O(CREATE,'W'):
case O(CREATE,WriteMostly):
/* set write-mostly for following devices */
writemostly = 1;
continue;
case O(MANAGE,'w'):
/* clear write-mostly for following devices */
writemostly = 2;
continue;
case O(GROW,'z'):
case O(CREATE,'z'):
case O(BUILD,'z'): /* size */
if (s.size > 0) {
pr_err("size may only be specified once. Second value is %s.\n", optarg);
exit(2);
}
if (strcmp(optarg, "max")==0)
s.size = MAX_SIZE;
else {
s.size = parse_size(optarg);
if (s.size == INVALID_SECTORS ||
s.size < 8) {
pr_err("invalid size: %s\n",
optarg);
exit(2);
}
/* convert sectors to K */
s.size /= 2;
}
continue;
case O(GROW,'Z'): /* array size */
if (array_size > 0) {
pr_err("array-size may only be specified once. Second value is %s.\n", optarg);
exit(2);
}
if (strcmp(optarg, "max") == 0)
array_size = MAX_SIZE;
else {
array_size = parse_size(optarg);
if (array_size == 0 ||
array_size == INVALID_SECTORS) {
pr_err("invalid array size: %s\n",
optarg);
exit(2);
}
}
continue;
case O(CREATE,DataOffset):
case O(GROW,DataOffset):
if (data_offset != INVALID_SECTORS) {
pr_err("data-offset may only be specified one. Second value is %s.\n", optarg);
exit(2);
}
if (mode == CREATE &&
strcmp(optarg, "variable") == 0)
data_offset = VARIABLE_OFFSET;
else
data_offset = parse_size(optarg);
if (data_offset == INVALID_SECTORS) {
pr_err("invalid data-offset: %s\n",
optarg);
exit(2);
}
continue;
case O(GROW,'l'):
case O(CREATE,'l'):
case O(BUILD,'l'): /* set raid level*/
if (s.level != UnSet) {
pr_err("raid level may only be set once. Second value is %s.\n", optarg);
exit(2);
}
s.level = map_name(pers, optarg);
if (s.level == UnSet) {
pr_err("invalid raid level: %s\n",
optarg);
exit(2);
}
if (s.level != 0 && s.level != LEVEL_LINEAR && s.level != 1 &&
s.level != LEVEL_MULTIPATH && s.level != LEVEL_FAULTY &&
s.level != 10 &&
mode == BUILD) {
pr_err("Raid level %s not permitted with --build.\n",
optarg);
exit(2);
}
if (s.sparedisks > 0 && s.level < 1 && s.level >= -1) {
pr_err("raid level %s is incompatible with spare-devices setting.\n",
optarg);
exit(2);
}
ident.level = s.level;
continue;
case O(GROW, 'p'): /* new layout */
case O(GROW, Layout):
if (s.layout_str) {
pr_err("layout may only be sent once. Second value was %s\n", optarg);
exit(2);
}
s.layout_str = optarg;
/* 'Grow' will parse the value */
continue;
case O(CREATE,'p'): /* raid5 layout */
case O(CREATE,Layout):
case O(BUILD,'p'): /* faulty layout */
case O(BUILD,Layout):
if (s.layout != UnSet) {
pr_err("layout may only be sent once. Second value was %s\n", optarg);
exit(2);
}
switch(s.level) {
default:
pr_err("layout not meaningful for %s arrays.\n",
map_num(pers, s.level));
exit(2);
case UnSet:
pr_err("raid level must be given before layout.\n");
exit(2);
case 5:
s.layout = map_name(r5layout, optarg);
if (s.layout==UnSet) {
pr_err("layout %s not understood for raid5.\n",
optarg);
exit(2);
}
break;
case 6:
s.layout = map_name(r6layout, optarg);
if (s.layout==UnSet) {
pr_err("layout %s not understood for raid6.\n",
optarg);
exit(2);
}
break;
case 10:
s.layout = parse_layout_10(optarg);
if (s.layout < 0) {
pr_err("layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg);
exit(2);
}
break;
case LEVEL_FAULTY:
/* Faulty
* modeNNN
*/
s.layout = parse_layout_faulty(optarg);
if (s.layout == -1) {
pr_err("layout %s not understood for faulty.\n",
optarg);
exit(2);
}
break;
}
continue;
case O(CREATE,AssumeClean):
case O(BUILD,AssumeClean): /* assume clean */
case O(GROW,AssumeClean):
s.assume_clean = 1;
continue;
case O(GROW,'n'):
case O(CREATE,'n'):
case O(BUILD,'n'): /* number of raid disks */
if (s.raiddisks) {
pr_err("raid-devices set twice: %d and %s\n",
s.raiddisks, optarg);
exit(2);
}
s.raiddisks = parse_num(optarg);
if (s.raiddisks <= 0) {
pr_err("invalid number of raid devices: %s\n",
optarg);
exit(2);
}
ident.raid_disks = s.raiddisks;
continue;
case O(CREATE,'x'): /* number of spare (eXtra) disks */
if (s.sparedisks) {
pr_err("spare-devices set twice: %d and %s\n",
s.sparedisks, optarg);
exit(2);
}
if (s.level != UnSet && s.level <= 0 && s.level >= -1) {
pr_err("spare-devices setting is incompatible with raid level %d\n",
s.level);
exit(2);
}
s.sparedisks = parse_num(optarg);
if (s.sparedisks < 0) {
pr_err("invalid number of spare-devices: %s\n",
optarg);
exit(2);
}
continue;
case O(CREATE,'a'):
case O(CREATE,Auto):
case O(BUILD,'a'):
case O(BUILD,Auto):
case O(INCREMENTAL,'a'):
case O(INCREMENTAL,Auto):
case O(ASSEMBLE,'a'):
case O(ASSEMBLE,Auto): /* auto-creation of device node */
c.autof = parse_auto(optarg, "--auto flag", 0);
continue;
case O(CREATE,Symlinks):
case O(BUILD,Symlinks):
case O(ASSEMBLE,Symlinks): /* auto creation of symlinks in /dev to /dev/md */
symlinks = optarg;
continue;
case O(BUILD,'f'): /* force honouring '-n 1' */
case O(BUILD,Force): /* force honouring '-n 1' */
case O(GROW,'f'): /* ditto */
case O(GROW,Force): /* ditto */
case O(CREATE,'f'): /* force honouring of device list */
case O(CREATE,Force): /* force honouring of device list */
case O(ASSEMBLE,'f'): /* force assembly */
case O(ASSEMBLE,Force): /* force assembly */
case O(MISC,'f'): /* force zero */
case O(MISC,Force): /* force zero */
case O(MANAGE,Force): /* add device which is too large */
c.force=1;
continue;
/* now for the Assemble options */
case O(ASSEMBLE, FreezeReshape): /* Freeze reshape during
* initrd phase */
case O(INCREMENTAL, FreezeReshape):
c.freeze_reshape = 1;
continue;
case O(CREATE,'u'): /* uuid of array */
case O(ASSEMBLE,'u'): /* uuid of array */
if (ident.uuid_set) {
pr_err("uuid cannot be set twice. Second value %s.\n", optarg);
exit(2);
}
if (parse_uuid(optarg, ident.uuid))
ident.uuid_set = 1;
else {
pr_err("Bad uuid: %s\n", optarg);
exit(2);
}
continue;
case O(CREATE,'N'):
case O(ASSEMBLE,'N'):
case O(MISC,'N'):
if (ident.name[0]) {
pr_err("name cannot be set twice. Second value %s.\n", optarg);
exit(2);
}
if (mode == MISC && !c.subarray) {
pr_err("-N/--name only valid with --update-subarray in misc mode\n");
exit(2);
}
if (strlen(optarg) > 32) {
pr_err("name '%s' is too long, 32 chars max.\n",
optarg);
exit(2);
}
strcpy(ident.name, optarg);
continue;
case O(ASSEMBLE,'m'): /* super-minor for array */
case O(ASSEMBLE,SuperMinor):
if (ident.super_minor != UnSet) {
pr_err("super-minor cannot be set twice. Second value: %s.\n", optarg);
exit(2);
}
if (strcmp(optarg, "dev")==0)
ident.super_minor = -2;
else {
ident.super_minor = parse_num(optarg);
if (ident.super_minor < 0) {
pr_err("Bad super-minor number: %s.\n", optarg);
exit(2);
}
}
continue;
case O(ASSEMBLE,'o'):
case O(MANAGE,'o'):
case O(CREATE,'o'):
c.readonly = 1;
continue;
case O(ASSEMBLE,'U'): /* update the superblock */
case O(MISC,'U'):
if (c.update) {
pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
c.update, optarg);
exit(2);
}
if (mode == MISC && !c.subarray) {
pr_err("Only subarrays can be updated in misc mode\n");
exit(2);
}
c.update = optarg;
if (strcmp(c.update, "sparc2.2")==0)
continue;
if (strcmp(c.update, "super-minor") == 0)
continue;
if (strcmp(c.update, "summaries")==0)
continue;
if (strcmp(c.update, "resync")==0)
continue;
if (strcmp(c.update, "uuid")==0)
continue;
if (strcmp(c.update, "name")==0)
continue;
if (strcmp(c.update, "homehost")==0)
continue;
if (strcmp(c.update, "devicesize")==0)
continue;
if (strcmp(c.update, "no-bitmap")==0)
continue;
if (strcmp(c.update, "bbl") == 0)
continue;
if (strcmp(c.update, "no-bbl") == 0)
continue;
if (strcmp(c.update, "metadata") == 0)
continue;
if (strcmp(c.update, "revert-reshape") == 0)
continue;
if (strcmp(c.update, "byteorder")==0) {
if (ss) {
pr_err("must not set metadata type with --update=byteorder.\n");
exit(2);
}
for(i=0; !ss && superlist[i]; i++)
ss = superlist[i]->match_metadata_desc(
"0.swap");
if (!ss) {
pr_err("INTERNAL ERROR cannot find 0.swap\n");
exit(2);
}
continue;
}
if (strcmp(c.update,"?") == 0 ||
strcmp(c.update, "help") == 0) {
outf = stdout;
fprintf(outf, "%s: ", Name);
} else {
outf = stderr;
fprintf(outf,
"%s: '--update=%s' is invalid. ",
Name, c.update);
}
fprintf(outf, "Valid --update options are:\n"
" 'sparc2.2', 'super-minor', 'uuid', 'name', 'resync',\n"
" 'summaries', 'homehost', 'byteorder', 'devicesize',\n"
" 'no-bitmap', 'metadata', 'revert-reshape'\n"
" 'bbl', 'no-bbl'\n"
);
exit(outf == stdout ? 0 : 2);
case O(MANAGE,'U'):
/* update=devicesize is allowed with --re-add */
if (devmode != 'A') {
pr_err("--update in Manage mode only allowed with --re-add.\n");
exit(1);
}
if (c.update) {
pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
c.update, optarg);
exit(2);
}
c.update = optarg;
if (strcmp(c.update, "devicesize") != 0 &&
strcmp(c.update, "bbl") != 0 &&
strcmp(c.update, "no-bbl") != 0) {
pr_err("only 'devicesize', 'bbl' and 'no-bbl' can be updated with --re-add\n");
exit(2);
}
continue;
case O(INCREMENTAL,NoDegraded):
pr_err("--no-degraded is deprecated in Incremental mode\n");
case O(ASSEMBLE,NoDegraded): /* --no-degraded */
c.runstop = -1; /* --stop isn't allowed for --assemble,
* so we overload slightly */
continue;
case O(ASSEMBLE,'c'):
case O(ASSEMBLE,ConfigFile):
case O(INCREMENTAL, 'c'):
case O(INCREMENTAL, ConfigFile):
case O(MISC, 'c'):
case O(MISC, ConfigFile):
case O(MONITOR,'c'):
case O(MONITOR,ConfigFile):
case O(CREATE,ConfigFile):
if (configfile) {
pr_err("configfile cannot be set twice. Second value is %s.\n", optarg);
exit(2);
}
configfile = optarg;
set_conffile(configfile);
/* FIXME possibly check that config file exists. Even parse it */
continue;
case O(ASSEMBLE,'s'): /* scan */
case O(MISC,'s'):
case O(MONITOR,'s'):
case O(INCREMENTAL,'s'):
c.scan = 1;
continue;
case O(MONITOR,'m'): /* mail address */
case O(MONITOR,EMail):
if (mailaddr)
pr_err("only specify one mailaddress. %s ignored.\n",
optarg);
else
mailaddr = optarg;
continue;
case O(MONITOR,'p'): /* alert program */
case O(MONITOR,ProgramOpt): /* alert program */
if (program)
pr_err("only specify one alter program. %s ignored.\n",
optarg);
else
program = optarg;
continue;
case O(MONITOR,'r'): /* rebuild increments */
case O(MONITOR,Increment):
increments = atoi(optarg);
if (increments > 99 || increments < 1) {
pr_err("please specify positive integer between 1 and 99 as rebuild increments.\n");
exit(2);
}
continue;
case O(MONITOR,'d'): /* delay in seconds */
case O(GROW, 'd'):
case O(BUILD,'d'): /* delay for bitmap updates */
case O(CREATE,'d'):
if (c.delay)
pr_err("only specify delay once. %s ignored.\n",
optarg);
else {
c.delay = parse_num(optarg);
if (c.delay < 1) {
pr_err("invalid delay: %s\n",
optarg);
exit(2);
}
}
continue;
case O(MONITOR,'f'): /* daemonise */
case O(MONITOR,Fork):
daemonise = 1;
continue;
case O(MONITOR,'i'): /* pid */
if (pidfile)
pr_err("only specify one pid file. %s ignored.\n",
optarg);
else
pidfile = optarg;
continue;
case O(MONITOR,'1'): /* oneshot */
oneshot = 1;
spare_sharing = 0;
continue;
case O(MONITOR,'t'): /* test */
c.test = 1;
continue;
case O(MONITOR,'y'): /* log messages to syslog */
openlog("mdadm", LOG_PID, SYSLOG_FACILITY);
dosyslog = 1;
continue;
case O(MONITOR, NoSharing):
spare_sharing = 0;
continue;
/* now the general management options. Some are applicable
* to other modes. None have arguments.
*/
case O(GROW,'a'):
case O(GROW,Add):
case O(MANAGE,'a'):
case O(MANAGE,Add): /* add a drive */
devmode = 'a';
continue;
case O(MANAGE,AddSpare): /* add drive - never re-add */
devmode = 'S';
continue;
case O(MANAGE,ReAdd):
devmode = 'A';
continue;
case O(MANAGE,'r'): /* remove a drive */
case O(MANAGE,Remove):
devmode = 'r';
continue;
case O(MANAGE,'f'): /* set faulty */
case O(MANAGE,Fail):
case O(INCREMENTAL,'f'):
case O(INCREMENTAL,Remove):
case O(INCREMENTAL,Fail): /* r for incremental is taken, use f
* even though we will both fail and
* remove the device */
devmode = 'f';
continue;
case O(MANAGE,Replace):
/* Mark these devices for replacement */
devmode = 'R';
continue;
case O(MANAGE,With):
/* These are the replacements to use */
if (devmode != 'R') {
pr_err("--with must follow --replace\n");
exit(2);
}
devmode = 'W';
continue;
case O(INCREMENTAL,'R'):
case O(MANAGE,'R'):
case O(ASSEMBLE,'R'):
case O(BUILD,'R'):
case O(CREATE,'R'): /* Run the array */
if (c.runstop < 0) {
pr_err("Cannot both Stop and Run an array\n");
exit(2);
}
c.runstop = 1;
continue;
case O(MANAGE,'S'):
if (c.runstop > 0) {
pr_err("Cannot both Run and Stop an array\n");
exit(2);
}
c.runstop = -1;
continue;
case O(MANAGE,'t'):
c.test = 1;
continue;
case O(MISC,'Q'):
case O(MISC,'D'):
case O(MISC,'E'):
case O(MISC,KillOpt):
case O(MISC,'R'):
case O(MISC,'S'):
case O(MISC,'X'):
case O(MISC, ExamineBB):
case O(MISC,'o'):
case O(MISC,'w'):
case O(MISC,'W'):
case O(MISC, WaitOpt):
case O(MISC, Waitclean):
case O(MISC, DetailPlatform):
case O(MISC, KillSubarray):
case O(MISC, UpdateSubarray):
case O(MISC, Dump):
case O(MISC, Restore):
case O(MISC ,Action):
if (opt == KillSubarray || opt == UpdateSubarray) {
if (c.subarray) {
pr_err("subarray can only be specified once\n");
exit(2);
}
c.subarray = optarg;
}
if (opt == Action) {
if (c.action) {
pr_err("Only one --action can be specified\n");
exit(2);
}
if (strcmp(optarg, "idle") == 0 ||
strcmp(optarg, "frozen") == 0 ||
strcmp(optarg, "check") == 0 ||
strcmp(optarg, "repair") == 0)
c.action = optarg;
else {
pr_err("action must be one of idle, frozen, check, repair\n");
exit(2);
}
}
if (devmode && devmode != opt &&
(devmode == 'E' || (opt == 'E' && devmode != 'Q'))) {
pr_err("--examine/-E cannot be given with ");
if (devmode == 'E') {