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