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