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