]>
Commit | Line | Data |
---|---|---|
64c4757e | 1 | /* |
9a9dab36 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. |
64c4757e | 3 | * |
6f02172d | 4 | * Copyright (C) 2001-2013 Neil Brown <neilb@suse.de> |
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 | |
e736b623 | 22 | * Email: <neilb@suse.de> |
c82f047c | 23 | * |
aba69144 | 24 | * Additions for bitmap and write-behind RAID options, Copyright (C) 2003-2004, |
c82f047c | 25 | * Paul Clements, SteelEye Technology, Inc. |
64c4757e NB |
26 | */ |
27 | ||
9a9dab36 | 28 | #include "mdadm.h" |
64c4757e | 29 | #include "md_p.h" |
dd0781e5 | 30 | #include <ctype.h> |
64c4757e | 31 | |
4977146a N |
32 | static int scan_assemble(struct supertype *ss, |
33 | struct context *c, | |
34 | struct mddev_ident *ident); | |
ef898ce6 | 35 | static int misc_scan(char devmode, struct context *c); |
ba728be7 | 36 | static int stop_scan(int verbose); |
7d27d1c0 | 37 | static int misc_list(struct mddev_dev *devlist, |
86da243f | 38 | struct mddev_ident *ident, |
74db60b0 | 39 | char *dump_directory, |
86da243f | 40 | struct supertype *ss, struct context *c); |
d56dd607 | 41 | const char Name[] = "mdadm"; |
7d27d1c0 | 42 | |
52826846 NB |
43 | int main(int argc, char *argv[]) |
44 | { | |
e0d19036 | 45 | int mode = 0; |
52826846 | 46 | int opt; |
e0d19036 | 47 | int option_index; |
52826846 | 48 | int rv; |
f9ce90ba | 49 | int i; |
52826846 | 50 | |
a93f8c65 | 51 | unsigned long long array_size = 0; |
40c9a66a | 52 | unsigned long long data_offset = INVALID_SECTORS; |
fa56eddb | 53 | struct mddev_ident ident; |
52826846 | 54 | char *configfile = NULL; |
1c7a808c | 55 | int devmode = 0; |
c82f047c | 56 | int bitmap_fd = -1; |
a655e550 N |
57 | struct mddev_dev *devlist = NULL; |
58 | struct mddev_dev **devlistend = & devlist; | |
59 | struct mddev_dev *dv; | |
52826846 | 60 | int devs_found = 0; |
38098016 | 61 | char *symlinks = NULL; |
2dddadb0 | 62 | int grow_continue = 0; |
f1ae21c4 NB |
63 | /* autof indicates whether and how to create device node. |
64 | * bottom 3 bits are style. Rest (when shifted) are number of parts | |
65 | * 0 - unset | |
66 | * 1 - don't create (no) | |
67 | * 2 - if is_standard, then create (yes) | |
68 | * 3 - create as 'md' - reject is_standard mdp (md) | |
69 | * 4 - create as 'mdp' - reject is_standard md (mdp) | |
70 | * 5 - default to md if not is_standard (md in config file) | |
71 | * 6 - default to mdp if not is_standard (part, or mdp in config file) | |
72 | */ | |
9e33d556 N |
73 | struct context c = { |
74 | .require_homehost = 1, | |
75 | }; | |
e705e81b N |
76 | struct shape s = { |
77 | .level = UnSet, | |
78 | .layout = UnSet, | |
79 | .bitmap_chunk = UnSet, | |
80 | }; | |
52826846 | 81 | |
05697ec1 | 82 | char sys_hostname[256]; |
52826846 NB |
83 | char *mailaddr = NULL; |
84 | char *program = NULL; | |
9a36a9b7 | 85 | int increments = 20; |
d013a55e | 86 | int daemonise = 0; |
b5e64645 | 87 | char *pidfile = NULL; |
aa88f531 | 88 | int oneshot = 0; |
edde9560 | 89 | int spare_sharing = 1; |
82d9eba6 | 90 | struct supertype *ss = NULL; |
dfd4d8ee | 91 | int writemostly = 0; |
c06487ce | 92 | char *shortopt = short_options; |
773135f5 | 93 | int dosyslog = 0; |
8382f19b | 94 | int rebuild_map = 0; |
950bc344 | 95 | char *remove_path = NULL; |
20b60dcd | 96 | char *udev_filename = NULL; |
74db60b0 | 97 | char *dump_directory = NULL; |
52826846 | 98 | |
3d4064cc | 99 | int print_help = 0; |
0047d254 | 100 | FILE *outf; |
e5329c37 | 101 | |
52826846 NB |
102 | int mdfd = -1; |
103 | ||
dfe47e00 NB |
104 | srandom(time(0) ^ getpid()); |
105 | ||
52826846 | 106 | ident.uuid_set=0; |
98c6faba NB |
107 | ident.level = UnSet; |
108 | ident.raid_disks = UnSet; | |
109 | ident.super_minor= UnSet; | |
52826846 | 110 | ident.devices=0; |
a75f2fbc NB |
111 | ident.spare_group = NULL; |
112 | ident.autof = 0; | |
a825febc | 113 | ident.st = NULL; |
c82f047c | 114 | ident.bitmap_fd = -1; |
7ef02d01 | 115 | ident.bitmap_file = NULL; |
947fd4dd | 116 | ident.name[0] = 0; |
aef35714 N |
117 | ident.container = NULL; |
118 | ident.member = NULL; | |
52826846 | 119 | |
e0d19036 NB |
120 | while ((option_index = -1) , |
121 | (opt=getopt_long(argc, argv, | |
c06487ce | 122 | shortopt, long_options, |
e0d19036 NB |
123 | &option_index)) != -1) { |
124 | int newmode = mode; | |
35904960 | 125 | /* firstly, some mode-independent options */ |
52826846 | 126 | switch(opt) { |
1c7a808c N |
127 | case HelpOptions: |
128 | print_help = 2; | |
129 | continue; | |
52826846 | 130 | case 'h': |
1c7a808c | 131 | print_help = 1; |
3d4064cc | 132 | continue; |
52826846 NB |
133 | |
134 | case 'V': | |
135 | fputs(Version, stderr); | |
136 | exit(0); | |
137 | ||
9e33d556 | 138 | case 'v': c.verbose++; |
52826846 NB |
139 | continue; |
140 | ||
0937132d | 141 | case 'q': c.verbose--; |
dab6685f NB |
142 | continue; |
143 | ||
c82f047c | 144 | case 'b': |
1c7a808c N |
145 | if (mode == ASSEMBLE || mode == BUILD || mode == CREATE |
146 | || mode == GROW || mode == INCREMENTAL | |
147 | || mode == MANAGE) | |
c82f047c | 148 | break; /* b means bitmap */ |
1c7a808c | 149 | case Brief: |
9e33d556 | 150 | c.brief = 1; |
cd29a5c8 NB |
151 | continue; |
152 | ||
9e33d556 | 153 | case 'Y': c.export++; |
54bad364 KS |
154 | continue; |
155 | ||
997aed5d | 156 | case HomeHost: |
0ac91628 | 157 | if (strcasecmp(optarg, "<ignore>") == 0) |
9e33d556 | 158 | c.require_homehost = 0; |
0ac91628 | 159 | else |
9e33d556 | 160 | c.homehost = optarg; |
997aed5d NB |
161 | continue; |
162 | ||
08ca2adf | 163 | case OffRootOpt: |
3e23ba9d | 164 | /* Silently ignore old option */ |
08ca2adf JS |
165 | continue; |
166 | ||
c2ecf5f6 | 167 | case Prefer: |
9e33d556 N |
168 | if (c.prefer) |
169 | free(c.prefer); | |
170 | if (asprintf(&c.prefer, "/%s/", optarg) <= 0) | |
171 | c.prefer = NULL; | |
c2ecf5f6 N |
172 | continue; |
173 | ||
e0d19036 NB |
174 | case ':': |
175 | case '?': | |
176 | fputs(Usage, stderr); | |
177 | exit(2); | |
178 | } | |
179 | /* second, figure out the mode. | |
180 | * Some options force the mode. Others | |
aba69144 | 181 | * set the mode if it isn't already |
e0d19036 NB |
182 | */ |
183 | ||
184 | switch(opt) { | |
1c7a808c | 185 | case ManageOpt: |
c06487ce | 186 | newmode = MANAGE; |
024768c4 | 187 | shortopt = short_bitmap_options; |
c06487ce | 188 | break; |
e0d19036 | 189 | case 'a': |
1c7a808c | 190 | case Add: |
f33a71f1 | 191 | case AddSpare: |
e0d19036 | 192 | case 'r': |
1c7a808c | 193 | case Remove: |
70c55e36 N |
194 | case Replace: |
195 | case With: | |
e0d19036 | 196 | case 'f': |
1c7a808c | 197 | case Fail: |
41a3b72a | 198 | case ReAdd: /* re-add */ |
4de90913 | 199 | case ClusterConfirm: |
c06487ce NB |
200 | if (!mode) { |
201 | newmode = MANAGE; | |
024768c4 | 202 | shortopt = short_bitmap_options; |
c06487ce | 203 | } |
0320ea45 | 204 | break; |
e0d19036 | 205 | |
18361a1a N |
206 | case 'A': newmode = ASSEMBLE; |
207 | shortopt = short_bitmap_auto_options; | |
208 | break; | |
209 | case 'B': newmode = BUILD; | |
210 | shortopt = short_bitmap_auto_options; | |
211 | break; | |
212 | case 'C': newmode = CREATE; | |
213 | shortopt = short_bitmap_auto_options; | |
214 | break; | |
215 | case 'F': newmode = MONITOR; | |
216 | break; | |
024768c4 DL |
217 | case 'G': newmode = GROW; |
218 | shortopt = short_bitmap_options; | |
219 | break; | |
95b79df0 | 220 | case 'I': newmode = INCREMENTAL; |
18361a1a N |
221 | shortopt = short_bitmap_auto_options; |
222 | break; | |
1f48664b | 223 | case AutoDetect: |
5a53aeec JS |
224 | newmode = AUTODETECT; |
225 | break; | |
e0d19036 | 226 | |
1c7a808c | 227 | case MiscOpt: |
e0d19036 NB |
228 | case 'D': |
229 | case 'E': | |
c82f047c | 230 | case 'X': |
5a53aeec | 231 | case 'Q': |
6d388a88 | 232 | case ExamineBB: |
74db60b0 N |
233 | case Dump: |
234 | case Restore: | |
a740cf64 | 235 | case Action: |
5a53aeec JS |
236 | newmode = MISC; |
237 | break; | |
238 | ||
e0d19036 NB |
239 | case 'R': |
240 | case 'S': | |
241 | case 'o': | |
242 | case 'w': | |
b90c0e9a | 243 | case 'W': |
1c7a808c | 244 | case WaitOpt: |
1770662b | 245 | case Waitclean: |
4cce4069 | 246 | case DetailPlatform: |
33414a01 | 247 | case KillSubarray: |
aa534678 | 248 | case UpdateSubarray: |
20b60dcd | 249 | case UdevRules: |
f7d3febc | 250 | case KillOpt: |
5a53aeec JS |
251 | if (!mode) |
252 | newmode = MISC; | |
253 | break; | |
254 | ||
255 | case NoSharing: | |
256 | newmode = MONITOR; | |
257 | break; | |
e0d19036 NB |
258 | } |
259 | if (mode && newmode == mode) { | |
260 | /* everybody happy ! */ | |
261 | } else if (mode && newmode != mode) { | |
262 | /* not allowed.. */ | |
e7b84f9d | 263 | pr_err(""); |
e0d19036 NB |
264 | if (option_index >= 0) |
265 | fprintf(stderr, "--%s", long_options[option_index].name); | |
266 | else | |
267 | fprintf(stderr, "-%c", opt); | |
e6b64cd0 | 268 | fprintf(stderr, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n", |
e0d19036 NB |
269 | map_num(modes, newmode), |
270 | map_num(modes, mode)); | |
271 | exit(2); | |
272 | } else if (!mode && newmode) { | |
273 | mode = newmode; | |
dec18cae | 274 | if (mode == MISC && devs_found) { |
e7b84f9d | 275 | pr_err("No action given for %s in --misc mode\n", |
dec18cae | 276 | devlist->devname); |
d33f1518 | 277 | cont_err("Action options must come before device names\n"); |
dec18cae N |
278 | exit(2); |
279 | } | |
e0d19036 NB |
280 | } else { |
281 | /* special case of -c --help */ | |
1c7a808c | 282 | if ((opt == 'c' || opt == ConfigFile) && |
e0d19036 NB |
283 | ( strncmp(optarg, "--h", 3)==0 || |
284 | strncmp(optarg, "-h", 2)==0)) { | |
0047d254 | 285 | fputs(Help_config, stdout); |
e0d19036 | 286 | exit(0); |
cd29a5c8 | 287 | } |
0320ea45 NB |
288 | |
289 | /* If first option is a device, don't force the mode yet */ | |
290 | if (opt == 1) { | |
291 | if (devs_found == 0) { | |
503975b9 | 292 | dv = xmalloc(sizeof(*dv)); |
0320ea45 NB |
293 | dv->devname = optarg; |
294 | dv->disposition = devmode; | |
dfd4d8ee | 295 | dv->writemostly = writemostly; |
da6b5ca9 | 296 | dv->used = 0; |
0320ea45 NB |
297 | dv->next = NULL; |
298 | *devlistend = dv; | |
299 | devlistend = &dv->next; | |
aba69144 | 300 | |
0320ea45 NB |
301 | devs_found++; |
302 | continue; | |
303 | } | |
304 | /* No mode yet, and this is the second device ... */ | |
e7b84f9d | 305 | pr_err("An option must be given to set the mode before a second device\n" |
a1331cc4 | 306 | " (%s) is listed\n", optarg); |
0320ea45 NB |
307 | exit(2); |
308 | } | |
e0d19036 | 309 | if (option_index >= 0) |
e7b84f9d | 310 | pr_err("--%s", long_options[option_index].name); |
e0d19036 | 311 | else |
e7b84f9d | 312 | pr_err("-%c", opt); |
0320ea45 | 313 | fprintf(stderr, " does not set the mode, and so cannot be the first option.\n"); |
e0d19036 NB |
314 | exit(2); |
315 | } | |
316 | ||
317 | /* if we just set the mode, then done */ | |
318 | switch(opt) { | |
1c7a808c N |
319 | case ManageOpt: |
320 | case MiscOpt: | |
e0d19036 NB |
321 | case 'A': |
322 | case 'B': | |
323 | case 'C': | |
324 | case 'F': | |
dd0781e5 | 325 | case 'G': |
8382f19b | 326 | case 'I': |
1f48664b | 327 | case AutoDetect: |
e0d19036 NB |
328 | continue; |
329 | } | |
330 | if (opt == 1) { | |
9eafa1de | 331 | /* an undecorated option - must be a device name. |
e0d19036 | 332 | */ |
9eafa1de MN |
333 | |
334 | if (devs_found > 0 && devmode == DetailPlatform) { | |
335 | pr_err("controller may only be specified once. %s ignored\n", | |
336 | optarg); | |
337 | continue; | |
338 | } | |
339 | ||
1c7a808c | 340 | if (devs_found > 0 && mode == MANAGE && !devmode) { |
7a862a02 | 341 | pr_err("Must give one of -a/-r/-f for subsequent devices at %s\n", optarg); |
52826846 NB |
342 | exit(2); |
343 | } | |
1c7a808c | 344 | if (devs_found > 0 && mode == GROW && !devmode) { |
7a862a02 | 345 | pr_err("Must give -a/--add for devices to add: %s\n", optarg); |
e5329c37 NB |
346 | exit(2); |
347 | } | |
503975b9 | 348 | dv = xmalloc(sizeof(*dv)); |
cd29a5c8 NB |
349 | dv->devname = optarg; |
350 | dv->disposition = devmode; | |
dfd4d8ee | 351 | dv->writemostly = writemostly; |
9008ed1c | 352 | dv->used = 0; |
cd29a5c8 NB |
353 | dv->next = NULL; |
354 | *devlistend = dv; | |
355 | devlistend = &dv->next; | |
aba69144 | 356 | |
52826846 NB |
357 | devs_found++; |
358 | continue; | |
682c7051 | 359 | } |
682c7051 | 360 | |
52826846 NB |
361 | /* We've got a mode, and opt is now something else which |
362 | * could depend on the mode */ | |
1c7a808c | 363 | #define O(a,b) ((a<<16)|b) |
52826846 | 364 | switch (O(mode,opt)) { |
7236ee7a | 365 | case O(GROW,'c'): |
1c7a808c | 366 | case O(GROW,ChunkSize): |
e0d19036 | 367 | case O(CREATE,'c'): |
1c7a808c | 368 | case O(CREATE,ChunkSize): |
e0d19036 | 369 | case O(BUILD,'c'): /* chunk or rounding */ |
1c7a808c | 370 | case O(BUILD,ChunkSize): /* chunk or rounding */ |
e705e81b | 371 | if (s.chunk) { |
7a862a02 | 372 | pr_err("chunk/rounding may only be specified once. Second value is %s.\n", optarg); |
52826846 NB |
373 | exit(2); |
374 | } | |
e705e81b | 375 | s.chunk = parse_size(optarg); |
822e393a N |
376 | if (s.chunk == INVALID_SECTORS || |
377 | s.chunk < 8 || (s.chunk&1)) { | |
e7b84f9d | 378 | pr_err("invalid chunk/rounding value: %s\n", |
52826846 NB |
379 | optarg); |
380 | exit(2); | |
381 | } | |
a252c078 | 382 | /* Convert sectors to K */ |
e705e81b | 383 | s.chunk /= 2; |
52826846 | 384 | continue; |
64c4757e | 385 | |
8382f19b | 386 | case O(INCREMENTAL, 'e'): |
f9ce90ba NB |
387 | case O(CREATE,'e'): |
388 | case O(ASSEMBLE,'e'): | |
389 | case O(MISC,'e'): /* set metadata (superblock) information */ | |
390 | if (ss) { | |
e7b84f9d | 391 | pr_err("metadata information already given\n"); |
f9ce90ba NB |
392 | exit(2); |
393 | } | |
aba69144 | 394 | for(i=0; !ss && superlist[i]; i++) |
82d9eba6 NB |
395 | ss = superlist[i]->match_metadata_desc(optarg); |
396 | ||
f9ce90ba | 397 | if (!ss) { |
e7b84f9d | 398 | pr_err("unrecognised metadata identifier: %s\n", optarg); |
f9ce90ba NB |
399 | exit(2); |
400 | } | |
401 | continue; | |
402 | ||
dfd4d8ee | 403 | case O(MANAGE,'W'): |
1c7a808c | 404 | case O(MANAGE,WriteMostly): |
dfd4d8ee | 405 | case O(BUILD,'W'): |
1c7a808c | 406 | case O(BUILD,WriteMostly): |
dfd4d8ee | 407 | case O(CREATE,'W'): |
1c7a808c | 408 | case O(CREATE,WriteMostly): |
dfd4d8ee NB |
409 | /* set write-mostly for following devices */ |
410 | writemostly = 1; | |
411 | continue; | |
412 | ||
b3d31955 N |
413 | case O(MANAGE,'w'): |
414 | /* clear write-mostly for following devices */ | |
415 | writemostly = 2; | |
416 | continue; | |
417 | ||
dd0781e5 | 418 | case O(GROW,'z'): |
25affb56 PC |
419 | case O(CREATE,'z'): |
420 | case O(BUILD,'z'): /* size */ | |
e705e81b | 421 | if (s.size > 0) { |
7a862a02 | 422 | pr_err("size may only be specified once. Second value is %s.\n", optarg); |
52826846 NB |
423 | exit(2); |
424 | } | |
dd0781e5 | 425 | if (strcmp(optarg, "max")==0) |
e705e81b | 426 | s.size = MAX_SIZE; |
dd0781e5 | 427 | else { |
e705e81b | 428 | s.size = parse_size(optarg); |
822e393a N |
429 | if (s.size == INVALID_SECTORS || |
430 | s.size < 8) { | |
e7b84f9d | 431 | pr_err("invalid size: %s\n", |
dd0781e5 NB |
432 | optarg); |
433 | exit(2); | |
434 | } | |
5f4fc0e1 | 435 | /* convert sectors to K */ |
e705e81b | 436 | s.size /= 2; |
52826846 NB |
437 | } |
438 | continue; | |
64c4757e | 439 | |
84e11361 | 440 | case O(GROW,'Z'): /* array size */ |
a93f8c65 | 441 | if (array_size > 0) { |
7a862a02 | 442 | pr_err("array-size may only be specified once. Second value is %s.\n", optarg); |
84e11361 N |
443 | exit(2); |
444 | } | |
445 | if (strcmp(optarg, "max") == 0) | |
a93f8c65 | 446 | array_size = MAX_SIZE; |
84e11361 N |
447 | else { |
448 | array_size = parse_size(optarg); | |
822e393a N |
449 | if (array_size == 0 || |
450 | array_size == INVALID_SECTORS) { | |
e7b84f9d | 451 | pr_err("invalid array size: %s\n", |
84e11361 N |
452 | optarg); |
453 | exit(2); | |
454 | } | |
455 | } | |
456 | continue; | |
457 | ||
40c9a66a N |
458 | case O(CREATE,DataOffset): |
459 | case O(GROW,DataOffset): | |
460 | if (data_offset != INVALID_SECTORS) { | |
7a862a02 | 461 | pr_err("data-offset may only be specified one. Second value is %s.\n", optarg); |
40c9a66a N |
462 | exit(2); |
463 | } | |
72ca9bcf N |
464 | if (mode == CREATE && |
465 | strcmp(optarg, "variable") == 0) | |
466 | data_offset = VARIABLE_OFFSET; | |
467 | else | |
468 | data_offset = parse_size(optarg); | |
40c9a66a | 469 | if (data_offset == INVALID_SECTORS) { |
ed503f89 | 470 | pr_err("invalid data-offset: %s\n", |
40c9a66a N |
471 | optarg); |
472 | exit(2); | |
473 | } | |
474 | continue; | |
475 | ||
7236ee7a | 476 | case O(GROW,'l'): |
e0d19036 NB |
477 | case O(CREATE,'l'): |
478 | case O(BUILD,'l'): /* set raid level*/ | |
e705e81b | 479 | if (s.level != UnSet) { |
7a862a02 | 480 | pr_err("raid level may only be set once. Second value is %s.\n", optarg); |
52826846 NB |
481 | exit(2); |
482 | } | |
e705e81b N |
483 | s.level = map_name(pers, optarg); |
484 | if (s.level == UnSet) { | |
e7b84f9d | 485 | pr_err("invalid raid level: %s\n", |
52826846 NB |
486 | optarg); |
487 | exit(2); | |
488 | } | |
e705e81b N |
489 | if (s.level != 0 && s.level != LEVEL_LINEAR && s.level != 1 && |
490 | s.level != LEVEL_MULTIPATH && s.level != LEVEL_FAULTY && | |
491 | s.level != 10 && | |
e0fe762a | 492 | mode == BUILD) { |
e7b84f9d | 493 | pr_err("Raid level %s not permitted with --build.\n", |
52826846 NB |
494 | optarg); |
495 | exit(2); | |
496 | } | |
e705e81b | 497 | if (s.sparedisks > 0 && s.level < 1 && s.level >= -1) { |
e7b84f9d | 498 | pr_err("raid level %s is incompatible with spare-devices setting.\n", |
52826846 NB |
499 | optarg); |
500 | exit(2); | |
501 | } | |
e705e81b | 502 | ident.level = s.level; |
52826846 | 503 | continue; |
64c4757e | 504 | |
19678e53 | 505 | case O(GROW, 'p'): /* new layout */ |
1c7a808c | 506 | case O(GROW, Layout): |
e705e81b | 507 | if (s.layout_str) { |
7a862a02 | 508 | pr_err("layout may only be sent once. Second value was %s\n", optarg); |
19678e53 N |
509 | exit(2); |
510 | } | |
e705e81b | 511 | s.layout_str = optarg; |
19678e53 N |
512 | /* 'Grow' will parse the value */ |
513 | continue; | |
514 | ||
e0d19036 | 515 | case O(CREATE,'p'): /* raid5 layout */ |
1c7a808c | 516 | case O(CREATE,Layout): |
b5e64645 | 517 | case O(BUILD,'p'): /* faulty layout */ |
1c7a808c | 518 | case O(BUILD,Layout): |
e705e81b | 519 | if (s.layout != UnSet) { |
7a862a02 | 520 | pr_err("layout may only be sent once. Second value was %s\n", optarg); |
52826846 NB |
521 | exit(2); |
522 | } | |
e705e81b | 523 | switch(s.level) { |
52826846 | 524 | default: |
e7b84f9d | 525 | pr_err("layout not meaningful for %s arrays.\n", |
e705e81b | 526 | map_num(pers, s.level)); |
52826846 | 527 | exit(2); |
98c6faba | 528 | case UnSet: |
e7b84f9d | 529 | pr_err("raid level must be given before layout.\n"); |
52826846 NB |
530 | exit(2); |
531 | ||
532 | case 5: | |
e705e81b N |
533 | s.layout = map_name(r5layout, optarg); |
534 | if (s.layout==UnSet) { | |
e7b84f9d | 535 | pr_err("layout %s not understood for raid5.\n", |
52826846 NB |
536 | optarg); |
537 | exit(2); | |
538 | } | |
539 | break; | |
b640a252 | 540 | case 6: |
e705e81b N |
541 | s.layout = map_name(r6layout, optarg); |
542 | if (s.layout==UnSet) { | |
e7b84f9d | 543 | pr_err("layout %s not understood for raid6.\n", |
b640a252 N |
544 | optarg); |
545 | exit(2); | |
546 | } | |
547 | break; | |
e5329c37 NB |
548 | |
549 | case 10: | |
e705e81b N |
550 | s.layout = parse_layout_10(optarg); |
551 | if (s.layout < 0) { | |
e7b84f9d | 552 | pr_err("layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg); |
e5329c37 NB |
553 | exit(2); |
554 | } | |
e5329c37 | 555 | break; |
19678e53 N |
556 | case LEVEL_FAULTY: |
557 | /* Faulty | |
558 | * modeNNN | |
559 | */ | |
e705e81b N |
560 | s.layout = parse_layout_faulty(optarg); |
561 | if (s.layout == -1) { | |
e7b84f9d | 562 | pr_err("layout %s not understood for faulty.\n", |
b5e64645 NB |
563 | optarg); |
564 | exit(2); | |
565 | } | |
4a06e2c2 | 566 | break; |
52826846 NB |
567 | } |
568 | continue; | |
569 | ||
997aed5d NB |
570 | case O(CREATE,AssumeClean): |
571 | case O(BUILD,AssumeClean): /* assume clean */ | |
ce52f92f | 572 | case O(GROW,AssumeClean): |
e705e81b | 573 | s.assume_clean = 1; |
dd0781e5 NB |
574 | continue; |
575 | ||
576 | case O(GROW,'n'): | |
e0d19036 NB |
577 | case O(CREATE,'n'): |
578 | case O(BUILD,'n'): /* number of raid disks */ | |
e705e81b | 579 | if (s.raiddisks) { |
e7b84f9d | 580 | pr_err("raid-devices set twice: %d and %s\n", |
e705e81b | 581 | s.raiddisks, optarg); |
52826846 NB |
582 | exit(2); |
583 | } | |
e705e81b N |
584 | s.raiddisks = parse_num(optarg); |
585 | if (s.raiddisks <= 0) { | |
e7b84f9d | 586 | pr_err("invalid number of raid devices: %s\n", |
52826846 NB |
587 | optarg); |
588 | exit(2); | |
589 | } | |
e705e81b | 590 | ident.raid_disks = s.raiddisks; |
52826846 | 591 | continue; |
7e6e839a | 592 | case O(ASSEMBLE, Nodes): |
529e2aa5 GJ |
593 | case O(CREATE, Nodes): |
594 | c.nodes = parse_num(optarg); | |
595 | if (c.nodes <= 0) { | |
596 | pr_err("invalid number for the number of cluster nodes: %s\n", | |
597 | optarg); | |
598 | exit(2); | |
599 | } | |
600 | continue; | |
7716570e | 601 | case O(CREATE, ClusterName): |
0aa2f15b | 602 | case O(ASSEMBLE, ClusterName): |
7716570e GJ |
603 | c.homecluster = optarg; |
604 | if (strlen(c.homecluster) > 64) { | |
605 | pr_err("Cluster name too big.\n"); | |
606 | exit(ERANGE); | |
607 | } | |
608 | continue; | |
18361a1a | 609 | case O(CREATE,'x'): /* number of spare (eXtra) disks */ |
e705e81b | 610 | if (s.sparedisks) { |
e7b84f9d | 611 | pr_err("spare-devices set twice: %d and %s\n", |
e705e81b | 612 | s.sparedisks, optarg); |
52826846 NB |
613 | exit(2); |
614 | } | |
e705e81b | 615 | if (s.level != UnSet && s.level <= 0 && s.level >= -1) { |
e7b84f9d | 616 | pr_err("spare-devices setting is incompatible with raid level %d\n", |
e705e81b | 617 | s.level); |
52826846 NB |
618 | exit(2); |
619 | } | |
e705e81b N |
620 | s.sparedisks = parse_num(optarg); |
621 | if (s.sparedisks < 0) { | |
e7b84f9d | 622 | pr_err("invalid number of spare-devices: %s\n", |
52826846 NB |
623 | optarg); |
624 | exit(2); | |
625 | } | |
626 | continue; | |
dd0781e5 NB |
627 | |
628 | case O(CREATE,'a'): | |
1c7a808c | 629 | case O(CREATE,Auto): |
dd0781e5 | 630 | case O(BUILD,'a'): |
1c7a808c | 631 | case O(BUILD,Auto): |
95b79df0 | 632 | case O(INCREMENTAL,'a'): |
1c7a808c N |
633 | case O(INCREMENTAL,Auto): |
634 | case O(ASSEMBLE,'a'): | |
635 | case O(ASSEMBLE,Auto): /* auto-creation of device node */ | |
9e33d556 | 636 | c.autof = parse_auto(optarg, "--auto flag", 0); |
dd0781e5 NB |
637 | continue; |
638 | ||
38098016 NB |
639 | case O(CREATE,Symlinks): |
640 | case O(BUILD,Symlinks): | |
641 | case O(ASSEMBLE,Symlinks): /* auto creation of symlinks in /dev to /dev/md */ | |
642 | symlinks = optarg; | |
643 | continue; | |
644 | ||
aa88f531 | 645 | case O(BUILD,'f'): /* force honouring '-n 1' */ |
1c7a808c | 646 | case O(BUILD,Force): /* force honouring '-n 1' */ |
bd72c2b2 | 647 | case O(GROW,'f'): /* ditto */ |
1c7a808c | 648 | case O(GROW,Force): /* ditto */ |
e0d19036 | 649 | case O(CREATE,'f'): /* force honouring of device list */ |
1c7a808c | 650 | case O(CREATE,Force): /* force honouring of device list */ |
e0d19036 | 651 | case O(ASSEMBLE,'f'): /* force assembly */ |
1c7a808c | 652 | case O(ASSEMBLE,Force): /* force assembly */ |
e0d19036 | 653 | case O(MISC,'f'): /* force zero */ |
1c7a808c | 654 | case O(MISC,Force): /* force zero */ |
11b391ec | 655 | case O(MANAGE,Force): /* add device which is too large */ |
9e33d556 | 656 | c.force=1; |
52826846 | 657 | continue; |
52826846 | 658 | /* now for the Assemble options */ |
b76b30e0 AK |
659 | case O(ASSEMBLE, FreezeReshape): /* Freeze reshape during |
660 | * initrd phase */ | |
661 | case O(INCREMENTAL, FreezeReshape): | |
9e33d556 | 662 | c.freeze_reshape = 1; |
b76b30e0 | 663 | continue; |
3d3dd91e | 664 | case O(CREATE,'u'): /* uuid of array */ |
e0d19036 | 665 | case O(ASSEMBLE,'u'): /* uuid of array */ |
52826846 | 666 | if (ident.uuid_set) { |
7a862a02 | 667 | pr_err("uuid cannot be set twice. Second value %s.\n", optarg); |
52826846 NB |
668 | exit(2); |
669 | } | |
670 | if (parse_uuid(optarg, ident.uuid)) | |
671 | ident.uuid_set = 1; | |
672 | else { | |
e7b84f9d | 673 | pr_err("Bad uuid: %s\n", optarg); |
52826846 NB |
674 | exit(2); |
675 | } | |
676 | continue; | |
677 | ||
947fd4dd NB |
678 | case O(CREATE,'N'): |
679 | case O(ASSEMBLE,'N'): | |
aa534678 | 680 | case O(MISC,'N'): |
947fd4dd | 681 | if (ident.name[0]) { |
7a862a02 | 682 | pr_err("name cannot be set twice. Second value %s.\n", optarg); |
947fd4dd NB |
683 | exit(2); |
684 | } | |
9e33d556 | 685 | if (mode == MISC && !c.subarray) { |
e7b84f9d | 686 | pr_err("-N/--name only valid with --update-subarray in misc mode\n"); |
aa534678 DW |
687 | exit(2); |
688 | } | |
947fd4dd | 689 | if (strlen(optarg) > 32) { |
e7b84f9d | 690 | pr_err("name '%s' is too long, 32 chars max.\n", |
947fd4dd NB |
691 | optarg); |
692 | exit(2); | |
693 | } | |
694 | strcpy(ident.name, optarg); | |
695 | continue; | |
696 | ||
e0d19036 | 697 | case O(ASSEMBLE,'m'): /* super-minor for array */ |
1c7a808c | 698 | case O(ASSEMBLE,SuperMinor): |
98c6faba | 699 | if (ident.super_minor != UnSet) { |
7a862a02 | 700 | pr_err("super-minor cannot be set twice. Second value: %s.\n", optarg); |
cd29a5c8 NB |
701 | exit(2); |
702 | } | |
d013a55e NB |
703 | if (strcmp(optarg, "dev")==0) |
704 | ident.super_minor = -2; | |
705 | else { | |
79868890 N |
706 | ident.super_minor = parse_num(optarg); |
707 | if (ident.super_minor < 0) { | |
e7b84f9d | 708 | pr_err("Bad super-minor number: %s.\n", optarg); |
d013a55e NB |
709 | exit(2); |
710 | } | |
cd29a5c8 NB |
711 | } |
712 | continue; | |
713 | ||
0ea8f5b1 N |
714 | case O(ASSEMBLE,'o'): |
715 | case O(MANAGE,'o'): | |
716 | case O(CREATE,'o'): | |
9e33d556 | 717 | c.readonly = 1; |
0ea8f5b1 N |
718 | continue; |
719 | ||
5787fa49 | 720 | case O(ASSEMBLE,'U'): /* update the superblock */ |
aa534678 | 721 | case O(MISC,'U'): |
9e33d556 | 722 | if (c.update) { |
7a862a02 | 723 | pr_err("Can only update one aspect of superblock, both %s and %s given.\n", |
9e33d556 | 724 | c.update, optarg); |
5787fa49 NB |
725 | exit(2); |
726 | } | |
9e33d556 | 727 | if (mode == MISC && !c.subarray) { |
7a862a02 | 728 | pr_err("Only subarrays can be updated in misc mode\n"); |
aa534678 DW |
729 | exit(2); |
730 | } | |
9e33d556 N |
731 | c.update = optarg; |
732 | if (strcmp(c.update, "sparc2.2")==0) | |
e5329c37 | 733 | continue; |
9e33d556 | 734 | if (strcmp(c.update, "super-minor") == 0) |
5787fa49 | 735 | continue; |
9e33d556 | 736 | if (strcmp(c.update, "summaries")==0) |
feb716e9 | 737 | continue; |
9e33d556 | 738 | if (strcmp(c.update, "resync")==0) |
e5329c37 | 739 | continue; |
9e33d556 | 740 | if (strcmp(c.update, "uuid")==0) |
7d99579f | 741 | continue; |
9e33d556 | 742 | if (strcmp(c.update, "name")==0) |
c4f12c13 | 743 | continue; |
9e33d556 | 744 | if (strcmp(c.update, "homehost")==0) |
0237e0ca | 745 | continue; |
0aa2f15b GJ |
746 | if (strcmp(c.update, "home-cluster")==0) |
747 | continue; | |
7e6e839a GJ |
748 | if (strcmp(c.update, "nodes")==0) |
749 | continue; | |
9e33d556 | 750 | if (strcmp(c.update, "devicesize")==0) |
bee8ec56 | 751 | continue; |
9e33d556 | 752 | if (strcmp(c.update, "no-bitmap")==0) |
5a31170d | 753 | continue; |
688e99a7 N |
754 | if (strcmp(c.update, "bbl") == 0) |
755 | continue; | |
756 | if (strcmp(c.update, "no-bbl") == 0) | |
757 | continue; | |
afa368f4 N |
758 | if (strcmp(c.update, "metadata") == 0) |
759 | continue; | |
199f1a1f N |
760 | if (strcmp(c.update, "revert-reshape") == 0) |
761 | continue; | |
9e33d556 | 762 | if (strcmp(c.update, "byteorder")==0) { |
586ed405 | 763 | if (ss) { |
7a862a02 | 764 | pr_err("must not set metadata type with --update=byteorder.\n"); |
586ed405 NB |
765 | exit(2); |
766 | } | |
aba69144 | 767 | for(i=0; !ss && superlist[i]; i++) |
833bb0f8 N |
768 | ss = superlist[i]->match_metadata_desc( |
769 | "0.swap"); | |
586ed405 | 770 | if (!ss) { |
7a862a02 | 771 | pr_err("INTERNAL ERROR cannot find 0.swap\n"); |
586ed405 NB |
772 | exit(2); |
773 | } | |
774 | ||
775 | continue; | |
776 | } | |
9e33d556 N |
777 | if (strcmp(c.update,"?") == 0 || |
778 | strcmp(c.update, "help") == 0) { | |
0047d254 | 779 | outf = stdout; |
d56dd607 | 780 | fprintf(outf, "%s: ", Name); |
0047d254 NB |
781 | } else { |
782 | outf = stderr; | |
783 | fprintf(outf, | |
d56dd607 PB |
784 | "%s: '--update=%s' is invalid. ", |
785 | Name, c.update); | |
0047d254 NB |
786 | } |
787 | fprintf(outf, "Valid --update options are:\n" | |
7e6e839a | 788 | " 'sparc2.2', 'super-minor', 'uuid', 'name', 'nodes', 'resync',\n" |
0aa2f15b | 789 | " 'summaries', 'homehost', 'home-cluster', 'byteorder', 'devicesize',\n" |
c60495c8 N |
790 | " 'no-bitmap', 'metadata', 'revert-reshape'\n" |
791 | " 'bbl', 'no-bbl'\n" | |
792 | ); | |
0047d254 | 793 | exit(outf == stdout ? 0 : 2); |
5787fa49 | 794 | |
833bb0f8 N |
795 | case O(MANAGE,'U'): |
796 | /* update=devicesize is allowed with --re-add */ | |
c8e1a230 | 797 | if (devmode != 'A') { |
7a862a02 | 798 | pr_err("--update in Manage mode only allowed with --re-add.\n"); |
833bb0f8 N |
799 | exit(1); |
800 | } | |
9e33d556 | 801 | if (c.update) { |
7a862a02 | 802 | pr_err("Can only update one aspect of superblock, both %s and %s given.\n", |
9e33d556 | 803 | c.update, optarg); |
833bb0f8 N |
804 | exit(2); |
805 | } | |
9e33d556 | 806 | c.update = optarg; |
688e99a7 N |
807 | if (strcmp(c.update, "devicesize") != 0 && |
808 | strcmp(c.update, "bbl") != 0 && | |
809 | strcmp(c.update, "no-bbl") != 0) { | |
7a862a02 | 810 | pr_err("only 'devicesize', 'bbl' and 'no-bbl' can be updated with --re-add\n"); |
833bb0f8 N |
811 | exit(2); |
812 | } | |
813 | continue; | |
814 | ||
172356c9 | 815 | case O(INCREMENTAL,NoDegraded): |
e7b84f9d | 816 | pr_err("--no-degraded is deprecated in Incremental mode\n"); |
997aed5d | 817 | case O(ASSEMBLE,NoDegraded): /* --no-degraded */ |
9e33d556 N |
818 | c.runstop = -1; /* --stop isn't allowed for --assemble, |
819 | * so we overload slightly */ | |
b8a8ccf9 NB |
820 | continue; |
821 | ||
1c7a808c N |
822 | case O(ASSEMBLE,'c'): |
823 | case O(ASSEMBLE,ConfigFile): | |
7b187ed7 | 824 | case O(INCREMENTAL, 'c'): |
1c7a808c | 825 | case O(INCREMENTAL, ConfigFile): |
2d465520 | 826 | case O(MISC, 'c'): |
1c7a808c | 827 | case O(MISC, ConfigFile): |
e0d19036 | 828 | case O(MONITOR,'c'): |
1c7a808c | 829 | case O(MONITOR,ConfigFile): |
9ccfd3be | 830 | case O(CREATE,ConfigFile): |
52826846 | 831 | if (configfile) { |
7a862a02 | 832 | pr_err("configfile cannot be set twice. Second value is %s.\n", optarg); |
52826846 NB |
833 | exit(2); |
834 | } | |
835 | configfile = optarg; | |
8aec876d | 836 | set_conffile(configfile); |
52826846 NB |
837 | /* FIXME possibly check that config file exists. Even parse it */ |
838 | continue; | |
e0d19036 NB |
839 | case O(ASSEMBLE,'s'): /* scan */ |
840 | case O(MISC,'s'): | |
841 | case O(MONITOR,'s'): | |
8382f19b | 842 | case O(INCREMENTAL,'s'): |
9e33d556 | 843 | c.scan = 1; |
52826846 NB |
844 | continue; |
845 | ||
e0d19036 | 846 | case O(MONITOR,'m'): /* mail address */ |
1c7a808c | 847 | case O(MONITOR,EMail): |
52826846 | 848 | if (mailaddr) |
e7b84f9d | 849 | pr_err("only specify one mailaddress. %s ignored.\n", |
52826846 NB |
850 | optarg); |
851 | else | |
852 | mailaddr = optarg; | |
853 | continue; | |
854 | ||
e0d19036 | 855 | case O(MONITOR,'p'): /* alert program */ |
1c7a808c | 856 | case O(MONITOR,ProgramOpt): /* alert program */ |
52826846 | 857 | if (program) |
e7b84f9d | 858 | pr_err("only specify one alter program. %s ignored.\n", |
52826846 NB |
859 | optarg); |
860 | else | |
861 | program = optarg; | |
862 | continue; | |
64c4757e | 863 | |
9a36a9b7 | 864 | case O(MONITOR,'r'): /* rebuild increments */ |
1c7a808c | 865 | case O(MONITOR,Increment): |
9a36a9b7 | 866 | increments = atoi(optarg); |
18361a1a | 867 | if (increments > 99 || increments < 1) { |
e7b84f9d | 868 | pr_err("please specify positive integer between 1 and 99 as rebuild increments.\n"); |
9a36a9b7 ZB |
869 | exit(2); |
870 | } | |
871 | continue; | |
872 | ||
e0d19036 | 873 | case O(MONITOR,'d'): /* delay in seconds */ |
f5e166fe | 874 | case O(GROW, 'd'): |
c82f047c NB |
875 | case O(BUILD,'d'): /* delay for bitmap updates */ |
876 | case O(CREATE,'d'): | |
9e33d556 | 877 | if (c.delay) |
e7b84f9d | 878 | pr_err("only specify delay once. %s ignored.\n", |
52826846 NB |
879 | optarg); |
880 | else { | |
9e33d556 N |
881 | c.delay = parse_num(optarg); |
882 | if (c.delay < 1) { | |
e7b84f9d | 883 | pr_err("invalid delay: %s\n", |
52826846 NB |
884 | optarg); |
885 | exit(2); | |
886 | } | |
887 | } | |
888 | continue; | |
d013a55e | 889 | case O(MONITOR,'f'): /* daemonise */ |
1c7a808c | 890 | case O(MONITOR,Fork): |
d013a55e NB |
891 | daemonise = 1; |
892 | continue; | |
b5e64645 NB |
893 | case O(MONITOR,'i'): /* pid */ |
894 | if (pidfile) | |
e7b84f9d | 895 | pr_err("only specify one pid file. %s ignored.\n", |
b5e64645 NB |
896 | optarg); |
897 | else | |
898 | pidfile = optarg; | |
899 | continue; | |
aa88f531 NB |
900 | case O(MONITOR,'1'): /* oneshot */ |
901 | oneshot = 1; | |
3f555346 | 902 | spare_sharing = 0; |
aa88f531 | 903 | continue; |
98c6faba | 904 | case O(MONITOR,'t'): /* test */ |
9e33d556 | 905 | c.test = 1; |
98c6faba | 906 | continue; |
773135f5 | 907 | case O(MONITOR,'y'): /* log messages to syslog */ |
6ac8aac2 | 908 | openlog("mdadm", LOG_PID, SYSLOG_FACILITY); |
773135f5 NB |
909 | dosyslog = 1; |
910 | continue; | |
edde9560 AC |
911 | case O(MONITOR, NoSharing): |
912 | spare_sharing = 0; | |
913 | continue; | |
18361a1a | 914 | |
52826846 NB |
915 | /* now the general management options. Some are applicable |
916 | * to other modes. None have arguments. | |
917 | */ | |
e5329c37 | 918 | case O(GROW,'a'): |
1c7a808c N |
919 | case O(GROW,Add): |
920 | case O(MANAGE,'a'): | |
921 | case O(MANAGE,Add): /* add a drive */ | |
52826846 | 922 | devmode = 'a'; |
fe80f49b | 923 | continue; |
f33a71f1 N |
924 | case O(MANAGE,AddSpare): /* add drive - never re-add */ |
925 | devmode = 'S'; | |
926 | continue; | |
997aed5d | 927 | case O(MANAGE,ReAdd): |
c8e1a230 | 928 | devmode = 'A'; |
52826846 | 929 | continue; |
e0d19036 | 930 | case O(MANAGE,'r'): /* remove a drive */ |
1c7a808c | 931 | case O(MANAGE,Remove): |
52826846 NB |
932 | devmode = 'r'; |
933 | continue; | |
e0d19036 | 934 | case O(MANAGE,'f'): /* set faulty */ |
1c7a808c N |
935 | case O(MANAGE,Fail): |
936 | case O(INCREMENTAL,'f'): | |
937 | case O(INCREMENTAL,Remove): | |
938 | case O(INCREMENTAL,Fail): /* r for incremental is taken, use f | |
7d27d1c0 N |
939 | * even though we will both fail and |
940 | * remove the device */ | |
52826846 NB |
941 | devmode = 'f'; |
942 | continue; | |
4de90913 GJ |
943 | case O(MANAGE, ClusterConfirm): |
944 | devmode = 'c'; | |
945 | continue; | |
70c55e36 N |
946 | case O(MANAGE,Replace): |
947 | /* Mark these devices for replacement */ | |
948 | devmode = 'R'; | |
949 | continue; | |
950 | case O(MANAGE,With): | |
951 | /* These are the replacements to use */ | |
952 | if (devmode != 'R') { | |
953 | pr_err("--with must follow --replace\n"); | |
954 | exit(2); | |
955 | } | |
956 | devmode = 'W'; | |
957 | continue; | |
8382f19b | 958 | case O(INCREMENTAL,'R'): |
e0d19036 NB |
959 | case O(MANAGE,'R'): |
960 | case O(ASSEMBLE,'R'): | |
961 | case O(BUILD,'R'): | |
962 | case O(CREATE,'R'): /* Run the array */ | |
9e33d556 | 963 | if (c.runstop < 0) { |
e7b84f9d | 964 | pr_err("Cannot both Stop and Run an array\n"); |
52826846 NB |
965 | exit(2); |
966 | } | |
9e33d556 | 967 | c.runstop = 1; |
52826846 | 968 | continue; |
e0d19036 | 969 | case O(MANAGE,'S'): |
9e33d556 | 970 | if (c.runstop > 0) { |
e7b84f9d | 971 | pr_err("Cannot both Run and Stop an array\n"); |
52826846 NB |
972 | exit(2); |
973 | } | |
9e33d556 | 974 | c.runstop = -1; |
52826846 | 975 | continue; |
7d2e6486 | 976 | case O(MANAGE,'t'): |
9e33d556 | 977 | c.test = 1; |
7d2e6486 | 978 | continue; |
52826846 | 979 | |
e0d19036 NB |
980 | case O(MISC,'Q'): |
981 | case O(MISC,'D'): | |
982 | case O(MISC,'E'): | |
f7d3febc | 983 | case O(MISC,KillOpt): |
e0d19036 NB |
984 | case O(MISC,'R'): |
985 | case O(MISC,'S'): | |
c82f047c | 986 | case O(MISC,'X'): |
6d388a88 | 987 | case O(MISC, ExamineBB): |
e0d19036 NB |
988 | case O(MISC,'o'): |
989 | case O(MISC,'w'): | |
b90c0e9a | 990 | case O(MISC,'W'): |
1c7a808c | 991 | case O(MISC, WaitOpt): |
1770662b | 992 | case O(MISC, Waitclean): |
4cce4069 | 993 | case O(MISC, DetailPlatform): |
33414a01 | 994 | case O(MISC, KillSubarray): |
aa534678 | 995 | case O(MISC, UpdateSubarray): |
74db60b0 N |
996 | case O(MISC, Dump): |
997 | case O(MISC, Restore): | |
a740cf64 | 998 | case O(MISC ,Action): |
5a53aeec | 999 | if (opt == KillSubarray || opt == UpdateSubarray) { |
9e33d556 | 1000 | if (c.subarray) { |
7a862a02 | 1001 | pr_err("subarray can only be specified once\n"); |
5a53aeec JS |
1002 | exit(2); |
1003 | } | |
9e33d556 | 1004 | c.subarray = optarg; |
5a53aeec | 1005 | } |
a740cf64 N |
1006 | if (opt == Action) { |
1007 | if (c.action) { | |
1008 | pr_err("Only one --action can be specified\n"); | |
1009 | exit(2); | |
1010 | } | |
1011 | if (strcmp(optarg, "idle") == 0 || | |
1012 | strcmp(optarg, "frozen") == 0 || | |
1013 | strcmp(optarg, "check") == 0 || | |
1014 | strcmp(optarg, "repair") == 0) | |
1015 | c.action = optarg; | |
1016 | else { | |
1017 | pr_err("action must be one of idle, frozen, check, repair\n"); | |
1018 | exit(2); | |
1019 | } | |
1020 | } | |
e0d19036 NB |
1021 | if (devmode && devmode != opt && |
1022 | (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) { | |
e7b84f9d | 1023 | pr_err("--examine/-E cannot be given with "); |
aa534678 DW |
1024 | if (devmode == 'E') { |
1025 | if (option_index >= 0) | |
1026 | fprintf(stderr, "--%s\n", | |
1027 | long_options[option_index].name); | |
1028 | else | |
1029 | fprintf(stderr, "-%c\n", opt); | |
1030 | } else if (isalpha(devmode)) | |
1031 | fprintf(stderr, "-%c\n", devmode); | |
1032 | else | |
1033 | fprintf(stderr, "previous option\n"); | |
e0d19036 NB |
1034 | exit(2); |
1035 | } | |
1036 | devmode = opt; | |
74db60b0 N |
1037 | if (opt == Dump || opt == Restore) { |
1038 | if (dump_directory != NULL) { | |
1039 | pr_err("dump/restore directory specified twice: %s and %s\n", | |
1040 | dump_directory, optarg); | |
1041 | exit(2); | |
1042 | } | |
1043 | dump_directory = optarg; | |
1044 | } | |
e0d19036 | 1045 | continue; |
7d27d1c0 N |
1046 | case O(MISC, UdevRules): |
1047 | if (devmode && devmode != opt) { | |
7a862a02 | 1048 | pr_err("--udev-rules must be the only option.\n"); |
7d27d1c0 N |
1049 | } else { |
1050 | if (udev_filename) | |
7a862a02 | 1051 | pr_err("only specify one udev rule filename. %s ignored.\n", |
7d27d1c0 N |
1052 | optarg); |
1053 | else | |
1054 | udev_filename = optarg; | |
1055 | } | |
1056 | devmode = opt; | |
1057 | continue; | |
feb716e9 | 1058 | case O(MISC,'t'): |
9e33d556 | 1059 | c.test = 1; |
feb716e9 | 1060 | continue; |
e0d19036 | 1061 | |
997aed5d | 1062 | case O(MISC, Sparc22): |
bd526cee | 1063 | if (devmode != 'E') { |
e7b84f9d | 1064 | pr_err("--sparc2.2 only allowed with --examine\n"); |
bd526cee NB |
1065 | exit(2); |
1066 | } | |
9e33d556 | 1067 | c.SparcAdjust = 1; |
bd526cee | 1068 | continue; |
c82f047c NB |
1069 | |
1070 | case O(ASSEMBLE,'b'): /* here we simply set the bitmap file */ | |
1c7a808c | 1071 | case O(ASSEMBLE,Bitmap): |
c82f047c | 1072 | if (!optarg) { |
e7b84f9d | 1073 | pr_err("bitmap file needed with -b in --assemble mode\n"); |
c82f047c NB |
1074 | exit(2); |
1075 | } | |
55935d51 | 1076 | if (strcmp(optarg, "internal")==0) { |
e7b84f9d | 1077 | pr_err("there is no need to specify --bitmap when assembling arrays with internal bitmaps\n"); |
55935d51 NB |
1078 | continue; |
1079 | } | |
c82f047c NB |
1080 | bitmap_fd = open(optarg, O_RDWR); |
1081 | if (!*optarg || bitmap_fd < 0) { | |
e7b84f9d | 1082 | pr_err("cannot open bitmap file %s: %s\n", optarg, strerror(errno)); |
c82f047c NB |
1083 | exit(2); |
1084 | } | |
1085 | ident.bitmap_fd = bitmap_fd; /* for Assemble */ | |
1086 | continue; | |
f5e166fe | 1087 | |
997aed5d NB |
1088 | case O(ASSEMBLE, BackupFile): |
1089 | case O(GROW, BackupFile): | |
06b0d786 NB |
1090 | /* Specify a file into which grow might place a backup, |
1091 | * or from which assemble might recover a backup | |
1092 | */ | |
9e33d556 | 1093 | if (c.backup_file) { |
e7b84f9d | 1094 | pr_err("backup file already specified, rejecting %s\n", optarg); |
06b0d786 NB |
1095 | exit(2); |
1096 | } | |
9e33d556 | 1097 | c.backup_file = optarg; |
06b0d786 NB |
1098 | continue; |
1099 | ||
2dddadb0 AK |
1100 | case O(GROW, Continue): |
1101 | /* Continue interrupted grow | |
1102 | */ | |
1103 | grow_continue = 1; | |
1104 | continue; | |
87f26d14 N |
1105 | case O(ASSEMBLE, InvalidBackup): |
1106 | /* Acknowledge that the backupfile is invalid, but ask | |
1107 | * to continue anyway | |
1108 | */ | |
9e33d556 | 1109 | c.invalid_backup = 1; |
87f26d14 N |
1110 | continue; |
1111 | ||
c82f047c | 1112 | case O(BUILD,'b'): |
1c7a808c N |
1113 | case O(BUILD,Bitmap): |
1114 | case O(CREATE,'b'): | |
1115 | case O(CREATE,Bitmap): /* here we create the bitmap */ | |
85375d6d | 1116 | case O(GROW,'b'): |
1c7a808c | 1117 | case O(GROW,Bitmap): |
1e0d770c NB |
1118 | if (strcmp(optarg, "internal")== 0 || |
1119 | strcmp(optarg, "none")== 0 || | |
1120 | strchr(optarg, '/') != NULL) { | |
e705e81b | 1121 | s.bitmap_file = optarg; |
1e0d770c NB |
1122 | continue; |
1123 | } | |
529e2aa5 GJ |
1124 | if (strcmp(optarg, "clustered")== 0) { |
1125 | s.bitmap_file = optarg; | |
1126 | /* Set the default number of cluster nodes | |
1127 | * to 4 if not already set by user | |
1128 | */ | |
1129 | if (c.nodes < 1) | |
1130 | c.nodes = 4; | |
1131 | continue; | |
1132 | } | |
1e0d770c | 1133 | /* probable typo */ |
e7b84f9d | 1134 | pr_err("bitmap file must contain a '/', or be 'internal', or 'none'\n" |
a1331cc4 | 1135 | " not '%s'\n", optarg); |
1e0d770c | 1136 | exit(2); |
c82f047c | 1137 | |
997aed5d NB |
1138 | case O(GROW,BitmapChunk): |
1139 | case O(BUILD,BitmapChunk): | |
1140 | case O(CREATE,BitmapChunk): /* bitmap chunksize */ | |
e705e81b | 1141 | s.bitmap_chunk = parse_size(optarg); |
822e393a N |
1142 | if (s.bitmap_chunk == 0 || |
1143 | s.bitmap_chunk == INVALID_SECTORS || | |
e705e81b | 1144 | s.bitmap_chunk & (s.bitmap_chunk - 1)) { |
e7b84f9d N |
1145 | pr_err("invalid bitmap chunksize: %s\n", |
1146 | optarg); | |
c82f047c NB |
1147 | exit(2); |
1148 | } | |
e705e81b | 1149 | s.bitmap_chunk = s.bitmap_chunk * 512; |
c82f047c | 1150 | continue; |
dfd4d8ee | 1151 | |
7d19ad0d | 1152 | case O(GROW, WriteBehind): |
997aed5d NB |
1153 | case O(BUILD, WriteBehind): |
1154 | case O(CREATE, WriteBehind): /* write-behind mode */ | |
e705e81b | 1155 | s.write_behind = DEFAULT_MAX_WRITE_BEHIND; |
dfd4d8ee | 1156 | if (optarg) { |
e705e81b N |
1157 | s.write_behind = parse_num(optarg); |
1158 | if (s.write_behind < 0 || | |
1159 | s.write_behind > 16383) { | |
e7b84f9d | 1160 | pr_err("Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg); |
dfd4d8ee NB |
1161 | exit(2); |
1162 | } | |
1163 | } | |
1164 | continue; | |
8382f19b NB |
1165 | |
1166 | case O(INCREMENTAL, 'r'): | |
1c7a808c | 1167 | case O(INCREMENTAL, RebuildMapOpt): |
8382f19b NB |
1168 | rebuild_map = 1; |
1169 | continue; | |
950bc344 PC |
1170 | case O(INCREMENTAL, IncrementalPath): |
1171 | remove_path = optarg; | |
1172 | continue; | |
52826846 NB |
1173 | } |
1174 | /* We have now processed all the valid options. Anything else is | |
1175 | * an error | |
1176 | */ | |
06b0d786 | 1177 | if (option_index > 0) |
e7b84f9d | 1178 | pr_err(":option --%s not valid in %s mode\n", |
06b0d786 NB |
1179 | long_options[option_index].name, |
1180 | map_num(modes, mode)); | |
1181 | else | |
e7b84f9d | 1182 | pr_err("option -%c not valid in %s mode\n", |
06b0d786 | 1183 | opt, map_num(modes, mode)); |
64c4757e | 1184 | exit(2); |
52826846 NB |
1185 | |
1186 | } | |
1187 | ||
3d4064cc | 1188 | if (print_help) { |
5187a385 | 1189 | char *help_text; |
3d4064cc NB |
1190 | if (print_help == 2) |
1191 | help_text = OptionHelp; | |
1192 | else | |
5187a385 N |
1193 | help_text = mode_help[mode]; |
1194 | if (help_text == NULL) | |
1195 | help_text = Help; | |
0047d254 | 1196 | fputs(help_text,stdout); |
3d4064cc NB |
1197 | exit(0); |
1198 | } | |
1199 | ||
0320ea45 NB |
1200 | if (!mode && devs_found) { |
1201 | mode = MISC; | |
1202 | devmode = 'Q'; | |
1203 | if (devlist->disposition == 0) | |
1204 | devlist->disposition = devmode; | |
1205 | } | |
52826846 NB |
1206 | if (!mode) { |
1207 | fputs(Usage, stderr); | |
64c4757e | 1208 | exit(2); |
64c4757e | 1209 | } |
38098016 NB |
1210 | |
1211 | if (symlinks) { | |
1212 | struct createinfo *ci = conf_get_create_info(); | |
1213 | ||
1214 | if (strcasecmp(symlinks, "yes") == 0) | |
1215 | ci->symlinks = 1; | |
1216 | else if (strcasecmp(symlinks, "no") == 0) | |
1217 | ci->symlinks = 0; | |
1218 | else { | |
e7b84f9d | 1219 | pr_err("option --symlinks must be 'no' or 'yes'\n"); |
38098016 NB |
1220 | exit(2); |
1221 | } | |
1222 | } | |
52826846 NB |
1223 | /* Ok, got the option parsing out of the way |
1224 | * hopefully it's mostly right but there might be some stuff | |
1225 | * missing | |
1226 | * | |
e0d19036 | 1227 | * That is mosty checked in the per-mode stuff but... |
52826846 | 1228 | * |
18361a1a N |
1229 | * For @,B,C and A without -s, the first device listed must be |
1230 | * an md device. We check that here and open it. | |
64c4757e | 1231 | */ |
52826846 | 1232 | |
18361a1a N |
1233 | if (mode == MANAGE || mode == BUILD || mode == CREATE |
1234 | || mode == GROW | |
9e33d556 | 1235 | || (mode == ASSEMBLE && ! c.scan)) { |
52826846 | 1236 | if (devs_found < 1) { |
e7b84f9d | 1237 | pr_err("an md device must be given in this mode\n"); |
52826846 NB |
1238 | exit(2); |
1239 | } | |
9e33d556 | 1240 | if ((int)ident.super_minor == -2 && c.autof) { |
e7b84f9d | 1241 | pr_err("--super-minor=dev is incompatible with --auto\n"); |
dd0781e5 NB |
1242 | exit(2); |
1243 | } | |
7f91af49 | 1244 | if (mode == MANAGE || mode == GROW) { |
6be1d39d | 1245 | mdfd = open_mddev(devlist->devname, 1); |
7f91af49 N |
1246 | if (mdfd < 0) |
1247 | exit(1); | |
1248 | } else | |
1249 | /* non-existent device is OK */ | |
1250 | mdfd = open_mddev(devlist->devname, 0); | |
1251 | if (mdfd == -2) { | |
7a862a02 | 1252 | pr_err("device %s exists but is not an md array.\n", devlist->devname); |
52826846 | 1253 | exit(1); |
7f91af49 | 1254 | } |
98c6faba | 1255 | if ((int)ident.super_minor == -2) { |
d013a55e | 1256 | struct stat stb; |
7f91af49 | 1257 | if (mdfd < 0) { |
7a862a02 | 1258 | pr_err("--super-minor=dev given, and listed device %s doesn't exist.\n", |
7f91af49 N |
1259 | devlist->devname); |
1260 | exit(1); | |
1261 | } | |
d013a55e | 1262 | fstat(mdfd, &stb); |
0df46c2a | 1263 | ident.super_minor = minor(stb.st_rdev); |
d013a55e | 1264 | } |
7f91af49 N |
1265 | if (mdfd >= 0 && mode != MANAGE && mode != GROW) { |
1266 | /* We don't really want this open yet, we just might | |
1267 | * have wanted to check some things | |
1268 | */ | |
1269 | close(mdfd); | |
1270 | mdfd = -1; | |
1271 | } | |
64c4757e | 1272 | } |
52826846 | 1273 | |
e705e81b N |
1274 | if (s.raiddisks) { |
1275 | if (s.raiddisks == 1 && !c.force && s.level != LEVEL_FAULTY) { | |
e7b84f9d | 1276 | pr_err("'1' is an unusual number of drives for an array, so it is probably\n" |
e4c4352e NB |
1277 | " a mistake. If you really mean it you will need to specify --force before\n" |
1278 | " setting the number of drives.\n"); | |
1279 | exit(2); | |
1280 | } | |
1281 | } | |
c82f047c | 1282 | |
86b77ddf | 1283 | if (c.homehost == NULL && c.require_homehost) |
9e33d556 N |
1284 | c.homehost = conf_get_homehost(&c.require_homehost); |
1285 | if (c.homehost == NULL || strcasecmp(c.homehost, "<system>")==0) { | |
05697ec1 NB |
1286 | if (gethostname(sys_hostname, sizeof(sys_hostname)) == 0) { |
1287 | sys_hostname[sizeof(sys_hostname)-1] = 0; | |
9e33d556 | 1288 | c.homehost = sys_hostname; |
05697ec1 NB |
1289 | } |
1290 | } | |
9e33d556 N |
1291 | if (c.homehost && (!c.homehost[0] || strcasecmp(c.homehost, "<none>") == 0)) { |
1292 | c.homehost = NULL; | |
1293 | c.require_homehost = 0; | |
0f23aa88 | 1294 | } |
997aed5d | 1295 | |
380487fd | 1296 | rv = 0; |
7716570e GJ |
1297 | if (c.homecluster == NULL && (c.nodes > 0)) { |
1298 | c.homecluster = conf_get_homecluster(); | |
1299 | if (c.homecluster == NULL) | |
1300 | rv = get_cluster_name(&c.homecluster); | |
380487fd | 1301 | if (rv) { |
7716570e GJ |
1302 | pr_err("The md can't get cluster name\n"); |
1303 | exit(1); | |
1304 | } | |
1305 | } | |
1306 | ||
8192902f N |
1307 | if (c.backup_file && data_offset != INVALID_SECTORS) { |
1308 | pr_err("--backup-file and --data-offset are incompatible\n"); | |
1309 | exit(2); | |
1310 | } | |
1311 | ||
18361a1a N |
1312 | if ((mode == MISC && devmode == 'E') |
1313 | || (mode == MONITOR && spare_sharing == 0)) | |
1314 | /* Anyone may try this */; | |
1315 | else if (geteuid() != 0) { | |
e7b84f9d | 1316 | pr_err("must be super-user to perform this action\n"); |
ac5678dd N |
1317 | exit(1); |
1318 | } | |
1319 | ||
9e33d556 | 1320 | ident.autof = c.autof; |
7f91af49 | 1321 | |
265460ab N |
1322 | if (c.scan && c.verbose < 2) |
1323 | /* --scan implied --brief unless -vv */ | |
1324 | c.brief = 1; | |
1325 | ||
52826846 | 1326 | switch(mode) { |
e0d19036 | 1327 | case MANAGE: |
52826846 | 1328 | /* readonly, add/remove, readwrite, runstop */ |
9e33d556 N |
1329 | if (c.readonly > 0) |
1330 | rv = Manage_ro(devlist->devname, mdfd, c.readonly); | |
52826846 | 1331 | if (!rv && devs_found>1) |
cd29a5c8 | 1332 | rv = Manage_subdevs(devlist->devname, mdfd, |
0937132d | 1333 | devlist->next, c.verbose, c.test, |
9e33d556 N |
1334 | c.update, c.force); |
1335 | if (!rv && c.readonly < 0) | |
1336 | rv = Manage_ro(devlist->devname, mdfd, c.readonly); | |
fe7e0e64 | 1337 | if (!rv && c.runstop > 0) |
d5a40416 | 1338 | rv = Manage_run(devlist->devname, mdfd, &c); |
fe7e0e64 N |
1339 | if (!rv && c.runstop < 0) |
1340 | rv = Manage_stop(devlist->devname, mdfd, c.verbose, 0); | |
52826846 | 1341 | break; |
e0d19036 | 1342 | case ASSEMBLE: |
d013a55e | 1343 | if (devs_found == 1 && ident.uuid_set == 0 && |
9e33d556 | 1344 | ident.super_minor == UnSet && ident.name[0] == 0 && !c.scan ) { |
d013a55e | 1345 | /* Only a device has been given, so get details from config file */ |
fa56eddb | 1346 | struct mddev_ident *array_ident = conf_get_ident(devlist->devname); |
b5e64645 | 1347 | if (array_ident == NULL) { |
e7b84f9d | 1348 | pr_err("%s not identified in config file.\n", |
b5e64645 | 1349 | devlist->devname); |
d013a55e | 1350 | rv |= 1; |
7f91af49 N |
1351 | if (mdfd >= 0) |
1352 | close(mdfd); | |
b5e64645 | 1353 | } else { |
7f91af49 | 1354 | if (array_ident->autof == 0) |
9e33d556 | 1355 | array_ident->autof = c.autof; |
7f91af49 | 1356 | rv |= Assemble(ss, devlist->devname, array_ident, |
4977146a | 1357 | NULL, &c); |
d013a55e | 1358 | } |
9e33d556 | 1359 | } else if (!c.scan) |
7f91af49 | 1360 | rv = Assemble(ss, devlist->devname, &ident, |
4977146a | 1361 | devlist->next, &c); |
18361a1a | 1362 | else if (devs_found > 0) { |
9e33d556 | 1363 | if (c.update && devs_found > 1) { |
e7b84f9d | 1364 | pr_err("can only update a single array at a time\n"); |
5787fa49 NB |
1365 | exit(1); |
1366 | } | |
9e33d556 | 1367 | if (c.backup_file && devs_found > 1) { |
e7b84f9d | 1368 | pr_err("can only assemble a single array when providing a backup file.\n"); |
06b0d786 NB |
1369 | exit(1); |
1370 | } | |
cd29a5c8 | 1371 | for (dv = devlist ; dv ; dv=dv->next) { |
fa56eddb | 1372 | struct mddev_ident *array_ident = conf_get_ident(dv->devname); |
52826846 | 1373 | if (array_ident == NULL) { |
e7b84f9d | 1374 | pr_err("%s not identified in config file.\n", |
cd29a5c8 | 1375 | dv->devname); |
52826846 NB |
1376 | rv |= 1; |
1377 | continue; | |
1378 | } | |
7f91af49 | 1379 | if (array_ident->autof == 0) |
9e33d556 | 1380 | array_ident->autof = c.autof; |
7f91af49 | 1381 | rv |= Assemble(ss, dv->devname, array_ident, |
4977146a | 1382 | NULL, &c); |
52826846 | 1383 | } |
5787fa49 | 1384 | } else { |
9e33d556 | 1385 | if (c.update) { |
e7b84f9d | 1386 | pr_err("--update not meaningful with a --scan assembly.\n"); |
da6b5ca9 NB |
1387 | exit(1); |
1388 | } | |
9e33d556 | 1389 | if (c.backup_file) { |
e7b84f9d | 1390 | pr_err("--backup_file not meaningful with a --scan assembly.\n"); |
da6b5ca9 NB |
1391 | exit(1); |
1392 | } | |
4977146a | 1393 | rv = scan_assemble(ss, &c, &ident); |
52826846 | 1394 | } |
3cbc4d12 | 1395 | |
52826846 | 1396 | break; |
e0d19036 | 1397 | case BUILD: |
9e33d556 N |
1398 | if (c.delay == 0) |
1399 | c.delay = DEFAULT_BITMAP_DELAY; | |
e705e81b | 1400 | if (s.write_behind && !s.bitmap_file) { |
e7b84f9d | 1401 | pr_err("write-behind mode requires a bitmap.\n"); |
dfd4d8ee NB |
1402 | rv = 1; |
1403 | break; | |
1404 | } | |
e705e81b | 1405 | if (s.raiddisks == 0) { |
e7b84f9d | 1406 | pr_err("no raid-devices specified.\n"); |
5b28bd56 NB |
1407 | rv = 1; |
1408 | break; | |
1409 | } | |
dfd4d8ee | 1410 | |
e705e81b N |
1411 | if (s.bitmap_file) { |
1412 | if (strcmp(s.bitmap_file, "internal")==0) { | |
e7b84f9d | 1413 | pr_err("'internal' bitmaps not supported with --build\n"); |
55935d51 NB |
1414 | rv |= 1; |
1415 | break; | |
1416 | } | |
c82f047c | 1417 | } |
a4e8316a | 1418 | rv = Build(devlist->devname, devlist->next, &s, &c); |
52826846 | 1419 | break; |
e0d19036 | 1420 | case CREATE: |
9e33d556 N |
1421 | if (c.delay == 0) |
1422 | c.delay = DEFAULT_BITMAP_DELAY; | |
529e2aa5 GJ |
1423 | |
1424 | if (c.nodes) { | |
1425 | if (!s.bitmap_file || strcmp(s.bitmap_file, "clustered") != 0) { | |
1426 | pr_err("--nodes argument only compatible with --bitmap=clustered\n"); | |
1427 | rv = 1; | |
1428 | break; | |
1429 | } | |
1430 | ||
1431 | if (s.level != 1) { | |
1432 | pr_err("--bitmap=clustered is currently supported with RAID mirror only\n"); | |
1433 | rv = 1; | |
1434 | break; | |
1435 | } | |
1436 | } | |
1437 | ||
e705e81b | 1438 | if (s.write_behind && !s.bitmap_file) { |
e7b84f9d | 1439 | pr_err("write-behind mode requires a bitmap.\n"); |
dfd4d8ee NB |
1440 | rv = 1; |
1441 | break; | |
1442 | } | |
e705e81b | 1443 | if (s.raiddisks == 0) { |
e7b84f9d | 1444 | pr_err("no raid-devices specified.\n"); |
5b28bd56 NB |
1445 | rv = 1; |
1446 | break; | |
1447 | } | |
f9ce90ba | 1448 | |
99cc42f4 N |
1449 | rv = Create(ss, devlist->devname, |
1450 | ident.name, ident.uuid_set ? ident.uuid : NULL, | |
171dccc8 | 1451 | devs_found-1, devlist->next, |
40c9a66a | 1452 | &s, &c, data_offset); |
52826846 | 1453 | break; |
e0d19036 | 1454 | case MISC: |
e0d19036 | 1455 | if (devmode == 'E') { |
9e33d556 | 1456 | if (devlist == NULL && !c.scan) { |
e7b84f9d | 1457 | pr_err("No devices to examine\n"); |
e0d19036 NB |
1458 | exit(2); |
1459 | } | |
1460 | if (devlist == NULL) | |
8aec876d | 1461 | devlist = conf_get_devs(); |
e0d19036 | 1462 | if (devlist == NULL) { |
e7b84f9d | 1463 | pr_err("No devices listed in %s\n", configfile?configfile:DefaultConfFile); |
e0d19036 NB |
1464 | exit(1); |
1465 | } | |
eec3f887 | 1466 | rv = Examine(devlist, &c, ss); |
4cce4069 | 1467 | } else if (devmode == DetailPlatform) { |
9eafa1de MN |
1468 | rv = Detail_Platform(ss ? ss->ss : NULL, ss ? c.scan : 1, |
1469 | c.verbose, c.export, | |
1470 | devlist ? devlist->devname : NULL); | |
7d27d1c0 | 1471 | } else if (devlist == NULL) { |
9e33d556 | 1472 | if (devmode == 'S' && c.scan) |
0937132d | 1473 | rv = stop_scan(c.verbose); |
9e33d556 | 1474 | else if ((devmode == 'D' || devmode == Waitclean) && c.scan) |
ef898ce6 | 1475 | rv = misc_scan(devmode, &c); |
7d27d1c0 N |
1476 | else if (devmode == UdevRules) |
1477 | rv = Write_rules(udev_filename); | |
1478 | else { | |
e7b84f9d | 1479 | pr_err("No devices given.\n"); |
7d27d1c0 | 1480 | exit(2); |
e0d19036 | 1481 | } |
7d27d1c0 | 1482 | } else |
74db60b0 | 1483 | rv = misc_list(devlist, &ident, dump_directory, ss, &c); |
9a9dab36 | 1484 | break; |
e0d19036 | 1485 | case MONITOR: |
9e33d556 | 1486 | if (!devlist && !c.scan) { |
e7b84f9d | 1487 | pr_err("Cannot monitor: need --scan or at least one device\n"); |
e0d19036 NB |
1488 | rv = 1; |
1489 | break; | |
1490 | } | |
b5e64645 | 1491 | if (pidfile && !daemonise) { |
e7b84f9d | 1492 | pr_err("Cannot write a pid file when not in daemon mode\n"); |
b5e64645 NB |
1493 | rv = 1; |
1494 | break; | |
1495 | } | |
9e33d556 | 1496 | if (c.delay == 0) { |
3e82d76d | 1497 | if (get_linux_version() > 2006016) |
ddc7201f | 1498 | /* mdstat responds to poll */ |
9e33d556 | 1499 | c.delay = 1000; |
ddc7201f | 1500 | else |
9e33d556 | 1501 | c.delay = 60; |
ddc7201f | 1502 | } |
95c50205 N |
1503 | if (c.delay == 0) |
1504 | c.delay = 60; | |
d013a55e | 1505 | rv= Monitor(devlist, mailaddr, program, |
95c50205 N |
1506 | &c, daemonise, oneshot, |
1507 | dosyslog, pidfile, increments, | |
1508 | spare_sharing); | |
9a9dab36 | 1509 | break; |
dd0781e5 NB |
1510 | |
1511 | case GROW: | |
a93f8c65 | 1512 | if (array_size > 0) { |
84e11361 N |
1513 | /* alway impose array size first, independent of |
1514 | * anything else | |
9ce510be N |
1515 | * Do not allow level or raid_disks changes at the |
1516 | * same time as that can be irreversibly destructive. | |
84e11361 N |
1517 | */ |
1518 | struct mdinfo sra; | |
1519 | int err; | |
e705e81b | 1520 | if (s.raiddisks || s.level != UnSet) { |
7a862a02 | 1521 | pr_err("cannot change array size in same operation as changing raiddisks or level.\n" |
9ce510be N |
1522 | " Change size first, then check that data is still intact.\n"); |
1523 | rv = 1; | |
1524 | break; | |
1525 | } | |
4dd2df09 | 1526 | sysfs_init(&sra, mdfd, NULL); |
a93f8c65 | 1527 | if (array_size == MAX_SIZE) |
84e11361 N |
1528 | err = sysfs_set_str(&sra, NULL, "array_size", "default"); |
1529 | else | |
1530 | err = sysfs_set_num(&sra, NULL, "array_size", array_size / 2); | |
1531 | if (err < 0) { | |
1532 | if (errno == E2BIG) | |
7a862a02 | 1533 | pr_err("--array-size setting is too large.\n"); |
84e11361 | 1534 | else |
7a862a02 | 1535 | pr_err("current kernel does not support setting --array-size\n"); |
84e11361 N |
1536 | rv = 1; |
1537 | break; | |
1538 | } | |
1539 | } | |
1c8b90df | 1540 | if (devs_found > 1 && s.raiddisks == 0 && s.level == UnSet) { |
e5329c37 | 1541 | /* must be '-a'. */ |
e705e81b | 1542 | if (s.size > 0 || s.chunk || s.layout_str != NULL || s.bitmap_file) { |
7a862a02 | 1543 | pr_err("--add cannot be used with other geometry changes in --grow mode\n"); |
e5329c37 NB |
1544 | rv = 1; |
1545 | break; | |
1546 | } | |
1547 | for (dv=devlist->next; dv ; dv=dv->next) { | |
e2e53a2d N |
1548 | rv = Grow_Add_device(devlist->devname, mdfd, |
1549 | dv->devname); | |
e5329c37 NB |
1550 | if (rv) |
1551 | break; | |
1552 | } | |
e705e81b N |
1553 | } else if (s.bitmap_file) { |
1554 | if (s.size > 0 || s.raiddisks || s.chunk || | |
1555 | s.layout_str != NULL || devs_found > 1) { | |
7a862a02 | 1556 | pr_err("--bitmap changes cannot be used with other geometry changes in --grow mode\n"); |
7236ee7a N |
1557 | rv = 1; |
1558 | break; | |
1559 | } | |
9e33d556 N |
1560 | if (c.delay == 0) |
1561 | c.delay = DEFAULT_BITMAP_DELAY; | |
50f01ba5 | 1562 | rv = Grow_addbitmap(devlist->devname, mdfd, &c, &s); |
2dddadb0 AK |
1563 | } else if (grow_continue) |
1564 | rv = Grow_continue_command(devlist->devname, | |
9e33d556 | 1565 | mdfd, c.backup_file, |
0937132d | 1566 | c.verbose); |
e705e81b | 1567 | else if (s.size > 0 || s.raiddisks || s.layout_str != NULL |
8876bf0b N |
1568 | || s.chunk != 0 || s.level != UnSet |
1569 | || data_offset != INVALID_SECTORS) { | |
32754b7d | 1570 | rv = Grow_reshape(devlist->devname, mdfd, |
40c9a66a N |
1571 | devlist->next, |
1572 | data_offset, &c, &s); | |
a93f8c65 | 1573 | } else if (array_size == 0) |
e7b84f9d | 1574 | pr_err("no changes to --grow\n"); |
dd0781e5 | 1575 | break; |
8382f19b NB |
1576 | case INCREMENTAL: |
1577 | if (rebuild_map) { | |
1578 | RebuildMap(); | |
1579 | } | |
9e33d556 | 1580 | if (c.scan) { |
9eaf410f N |
1581 | rv = 1; |
1582 | if (devlist) { | |
1583 | pr_err("In --incremental mode, a device cannot be given with --scan.\n"); | |
1584 | break; | |
1585 | } | |
9e33d556 | 1586 | if (c.runstop <= 0) { |
e7b84f9d | 1587 | pr_err("--incremental --scan meaningless without --run.\n"); |
8382f19b NB |
1588 | break; |
1589 | } | |
29ba4804 | 1590 | if (devmode == 'f') { |
e7b84f9d | 1591 | pr_err("--incremental --scan --fail not supported.\n"); |
29ba4804 N |
1592 | break; |
1593 | } | |
d5a40416 | 1594 | rv = IncrementalScan(&c, NULL); |
8382f19b NB |
1595 | } |
1596 | if (!devlist) { | |
9e33d556 | 1597 | if (!rebuild_map && !c.scan) { |
e7b84f9d | 1598 | pr_err("--incremental requires a device.\n"); |
8382f19b NB |
1599 | rv = 1; |
1600 | } | |
1601 | break; | |
1602 | } | |
b11fe74d N |
1603 | if (devmode == 'f') { |
1604 | if (devlist->next) { | |
1605 | pr_err("'--incremental --fail' can only handle one device.\n"); | |
1606 | rv = 1; | |
1607 | break; | |
1608 | } | |
950bc344 | 1609 | rv = IncrementalRemove(devlist->devname, remove_path, |
0937132d | 1610 | c.verbose); |
b11fe74d N |
1611 | } else |
1612 | rv = Incremental(devlist, &c, ss); | |
1f48664b NB |
1613 | break; |
1614 | case AUTODETECT: | |
1615 | autodetect(); | |
1616 | break; | |
64c4757e | 1617 | } |
52826846 | 1618 | exit(rv); |
64c4757e | 1619 | } |
3cbc4d12 | 1620 | |
4977146a N |
1621 | static int scan_assemble(struct supertype *ss, |
1622 | struct context *c, | |
1623 | struct mddev_ident *ident) | |
3cbc4d12 N |
1624 | { |
1625 | struct mddev_ident *a, *array_list = conf_get_ident(NULL); | |
1626 | struct mddev_dev *devlist = conf_get_devs(); | |
1627 | struct map_ent *map = NULL; | |
1628 | int cnt = 0; | |
1629 | int rv = 0; | |
1630 | int failures, successes; | |
1631 | ||
1632 | if (conf_verify_devnames(array_list)) { | |
7a862a02 | 1633 | pr_err("Duplicate MD device names in conf file were found.\n"); |
3cbc4d12 N |
1634 | return 1; |
1635 | } | |
1636 | if (devlist == NULL) { | |
e7b84f9d | 1637 | pr_err("No devices listed in conf file were found.\n"); |
3cbc4d12 N |
1638 | return 1; |
1639 | } | |
1640 | for (a = array_list; a ; a = a->next) { | |
1641 | a->assembled = 0; | |
1642 | if (a->autof == 0) | |
4977146a | 1643 | a->autof = c->autof; |
3cbc4d12 N |
1644 | } |
1645 | if (map_lock(&map)) | |
1ade5cc1 | 1646 | pr_err("failed to get exclusive lock on mapfile\n"); |
3cbc4d12 N |
1647 | do { |
1648 | failures = 0; | |
1649 | successes = 0; | |
1650 | rv = 0; | |
1651 | for (a = array_list; a ; a = a->next) { | |
1652 | int r; | |
1653 | if (a->assembled) | |
1654 | continue; | |
1655 | if (a->devname && | |
1656 | strcasecmp(a->devname, "<ignore>") == 0) | |
1657 | continue; | |
1011e834 | 1658 | |
3cbc4d12 | 1659 | r = Assemble(ss, a->devname, |
4977146a | 1660 | a, NULL, c); |
3cbc4d12 N |
1661 | if (r == 0) { |
1662 | a->assembled = 1; | |
1663 | successes++; | |
1664 | } else | |
1665 | failures++; | |
1666 | rv |= r; | |
1667 | cnt++; | |
1668 | } | |
1669 | } while (failures && successes); | |
4977146a | 1670 | if (c->homehost && cnt == 0) { |
3cbc4d12 N |
1671 | /* Maybe we can auto-assemble something. |
1672 | * Repeatedly call Assemble in auto-assemble mode | |
1673 | * until it fails | |
1674 | */ | |
1675 | int rv2; | |
1676 | int acnt; | |
4977146a | 1677 | ident->autof = c->autof; |
3cbc4d12 N |
1678 | do { |
1679 | struct mddev_dev *devlist = conf_get_devs(); | |
1680 | acnt = 0; | |
1681 | do { | |
1682 | rv2 = Assemble(ss, NULL, | |
1683 | ident, | |
4977146a | 1684 | devlist, c); |
3cbc4d12 N |
1685 | if (rv2==0) { |
1686 | cnt++; | |
1687 | acnt++; | |
1688 | } | |
1689 | } while (rv2!=2); | |
1690 | /* Incase there are stacked devices, we need to go around again */ | |
1691 | } while (acnt); | |
1692 | if (cnt == 0 && rv == 0) { | |
e7b84f9d | 1693 | pr_err("No arrays found in config file or automatically\n"); |
3cbc4d12 N |
1694 | rv = 1; |
1695 | } else if (cnt) | |
1696 | rv = 0; | |
1697 | } else if (cnt == 0 && rv == 0) { | |
e7b84f9d | 1698 | pr_err("No arrays found in config file\n"); |
3cbc4d12 N |
1699 | rv = 1; |
1700 | } | |
1701 | map_unlock(&map); | |
1702 | return rv; | |
1703 | } | |
7d27d1c0 | 1704 | |
ef898ce6 | 1705 | static int misc_scan(char devmode, struct context *c) |
7d27d1c0 N |
1706 | { |
1707 | /* apply --detail or --wait-clean to | |
1708 | * all devices in /proc/mdstat | |
1709 | */ | |
1710 | struct mdstat_ent *ms = mdstat_read(0, 1); | |
1711 | struct mdstat_ent *e; | |
1712 | struct map_ent *map = NULL; | |
1713 | int members; | |
7d27d1c0 N |
1714 | int rv = 0; |
1715 | ||
1716 | for (members = 0; members <= 1; members++) { | |
1717 | for (e=ms ; e ; e=e->next) { | |
743eaf8b | 1718 | char *name = NULL; |
7d27d1c0 | 1719 | struct map_ent *me; |
743eaf8b | 1720 | struct stat stb; |
7d27d1c0 N |
1721 | int member = e->metadata_version && |
1722 | strncmp(e->metadata_version, | |
1723 | "external:/", 10) == 0; | |
1724 | if (members != member) | |
1725 | continue; | |
4dd2df09 | 1726 | me = map_by_devnm(&map, e->devnm); |
7d27d1c0 N |
1727 | if (me && me->path |
1728 | && strcmp(me->path, "/unknown") != 0) | |
1729 | name = me->path; | |
743eaf8b N |
1730 | if (name == NULL || |
1731 | stat(name, &stb) != 0) | |
4dd2df09 | 1732 | name = get_md_name(e->devnm); |
7d27d1c0 N |
1733 | |
1734 | if (!name) { | |
e7b84f9d | 1735 | pr_err("cannot find device file for %s\n", |
9581efb1 | 1736 | e->devnm); |
7d27d1c0 N |
1737 | continue; |
1738 | } | |
1739 | if (devmode == 'D') | |
ef898ce6 | 1740 | rv |= Detail(name, c); |
7d27d1c0 | 1741 | else |
ef898ce6 | 1742 | rv |= WaitClean(name, -1, c->verbose); |
7d27d1c0 N |
1743 | put_md_name(name); |
1744 | } | |
1745 | } | |
1746 | free_mdstat(ms); | |
1747 | return rv; | |
1748 | } | |
1749 | ||
ba728be7 | 1750 | static int stop_scan(int verbose) |
7d27d1c0 N |
1751 | { |
1752 | /* apply --stop to all devices in /proc/mdstat */ | |
1753 | /* Due to possible stacking of devices, repeat until | |
1754 | * nothing more can be stopped | |
1755 | */ | |
1756 | int progress=1, err; | |
1757 | int last = 0; | |
1758 | int rv = 0; | |
1759 | do { | |
1760 | struct mdstat_ent *ms = mdstat_read(0, 0); | |
1761 | struct mdstat_ent *e; | |
1762 | ||
1763 | if (!progress) last = 1; | |
1764 | progress = 0; err = 0; | |
1765 | for (e=ms ; e ; e=e->next) { | |
4dd2df09 | 1766 | char *name = get_md_name(e->devnm); |
7d27d1c0 N |
1767 | int mdfd; |
1768 | ||
1769 | if (!name) { | |
e7b84f9d | 1770 | pr_err("cannot find device file for %s\n", |
9581efb1 | 1771 | e->devnm); |
7d27d1c0 N |
1772 | continue; |
1773 | } | |
1774 | mdfd = open_mddev(name, 1); | |
1775 | if (mdfd >= 0) { | |
fe7e0e64 | 1776 | if (Manage_stop(name, mdfd, verbose, !last)) |
7d27d1c0 N |
1777 | err = 1; |
1778 | else | |
1779 | progress = 1; | |
1780 | close(mdfd); | |
1781 | } | |
1782 | ||
1783 | put_md_name(name); | |
1784 | } | |
1785 | free_mdstat(ms); | |
1786 | } while (!last && err); | |
1787 | if (err) | |
1788 | rv |= 1; | |
1789 | return rv; | |
1790 | } | |
1791 | ||
1792 | static int misc_list(struct mddev_dev *devlist, | |
86da243f | 1793 | struct mddev_ident *ident, |
74db60b0 | 1794 | char *dump_directory, |
86da243f | 1795 | struct supertype *ss, struct context *c) |
7d27d1c0 N |
1796 | { |
1797 | struct mddev_dev *dv; | |
1798 | int rv = 0; | |
1799 | ||
74db60b0 | 1800 | for (dv=devlist ; dv; dv=(rv & 16) ? NULL : dv->next) { |
7d27d1c0 N |
1801 | int mdfd; |
1802 | ||
1803 | switch(dv->disposition) { | |
1804 | case 'D': | |
ef898ce6 | 1805 | rv |= Detail(dv->devname, c); |
7d27d1c0 N |
1806 | continue; |
1807 | case KillOpt: /* Zero superblock */ | |
1808 | if (ss) | |
86da243f | 1809 | rv |= Kill(dv->devname, ss, c->force, c->verbose,0); |
7d27d1c0 | 1810 | else { |
86da243f | 1811 | int v = c->verbose; |
7d27d1c0 | 1812 | do { |
86da243f | 1813 | rv |= Kill(dv->devname, NULL, c->force, v, 0); |
ba728be7 | 1814 | v = -1; |
7d27d1c0 N |
1815 | } while (rv == 0); |
1816 | rv &= ~2; | |
1817 | } | |
1818 | continue; | |
1819 | case 'Q': | |
1820 | rv |= Query(dv->devname); continue; | |
1821 | case 'X': | |
86da243f | 1822 | rv |= ExamineBitmap(dv->devname, c->brief, ss); continue; |
6d388a88 N |
1823 | case ExamineBB: |
1824 | rv |= ExamineBadblocks(dv->devname, c->brief, ss); continue; | |
7d27d1c0 N |
1825 | case 'W': |
1826 | case WaitOpt: | |
1827 | rv |= Wait(dv->devname); continue; | |
1828 | case Waitclean: | |
86da243f | 1829 | rv |= WaitClean(dv->devname, -1, c->verbose); continue; |
7d27d1c0 | 1830 | case KillSubarray: |
86da243f | 1831 | rv |= Kill_subarray(dv->devname, c->subarray, c->verbose); |
7d27d1c0 N |
1832 | continue; |
1833 | case UpdateSubarray: | |
86da243f | 1834 | if (c->update == NULL) { |
e7b84f9d | 1835 | pr_err("-U/--update must be specified with --update-subarray\n"); |
7d27d1c0 N |
1836 | rv |= 1; |
1837 | continue; | |
1838 | } | |
86da243f N |
1839 | rv |= Update_subarray(dv->devname, c->subarray, |
1840 | c->update, ident, c->verbose); | |
7d27d1c0 | 1841 | continue; |
74db60b0 N |
1842 | case Dump: |
1843 | rv |= Dump_metadata(dv->devname, dump_directory, c, ss); | |
1844 | continue; | |
1845 | case Restore: | |
1846 | rv |= Restore_metadata(dv->devname, dump_directory, c, ss, | |
1847 | (dv == devlist && dv->next == NULL)); | |
1848 | continue; | |
a740cf64 N |
1849 | case Action: |
1850 | rv |= SetAction(dv->devname, c->action); | |
1851 | continue; | |
7d27d1c0 | 1852 | } |
e6dd89da N |
1853 | if (dv->devname[0] == '/') |
1854 | mdfd = open_mddev(dv->devname, 1); | |
1855 | else { | |
1856 | mdfd = open_dev(dv->devname); | |
1857 | if (mdfd < 0) | |
1858 | pr_err("Cannot open %s\n", dv->devname); | |
1859 | } | |
7d27d1c0 N |
1860 | if (mdfd>=0) { |
1861 | switch(dv->disposition) { | |
1862 | case 'R': | |
d5a40416 N |
1863 | c->runstop = 1; |
1864 | rv |= Manage_run(dv->devname, mdfd, c); break; | |
7d27d1c0 | 1865 | case 'S': |
fe7e0e64 | 1866 | rv |= Manage_stop(dv->devname, mdfd, c->verbose, 0); break; |
7d27d1c0 N |
1867 | case 'o': |
1868 | rv |= Manage_ro(dv->devname, mdfd, 1); break; | |
1869 | case 'w': | |
1870 | rv |= Manage_ro(dv->devname, mdfd, -1); break; | |
1871 | } | |
1872 | close(mdfd); | |
1873 | } else | |
1874 | rv |= 1; | |
1875 | } | |
1876 | return rv; | |
1877 | } | |
a740cf64 N |
1878 | |
1879 | int SetAction(char *dev, char *action) | |
1880 | { | |
1881 | int fd = open(dev, O_RDONLY); | |
1882 | struct mdinfo mdi; | |
1883 | if (fd < 0) { | |
1884 | pr_err("Couldn't open %s: %s\n", dev, strerror(errno)); | |
1885 | return 1; | |
1886 | } | |
1887 | sysfs_init(&mdi, fd, NULL); | |
1888 | close(fd); | |
1889 | if (!mdi.sys_name[0]) { | |
1890 | pr_err("%s is no an md array\n", dev); | |
1891 | return 1; | |
1892 | } | |
1893 | ||
1894 | if (sysfs_set_str(&mdi, NULL, "sync_action", action) < 0) { | |
1895 | pr_err("Count not set action for %s to %s: %s\n", | |
1896 | dev, action, strerror(errno)); | |
1897 | return 1; | |
1898 | } | |
1899 | return 0; | |
1900 | } |