]>
Commit | Line | Data |
---|---|---|
979afcb8 PS |
1 | /* |
2 | * raid6check - extended consistency check for RAID-6 | |
3 | * | |
4 | * Copyright (C) 2011 Piergiorgio Sartor | |
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: Piergiorgio Sartor | |
22 | * Based on "restripe.c" from "mdadm" codebase | |
23 | */ | |
24 | ||
25 | #include "mdadm.h" | |
26 | #include <stdint.h> | |
8d8ab389 PS |
27 | #include <signal.h> |
28 | #include <sys/mman.h> | |
979afcb8 | 29 | |
635b5861 BS |
30 | enum repair { |
31 | NO_REPAIR = 0, | |
32 | MANUAL_REPAIR, | |
33 | AUTO_REPAIR | |
34 | }; | |
35 | ||
979afcb8 PS |
36 | int geo_map(int block, unsigned long long stripe, int raid_disks, |
37 | int level, int layout); | |
38 | void qsyndrome(uint8_t *p, uint8_t *q, uint8_t **sources, int disks, int size); | |
39 | void make_tables(void); | |
f2e29ad6 RB |
40 | void ensure_zero_has_size(int chunk_size); |
41 | void raid6_datap_recov(int disks, size_t bytes, int faila, uint8_t **ptrs); | |
42 | void raid6_2data_recov(int disks, size_t bytes, int faila, int failb, | |
43 | uint8_t **ptrs); | |
44 | void xor_blocks(char *target, char **sources, int disks, int size); | |
45 | ||
979afcb8 PS |
46 | /* Collect per stripe consistency information */ |
47 | void raid6_collect(int chunk_size, uint8_t *p, uint8_t *q, | |
48 | char *chunkP, char *chunkQ, int *results) | |
49 | { | |
50 | int i; | |
51 | int data_id; | |
52 | uint8_t Px, Qx; | |
53 | extern uint8_t raid6_gflog[]; | |
54 | ||
55 | for(i = 0; i < chunk_size; i++) { | |
56 | Px = (uint8_t)chunkP[i] ^ (uint8_t)p[i]; | |
57 | Qx = (uint8_t)chunkQ[i] ^ (uint8_t)q[i]; | |
58 | ||
59 | if((Px != 0) && (Qx == 0)) | |
60 | results[i] = -1; | |
61 | ||
62 | if((Px == 0) && (Qx != 0)) | |
63 | results[i] = -2; | |
64 | ||
65 | if((Px != 0) && (Qx != 0)) { | |
66 | data_id = (raid6_gflog[Qx] - raid6_gflog[Px]); | |
67 | if(data_id < 0) data_id += 255; | |
68 | results[i] = data_id; | |
69 | } | |
70 | ||
71 | if((Px == 0) && (Qx == 0)) | |
72 | results[i] = -255; | |
73 | } | |
74 | } | |
75 | ||
76 | /* Try to find out if a specific disk has problems */ | |
77 | int raid6_stats(int *results, int raid_disks, int chunk_size) | |
78 | { | |
79 | int i; | |
80 | int curr_broken_disk = -255; | |
81 | int prev_broken_disk = -255; | |
82 | int broken_status = 0; | |
83 | ||
84 | for(i = 0; i < chunk_size; i++) { | |
85 | ||
86 | if(results[i] != -255) | |
87 | curr_broken_disk = results[i]; | |
88 | ||
89 | if(curr_broken_disk >= raid_disks) | |
90 | broken_status = 2; | |
91 | ||
92 | switch(broken_status) { | |
93 | case 0: | |
94 | if(curr_broken_disk != -255) { | |
95 | prev_broken_disk = curr_broken_disk; | |
96 | broken_status = 1; | |
97 | } | |
98 | break; | |
99 | ||
100 | case 1: | |
101 | if(curr_broken_disk != prev_broken_disk) | |
102 | broken_status = 2; | |
103 | break; | |
104 | ||
105 | case 2: | |
106 | default: | |
107 | curr_broken_disk = prev_broken_disk = -65535; | |
108 | break; | |
109 | } | |
110 | } | |
111 | ||
112 | return curr_broken_disk; | |
113 | } | |
114 | ||
351d7680 RB |
115 | int lock_stripe(struct mdinfo *info, unsigned long long start, |
116 | int chunk_size, int data_disks, sighandler_t *sig) { | |
117 | int rv; | |
118 | if(mlockall(MCL_CURRENT | MCL_FUTURE) != 0) { | |
119 | return 2; | |
120 | } | |
121 | ||
122 | sig[0] = signal(SIGTERM, SIG_IGN); | |
123 | sig[1] = signal(SIGINT, SIG_IGN); | |
124 | sig[2] = signal(SIGQUIT, SIG_IGN); | |
125 | ||
126 | rv = sysfs_set_num(info, NULL, "suspend_lo", start * chunk_size * data_disks); | |
127 | rv |= sysfs_set_num(info, NULL, "suspend_hi", (start + 1) * chunk_size * data_disks); | |
128 | return rv * 256; | |
129 | } | |
130 | ||
131 | int unlock_all_stripes(struct mdinfo *info, sighandler_t *sig) { | |
132 | int rv; | |
133 | rv = sysfs_set_num(info, NULL, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL); | |
134 | rv |= sysfs_set_num(info, NULL, "suspend_hi", 0); | |
135 | rv |= sysfs_set_num(info, NULL, "suspend_lo", 0); | |
136 | ||
137 | signal(SIGQUIT, sig[2]); | |
138 | signal(SIGINT, sig[1]); | |
139 | signal(SIGTERM, sig[0]); | |
140 | ||
141 | if(munlockall() != 0) | |
142 | return 3; | |
143 | return rv * 256; | |
144 | } | |
145 | ||
8d8ab389 | 146 | int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets, |
979afcb8 | 147 | int raid_disks, int chunk_size, int level, int layout, |
f2e29ad6 | 148 | unsigned long long start, unsigned long long length, char *name[], |
635b5861 | 149 | enum repair repair, int failed_disk1, int failed_disk2) |
979afcb8 PS |
150 | { |
151 | /* read the data and p and q blocks, and check we got them right */ | |
503975b9 N |
152 | char *stripe_buf = xmalloc(raid_disks * chunk_size); |
153 | char **stripes = xmalloc(raid_disks * sizeof(char*)); | |
154 | char **blocks = xmalloc(raid_disks * sizeof(char*)); | |
696e95a1 | 155 | int *block_index_for_slot = xmalloc(raid_disks * sizeof(int)); |
503975b9 N |
156 | uint8_t *p = xmalloc(chunk_size); |
157 | uint8_t *q = xmalloc(chunk_size); | |
158 | int *results = xmalloc(chunk_size * sizeof(int)); | |
351d7680 | 159 | sighandler_t *sig = xmalloc(3 * sizeof(sighandler_t)); |
979afcb8 PS |
160 | |
161 | int i; | |
162 | int diskP, diskQ; | |
163 | int data_disks = raid_disks - 2; | |
af3c3750 | 164 | int err = 0; |
979afcb8 PS |
165 | |
166 | extern int tables_ready; | |
167 | ||
168 | if (!tables_ready) | |
169 | make_tables(); | |
170 | ||
171 | for ( i = 0 ; i < raid_disks ; i++) | |
172 | stripes[i] = stripe_buf + i * chunk_size; | |
173 | ||
174 | while (length > 0) { | |
175 | int disk; | |
176 | ||
af3c3750 PS |
177 | printf("pos --> %llu\n", start); |
178 | ||
351d7680 RB |
179 | err = lock_stripe(info, start, chunk_size, data_disks, sig); |
180 | if(err != 0) { | |
181 | if (err != 2) | |
182 | unlock_all_stripes(info, sig); | |
8d8ab389 PS |
183 | goto exitCheck; |
184 | } | |
979afcb8 | 185 | for (i = 0 ; i < raid_disks ; i++) { |
2161adce BS |
186 | off64_t seek_res = lseek64(source[i], offsets[i] + start * chunk_size, |
187 | SEEK_SET); | |
188 | if (seek_res < 0) { | |
189 | fprintf(stderr, "lseek to source %d failed\n", i); | |
190 | unlock_all_stripes(info, sig); | |
191 | err = -1; | |
192 | goto exitCheck; | |
193 | } | |
2c7b668d BS |
194 | int read_res = read(source[i], stripes[i], chunk_size); |
195 | if (read_res < chunk_size) { | |
196 | fprintf(stderr, "Failed to read complete chunk disk %d, aborting\n", i); | |
197 | unlock_all_stripes(info, sig); | |
2161adce | 198 | err = -1; |
2c7b668d BS |
199 | goto exitCheck; |
200 | } | |
979afcb8 | 201 | } |
351d7680 RB |
202 | err = unlock_all_stripes(info, sig); |
203 | if(err != 0) | |
8d8ab389 | 204 | goto exitCheck; |
8d8ab389 | 205 | |
979afcb8 | 206 | for (i = 0 ; i < data_disks ; i++) { |
af3c3750 | 207 | int disk = geo_map(i, start, raid_disks, level, layout); |
979afcb8 | 208 | blocks[i] = stripes[disk]; |
696e95a1 | 209 | block_index_for_slot[disk] = i; |
979afcb8 PS |
210 | printf("%d->%d\n", i, disk); |
211 | } | |
212 | ||
213 | qsyndrome(p, q, (uint8_t**)blocks, data_disks, chunk_size); | |
af3c3750 | 214 | diskP = geo_map(-1, start, raid_disks, level, layout); |
f2e29ad6 RB |
215 | diskQ = geo_map(-2, start, raid_disks, level, layout); |
216 | blocks[data_disks] = stripes[diskP]; | |
696e95a1 | 217 | block_index_for_slot[diskP] = data_disks; |
f2e29ad6 | 218 | blocks[data_disks+1] = stripes[diskQ]; |
696e95a1 | 219 | block_index_for_slot[diskQ] = data_disks+1; |
f2e29ad6 | 220 | |
979afcb8 | 221 | if (memcmp(p, stripes[diskP], chunk_size) != 0) { |
af3c3750 | 222 | printf("P(%d) wrong at %llu\n", diskP, start); |
979afcb8 | 223 | } |
979afcb8 | 224 | if (memcmp(q, stripes[diskQ], chunk_size) != 0) { |
af3c3750 | 225 | printf("Q(%d) wrong at %llu\n", diskQ, start); |
979afcb8 | 226 | } |
af3c3750 | 227 | raid6_collect(chunk_size, p, q, stripes[diskP], stripes[diskQ], results); |
979afcb8 PS |
228 | disk = raid6_stats(results, raid_disks, chunk_size); |
229 | ||
230 | if(disk >= -2) { | |
af3c3750 | 231 | disk = geo_map(disk, start, raid_disks, level, layout); |
979afcb8 PS |
232 | } |
233 | if(disk >= 0) { | |
af3c3750 PS |
234 | printf("Error detected at %llu: possible failed disk slot: %d --> %s\n", |
235 | start, disk, name[disk]); | |
979afcb8 PS |
236 | } |
237 | if(disk == -65535) { | |
af3c3750 | 238 | printf("Error detected at %llu: disk slot unknown\n", start); |
979afcb8 | 239 | } |
635b5861 | 240 | if(repair == MANUAL_REPAIR) { |
f2e29ad6 RB |
241 | printf("Repairing stripe %llu\n", start); |
242 | printf("Assuming slots %d (%s) and %d (%s) are incorrect\n", | |
243 | failed_disk1, name[failed_disk1], | |
244 | failed_disk2, name[failed_disk2]); | |
245 | ||
246 | if (failed_disk1 == diskQ || failed_disk2 == diskQ) { | |
247 | char *all_but_failed_blocks[data_disks]; | |
696e95a1 | 248 | int failed_data_or_p; |
f2e29ad6 RB |
249 | int failed_block_index; |
250 | ||
251 | if (failed_disk1 == diskQ) | |
696e95a1 | 252 | failed_data_or_p = failed_disk2; |
f2e29ad6 | 253 | else |
696e95a1 RB |
254 | failed_data_or_p = failed_disk1; |
255 | printf("Repairing D/P(%d) and Q\n", failed_data_or_p); | |
256 | failed_block_index = block_index_for_slot[failed_data_or_p]; | |
f2e29ad6 RB |
257 | for (i=0; i < data_disks; i++) |
258 | if (failed_block_index == i) | |
259 | all_but_failed_blocks[i] = stripes[diskP]; | |
260 | else | |
261 | all_but_failed_blocks[i] = blocks[i]; | |
696e95a1 | 262 | xor_blocks(stripes[failed_data_or_p], |
f2e29ad6 RB |
263 | all_but_failed_blocks, data_disks, chunk_size); |
264 | qsyndrome(p, (uint8_t*)stripes[diskQ], (uint8_t**)blocks, data_disks, chunk_size); | |
265 | } else { | |
266 | ensure_zero_has_size(chunk_size); | |
267 | if (failed_disk1 == diskP || failed_disk2 == diskP) { | |
268 | int failed_data, failed_block_index; | |
269 | if (failed_disk1 == diskP) | |
270 | failed_data = failed_disk2; | |
271 | else | |
272 | failed_data = failed_disk1; | |
696e95a1 | 273 | failed_block_index = block_index_for_slot[failed_data]; |
f2e29ad6 RB |
274 | printf("Repairing D(%d) and P\n", failed_data); |
275 | raid6_datap_recov(raid_disks, chunk_size, failed_block_index, (uint8_t**)blocks); | |
276 | } else { | |
277 | printf("Repairing D and D\n"); | |
696e95a1 RB |
278 | int failed_block_index1 = block_index_for_slot[failed_disk1]; |
279 | int failed_block_index2 = block_index_for_slot[failed_disk2]; | |
f2e29ad6 RB |
280 | if (failed_block_index1 > failed_block_index2) { |
281 | int t = failed_block_index1; | |
282 | failed_block_index1 = failed_block_index2; | |
283 | failed_block_index2 = t; | |
284 | } | |
285 | raid6_2data_recov(raid_disks, chunk_size, failed_block_index1, failed_block_index2, (uint8_t**)blocks); | |
286 | } | |
287 | } | |
351d7680 RB |
288 | |
289 | err = lock_stripe(info, start, chunk_size, data_disks, sig); | |
290 | if(err != 0) { | |
291 | if (err != 2) | |
292 | unlock_all_stripes(info, sig); | |
f2e29ad6 RB |
293 | goto exitCheck; |
294 | } | |
351d7680 | 295 | |
2c7b668d | 296 | int write_res1, write_res2; |
2161adce | 297 | off64_t seek_res; |
2c7b668d | 298 | |
2161adce BS |
299 | seek_res = lseek64(source[failed_disk1], |
300 | offsets[failed_disk1] + start * chunk_size, SEEK_SET); | |
301 | if (seek_res < 0) { | |
302 | fprintf(stderr, "lseek failed for failed_disk1\n"); | |
303 | unlock_all_stripes(info, sig); | |
304 | err = -1; | |
305 | goto exitCheck; | |
306 | } | |
2c7b668d | 307 | write_res1 = write(source[failed_disk1], stripes[failed_disk1], chunk_size); |
2161adce | 308 | |
2161adce BS |
309 | seek_res = lseek64(source[failed_disk2], |
310 | offsets[failed_disk2] + start * chunk_size, SEEK_SET); | |
311 | if (seek_res < 0) { | |
312 | fprintf(stderr, "lseek failed for failed_disk1\n"); | |
313 | unlock_all_stripes(info, sig); | |
314 | err = -1; | |
315 | goto exitCheck; | |
316 | } | |
2c7b668d | 317 | write_res2 = write(source[failed_disk2], stripes[failed_disk2], chunk_size); |
f2e29ad6 | 318 | |
8a63c731 RB |
319 | err = unlock_all_stripes(info, sig); |
320 | if(err != 0) | |
321 | goto exitCheck; | |
2c7b668d | 322 | |
2c7b668d BS |
323 | if (write_res1 != chunk_size || write_res2 != chunk_size) { |
324 | fprintf(stderr, "Failed to write a complete chunk.\n"); | |
325 | goto exitCheck; | |
326 | } | |
327 | ||
635b5861 | 328 | } else if (disk >= 0 && repair == AUTO_REPAIR) { |
8a63c731 RB |
329 | printf("Auto-repairing slot %d (%s)\n", disk, name[disk]); |
330 | if (disk == diskQ) { | |
331 | qsyndrome(p, (uint8_t*)stripes[diskQ], (uint8_t**)blocks, data_disks, chunk_size); | |
332 | } else { | |
333 | char *all_but_failed_blocks[data_disks]; | |
334 | int failed_block_index = block_index_for_slot[disk]; | |
335 | for (i=0; i < data_disks; i++) | |
336 | if (failed_block_index == i) | |
337 | all_but_failed_blocks[i] = stripes[diskP]; | |
338 | else | |
339 | all_but_failed_blocks[i] = blocks[i]; | |
340 | xor_blocks(stripes[disk], | |
341 | all_but_failed_blocks, data_disks, chunk_size); | |
342 | } | |
343 | ||
344 | err = lock_stripe(info, start, chunk_size, data_disks, sig); | |
345 | if(err != 0) { | |
346 | if (err != 2) | |
347 | unlock_all_stripes(info, sig); | |
348 | goto exitCheck; | |
349 | } | |
350 | ||
351 | lseek64(source[disk], offsets[disk] + start * chunk_size, 0); | |
2c7b668d | 352 | int write_res = write(source[disk], stripes[disk], chunk_size); |
8a63c731 | 353 | |
351d7680 | 354 | err = unlock_all_stripes(info, sig); |
2c7b668d | 355 | if(err != 0 || write_res != chunk_size) |
f2e29ad6 | 356 | goto exitCheck; |
2c7b668d BS |
357 | |
358 | if (write_res != chunk_size) { | |
359 | fprintf(stderr, "Failed to write a full chunk.\n"); | |
360 | goto exitCheck; | |
361 | } | |
f2e29ad6 RB |
362 | } |
363 | ||
af3c3750 PS |
364 | length--; |
365 | start++; | |
979afcb8 PS |
366 | } |
367 | ||
af3c3750 PS |
368 | exitCheck: |
369 | ||
979afcb8 PS |
370 | free(stripe_buf); |
371 | free(stripes); | |
372 | free(blocks); | |
3a89d754 | 373 | free(block_index_for_slot); |
979afcb8 PS |
374 | free(p); |
375 | free(q); | |
376 | free(results); | |
3a89d754 | 377 | free(sig); |
979afcb8 | 378 | |
af3c3750 | 379 | return err; |
979afcb8 PS |
380 | } |
381 | ||
382 | unsigned long long getnum(char *str, char **err) | |
383 | { | |
384 | char *e; | |
385 | unsigned long long rv = strtoull(str, &e, 10); | |
386 | if (e==str || *e) { | |
387 | *err = str; | |
388 | return 0; | |
389 | } | |
390 | return rv; | |
391 | } | |
392 | ||
393 | int main(int argc, char *argv[]) | |
394 | { | |
a9c2c6c6 | 395 | /* md_device start length */ |
af3c3750 PS |
396 | int *fds = NULL; |
397 | char *buf = NULL; | |
398 | char **disk_name = NULL; | |
399 | unsigned long long *offsets = NULL; | |
400 | int raid_disks = 0; | |
2cf31121 | 401 | int active_disks; |
af3c3750 PS |
402 | int chunk_size = 0; |
403 | int layout = -1; | |
979afcb8 | 404 | int level = 6; |
635b5861 | 405 | enum repair repair = NO_REPAIR; |
2c7b668d BS |
406 | int failed_disk1 = -1; |
407 | int failed_disk2 = -1; | |
979afcb8 PS |
408 | unsigned long long start, length; |
409 | int i; | |
a9c2c6c6 | 410 | int mdfd; |
8d8ab389 | 411 | struct mdinfo *info = NULL, *comp = NULL; |
979afcb8 | 412 | char *err = NULL; |
af3c3750 PS |
413 | int exit_err = 0; |
414 | int close_flag = 0; | |
415 | char *prg = strrchr(argv[0], '/'); | |
416 | ||
417 | if (prg == NULL) | |
418 | prg = argv[0]; | |
419 | else | |
420 | prg++; | |
421 | ||
422 | if (argc < 4) { | |
8a63c731 | 423 | fprintf(stderr, "Usage: %s md_device start_stripe length_stripes [autorepair]\n", prg); |
f2e29ad6 | 424 | fprintf(stderr, " or: %s md_device repair stripe failed_slot_1 failed_slot_2\n", prg); |
af3c3750 PS |
425 | exit_err = 1; |
426 | goto exitHere; | |
979afcb8 PS |
427 | } |
428 | ||
a9c2c6c6 PS |
429 | mdfd = open(argv[1], O_RDONLY); |
430 | if(mdfd < 0) { | |
431 | perror(argv[1]); | |
e7b84f9d | 432 | fprintf(stderr, "%s: cannot open %s\n", prg, argv[1]); |
af3c3750 PS |
433 | exit_err = 2; |
434 | goto exitHere; | |
a9c2c6c6 PS |
435 | } |
436 | ||
f8fcf7a1 | 437 | info = sysfs_read(mdfd, NULL, |
a9c2c6c6 PS |
438 | GET_LEVEL| |
439 | GET_LAYOUT| | |
440 | GET_DISKS| | |
2cf31121 | 441 | GET_DEGRADED | |
a9c2c6c6 PS |
442 | GET_COMPONENT| |
443 | GET_CHUNK| | |
444 | GET_DEVS| | |
445 | GET_OFFSET| | |
446 | GET_SIZE); | |
447 | ||
8d8ab389 PS |
448 | if(info == NULL) { |
449 | fprintf(stderr, "%s: Error reading sysfs information of %s\n", prg, argv[1]); | |
450 | exit_err = 9; | |
451 | goto exitHere; | |
452 | } | |
453 | ||
a9c2c6c6 PS |
454 | if(info->array.level != level) { |
455 | fprintf(stderr, "%s: %s not a RAID-6\n", prg, argv[1]); | |
af3c3750 PS |
456 | exit_err = 3; |
457 | goto exitHere; | |
a9c2c6c6 PS |
458 | } |
459 | ||
2cf31121 PS |
460 | if(info->array.failed_disks > 0) { |
461 | fprintf(stderr, "%s: %s degraded array\n", prg, argv[1]); | |
462 | exit_err = 8; | |
463 | goto exitHere; | |
464 | } | |
465 | ||
a9c2c6c6 PS |
466 | printf("layout: %d\n", info->array.layout); |
467 | printf("disks: %d\n", info->array.raid_disks); | |
af3c3750 PS |
468 | printf("component size: %llu\n", info->component_size * 512); |
469 | printf("total stripes: %llu\n", (info->component_size * 512) / info->array.chunk_size); | |
a9c2c6c6 PS |
470 | printf("chunk size: %d\n", info->array.chunk_size); |
471 | printf("\n"); | |
472 | ||
473 | comp = info->devs; | |
2cf31121 | 474 | for(i = 0, active_disks = 0; active_disks < info->array.raid_disks; i++) { |
a9c2c6c6 | 475 | printf("disk: %d - offset: %llu - size: %llu - name: %s - slot: %d\n", |
af3c3750 | 476 | i, comp->data_offset * 512, comp->component_size * 512, |
a9c2c6c6 PS |
477 | map_dev(comp->disk.major, comp->disk.minor, 0), |
478 | comp->disk.raid_disk); | |
2cf31121 PS |
479 | if(comp->disk.raid_disk >= 0) |
480 | active_disks++; | |
a9c2c6c6 PS |
481 | comp = comp->next; |
482 | } | |
483 | printf("\n"); | |
484 | ||
485 | close(mdfd); | |
486 | ||
487 | raid_disks = info->array.raid_disks; | |
488 | chunk_size = info->array.chunk_size; | |
489 | layout = info->array.layout; | |
f2e29ad6 RB |
490 | if (strcmp(argv[2], "repair")==0) { |
491 | if (argc < 6) { | |
492 | fprintf(stderr, "For repair mode, call %s md_device repair stripe failed_slot_1 failed_slot_2\n", prg); | |
493 | exit_err = 1; | |
494 | goto exitHere; | |
495 | } | |
635b5861 | 496 | repair = MANUAL_REPAIR; |
f2e29ad6 RB |
497 | start = getnum(argv[3], &err); |
498 | length = 1; | |
499 | failed_disk1 = getnum(argv[4], &err); | |
500 | failed_disk2 = getnum(argv[5], &err); | |
501 | ||
b67e45b8 | 502 | if(failed_disk1 >= info->array.raid_disks) { |
f2e29ad6 RB |
503 | fprintf(stderr, "%s: failed_slot_1 index is higher than number of devices in raid\n", prg); |
504 | exit_err = 4; | |
505 | goto exitHere; | |
506 | } | |
b67e45b8 | 507 | if(failed_disk2 >= info->array.raid_disks) { |
f2e29ad6 RB |
508 | fprintf(stderr, "%s: failed_slot_2 index is higher than number of devices in raid\n", prg); |
509 | exit_err = 4; | |
510 | goto exitHere; | |
511 | } | |
512 | if(failed_disk1 == failed_disk2) { | |
513 | fprintf(stderr, "%s: failed_slot_1 and failed_slot_2 are the same\n", prg); | |
514 | exit_err = 4; | |
515 | goto exitHere; | |
516 | } | |
517 | } | |
518 | else { | |
519 | start = getnum(argv[2], &err); | |
520 | length = getnum(argv[3], &err); | |
8a63c731 | 521 | if (argc >= 5 && strcmp(argv[4], "autorepair")==0) |
635b5861 | 522 | repair = AUTO_REPAIR; |
f2e29ad6 | 523 | } |
a9c2c6c6 | 524 | |
979afcb8 | 525 | if (err) { |
a9c2c6c6 | 526 | fprintf(stderr, "%s: Bad number: %s\n", prg, err); |
af3c3750 PS |
527 | exit_err = 4; |
528 | goto exitHere; | |
979afcb8 | 529 | } |
a9c2c6c6 | 530 | |
af3c3750 PS |
531 | if(start > ((info->component_size * 512) / chunk_size)) { |
532 | start = (info->component_size * 512) / chunk_size; | |
533 | fprintf(stderr, "%s: start beyond disks size\n", prg); | |
534 | } | |
a9c2c6c6 | 535 | |
af3c3750 PS |
536 | if((length == 0) || |
537 | ((length + start) > ((info->component_size * 512) / chunk_size))) { | |
538 | length = (info->component_size * 512) / chunk_size - start; | |
979afcb8 | 539 | } |
a9c2c6c6 | 540 | |
503975b9 N |
541 | disk_name = xmalloc(raid_disks * sizeof(*disk_name)); |
542 | fds = xmalloc(raid_disks * sizeof(*fds)); | |
543 | offsets = xcalloc(raid_disks, sizeof(*offsets)); | |
544 | buf = xmalloc(raid_disks * chunk_size); | |
af3c3750 | 545 | |
af3c3750 PS |
546 | for(i=0; i<raid_disks; i++) { |
547 | fds[i] = -1; | |
548 | } | |
549 | close_flag = 1; | |
979afcb8 | 550 | |
a9c2c6c6 | 551 | comp = info->devs; |
2cf31121 | 552 | for (i=0, active_disks=0; active_disks<raid_disks; i++) { |
a9c2c6c6 | 553 | int disk_slot = comp->disk.raid_disk; |
2cf31121 PS |
554 | if(disk_slot >= 0) { |
555 | disk_name[disk_slot] = map_dev(comp->disk.major, comp->disk.minor, 0); | |
556 | offsets[disk_slot] = comp->data_offset * 512; | |
557 | fds[disk_slot] = open(disk_name[disk_slot], O_RDWR); | |
558 | if (fds[disk_slot] < 0) { | |
559 | perror(disk_name[disk_slot]); | |
560 | fprintf(stderr,"%s: cannot open %s\n", prg, disk_name[disk_slot]); | |
561 | exit_err = 6; | |
562 | goto exitHere; | |
563 | } | |
564 | active_disks++; | |
979afcb8 | 565 | } |
a9c2c6c6 | 566 | comp = comp->next; |
979afcb8 PS |
567 | } |
568 | ||
8d8ab389 | 569 | int rv = check_stripes(info, fds, offsets, |
979afcb8 | 570 | raid_disks, chunk_size, level, layout, |
f2e29ad6 | 571 | start, length, disk_name, repair, failed_disk1, failed_disk2); |
979afcb8 PS |
572 | if (rv != 0) { |
573 | fprintf(stderr, | |
a9c2c6c6 | 574 | "%s: check_stripes returned %d\n", prg, rv); |
af3c3750 PS |
575 | exit_err = 7; |
576 | goto exitHere; | |
979afcb8 PS |
577 | } |
578 | ||
af3c3750 PS |
579 | exitHere: |
580 | ||
581 | if (close_flag) | |
582 | for(i = 0; i < raid_disks; i++) | |
583 | close(fds[i]); | |
584 | ||
a9c2c6c6 | 585 | free(disk_name); |
979afcb8 PS |
586 | free(fds); |
587 | free(offsets); | |
588 | free(buf); | |
589 | ||
af3c3750 | 590 | exit(exit_err); |
979afcb8 | 591 | } |