]>
Commit | Line | Data |
---|---|---|
64c4757e | 1 | /* |
9a9dab36 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. |
64c4757e | 3 | * |
e736b623 | 4 | * Copyright (C) 2001-2009 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 | |
dd0781e5 | 32 | |
52826846 NB |
33 | int main(int argc, char *argv[]) |
34 | { | |
e0d19036 | 35 | int mode = 0; |
52826846 | 36 | int opt; |
e0d19036 | 37 | int option_index; |
52826846 NB |
38 | char *c; |
39 | int rv; | |
f9ce90ba | 40 | int i; |
52826846 NB |
41 | |
42 | int chunk = 0; | |
5dd497ee | 43 | long long size = -1; |
84e11361 | 44 | long long array_size = -1; |
98c6faba NB |
45 | int level = UnSet; |
46 | int layout = UnSet; | |
19678e53 | 47 | char *layout_str = NULL; |
52826846 NB |
48 | int raiddisks = 0; |
49 | int sparedisks = 0; | |
50 | struct mddev_ident_s ident; | |
51 | char *configfile = NULL; | |
cd29a5c8 | 52 | char *cp; |
5787fa49 | 53 | char *update = NULL; |
52826846 NB |
54 | int scan = 0; |
55 | char devmode = 0; | |
56 | int runstop = 0; | |
57 | int readonly = 0; | |
dfd4d8ee | 58 | int write_behind = 0; |
c82f047c NB |
59 | int bitmap_fd = -1; |
60 | char *bitmap_file = NULL; | |
06b0d786 | 61 | char *backup_file = NULL; |
c82f047c | 62 | int bitmap_chunk = UnSet; |
bd526cee | 63 | int SparcAdjust = 0; |
cd29a5c8 NB |
64 | mddev_dev_t devlist = NULL; |
65 | mddev_dev_t *devlistend = & devlist; | |
66 | mddev_dev_t dv; | |
52826846 NB |
67 | int devs_found = 0; |
68 | int verbose = 0; | |
dab6685f | 69 | int quiet = 0; |
cd29a5c8 | 70 | int brief = 0; |
52826846 | 71 | int force = 0; |
feb716e9 | 72 | int test = 0; |
54bad364 | 73 | int export = 0; |
dd0781e5 | 74 | int assume_clean = 0; |
38098016 | 75 | char *symlinks = NULL; |
f1ae21c4 NB |
76 | /* autof indicates whether and how to create device node. |
77 | * bottom 3 bits are style. Rest (when shifted) are number of parts | |
78 | * 0 - unset | |
79 | * 1 - don't create (no) | |
80 | * 2 - if is_standard, then create (yes) | |
81 | * 3 - create as 'md' - reject is_standard mdp (md) | |
82 | * 4 - create as 'mdp' - reject is_standard md (mdp) | |
83 | * 5 - default to md if not is_standard (md in config file) | |
84 | * 6 - default to mdp if not is_standard (part, or mdp in config file) | |
85 | */ | |
86 | int autof = 0; | |
52826846 | 87 | |
997aed5d | 88 | char *homehost = NULL; |
05697ec1 | 89 | char sys_hostname[256]; |
0ac91628 | 90 | int require_homehost = 1; |
52826846 NB |
91 | char *mailaddr = NULL; |
92 | char *program = NULL; | |
9a36a9b7 | 93 | int increments = 20; |
52826846 | 94 | int delay = 0; |
d013a55e | 95 | int daemonise = 0; |
b5e64645 | 96 | char *pidfile = NULL; |
aa88f531 | 97 | int oneshot = 0; |
82d9eba6 | 98 | struct supertype *ss = NULL; |
dfd4d8ee | 99 | int writemostly = 0; |
fe80f49b | 100 | int re_add = 0; |
c06487ce | 101 | char *shortopt = short_options; |
773135f5 | 102 | int dosyslog = 0; |
8382f19b | 103 | int rebuild_map = 0; |
589395d6 | 104 | int auto_update_home = 0; |
33414a01 | 105 | char *subarray = NULL; |
52826846 | 106 | |
3d4064cc | 107 | int print_help = 0; |
0047d254 | 108 | FILE *outf; |
e5329c37 | 109 | |
52826846 NB |
110 | int mdfd = -1; |
111 | ||
dfe47e00 NB |
112 | srandom(time(0) ^ getpid()); |
113 | ||
52826846 | 114 | ident.uuid_set=0; |
98c6faba NB |
115 | ident.level = UnSet; |
116 | ident.raid_disks = UnSet; | |
117 | ident.super_minor= UnSet; | |
52826846 | 118 | ident.devices=0; |
a75f2fbc NB |
119 | ident.spare_group = NULL; |
120 | ident.autof = 0; | |
a825febc | 121 | ident.st = NULL; |
c82f047c | 122 | ident.bitmap_fd = -1; |
7ef02d01 | 123 | ident.bitmap_file = NULL; |
947fd4dd | 124 | ident.name[0] = 0; |
aef35714 N |
125 | ident.container = NULL; |
126 | ident.member = NULL; | |
52826846 | 127 | |
e0d19036 NB |
128 | while ((option_index = -1) , |
129 | (opt=getopt_long(argc, argv, | |
c06487ce | 130 | shortopt, long_options, |
e0d19036 NB |
131 | &option_index)) != -1) { |
132 | int newmode = mode; | |
35904960 | 133 | /* firstly, some mode-independent options */ |
52826846 | 134 | switch(opt) { |
52826846 | 135 | case 'h': |
aba69144 | 136 | if (option_index > 0 && |
56eedc1a | 137 | strcmp(long_options[option_index].name, "help-options")==0) |
3d4064cc | 138 | print_help = 2; |
56eedc1a | 139 | else |
3d4064cc NB |
140 | print_help = 1; |
141 | continue; | |
52826846 NB |
142 | |
143 | case 'V': | |
144 | fputs(Version, stderr); | |
145 | exit(0); | |
146 | ||
22892d56 | 147 | case 'v': verbose++; |
52826846 NB |
148 | continue; |
149 | ||
dab6685f NB |
150 | case 'q': quiet++; |
151 | continue; | |
152 | ||
c82f047c | 153 | case 'b': |
a1331cc4 N |
154 | if (mode == ASSEMBLE || mode == BUILD || mode == CREATE || mode == GROW || |
155 | mode == INCREMENTAL || mode == MANAGE) | |
c82f047c NB |
156 | break; /* b means bitmap */ |
157 | brief = 1; | |
cd29a5c8 NB |
158 | continue; |
159 | ||
54bad364 KS |
160 | case 'Y': export++; |
161 | continue; | |
162 | ||
997aed5d | 163 | case HomeHost: |
0ac91628 N |
164 | if (strcasecmp(optarg, "<ignore>") == 0) |
165 | require_homehost = 0; | |
166 | else | |
167 | homehost = optarg; | |
997aed5d NB |
168 | continue; |
169 | ||
e0d19036 NB |
170 | case ':': |
171 | case '?': | |
172 | fputs(Usage, stderr); | |
173 | exit(2); | |
174 | } | |
175 | /* second, figure out the mode. | |
176 | * Some options force the mode. Others | |
aba69144 | 177 | * set the mode if it isn't already |
e0d19036 NB |
178 | */ |
179 | ||
180 | switch(opt) { | |
181 | case '@': /* just incase they say --manage */ | |
c06487ce | 182 | newmode = MANAGE; |
024768c4 | 183 | shortopt = short_bitmap_options; |
c06487ce | 184 | break; |
e0d19036 NB |
185 | case 'a': |
186 | case 'r': | |
187 | case 'f': | |
41a3b72a | 188 | case ReAdd: /* re-add */ |
c06487ce NB |
189 | if (!mode) { |
190 | newmode = MANAGE; | |
024768c4 | 191 | shortopt = short_bitmap_options; |
c06487ce | 192 | } |
0320ea45 | 193 | break; |
e0d19036 | 194 | |
c06487ce NB |
195 | case 'A': newmode = ASSEMBLE; shortopt = short_bitmap_auto_options; break; |
196 | case 'B': newmode = BUILD; shortopt = short_bitmap_auto_options; break; | |
197 | case 'C': newmode = CREATE; shortopt = short_bitmap_auto_options; break; | |
e0d19036 | 198 | case 'F': newmode = MONITOR;break; |
024768c4 DL |
199 | case 'G': newmode = GROW; |
200 | shortopt = short_bitmap_options; | |
201 | break; | |
95b79df0 DW |
202 | case 'I': newmode = INCREMENTAL; |
203 | shortopt = short_bitmap_auto_options; break; | |
1f48664b NB |
204 | case AutoDetect: |
205 | newmode = AUTODETECT; break; | |
e0d19036 NB |
206 | |
207 | case '#': | |
208 | case 'D': | |
209 | case 'E': | |
c82f047c | 210 | case 'X': |
e0d19036 NB |
211 | case 'Q': newmode = MISC; break; |
212 | case 'R': | |
213 | case 'S': | |
214 | case 'o': | |
215 | case 'w': | |
b90c0e9a | 216 | case 'W': |
1770662b | 217 | case Waitclean: |
4cce4069 | 218 | case DetailPlatform: |
33414a01 | 219 | case KillSubarray: |
aa534678 DW |
220 | case UpdateSubarray: |
221 | if (opt == KillSubarray || opt == UpdateSubarray) { | |
222 | if (subarray) { | |
223 | fprintf(stderr, Name ": subarray can only be specified once\n"); | |
224 | exit(2); | |
225 | } | |
33414a01 | 226 | subarray = optarg; |
aa534678 | 227 | } |
e0d19036 NB |
228 | case 'K': if (!mode) newmode = MISC; break; |
229 | } | |
230 | if (mode && newmode == mode) { | |
231 | /* everybody happy ! */ | |
232 | } else if (mode && newmode != mode) { | |
233 | /* not allowed.. */ | |
234 | fprintf(stderr, Name ": "); | |
235 | if (option_index >= 0) | |
236 | fprintf(stderr, "--%s", long_options[option_index].name); | |
237 | else | |
238 | fprintf(stderr, "-%c", opt); | |
e6b64cd0 | 239 | fprintf(stderr, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n", |
e0d19036 NB |
240 | map_num(modes, newmode), |
241 | map_num(modes, mode)); | |
242 | exit(2); | |
243 | } else if (!mode && newmode) { | |
244 | mode = newmode; | |
245 | } else { | |
246 | /* special case of -c --help */ | |
aba69144 | 247 | if (opt == 'c' && |
e0d19036 NB |
248 | ( strncmp(optarg, "--h", 3)==0 || |
249 | strncmp(optarg, "-h", 2)==0)) { | |
0047d254 | 250 | fputs(Help_config, stdout); |
e0d19036 | 251 | exit(0); |
cd29a5c8 | 252 | } |
0320ea45 NB |
253 | |
254 | /* If first option is a device, don't force the mode yet */ | |
255 | if (opt == 1) { | |
256 | if (devs_found == 0) { | |
257 | dv = malloc(sizeof(*dv)); | |
258 | if (dv == NULL) { | |
259 | fprintf(stderr, Name ": malloc failed\n"); | |
260 | exit(3); | |
261 | } | |
262 | dv->devname = optarg; | |
263 | dv->disposition = devmode; | |
dfd4d8ee | 264 | dv->writemostly = writemostly; |
fe80f49b | 265 | dv->re_add = re_add; |
da6b5ca9 | 266 | dv->used = 0; |
9008ed1c | 267 | dv->content = NULL; |
0320ea45 NB |
268 | dv->next = NULL; |
269 | *devlistend = dv; | |
270 | devlistend = &dv->next; | |
aba69144 | 271 | |
0320ea45 NB |
272 | devs_found++; |
273 | continue; | |
274 | } | |
275 | /* No mode yet, and this is the second device ... */ | |
a1331cc4 N |
276 | fprintf(stderr, Name ": An option must be given to set the mode before a second device\n" |
277 | " (%s) is listed\n", optarg); | |
0320ea45 NB |
278 | exit(2); |
279 | } | |
e0d19036 | 280 | if (option_index >= 0) |
0320ea45 | 281 | fprintf(stderr, Name ": --%s", long_options[option_index].name); |
e0d19036 | 282 | else |
0320ea45 NB |
283 | fprintf(stderr, Name ": -%c", opt); |
284 | fprintf(stderr, " does not set the mode, and so cannot be the first option.\n"); | |
e0d19036 NB |
285 | exit(2); |
286 | } | |
287 | ||
288 | /* if we just set the mode, then done */ | |
289 | switch(opt) { | |
290 | case '@': | |
291 | case '#': | |
292 | case 'A': | |
293 | case 'B': | |
294 | case 'C': | |
295 | case 'F': | |
dd0781e5 | 296 | case 'G': |
8382f19b | 297 | case 'I': |
1f48664b | 298 | case AutoDetect: |
e0d19036 NB |
299 | continue; |
300 | } | |
301 | if (opt == 1) { | |
302 | /* an undecorated option - must be a device name. | |
303 | */ | |
cd29a5c8 | 304 | if (devs_found > 0 && mode == '@' && !devmode) { |
dd0781e5 | 305 | fprintf(stderr, Name ": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg); |
52826846 NB |
306 | exit(2); |
307 | } | |
e5329c37 NB |
308 | if (devs_found > 0 && mode == 'G' && !devmode) { |
309 | fprintf(stderr, Name ": Must give one of -a for devices do add: %s\n", optarg); | |
310 | exit(2); | |
311 | } | |
cd29a5c8 NB |
312 | dv = malloc(sizeof(*dv)); |
313 | if (dv == NULL) { | |
314 | fprintf(stderr, Name ": malloc failed\n"); | |
315 | exit(3); | |
316 | } | |
317 | dv->devname = optarg; | |
318 | dv->disposition = devmode; | |
dfd4d8ee | 319 | dv->writemostly = writemostly; |
fe80f49b | 320 | dv->re_add = re_add; |
9008ed1c N |
321 | dv->used = 0; |
322 | dv->content = NULL; | |
cd29a5c8 NB |
323 | dv->next = NULL; |
324 | *devlistend = dv; | |
325 | devlistend = &dv->next; | |
aba69144 | 326 | |
52826846 NB |
327 | devs_found++; |
328 | continue; | |
682c7051 | 329 | } |
682c7051 | 330 | |
52826846 NB |
331 | /* We've got a mode, and opt is now something else which |
332 | * could depend on the mode */ | |
333 | #define O(a,b) ((a<<8)|b) | |
334 | switch (O(mode,opt)) { | |
7236ee7a | 335 | case O(GROW,'c'): |
e0d19036 NB |
336 | case O(CREATE,'c'): |
337 | case O(BUILD,'c'): /* chunk or rounding */ | |
52826846 NB |
338 | if (chunk) { |
339 | fprintf(stderr, Name ": chunk/rounding may only be specified once. " | |
340 | "Second value is %s.\n", optarg); | |
341 | exit(2); | |
342 | } | |
343 | chunk = strtol(optarg, &c, 10); | |
344 | if (!optarg[0] || *c || chunk<4 || ((chunk-1)&chunk)) { | |
345 | fprintf(stderr, Name ": invalid chunk/rounding value: %s\n", | |
346 | optarg); | |
347 | exit(2); | |
348 | } | |
349 | continue; | |
64c4757e | 350 | |
e0fe762a | 351 | #if 0 |
589395d6 NB |
352 | case O(ASSEMBLE,AutoHomeHost): |
353 | auto_update_home = 1; | |
354 | continue; | |
e0fe762a | 355 | #endif |
8382f19b | 356 | case O(INCREMENTAL, 'e'): |
f9ce90ba NB |
357 | case O(CREATE,'e'): |
358 | case O(ASSEMBLE,'e'): | |
359 | case O(MISC,'e'): /* set metadata (superblock) information */ | |
360 | if (ss) { | |
361 | fprintf(stderr, Name ": metadata information already given\n"); | |
362 | exit(2); | |
363 | } | |
aba69144 | 364 | for(i=0; !ss && superlist[i]; i++) |
82d9eba6 NB |
365 | ss = superlist[i]->match_metadata_desc(optarg); |
366 | ||
f9ce90ba NB |
367 | if (!ss) { |
368 | fprintf(stderr, Name ": unrecognised metadata identifier: %s\n", optarg); | |
369 | exit(2); | |
370 | } | |
371 | continue; | |
372 | ||
dfd4d8ee NB |
373 | case O(MANAGE,'W'): |
374 | case O(BUILD,'W'): | |
375 | case O(CREATE,'W'): | |
376 | /* set write-mostly for following devices */ | |
377 | writemostly = 1; | |
378 | continue; | |
379 | ||
b3d31955 N |
380 | case O(MANAGE,'w'): |
381 | /* clear write-mostly for following devices */ | |
382 | writemostly = 2; | |
383 | continue; | |
384 | ||
385 | ||
dd0781e5 | 386 | case O(GROW,'z'): |
25affb56 PC |
387 | case O(CREATE,'z'): |
388 | case O(BUILD,'z'): /* size */ | |
dd0781e5 | 389 | if (size >= 0) { |
52826846 NB |
390 | fprintf(stderr, Name ": size may only be specified once. " |
391 | "Second value is %s.\n", optarg); | |
392 | exit(2); | |
393 | } | |
dd0781e5 NB |
394 | if (strcmp(optarg, "max")==0) |
395 | size = 0; | |
396 | else { | |
5f4fc0e1 N |
397 | size = parse_size(optarg); |
398 | if (size < 8) { | |
dd0781e5 NB |
399 | fprintf(stderr, Name ": invalid size: %s\n", |
400 | optarg); | |
401 | exit(2); | |
402 | } | |
5f4fc0e1 N |
403 | /* convert sectors to K */ |
404 | size /= 2; | |
52826846 NB |
405 | } |
406 | continue; | |
64c4757e | 407 | |
84e11361 N |
408 | case O(GROW,'Z'): /* array size */ |
409 | if (array_size >= 0) { | |
410 | fprintf(stderr, Name ": array-size may only be specified once. " | |
411 | "Second value is %s.\n", optarg); | |
412 | exit(2); | |
413 | } | |
414 | if (strcmp(optarg, "max") == 0) | |
415 | array_size = 0; | |
416 | else { | |
417 | array_size = parse_size(optarg); | |
418 | if (array_size <= 0) { | |
419 | fprintf(stderr, Name ": invalid array size: %s\n", | |
420 | optarg); | |
421 | exit(2); | |
422 | } | |
423 | } | |
424 | continue; | |
425 | ||
7236ee7a | 426 | case O(GROW,'l'): |
e0d19036 NB |
427 | case O(CREATE,'l'): |
428 | case O(BUILD,'l'): /* set raid level*/ | |
98c6faba | 429 | if (level != UnSet) { |
52826846 NB |
430 | fprintf(stderr, Name ": raid level may only be set once. " |
431 | "Second value is %s.\n", optarg); | |
432 | exit(2); | |
433 | } | |
434 | level = map_name(pers, optarg); | |
98c6faba | 435 | if (level == UnSet) { |
52826846 NB |
436 | fprintf(stderr, Name ": invalid raid level: %s\n", |
437 | optarg); | |
438 | exit(2); | |
439 | } | |
e0fe762a N |
440 | if (level != 0 && level != LEVEL_LINEAR && level != 1 && |
441 | level != LEVEL_MULTIPATH && level != LEVEL_FAULTY && | |
442 | level != 10 && | |
443 | mode == BUILD) { | |
52826846 NB |
444 | fprintf(stderr, Name ": Raid level %s not permitted with --build.\n", |
445 | optarg); | |
446 | exit(2); | |
447 | } | |
e0d19036 | 448 | if (sparedisks > 0 && level < 1 && level >= -1) { |
b83d95f3 | 449 | fprintf(stderr, Name ": raid level %s is incompatible with spare-devices setting.\n", |
52826846 NB |
450 | optarg); |
451 | exit(2); | |
452 | } | |
cd29a5c8 | 453 | ident.level = level; |
52826846 | 454 | continue; |
64c4757e | 455 | |
19678e53 N |
456 | case O(GROW, 'p'): /* new layout */ |
457 | if (layout_str) { | |
458 | fprintf(stderr,Name ": layout may only be sent once. " | |
459 | "Second value was %s\n", optarg); | |
460 | exit(2); | |
461 | } | |
462 | layout_str = optarg; | |
463 | /* 'Grow' will parse the value */ | |
464 | continue; | |
465 | ||
e0d19036 | 466 | case O(CREATE,'p'): /* raid5 layout */ |
b5e64645 | 467 | case O(BUILD,'p'): /* faulty layout */ |
e5329c37 | 468 | if (layout != UnSet) { |
52826846 NB |
469 | fprintf(stderr,Name ": layout may only be sent once. " |
470 | "Second value was %s\n", optarg); | |
471 | exit(2); | |
472 | } | |
473 | switch(level) { | |
474 | default: | |
56eb10c0 | 475 | fprintf(stderr, Name ": layout not meaningful for %s arrays.\n", |
52826846 NB |
476 | map_num(pers, level)); |
477 | exit(2); | |
98c6faba | 478 | case UnSet: |
52826846 NB |
479 | fprintf(stderr, Name ": raid level must be given before layout.\n"); |
480 | exit(2); | |
481 | ||
482 | case 5: | |
483 | layout = map_name(r5layout, optarg); | |
98c6faba | 484 | if (layout==UnSet) { |
52826846 NB |
485 | fprintf(stderr, Name ": layout %s not understood for raid5.\n", |
486 | optarg); | |
487 | exit(2); | |
488 | } | |
489 | break; | |
b640a252 N |
490 | case 6: |
491 | layout = map_name(r6layout, optarg); | |
492 | if (layout==UnSet) { | |
493 | fprintf(stderr, Name ": layout %s not understood for raid6.\n", | |
494 | optarg); | |
495 | exit(2); | |
496 | } | |
497 | break; | |
e5329c37 NB |
498 | |
499 | case 10: | |
4a06e2c2 N |
500 | layout = parse_layout_10(optarg); |
501 | if (layout < 0) { | |
b578481c | 502 | fprintf(stderr, Name ": layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg); |
e5329c37 NB |
503 | exit(2); |
504 | } | |
e5329c37 | 505 | break; |
19678e53 N |
506 | case LEVEL_FAULTY: |
507 | /* Faulty | |
508 | * modeNNN | |
509 | */ | |
4a06e2c2 N |
510 | layout = parse_layout_faulty(optarg); |
511 | if (layout == -1) { | |
b5e64645 NB |
512 | fprintf(stderr, Name ": layout %s not understood for faulty.\n", |
513 | optarg); | |
514 | exit(2); | |
515 | } | |
4a06e2c2 | 516 | break; |
52826846 NB |
517 | } |
518 | continue; | |
519 | ||
997aed5d NB |
520 | case O(CREATE,AssumeClean): |
521 | case O(BUILD,AssumeClean): /* assume clean */ | |
dd0781e5 NB |
522 | assume_clean = 1; |
523 | continue; | |
524 | ||
525 | case O(GROW,'n'): | |
e0d19036 NB |
526 | case O(CREATE,'n'): |
527 | case O(BUILD,'n'): /* number of raid disks */ | |
52826846 | 528 | if (raiddisks) { |
b83d95f3 | 529 | fprintf(stderr, Name ": raid-devices set twice: %d and %s\n", |
52826846 NB |
530 | raiddisks, optarg); |
531 | exit(2); | |
532 | } | |
533 | raiddisks = strtol(optarg, &c, 10); | |
e4c4352e | 534 | if (!optarg[0] || *c || raiddisks<=0) { |
b83d95f3 | 535 | fprintf(stderr, Name ": invalid number of raid devices: %s\n", |
52826846 NB |
536 | optarg); |
537 | exit(2); | |
538 | } | |
cd29a5c8 | 539 | ident.raid_disks = raiddisks; |
52826846 NB |
540 | continue; |
541 | ||
e0d19036 | 542 | case O(CREATE,'x'): /* number of spare (eXtra) discs */ |
52826846 | 543 | if (sparedisks) { |
b83d95f3 | 544 | fprintf(stderr,Name ": spare-devices set twice: %d and %s\n", |
52826846 NB |
545 | sparedisks, optarg); |
546 | exit(2); | |
547 | } | |
98c6faba | 548 | if (level != UnSet && level <= 0 && level >= -1) { |
b83d95f3 | 549 | fprintf(stderr, Name ": spare-devices setting is incompatible with raid level %d\n", |
52826846 NB |
550 | level); |
551 | exit(2); | |
552 | } | |
553 | sparedisks = strtol(optarg, &c, 10); | |
e4c4352e | 554 | if (!optarg[0] || *c || sparedisks < 0) { |
b83d95f3 | 555 | fprintf(stderr, Name ": invalid number of spare-devices: %s\n", |
52826846 NB |
556 | optarg); |
557 | exit(2); | |
558 | } | |
559 | continue; | |
dd0781e5 NB |
560 | |
561 | case O(CREATE,'a'): | |
562 | case O(BUILD,'a'): | |
95b79df0 | 563 | case O(INCREMENTAL,'a'): |
dd0781e5 | 564 | case O(ASSEMBLE,'a'): /* auto-creation of device node */ |
f1ae21c4 | 565 | autof = parse_auto(optarg, "--auto flag", 0); |
dd0781e5 NB |
566 | continue; |
567 | ||
38098016 NB |
568 | case O(CREATE,Symlinks): |
569 | case O(BUILD,Symlinks): | |
570 | case O(ASSEMBLE,Symlinks): /* auto creation of symlinks in /dev to /dev/md */ | |
571 | symlinks = optarg; | |
572 | continue; | |
573 | ||
aa88f531 | 574 | case O(BUILD,'f'): /* force honouring '-n 1' */ |
bd72c2b2 | 575 | case O(GROW,'f'): /* ditto */ |
e0d19036 NB |
576 | case O(CREATE,'f'): /* force honouring of device list */ |
577 | case O(ASSEMBLE,'f'): /* force assembly */ | |
578 | case O(MISC,'f'): /* force zero */ | |
52826846 NB |
579 | force=1; |
580 | continue; | |
581 | ||
582 | /* now for the Assemble options */ | |
3d3dd91e | 583 | case O(CREATE,'u'): /* uuid of array */ |
e0d19036 | 584 | case O(ASSEMBLE,'u'): /* uuid of array */ |
52826846 | 585 | if (ident.uuid_set) { |
cd29a5c8 | 586 | fprintf(stderr, Name ": uuid cannot be set twice. " |
52826846 NB |
587 | "Second value %s.\n", optarg); |
588 | exit(2); | |
589 | } | |
590 | if (parse_uuid(optarg, ident.uuid)) | |
591 | ident.uuid_set = 1; | |
592 | else { | |
593 | fprintf(stderr,Name ": Bad uuid: %s\n", optarg); | |
594 | exit(2); | |
595 | } | |
596 | continue; | |
597 | ||
947fd4dd NB |
598 | case O(CREATE,'N'): |
599 | case O(ASSEMBLE,'N'): | |
aa534678 | 600 | case O(MISC,'N'): |
947fd4dd NB |
601 | if (ident.name[0]) { |
602 | fprintf(stderr, Name ": name cannot be set twice. " | |
603 | "Second value %s.\n", optarg); | |
604 | exit(2); | |
605 | } | |
aa534678 DW |
606 | if (mode == MISC && !subarray) { |
607 | fprintf(stderr, Name ": -N/--name only valid with --update-subarray in misc mode\n"); | |
608 | exit(2); | |
609 | } | |
947fd4dd NB |
610 | if (strlen(optarg) > 32) { |
611 | fprintf(stderr, Name ": name '%s' is too long, 32 chars max.\n", | |
612 | optarg); | |
613 | exit(2); | |
614 | } | |
615 | strcpy(ident.name, optarg); | |
616 | continue; | |
617 | ||
e0d19036 | 618 | case O(ASSEMBLE,'m'): /* super-minor for array */ |
98c6faba | 619 | if (ident.super_minor != UnSet) { |
cd29a5c8 NB |
620 | fprintf(stderr, Name ": super-minor cannot be set twice. " |
621 | "Second value: %s.\n", optarg); | |
622 | exit(2); | |
623 | } | |
d013a55e NB |
624 | if (strcmp(optarg, "dev")==0) |
625 | ident.super_minor = -2; | |
626 | else { | |
627 | ident.super_minor = strtoul(optarg, &cp, 10); | |
628 | if (!optarg[0] || *cp) { | |
629 | fprintf(stderr, Name ": Bad super-minor number: %s.\n", optarg); | |
630 | exit(2); | |
631 | } | |
cd29a5c8 NB |
632 | } |
633 | continue; | |
634 | ||
5787fa49 | 635 | case O(ASSEMBLE,'U'): /* update the superblock */ |
aa534678 | 636 | case O(MISC,'U'): |
5787fa49 NB |
637 | if (update) { |
638 | fprintf(stderr, Name ": Can only update one aspect of superblock, both %s and %s given.\n", | |
639 | update, optarg); | |
640 | exit(2); | |
641 | } | |
aa534678 DW |
642 | if (mode == MISC && !subarray) { |
643 | fprintf(stderr, Name ": Only subarrays can be updated in misc mode\n"); | |
644 | exit(2); | |
645 | } | |
5787fa49 | 646 | update = optarg; |
aba69144 | 647 | if (strcmp(update, "sparc2.2")==0) |
e5329c37 | 648 | continue; |
5787fa49 NB |
649 | if (strcmp(update, "super-minor") == 0) |
650 | continue; | |
feb716e9 NB |
651 | if (strcmp(update, "summaries")==0) |
652 | continue; | |
e5329c37 NB |
653 | if (strcmp(update, "resync")==0) |
654 | continue; | |
7d99579f NB |
655 | if (strcmp(update, "uuid")==0) |
656 | continue; | |
c4f12c13 NB |
657 | if (strcmp(update, "name")==0) |
658 | continue; | |
0237e0ca NB |
659 | if (strcmp(update, "homehost")==0) |
660 | continue; | |
bee8ec56 NB |
661 | if (strcmp(update, "devicesize")==0) |
662 | continue; | |
1f9476aa N |
663 | if (strcmp(update, "no-bitmap")==0) |
664 | continue; | |
586ed405 NB |
665 | if (strcmp(update, "byteorder")==0) { |
666 | if (ss) { | |
667 | fprintf(stderr, Name ": must not set metadata type with --update=byteorder.\n"); | |
668 | exit(2); | |
669 | } | |
aba69144 | 670 | for(i=0; !ss && superlist[i]; i++) |
586ed405 NB |
671 | ss = superlist[i]->match_metadata_desc("0.swap"); |
672 | if (!ss) { | |
673 | fprintf(stderr, Name ": INTERNAL ERROR cannot find 0.swap\n"); | |
674 | exit(2); | |
675 | } | |
676 | ||
677 | continue; | |
678 | } | |
0047d254 NB |
679 | if (strcmp(update,"?") == 0 || |
680 | strcmp(update, "help") == 0) { | |
681 | outf = stdout; | |
682 | fprintf(outf, Name ": "); | |
683 | } else { | |
684 | outf = stderr; | |
685 | fprintf(outf, | |
686 | Name ": '--update=%s' is invalid. ", | |
687 | update); | |
688 | } | |
689 | fprintf(outf, "Valid --update options are:\n" | |
bee8ec56 | 690 | " 'sparc2.2', 'super-minor', 'uuid', 'name', 'resync',\n" |
1f9476aa N |
691 | " 'summaries', 'homehost', 'byteorder', 'devicesize',\n" |
692 | " 'no-bitmap'\n"); | |
0047d254 | 693 | exit(outf == stdout ? 0 : 2); |
5787fa49 | 694 | |
172356c9 DW |
695 | case O(INCREMENTAL,NoDegraded): |
696 | fprintf(stderr, Name ": --no-degraded is deprecated in Incremental mode\n"); | |
997aed5d | 697 | case O(ASSEMBLE,NoDegraded): /* --no-degraded */ |
0047d254 NB |
698 | runstop = -1; /* --stop isn't allowed for --assemble, |
699 | * so we overload slightly */ | |
b8a8ccf9 NB |
700 | continue; |
701 | ||
e0d19036 | 702 | case O(ASSEMBLE,'c'): /* config file */ |
7b187ed7 | 703 | case O(INCREMENTAL, 'c'): |
2d465520 | 704 | case O(MISC, 'c'): |
e0d19036 | 705 | case O(MONITOR,'c'): |
52826846 NB |
706 | if (configfile) { |
707 | fprintf(stderr, Name ": configfile cannot be set twice. " | |
708 | "Second value is %s.\n", optarg); | |
709 | exit(2); | |
710 | } | |
711 | configfile = optarg; | |
8aec876d | 712 | set_conffile(configfile); |
52826846 NB |
713 | /* FIXME possibly check that config file exists. Even parse it */ |
714 | continue; | |
e0d19036 NB |
715 | case O(ASSEMBLE,'s'): /* scan */ |
716 | case O(MISC,'s'): | |
717 | case O(MONITOR,'s'): | |
8382f19b | 718 | case O(INCREMENTAL,'s'): |
52826846 NB |
719 | scan = 1; |
720 | continue; | |
721 | ||
e0d19036 | 722 | case O(MONITOR,'m'): /* mail address */ |
52826846 NB |
723 | if (mailaddr) |
724 | fprintf(stderr, Name ": only specify one mailaddress. %s ignored.\n", | |
725 | optarg); | |
726 | else | |
727 | mailaddr = optarg; | |
728 | continue; | |
729 | ||
e0d19036 | 730 | case O(MONITOR,'p'): /* alert program */ |
52826846 NB |
731 | if (program) |
732 | fprintf(stderr, Name ": only specify one alter program. %s ignored.\n", | |
733 | optarg); | |
734 | else | |
735 | program = optarg; | |
736 | continue; | |
64c4757e | 737 | |
9a36a9b7 ZB |
738 | case O(MONITOR,'r'): /* rebuild increments */ |
739 | increments = atoi(optarg); | |
740 | if (increments>99 || increments<1) { | |
741 | fprintf(stderr, Name ": please specify positive integer between 1 and 99 as rebuild increments.\n"); | |
742 | exit(2); | |
743 | } | |
744 | continue; | |
745 | ||
e0d19036 | 746 | case O(MONITOR,'d'): /* delay in seconds */ |
f5e166fe | 747 | case O(GROW, 'd'): |
c82f047c NB |
748 | case O(BUILD,'d'): /* delay for bitmap updates */ |
749 | case O(CREATE,'d'): | |
52826846 NB |
750 | if (delay) |
751 | fprintf(stderr, Name ": only specify delay once. %s ignored.\n", | |
752 | optarg); | |
753 | else { | |
754 | delay = strtol(optarg, &c, 10); | |
755 | if (!optarg[0] || *c || delay<1) { | |
756 | fprintf(stderr, Name ": invalid delay: %s\n", | |
757 | optarg); | |
758 | exit(2); | |
759 | } | |
760 | } | |
761 | continue; | |
d013a55e NB |
762 | case O(MONITOR,'f'): /* daemonise */ |
763 | daemonise = 1; | |
764 | continue; | |
b5e64645 NB |
765 | case O(MONITOR,'i'): /* pid */ |
766 | if (pidfile) | |
767 | fprintf(stderr, Name ": only specify one pid file. %s ignored.\n", | |
768 | optarg); | |
769 | else | |
770 | pidfile = optarg; | |
771 | continue; | |
aa88f531 NB |
772 | case O(MONITOR,'1'): /* oneshot */ |
773 | oneshot = 1; | |
774 | continue; | |
98c6faba NB |
775 | case O(MONITOR,'t'): /* test */ |
776 | test = 1; | |
777 | continue; | |
773135f5 | 778 | case O(MONITOR,'y'): /* log messages to syslog */ |
6ac8aac2 | 779 | openlog("mdadm", LOG_PID, SYSLOG_FACILITY); |
773135f5 NB |
780 | dosyslog = 1; |
781 | continue; | |
52826846 NB |
782 | |
783 | /* now the general management options. Some are applicable | |
784 | * to other modes. None have arguments. | |
785 | */ | |
e5329c37 | 786 | case O(GROW,'a'): |
dd0781e5 | 787 | case O(MANAGE,'a'): /* add a drive */ |
52826846 | 788 | devmode = 'a'; |
fe80f49b NB |
789 | re_add = 0; |
790 | continue; | |
997aed5d | 791 | case O(MANAGE,ReAdd): |
fe80f49b NB |
792 | devmode = 'a'; |
793 | re_add = 1; | |
52826846 | 794 | continue; |
e0d19036 | 795 | case O(MANAGE,'r'): /* remove a drive */ |
52826846 NB |
796 | devmode = 'r'; |
797 | continue; | |
e0d19036 | 798 | case O(MANAGE,'f'): /* set faulty */ |
29ba4804 N |
799 | case O(INCREMENTAL,'f'): /* r for incremental is taken, use f |
800 | * even though we will both fail and | |
801 | * remove the device */ | |
52826846 NB |
802 | devmode = 'f'; |
803 | continue; | |
8382f19b | 804 | case O(INCREMENTAL,'R'): |
e0d19036 NB |
805 | case O(MANAGE,'R'): |
806 | case O(ASSEMBLE,'R'): | |
807 | case O(BUILD,'R'): | |
808 | case O(CREATE,'R'): /* Run the array */ | |
52826846 NB |
809 | if (runstop < 0) { |
810 | fprintf(stderr, Name ": Cannot both Stop and Run an array\n"); | |
811 | exit(2); | |
812 | } | |
813 | runstop = 1; | |
814 | continue; | |
e0d19036 | 815 | case O(MANAGE,'S'): |
52826846 NB |
816 | if (runstop > 0) { |
817 | fprintf(stderr, Name ": Cannot both Run and Stop an array\n"); | |
818 | exit(2); | |
819 | } | |
820 | runstop = -1; | |
821 | continue; | |
7d2e6486 N |
822 | case O(MANAGE,'t'): |
823 | test = 1; | |
824 | continue; | |
52826846 | 825 | |
e0d19036 NB |
826 | case O(MISC,'Q'): |
827 | case O(MISC,'D'): | |
828 | case O(MISC,'E'): | |
829 | case O(MISC,'K'): | |
830 | case O(MISC,'R'): | |
831 | case O(MISC,'S'): | |
c82f047c | 832 | case O(MISC,'X'): |
e0d19036 NB |
833 | case O(MISC,'o'): |
834 | case O(MISC,'w'): | |
b90c0e9a | 835 | case O(MISC,'W'): |
1770662b | 836 | case O(MISC, Waitclean): |
4cce4069 | 837 | case O(MISC, DetailPlatform): |
33414a01 | 838 | case O(MISC, KillSubarray): |
aa534678 | 839 | case O(MISC, UpdateSubarray): |
e0d19036 NB |
840 | if (devmode && devmode != opt && |
841 | (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) { | |
aa534678 DW |
842 | fprintf(stderr, Name ": --examine/-E cannot be given with "); |
843 | if (devmode == 'E') { | |
844 | if (option_index >= 0) | |
845 | fprintf(stderr, "--%s\n", | |
846 | long_options[option_index].name); | |
847 | else | |
848 | fprintf(stderr, "-%c\n", opt); | |
849 | } else if (isalpha(devmode)) | |
850 | fprintf(stderr, "-%c\n", devmode); | |
851 | else | |
852 | fprintf(stderr, "previous option\n"); | |
e0d19036 NB |
853 | exit(2); |
854 | } | |
855 | devmode = opt; | |
856 | continue; | |
feb716e9 NB |
857 | case O(MISC,'t'): |
858 | test = 1; | |
859 | continue; | |
e0d19036 | 860 | |
997aed5d | 861 | case O(MISC, Sparc22): |
bd526cee NB |
862 | if (devmode != 'E') { |
863 | fprintf(stderr, Name ": --sparc2.2 only allowed with --examine\n"); | |
864 | exit(2); | |
865 | } | |
866 | SparcAdjust = 1; | |
867 | continue; | |
c82f047c NB |
868 | |
869 | case O(ASSEMBLE,'b'): /* here we simply set the bitmap file */ | |
870 | if (!optarg) { | |
871 | fprintf(stderr, Name ": bitmap file needed with -b in --assemble mode\n"); | |
872 | exit(2); | |
873 | } | |
55935d51 NB |
874 | if (strcmp(optarg, "internal")==0) { |
875 | fprintf(stderr, Name ": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n"); | |
876 | continue; | |
877 | } | |
c82f047c NB |
878 | bitmap_fd = open(optarg, O_RDWR); |
879 | if (!*optarg || bitmap_fd < 0) { | |
880 | fprintf(stderr, Name ": cannot open bitmap file %s: %s\n", optarg, strerror(errno)); | |
881 | exit(2); | |
882 | } | |
883 | ident.bitmap_fd = bitmap_fd; /* for Assemble */ | |
884 | continue; | |
f5e166fe | 885 | |
997aed5d NB |
886 | case O(ASSEMBLE, BackupFile): |
887 | case O(GROW, BackupFile): | |
06b0d786 NB |
888 | /* Specify a file into which grow might place a backup, |
889 | * or from which assemble might recover a backup | |
890 | */ | |
891 | if (backup_file) { | |
892 | fprintf(stderr, Name ": backup file already specified, rejecting %s\n", optarg); | |
893 | exit(2); | |
894 | } | |
895 | backup_file = optarg; | |
896 | continue; | |
897 | ||
c82f047c NB |
898 | case O(BUILD,'b'): |
899 | case O(CREATE,'b'): /* here we create the bitmap */ | |
85375d6d NB |
900 | if (strcmp(optarg, "none") == 0) { |
901 | fprintf(stderr, Name ": '--bitmap none' only" | |
902 | " support for --grow\n"); | |
903 | exit(2); | |
904 | } | |
905 | /* FALL THROUGH */ | |
906 | case O(GROW,'b'): | |
1e0d770c NB |
907 | if (strcmp(optarg, "internal")== 0 || |
908 | strcmp(optarg, "none")== 0 || | |
909 | strchr(optarg, '/') != NULL) { | |
910 | bitmap_file = optarg; | |
911 | continue; | |
912 | } | |
913 | /* probable typo */ | |
a1331cc4 N |
914 | fprintf(stderr, Name ": bitmap file must contain a '/', or be 'internal', or 'none'\n" |
915 | " not '%s'\n", optarg); | |
1e0d770c | 916 | exit(2); |
c82f047c | 917 | |
997aed5d NB |
918 | case O(GROW,BitmapChunk): |
919 | case O(BUILD,BitmapChunk): | |
920 | case O(CREATE,BitmapChunk): /* bitmap chunksize */ | |
c82f047c NB |
921 | bitmap_chunk = strtol(optarg, &c, 10); |
922 | if (!optarg[0] || *c || bitmap_chunk < 0 || | |
923 | bitmap_chunk & (bitmap_chunk - 1)) { | |
924 | fprintf(stderr, Name ": invalid bitmap chunksize: %s\n", | |
925 | optarg); | |
926 | exit(2); | |
927 | } | |
928 | /* convert K to B, chunk of 0K means 512B */ | |
929 | bitmap_chunk = bitmap_chunk ? bitmap_chunk * 1024 : 512; | |
930 | continue; | |
dfd4d8ee | 931 | |
7d19ad0d | 932 | case O(GROW, WriteBehind): |
997aed5d NB |
933 | case O(BUILD, WriteBehind): |
934 | case O(CREATE, WriteBehind): /* write-behind mode */ | |
dfd4d8ee NB |
935 | write_behind = DEFAULT_MAX_WRITE_BEHIND; |
936 | if (optarg) { | |
937 | write_behind = strtol(optarg, &c, 10); | |
938 | if (write_behind < 0 || *c || | |
939 | write_behind > 16383) { | |
940 | fprintf(stderr, Name ": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg); | |
941 | exit(2); | |
942 | } | |
943 | } | |
944 | continue; | |
8382f19b NB |
945 | |
946 | case O(INCREMENTAL, 'r'): | |
947 | rebuild_map = 1; | |
948 | continue; | |
52826846 NB |
949 | } |
950 | /* We have now processed all the valid options. Anything else is | |
951 | * an error | |
952 | */ | |
06b0d786 NB |
953 | if (option_index > 0) |
954 | fprintf(stderr, Name ":option --%s not valid in %s mode\n", | |
955 | long_options[option_index].name, | |
956 | map_num(modes, mode)); | |
957 | else | |
958 | fprintf(stderr, Name ": option -%c not valid in %s mode\n", | |
959 | opt, map_num(modes, mode)); | |
64c4757e | 960 | exit(2); |
52826846 NB |
961 | |
962 | } | |
963 | ||
3d4064cc NB |
964 | if (print_help) { |
965 | char *help_text = Help; | |
966 | if (print_help == 2) | |
967 | help_text = OptionHelp; | |
968 | else | |
969 | switch (mode) { | |
970 | case ASSEMBLE : help_text = Help_assemble; break; | |
971 | case BUILD : help_text = Help_build; break; | |
972 | case CREATE : help_text = Help_create; break; | |
973 | case MANAGE : help_text = Help_manage; break; | |
974 | case MISC : help_text = Help_misc; break; | |
975 | case MONITOR : help_text = Help_monitor; break; | |
976 | case GROW : help_text = Help_grow; break; | |
8382f19b | 977 | case INCREMENTAL:help_text= Help_incr; break; |
3d4064cc | 978 | } |
0047d254 | 979 | fputs(help_text,stdout); |
3d4064cc NB |
980 | exit(0); |
981 | } | |
982 | ||
0320ea45 NB |
983 | if (!mode && devs_found) { |
984 | mode = MISC; | |
985 | devmode = 'Q'; | |
986 | if (devlist->disposition == 0) | |
987 | devlist->disposition = devmode; | |
988 | } | |
52826846 NB |
989 | if (!mode) { |
990 | fputs(Usage, stderr); | |
64c4757e | 991 | exit(2); |
64c4757e | 992 | } |
38098016 NB |
993 | |
994 | if (symlinks) { | |
995 | struct createinfo *ci = conf_get_create_info(); | |
996 | ||
997 | if (strcasecmp(symlinks, "yes") == 0) | |
998 | ci->symlinks = 1; | |
999 | else if (strcasecmp(symlinks, "no") == 0) | |
1000 | ci->symlinks = 0; | |
1001 | else { | |
1002 | fprintf(stderr, Name ": option --symlinks must be 'no' or 'yes'\n"); | |
1003 | exit(2); | |
1004 | } | |
1005 | } | |
52826846 NB |
1006 | /* Ok, got the option parsing out of the way |
1007 | * hopefully it's mostly right but there might be some stuff | |
1008 | * missing | |
1009 | * | |
e0d19036 | 1010 | * That is mosty checked in the per-mode stuff but... |
52826846 NB |
1011 | * |
1012 | * For @,B,C and A without -s, the first device listed must be an md device | |
1013 | * we check that here and open it. | |
64c4757e | 1014 | */ |
52826846 | 1015 | |
dd0781e5 NB |
1016 | if (mode==MANAGE || mode == BUILD || mode == CREATE || mode == GROW || |
1017 | (mode == ASSEMBLE && ! scan)) { | |
52826846 NB |
1018 | if (devs_found < 1) { |
1019 | fprintf(stderr, Name ": an md device must be given in this mode\n"); | |
1020 | exit(2); | |
1021 | } | |
dd0781e5 | 1022 | if ((int)ident.super_minor == -2 && autof) { |
aba69144 | 1023 | fprintf(stderr, Name ": --super-minor=dev is incompatible with --auto\n"); |
dd0781e5 NB |
1024 | exit(2); |
1025 | } | |
7f91af49 | 1026 | if (mode == MANAGE || mode == GROW) { |
6be1d39d | 1027 | mdfd = open_mddev(devlist->devname, 1); |
7f91af49 N |
1028 | if (mdfd < 0) |
1029 | exit(1); | |
1030 | } else | |
1031 | /* non-existent device is OK */ | |
1032 | mdfd = open_mddev(devlist->devname, 0); | |
1033 | if (mdfd == -2) { | |
1034 | fprintf(stderr, Name ": device %s exists but is not an " | |
1035 | "md array.\n", devlist->devname); | |
52826846 | 1036 | exit(1); |
7f91af49 | 1037 | } |
98c6faba | 1038 | if ((int)ident.super_minor == -2) { |
d013a55e | 1039 | struct stat stb; |
7f91af49 N |
1040 | if (mdfd < 0) { |
1041 | fprintf(stderr, Name ": --super-minor=dev given, and " | |
1042 | "listed device %s doesn't exist.\n", | |
1043 | devlist->devname); | |
1044 | exit(1); | |
1045 | } | |
d013a55e | 1046 | fstat(mdfd, &stb); |
0df46c2a | 1047 | ident.super_minor = minor(stb.st_rdev); |
d013a55e | 1048 | } |
7f91af49 N |
1049 | if (mdfd >= 0 && mode != MANAGE && mode != GROW) { |
1050 | /* We don't really want this open yet, we just might | |
1051 | * have wanted to check some things | |
1052 | */ | |
1053 | close(mdfd); | |
1054 | mdfd = -1; | |
1055 | } | |
64c4757e | 1056 | } |
52826846 | 1057 | |
e4c4352e | 1058 | if (raiddisks) { |
e4c4352e NB |
1059 | if (raiddisks == 1 && !force && level != -5) { |
1060 | fprintf(stderr, Name ": '1' is an unusual number of drives for an array, so it is probably\n" | |
1061 | " a mistake. If you really mean it you will need to specify --force before\n" | |
1062 | " setting the number of drives.\n"); | |
1063 | exit(2); | |
1064 | } | |
1065 | } | |
c82f047c | 1066 | |
997aed5d | 1067 | if (homehost == NULL) |
0ac91628 | 1068 | homehost = conf_get_homehost(&require_homehost); |
9180c81b | 1069 | if (homehost == NULL || strcmp(homehost, "<system>")==0) { |
05697ec1 NB |
1070 | if (gethostname(sys_hostname, sizeof(sys_hostname)) == 0) { |
1071 | sys_hostname[sizeof(sys_hostname)-1] = 0; | |
1072 | homehost = sys_hostname; | |
1073 | } | |
1074 | } | |
997aed5d | 1075 | |
ac5678dd N |
1076 | if ((mode != MISC || devmode != 'E') && |
1077 | geteuid() != 0) { | |
1078 | fprintf(stderr, Name ": must be super-user to perform this action\n"); | |
1079 | exit(1); | |
1080 | } | |
1081 | ||
7f91af49 N |
1082 | ident.autof = autof; |
1083 | ||
52826846 NB |
1084 | rv = 0; |
1085 | switch(mode) { | |
e0d19036 | 1086 | case MANAGE: |
52826846 NB |
1087 | /* readonly, add/remove, readwrite, runstop */ |
1088 | if (readonly>0) | |
cd29a5c8 | 1089 | rv = Manage_ro(devlist->devname, mdfd, readonly); |
52826846 | 1090 | if (!rv && devs_found>1) |
cd29a5c8 | 1091 | rv = Manage_subdevs(devlist->devname, mdfd, |
7d2e6486 | 1092 | devlist->next, verbose-quiet, test); |
52826846 | 1093 | if (!rv && readonly < 0) |
cd29a5c8 | 1094 | rv = Manage_ro(devlist->devname, mdfd, readonly); |
52826846 | 1095 | if (!rv && runstop) |
ab56093f | 1096 | rv = Manage_runstop(devlist->devname, mdfd, runstop, quiet); |
52826846 | 1097 | break; |
e0d19036 | 1098 | case ASSEMBLE: |
d013a55e | 1099 | if (devs_found == 1 && ident.uuid_set == 0 && |
947fd4dd | 1100 | ident.super_minor == UnSet && ident.name[0] == 0 && !scan ) { |
d013a55e | 1101 | /* Only a device has been given, so get details from config file */ |
8aec876d | 1102 | mddev_ident_t array_ident = conf_get_ident(devlist->devname); |
b5e64645 NB |
1103 | if (array_ident == NULL) { |
1104 | fprintf(stderr, Name ": %s not identified in config file.\n", | |
1105 | devlist->devname); | |
d013a55e | 1106 | rv |= 1; |
7f91af49 N |
1107 | if (mdfd >= 0) |
1108 | close(mdfd); | |
b5e64645 | 1109 | } else { |
7f91af49 N |
1110 | if (array_ident->autof == 0) |
1111 | array_ident->autof = autof; | |
1112 | rv |= Assemble(ss, devlist->devname, array_ident, | |
1113 | NULL, backup_file, | |
0ac91628 N |
1114 | readonly, runstop, update, |
1115 | homehost, require_homehost, | |
1116 | verbose-quiet, force); | |
d013a55e NB |
1117 | } |
1118 | } else if (!scan) | |
7f91af49 | 1119 | rv = Assemble(ss, devlist->devname, &ident, |
06b0d786 | 1120 | devlist->next, backup_file, |
0ac91628 N |
1121 | readonly, runstop, update, |
1122 | homehost, require_homehost, | |
1123 | verbose-quiet, force); | |
5787fa49 NB |
1124 | else if (devs_found>0) { |
1125 | if (update && devs_found > 1) { | |
1126 | fprintf(stderr, Name ": can only update a single array at a time\n"); | |
1127 | exit(1); | |
1128 | } | |
06b0d786 NB |
1129 | if (backup_file && devs_found > 1) { |
1130 | fprintf(stderr, Name ": can only assemble a single array when providing a backup file.\n"); | |
1131 | exit(1); | |
1132 | } | |
cd29a5c8 | 1133 | for (dv = devlist ; dv ; dv=dv->next) { |
8aec876d | 1134 | mddev_ident_t array_ident = conf_get_ident(dv->devname); |
52826846 NB |
1135 | if (array_ident == NULL) { |
1136 | fprintf(stderr, Name ": %s not identified in config file.\n", | |
cd29a5c8 | 1137 | dv->devname); |
52826846 NB |
1138 | rv |= 1; |
1139 | continue; | |
1140 | } | |
7f91af49 N |
1141 | if (array_ident->autof == 0) |
1142 | array_ident->autof = autof; | |
1143 | rv |= Assemble(ss, dv->devname, array_ident, | |
06b0d786 | 1144 | NULL, backup_file, |
0ac91628 N |
1145 | readonly, runstop, update, |
1146 | homehost, require_homehost, | |
1147 | verbose-quiet, force); | |
52826846 | 1148 | } |
5787fa49 | 1149 | } else { |
b179246f | 1150 | mddev_ident_t a, array_list = conf_get_ident(NULL); |
8aec876d | 1151 | mddev_dev_t devlist = conf_get_devs(); |
da6b5ca9 | 1152 | int cnt = 0; |
b179246f | 1153 | int failures, successes; |
da6b5ca9 NB |
1154 | if (devlist == NULL) { |
1155 | fprintf(stderr, Name ": No devices listed in conf file were found.\n"); | |
1156 | exit(1); | |
1157 | } | |
1158 | if (update) { | |
1159 | fprintf(stderr, Name ": --update not meaningful with a --scan assembly.\n"); | |
1160 | exit(1); | |
1161 | } | |
1162 | if (backup_file) { | |
1163 | fprintf(stderr, Name ": --backup_file not meaningful with a --scan assembly.\n"); | |
1164 | exit(1); | |
1165 | } | |
b179246f N |
1166 | for (a = array_list; a ; a = a->next) { |
1167 | a->assembled = 0; | |
1168 | if (a->autof == 0) | |
1169 | a->autof = autof; | |
da6b5ca9 | 1170 | } |
b179246f N |
1171 | do { |
1172 | failures = 0; | |
1173 | successes = 0; | |
1174 | rv = 0; | |
1175 | for (a = array_list; a ; a = a->next) { | |
1176 | int r; | |
1177 | if (a->assembled) | |
1178 | continue; | |
1179 | if (a->devname && | |
1180 | strcasecmp(a->devname, "<ignore>") == 0) | |
1181 | continue; | |
1182 | ||
1183 | r = Assemble(ss, a->devname, | |
1184 | a, | |
1185 | NULL, NULL, | |
1186 | readonly, runstop, NULL, | |
1187 | homehost, require_homehost, | |
1188 | verbose-quiet, force); | |
1189 | if (r == 0) { | |
1190 | a->assembled = 1; | |
1191 | successes++; | |
1192 | } else | |
1193 | failures++; | |
1194 | rv |= r; | |
1195 | cnt++; | |
1196 | } | |
1197 | } while (failures && successes); | |
a30b2ecd | 1198 | if (homehost && cnt == 0) { |
da6b5ca9 | 1199 | /* Maybe we can auto-assemble something. |
7f91af49 | 1200 | * Repeatedly call Assemble in auto-assemble mode |
da6b5ca9 NB |
1201 | * until it fails |
1202 | */ | |
1203 | int rv2; | |
d55e3aef NB |
1204 | int acnt; |
1205 | ident.autof = autof; | |
da6b5ca9 | 1206 | do { |
1c203a4b | 1207 | mddev_dev_t devlist = conf_get_devs(); |
d55e3aef NB |
1208 | acnt = 0; |
1209 | do { | |
7f91af49 | 1210 | rv2 = Assemble(ss, NULL, |
8aec876d | 1211 | &ident, |
1c203a4b | 1212 | devlist, NULL, |
0ac91628 N |
1213 | readonly, runstop, NULL, |
1214 | homehost, require_homehost, | |
1215 | verbose-quiet, force); | |
d55e3aef NB |
1216 | if (rv2==0) { |
1217 | cnt++; | |
1218 | acnt++; | |
1219 | } | |
589395d6 NB |
1220 | if (rv2 == 1) |
1221 | /* found something so even though assembly failed we | |
1222 | * want to avoid auto-updates | |
1223 | */ | |
1224 | auto_update_home = 0; | |
d55e3aef NB |
1225 | } while (rv2!=2); |
1226 | /* Incase there are stacked devices, we need to go around again */ | |
d55e3aef | 1227 | } while (acnt); |
e0fe762a | 1228 | #if 0 |
589395d6 NB |
1229 | if (cnt == 0 && auto_update_home && homehost) { |
1230 | /* Nothing found, maybe we need to bootstrap homehost info */ | |
1231 | do { | |
1232 | acnt = 0; | |
1233 | do { | |
7f91af49 | 1234 | rv2 = Assemble(ss, NULL, |
8aec876d | 1235 | &ident, |
43f2372a | 1236 | NULL, NULL, |
0ac91628 N |
1237 | readonly, runstop, "homehost", |
1238 | homehost, require_homehost, | |
1239 | verbose-quiet, force); | |
589395d6 NB |
1240 | if (rv2==0) { |
1241 | cnt++; | |
1242 | acnt++; | |
1243 | } | |
1244 | } while (rv2!=2); | |
1245 | /* Incase there are stacked devices, we need to go around again */ | |
589395d6 NB |
1246 | } while (acnt); |
1247 | } | |
e0fe762a | 1248 | #endif |
da6b5ca9 NB |
1249 | if (cnt == 0 && rv == 0) { |
1250 | fprintf(stderr, Name ": No arrays found in config file or automatically\n"); | |
1251 | rv = 1; | |
1c203a4b NB |
1252 | } else if (cnt) |
1253 | rv = 0; | |
da6b5ca9 NB |
1254 | } else if (cnt == 0 && rv == 0) { |
1255 | fprintf(stderr, Name ": No arrays found in config file\n"); | |
1256 | rv = 1; | |
1257 | } | |
52826846 NB |
1258 | } |
1259 | break; | |
e0d19036 | 1260 | case BUILD: |
c82f047c | 1261 | if (delay == 0) delay = DEFAULT_BITMAP_DELAY; |
dfd4d8ee NB |
1262 | if (write_behind && !bitmap_file) { |
1263 | fprintf(stderr, Name ": write-behind mode requires a bitmap.\n"); | |
1264 | rv = 1; | |
1265 | break; | |
1266 | } | |
5b28bd56 | 1267 | if (raiddisks == 0) { |
e5669f40 | 1268 | fprintf(stderr, Name ": no raid-devices specified.\n"); |
5b28bd56 NB |
1269 | rv = 1; |
1270 | break; | |
1271 | } | |
dfd4d8ee | 1272 | |
c82f047c | 1273 | if (bitmap_file) { |
55935d51 NB |
1274 | if (strcmp(bitmap_file, "internal")==0) { |
1275 | fprintf(stderr, Name ": 'internal' bitmaps not supported with --build\n"); | |
1276 | rv |= 1; | |
1277 | break; | |
1278 | } | |
c82f047c | 1279 | } |
7f91af49 | 1280 | rv = Build(devlist->devname, chunk, level, layout, |
c82f047c | 1281 | raiddisks, devlist->next, assume_clean, |
7f91af49 | 1282 | bitmap_file, bitmap_chunk, write_behind, |
83208785 | 1283 | delay, verbose-quiet, autof, size); |
52826846 | 1284 | break; |
e0d19036 | 1285 | case CREATE: |
c82f047c | 1286 | if (delay == 0) delay = DEFAULT_BITMAP_DELAY; |
dfd4d8ee NB |
1287 | if (write_behind && !bitmap_file) { |
1288 | fprintf(stderr, Name ": write-behind mode requires a bitmap.\n"); | |
1289 | rv = 1; | |
1290 | break; | |
1291 | } | |
5b28bd56 | 1292 | if (raiddisks == 0) { |
e5669f40 | 1293 | fprintf(stderr, Name ": no raid-devices specified.\n"); |
5b28bd56 NB |
1294 | rv = 1; |
1295 | break; | |
1296 | } | |
f9ce90ba | 1297 | |
7f91af49 | 1298 | rv = Create(ss, devlist->devname, chunk, level, layout, size<0 ? 0 : size, |
05697ec1 | 1299 | raiddisks, sparedisks, ident.name, homehost, |
3d3dd91e | 1300 | ident.uuid_set ? ident.uuid : NULL, |
47d79ef8 | 1301 | devs_found-1, devlist->next, runstop, verbose-quiet, force, assume_clean, |
7f91af49 | 1302 | bitmap_file, bitmap_chunk, write_behind, delay, autof); |
52826846 | 1303 | break; |
e0d19036 | 1304 | case MISC: |
e0d19036 NB |
1305 | if (devmode == 'E') { |
1306 | if (devlist == NULL && !scan) { | |
1307 | fprintf(stderr, Name ": No devices to examine\n"); | |
1308 | exit(2); | |
1309 | } | |
1310 | if (devlist == NULL) | |
8aec876d | 1311 | devlist = conf_get_devs(); |
e0d19036 | 1312 | if (devlist == NULL) { |
c913b90e | 1313 | fprintf(stderr, Name ": No devices listed in %s\n", configfile?configfile:DefaultConfFile); |
e0d19036 NB |
1314 | exit(1); |
1315 | } | |
e843d5d7 NB |
1316 | if (brief && verbose) |
1317 | brief = 2; | |
0d726f17 KS |
1318 | rv = Examine(devlist, scan?(verbose>1?0:verbose+1):brief, |
1319 | export, scan, | |
1320 | SparcAdjust, ss, homehost); | |
4cce4069 DW |
1321 | } else if (devmode == DetailPlatform) { |
1322 | rv = Detail_Platform(ss ? ss->ss : NULL, ss ? scan : 1, verbose); | |
e0d19036 NB |
1323 | } else { |
1324 | if (devlist == NULL) { | |
fabbfd48 DW |
1325 | if ((devmode=='D' || devmode == Waitclean) && scan) { |
1326 | /* apply --detail or --wait-clean to | |
1327 | * all devices in /proc/mdstat | |
1328 | */ | |
22a88995 | 1329 | struct mdstat_ent *ms = mdstat_read(0, 1); |
e0d19036 | 1330 | struct mdstat_ent *e; |
35904960 | 1331 | struct map_ent *map = NULL; |
8f1b2bbb | 1332 | int members; |
fabbfd48 DW |
1333 | int v = verbose>1?0:verbose+1; |
1334 | ||
8f1b2bbb | 1335 | for (members = 0; members <= 1; members++) { |
e0d19036 | 1336 | for (e=ms ; e ; e=e->next) { |
35904960 N |
1337 | char *name; |
1338 | struct map_ent *me; | |
8f1b2bbb N |
1339 | int member = e->metadata_version && |
1340 | strncmp(e->metadata_version, | |
1341 | "external:/", 10) == 0; | |
1342 | if (members != member) | |
1343 | continue; | |
35904960 | 1344 | me = map_by_devnum(&map, e->devnum); |
8615dcff N |
1345 | if (me && me->path |
1346 | && strcmp(me->path, "/unknown") != 0) | |
35904960 N |
1347 | name = me->path; |
1348 | else | |
1349 | name = get_md_name(e->devnum); | |
e0d19036 NB |
1350 | |
1351 | if (!name) { | |
1352 | fprintf(stderr, Name ": cannot find device file for %s\n", | |
1353 | e->dev); | |
1354 | continue; | |
1355 | } | |
fabbfd48 DW |
1356 | if (devmode == 'D') |
1357 | rv |= Detail(name, v, | |
1358 | export, test, | |
1359 | homehost); | |
1360 | else | |
9f1da824 | 1361 | rv |= WaitClean(name, -1, v); |
91f068bf NB |
1362 | put_md_name(name); |
1363 | } | |
8f1b2bbb | 1364 | } |
89a10d84 | 1365 | free_mdstat(ms); |
91f068bf NB |
1366 | } else if (devmode == 'S' && scan) { |
1367 | /* apply --stop to all devices in /proc/mdstat */ | |
1368 | /* Due to possible stacking of devices, repeat until | |
1369 | * nothing more can be stopped | |
1370 | */ | |
1371 | int progress=1, err; | |
1372 | int last = 0; | |
1373 | do { | |
22a88995 | 1374 | struct mdstat_ent *ms = mdstat_read(0, 0); |
91f068bf NB |
1375 | struct mdstat_ent *e; |
1376 | ||
1377 | if (!progress) last = 1; | |
1378 | progress = 0; err = 0; | |
1379 | for (e=ms ; e ; e=e->next) { | |
1380 | char *name = get_md_name(e->devnum); | |
1381 | ||
1382 | if (!name) { | |
1383 | fprintf(stderr, Name ": cannot find device file for %s\n", | |
1384 | e->dev); | |
1385 | continue; | |
1386 | } | |
6be1d39d | 1387 | mdfd = open_mddev(name, 1); |
43fc1676 | 1388 | if (mdfd >= 0) { |
ab56093f | 1389 | if (Manage_runstop(name, mdfd, -1, quiet?1:last?0:-1)) |
91f068bf NB |
1390 | err = 1; |
1391 | else | |
1392 | progress = 1; | |
43fc1676 NB |
1393 | close(mdfd); |
1394 | } | |
91f068bf NB |
1395 | |
1396 | put_md_name(name); | |
e0d19036 | 1397 | } |
89a10d84 | 1398 | free_mdstat(ms); |
91f068bf | 1399 | } while (!last && err); |
f9c25f1d | 1400 | if (err) rv |= 1; |
91f068bf | 1401 | } else { |
e0d19036 NB |
1402 | fprintf(stderr, Name ": No devices given.\n"); |
1403 | exit(2); | |
1404 | } | |
1405 | } | |
1406 | for (dv=devlist ; dv; dv=dv->next) { | |
1407 | switch(dv->disposition) { | |
1408 | case 'D': | |
54bad364 KS |
1409 | rv |= Detail(dv->devname, |
1410 | brief?1+verbose:0, | |
1411 | export, test, homehost); | |
1412 | continue; | |
e0d19036 | 1413 | case 'K': /* Zero superblock */ |
9277cc77 N |
1414 | if (ss) |
1415 | rv |= Kill(dv->devname, ss, force, quiet,0); | |
1416 | else { | |
1417 | int q = quiet; | |
1418 | do { | |
1419 | rv |= Kill(dv->devname, NULL, force, q, 0); | |
1420 | q = 1; | |
4c619b29 | 1421 | } while (rv == 0); |
9277cc77 N |
1422 | rv &= ~2; |
1423 | } | |
111d01fc | 1424 | continue; |
e0d19036 NB |
1425 | case 'Q': |
1426 | rv |= Query(dv->devname); continue; | |
c82f047c | 1427 | case 'X': |
55935d51 | 1428 | rv |= ExamineBitmap(dv->devname, brief, ss); continue; |
b90c0e9a NB |
1429 | case 'W': |
1430 | rv |= Wait(dv->devname); continue; | |
1770662b | 1431 | case Waitclean: |
9f1da824 | 1432 | rv |= WaitClean(dv->devname, -1, verbose-quiet); continue; |
33414a01 DW |
1433 | case KillSubarray: |
1434 | rv |= Kill_subarray(dv->devname, subarray, quiet); | |
1435 | continue; | |
aa534678 DW |
1436 | case UpdateSubarray: |
1437 | if (update == NULL) { | |
1438 | fprintf(stderr, | |
1439 | Name ": -U/--update must be specified with --update-subarray\n"); | |
1440 | rv |= 1; | |
1441 | continue; | |
1442 | } | |
1443 | rv |= Update_subarray(dv->devname, subarray, update, &ident, quiet); | |
1444 | continue; | |
e0d19036 | 1445 | } |
6be1d39d | 1446 | mdfd = open_mddev(dv->devname, 1); |
43fc1676 | 1447 | if (mdfd>=0) { |
e0d19036 NB |
1448 | switch(dv->disposition) { |
1449 | case 'R': | |
ab56093f | 1450 | rv |= Manage_runstop(dv->devname, mdfd, 1, quiet); break; |
e0d19036 | 1451 | case 'S': |
ab56093f | 1452 | rv |= Manage_runstop(dv->devname, mdfd, -1, quiet); break; |
e0d19036 NB |
1453 | case 'o': |
1454 | rv |= Manage_ro(dv->devname, mdfd, 1); break; | |
1455 | case 'w': | |
1456 | rv |= Manage_ro(dv->devname, mdfd, -1); break; | |
1457 | } | |
43fc1676 | 1458 | close(mdfd); |
7f48e210 NB |
1459 | } else |
1460 | rv |= 1; | |
e0d19036 | 1461 | } |
cd29a5c8 | 1462 | } |
9a9dab36 | 1463 | break; |
e0d19036 | 1464 | case MONITOR: |
e0d19036 NB |
1465 | if (!devlist && !scan) { |
1466 | fprintf(stderr, Name ": Cannot monitor: need --scan or at least one device\n"); | |
1467 | rv = 1; | |
1468 | break; | |
1469 | } | |
b5e64645 NB |
1470 | if (pidfile && !daemonise) { |
1471 | fprintf(stderr, Name ": Cannot write a pid file when not in daemon mode\n"); | |
1472 | rv = 1; | |
1473 | break; | |
1474 | } | |
ddc7201f N |
1475 | if (delay == 0) { |
1476 | if (get_linux_version() > 20616) | |
1477 | /* mdstat responds to poll */ | |
1478 | delay = 1000; | |
1479 | else | |
1480 | delay = 60; | |
1481 | } | |
d013a55e | 1482 | rv= Monitor(devlist, mailaddr, program, |
773135f5 | 1483 | delay?delay:60, daemonise, scan, oneshot, |
9a36a9b7 | 1484 | dosyslog, test, pidfile, increments); |
9a9dab36 | 1485 | break; |
dd0781e5 NB |
1486 | |
1487 | case GROW: | |
84e11361 N |
1488 | if (array_size >= 0) { |
1489 | /* alway impose array size first, independent of | |
1490 | * anything else | |
9ce510be N |
1491 | * Do not allow level or raid_disks changes at the |
1492 | * same time as that can be irreversibly destructive. | |
84e11361 N |
1493 | */ |
1494 | struct mdinfo sra; | |
1495 | int err; | |
9ce510be N |
1496 | if (raiddisks || level != UnSet) { |
1497 | fprintf(stderr, Name ": cannot change array size in same operation " | |
1498 | "as changing raiddisks or level.\n" | |
1499 | " Change size first, then check that data is still intact.\n"); | |
1500 | rv = 1; | |
1501 | break; | |
1502 | } | |
84e11361 N |
1503 | sysfs_init(&sra, mdfd, 0); |
1504 | if (array_size == 0) | |
1505 | err = sysfs_set_str(&sra, NULL, "array_size", "default"); | |
1506 | else | |
1507 | err = sysfs_set_num(&sra, NULL, "array_size", array_size / 2); | |
1508 | if (err < 0) { | |
1509 | if (errno == E2BIG) | |
1510 | fprintf(stderr, Name ": --array-size setting" | |
1511 | " is too large.\n"); | |
1512 | else | |
1513 | fprintf(stderr, Name ": current kernel does" | |
1514 | " not support setting --array-size\n"); | |
1515 | rv = 1; | |
1516 | break; | |
1517 | } | |
1518 | } | |
dd0781e5 | 1519 | if (devs_found > 1) { |
aba69144 | 1520 | |
e5329c37 | 1521 | /* must be '-a'. */ |
7236ee7a N |
1522 | if (size >= 0 || raiddisks || chunk || layout_str != NULL || bitmap_file) { |
1523 | fprintf(stderr, Name ": --add cannot be used with other geometry changes in --grow mode\n"); | |
e5329c37 NB |
1524 | rv = 1; |
1525 | break; | |
1526 | } | |
1527 | for (dv=devlist->next; dv ; dv=dv->next) { | |
1528 | rv = Grow_Add_device(devlist->devname, mdfd, dv->devname); | |
1529 | if (rv) | |
1530 | break; | |
1531 | } | |
7236ee7a N |
1532 | } else if (bitmap_file) { |
1533 | if (size >= 0 || raiddisks || chunk || layout_str != NULL) { | |
1534 | fprintf(stderr, Name ": --bitmap changes cannot be used with other geometry changes in --grow mode\n"); | |
1535 | rv = 1; | |
1536 | break; | |
1537 | } | |
1538 | if (delay == 0) | |
1539 | delay = DEFAULT_BITMAP_DELAY; | |
f5e166fe | 1540 | rv = Grow_addbitmap(devlist->devname, mdfd, bitmap_file, |
8fac0577 | 1541 | bitmap_chunk, delay, write_behind, force); |
7236ee7a N |
1542 | } else if (size >= 0 || raiddisks != 0 || layout_str != NULL |
1543 | || chunk != 0 || level != UnSet) { | |
1544 | rv = Grow_reshape(devlist->devname, mdfd, quiet, backup_file, | |
1545 | size, level, layout_str, chunk, raiddisks); | |
84e11361 | 1546 | } else if (array_size < 0) |
b5e64645 | 1547 | fprintf(stderr, Name ": no changes to --grow\n"); |
dd0781e5 | 1548 | break; |
8382f19b NB |
1549 | case INCREMENTAL: |
1550 | if (rebuild_map) { | |
1551 | RebuildMap(); | |
1552 | } | |
1553 | if (scan) { | |
1554 | if (runstop <= 0) { | |
1555 | fprintf(stderr, Name | |
1556 | ": --incremental --scan meaningless without --run.\n"); | |
1557 | break; | |
1558 | } | |
29ba4804 N |
1559 | if (devmode == 'f') { |
1560 | fprintf(stderr, Name | |
1561 | ": --incremental --scan --fail not supported.\n"); | |
1562 | break; | |
1563 | } | |
8382f19b NB |
1564 | rv = IncrementalScan(verbose); |
1565 | } | |
1566 | if (!devlist) { | |
1567 | if (!rebuild_map && !scan) { | |
1568 | fprintf(stderr, Name | |
1569 | ": --incremental requires a device.\n"); | |
1570 | rv = 1; | |
1571 | } | |
1572 | break; | |
1573 | } | |
1574 | if (devlist->next) { | |
1575 | fprintf(stderr, Name | |
1576 | ": --incremental can only handle one device.\n"); | |
1577 | rv = 1; | |
1578 | break; | |
1579 | } | |
29ba4804 N |
1580 | if (devmode == 'f') { |
1581 | rv = IncrementalRemove(devlist->devname, verbose-quiet); | |
1582 | break; | |
1583 | } | |
8382f19b | 1584 | rv = Incremental(devlist->devname, verbose-quiet, runstop, |
0ac91628 | 1585 | ss, homehost, require_homehost, autof); |
1f48664b NB |
1586 | break; |
1587 | case AUTODETECT: | |
1588 | autodetect(); | |
1589 | break; | |
64c4757e | 1590 | } |
52826846 | 1591 | exit(rv); |
64c4757e | 1592 | } |