]> git.ipfire.org Git - thirdparty/mdadm.git/blob - raid6check.c
imsm: fix first volume autolayout with IMSM_NO_PLATFORM
[thirdparty/mdadm.git] / raid6check.c
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>
27 #include <sys/mman.h>
28
29 #define CHECK_PAGE_BITS (12)
30 #define CHECK_PAGE_SIZE (1 << CHECK_PAGE_BITS)
31
32 char const Name[] = "raid6check";
33
34 enum repair {
35 NO_REPAIR = 0,
36 MANUAL_REPAIR,
37 AUTO_REPAIR
38 };
39
40 int geo_map(int block, unsigned long long stripe, int raid_disks,
41 int level, int layout);
42 int is_ddf(int layout);
43 void qsyndrome(uint8_t *p, uint8_t *q, uint8_t **sources, int disks, int size);
44 void make_tables(void);
45 void ensure_zero_has_size(int chunk_size);
46 void raid6_datap_recov(int disks, size_t bytes, int faila, uint8_t **ptrs,
47 int neg_offset);
48 void raid6_2data_recov(int disks, size_t bytes, int faila, int failb,
49 uint8_t **ptrs, int neg_offset);
50 void xor_blocks(char *target, char **sources, int disks, int size);
51
52 /* Collect per stripe consistency information */
53 void raid6_collect(int chunk_size, uint8_t *p, uint8_t *q,
54 char *chunkP, char *chunkQ, int *results)
55 {
56 int i;
57 int data_id;
58 uint8_t Px, Qx;
59 extern uint8_t raid6_gflog[];
60
61 for(i = 0; i < chunk_size; i++) {
62 Px = (uint8_t)chunkP[i] ^ (uint8_t)p[i];
63 Qx = (uint8_t)chunkQ[i] ^ (uint8_t)q[i];
64
65 if((Px != 0) && (Qx == 0))
66 results[i] = -1;
67
68 if((Px == 0) && (Qx != 0))
69 results[i] = -2;
70
71 if((Px != 0) && (Qx != 0)) {
72 data_id = (raid6_gflog[Qx] - raid6_gflog[Px]);
73 if(data_id < 0) data_id += 255;
74 results[i] = data_id;
75 }
76
77 if((Px == 0) && (Qx == 0))
78 results[i] = -255;
79 }
80 }
81
82 /* Try to find out if a specific disk has problems in a CHECK_PAGE_SIZE page size */
83 int raid6_stats_blk(int *results, int raid_disks)
84 {
85 int i;
86 int curr_broken_disk = -255;
87 int prev_broken_disk = -255;
88 int broken_status = 0;
89
90 for(i = 0; i < CHECK_PAGE_SIZE; i++) {
91
92 if(results[i] != -255)
93 curr_broken_disk = results[i];
94
95 if(curr_broken_disk >= raid_disks)
96 broken_status = 2;
97
98 switch(broken_status) {
99 case 0:
100 if(curr_broken_disk != -255) {
101 prev_broken_disk = curr_broken_disk;
102 broken_status = 1;
103 }
104 break;
105
106 case 1:
107 if(curr_broken_disk != prev_broken_disk)
108 broken_status = 2;
109 break;
110
111 case 2:
112 default:
113 curr_broken_disk = prev_broken_disk = -65535;
114 break;
115 }
116 }
117
118 return curr_broken_disk;
119 }
120
121 /* Collect disks status for a strip in CHECK_PAGE_SIZE page size blocks */
122 void raid6_stats(int *disk, int *results, int raid_disks, int chunk_size)
123 {
124 int i, j;
125
126 for(i = 0, j = 0; i < chunk_size; i += CHECK_PAGE_SIZE, j++) {
127 disk[j] = raid6_stats_blk(&results[i], raid_disks);
128 }
129 }
130
131 int lock_stripe(struct mdinfo *info, unsigned long long start,
132 int chunk_size, int data_disks, sighandler_t *sig)
133 {
134 int rv;
135
136 sig[0] = signal_s(SIGTERM, SIG_IGN);
137 sig[1] = signal_s(SIGINT, SIG_IGN);
138 sig[2] = signal_s(SIGQUIT, SIG_IGN);
139
140 if (sig[0] == SIG_ERR || sig[1] == SIG_ERR || sig[2] == SIG_ERR)
141 return 1;
142
143 if(mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
144 return 2;
145 }
146
147 rv = sysfs_set_num(info, NULL, "suspend_lo", start * chunk_size * data_disks);
148 rv |= sysfs_set_num(info, NULL, "suspend_hi", (start + 1) * chunk_size * data_disks);
149 return rv * 256;
150 }
151
152 int unlock_all_stripes(struct mdinfo *info, sighandler_t *sig)
153 {
154 int rv;
155 rv = sysfs_set_num(info, NULL, "suspend_lo", 0x7FFFFFFFFFFFFFFFULL);
156 rv |= sysfs_set_num(info, NULL, "suspend_hi", 0);
157 rv |= sysfs_set_num(info, NULL, "suspend_lo", 0);
158
159 signal_s(SIGQUIT, sig[2]);
160 signal_s(SIGINT, sig[1]);
161 signal_s(SIGTERM, sig[0]);
162
163 if(munlockall() != 0)
164 return 3;
165 return rv * 256;
166 }
167
168 /* Autorepair */
169 int autorepair(int *disk, unsigned long long start, int chunk_size,
170 char *name[], int raid_disks, int syndrome_disks, char **blocks_page,
171 char **blocks, uint8_t *p, int *block_index_for_slot,
172 int *source, unsigned long long *offsets)
173 {
174 int i, j;
175 int pages_to_write_count = 0;
176 int page_to_write[chunk_size >> CHECK_PAGE_BITS];
177 for(j = 0; j < (chunk_size >> CHECK_PAGE_BITS); j++) {
178 if (disk[j] >= -2 && block_index_for_slot[disk[j]] >= 0) {
179 int slot = block_index_for_slot[disk[j]];
180 printf("Auto-repairing slot %d (%s)\n", slot, name[slot]);
181 pages_to_write_count++;
182 page_to_write[j] = 1;
183 for(i = -2; i < syndrome_disks; i++) {
184 blocks_page[i] = blocks[i] + j * CHECK_PAGE_SIZE;
185 }
186 if (disk[j] == -2) {
187 qsyndrome(p, (uint8_t*)blocks_page[-2],
188 (uint8_t**)blocks_page,
189 syndrome_disks, CHECK_PAGE_SIZE);
190 }
191 else {
192 char *all_but_failed_blocks[syndrome_disks];
193 for(i = 0; i < syndrome_disks; i++) {
194 if (i == disk[j])
195 all_but_failed_blocks[i] = blocks_page[-1];
196 else
197 all_but_failed_blocks[i] = blocks_page[i];
198 }
199 xor_blocks(blocks_page[disk[j]],
200 all_but_failed_blocks, syndrome_disks,
201 CHECK_PAGE_SIZE);
202 }
203 }
204 else {
205 page_to_write[j] = 0;
206 }
207 }
208
209 if(pages_to_write_count > 0) {
210 int write_res = 0;
211 for(j = 0; j < (chunk_size >> CHECK_PAGE_BITS); j++) {
212 if(page_to_write[j] == 1) {
213 int slot = block_index_for_slot[disk[j]];
214 lseek64(source[slot], offsets[slot] + start * chunk_size + j * CHECK_PAGE_SIZE, SEEK_SET);
215 write_res += write(source[slot],
216 blocks[disk[j]] + j * CHECK_PAGE_SIZE,
217 CHECK_PAGE_SIZE);
218 }
219 }
220
221 if (write_res != (CHECK_PAGE_SIZE * pages_to_write_count)) {
222 fprintf(stderr, "Failed to write a full chunk.\n");
223 return -1;
224 }
225 }
226
227 return 0;
228 }
229
230 /* Manual repair */
231 int manual_repair(int chunk_size, int syndrome_disks,
232 int failed_slot1, int failed_slot2,
233 unsigned long long start, int *block_index_for_slot,
234 char *name[], char **stripes, char **blocks, uint8_t *p,
235 int *source, unsigned long long *offsets)
236 {
237 int i;
238 int fd1 = block_index_for_slot[failed_slot1];
239 int fd2 = block_index_for_slot[failed_slot2];
240 printf("Repairing stripe %llu\n", start);
241 printf("Assuming slots %d (%s) and %d (%s) are incorrect\n",
242 fd1, name[fd1],
243 fd2, name[fd2]);
244
245 if (failed_slot1 == -2 || failed_slot2 == -2) {
246 char *all_but_failed_blocks[syndrome_disks];
247 int failed_data_or_p;
248
249 if (failed_slot1 == -2)
250 failed_data_or_p = failed_slot2;
251 else
252 failed_data_or_p = failed_slot1;
253
254 printf("Repairing D/P(%d) and Q\n", failed_data_or_p);
255
256 for (i = 0; i < syndrome_disks; i++) {
257 if (i == failed_data_or_p)
258 all_but_failed_blocks[i] = blocks[-1];
259 else
260 all_but_failed_blocks[i] = blocks[i];
261 }
262 xor_blocks(blocks[failed_data_or_p],
263 all_but_failed_blocks, syndrome_disks, chunk_size);
264 qsyndrome(p, (uint8_t*)blocks[-2], (uint8_t**)blocks,
265 syndrome_disks, chunk_size);
266 } else {
267 ensure_zero_has_size(chunk_size);
268 if (failed_slot1 == -1 || failed_slot2 == -1) {
269 int failed_data;
270 if (failed_slot1 == -1)
271 failed_data = failed_slot2;
272 else
273 failed_data = failed_slot1;
274
275 printf("Repairing D(%d) and P\n", failed_data);
276 raid6_datap_recov(syndrome_disks+2, chunk_size,
277 failed_data, (uint8_t**)blocks, 1);
278 } else {
279 printf("Repairing D and D\n");
280 raid6_2data_recov(syndrome_disks+2, chunk_size,
281 failed_slot1, failed_slot2,
282 (uint8_t**)blocks, 1);
283 }
284 }
285
286 int write_res1, write_res2;
287 off64_t seek_res;
288
289 seek_res = lseek64(source[fd1],
290 offsets[fd1] + start * chunk_size, SEEK_SET);
291 if (seek_res < 0) {
292 fprintf(stderr, "lseek failed for failed_disk1\n");
293 return -1;
294 }
295 write_res1 = write(source[fd1], blocks[failed_slot1], chunk_size);
296
297 seek_res = lseek64(source[fd2],
298 offsets[fd2] + start * chunk_size, SEEK_SET);
299 if (seek_res < 0) {
300 fprintf(stderr, "lseek failed for failed_disk2\n");
301 return -1;
302 }
303 write_res2 = write(source[fd2], blocks[failed_slot2], chunk_size);
304
305 if (write_res1 != chunk_size || write_res2 != chunk_size) {
306 fprintf(stderr, "Failed to write a complete chunk.\n");
307 return -2;
308 }
309
310 return 0;
311 }
312
313 int check_stripes(struct mdinfo *info, int *source, unsigned long long *offsets,
314 int raid_disks, int chunk_size, int level, int layout,
315 unsigned long long start, unsigned long long length, char *name[],
316 enum repair repair, int failed_disk1, int failed_disk2)
317 {
318 /* read the data and p and q blocks, and check we got them right */
319 int data_disks = raid_disks - 2;
320 int syndrome_disks = data_disks + is_ddf(layout) * 2;
321 char *stripe_buf;
322
323 /* stripes[] is indexed by raid_disk and holds chunks from each device */
324 char **stripes = xmalloc(raid_disks * sizeof(char*));
325
326 /* blocks[] is indexed by syndrome number and points to either one of the
327 * chunks from 'stripes[]', or to a chunk of zeros. -1 and -2 are
328 * P and Q */
329 char **blocks = xmalloc((syndrome_disks + 2) * sizeof(char*));
330
331 /* blocks_page[] is a temporary index to just one page of the chunks
332 * that blocks[] points to. */
333 char **blocks_page = xmalloc((syndrome_disks + 2) * sizeof(char*));
334
335 /* block_index_for_slot[] provides the reverse mapping from blocks to stripes.
336 * The index is a syndrome position, the content is a raid_disk number.
337 * indicies -1 and -2 work, and are P and Q disks */
338 int *block_index_for_slot = xmalloc((syndrome_disks+2) * sizeof(int));
339
340 /* 'p' and 'q' contain calcualted P and Q, to be compared with
341 * blocks[-1] and blocks[-2];
342 */
343 uint8_t *p = xmalloc(chunk_size);
344 uint8_t *q = xmalloc(chunk_size);
345 char *zero = xmalloc(chunk_size);
346 int *results = xmalloc(chunk_size * sizeof(int));
347 sighandler_t *sig = xmalloc(3 * sizeof(sighandler_t));
348
349 int i, j;
350 int diskP, diskQ, diskD;
351 int err = 0;
352
353 extern int tables_ready;
354
355 if (!tables_ready)
356 make_tables();
357
358 if (posix_memalign((void**)&stripe_buf, 4096, raid_disks * chunk_size) != 0)
359 exit(4);
360 block_index_for_slot += 2;
361 blocks += 2;
362 blocks_page += 2;
363
364 memset(zero, 0, chunk_size);
365 for ( i = 0 ; i < raid_disks ; i++)
366 stripes[i] = stripe_buf + i * chunk_size;
367
368 while (length > 0) {
369 /* The syndrome number of the broken disk is recorded
370 * in 'disk[]' which allows a different broken disk for
371 * each page.
372 */
373 int disk[chunk_size >> CHECK_PAGE_BITS];
374
375 err = lock_stripe(info, start, chunk_size, data_disks, sig);
376 if(err != 0) {
377 if (err != 2)
378 unlock_all_stripes(info, sig);
379 goto exitCheck;
380 }
381 for (i = 0 ; i < raid_disks ; i++) {
382 off64_t seek_res = lseek64(source[i], offsets[i] + start * chunk_size,
383 SEEK_SET);
384 if (seek_res < 0) {
385 fprintf(stderr, "lseek to source %d failed\n", i);
386 unlock_all_stripes(info, sig);
387 err = -1;
388 goto exitCheck;
389 }
390 int read_res = read(source[i], stripes[i], chunk_size);
391 if (read_res < chunk_size) {
392 fprintf(stderr, "Failed to read complete chunk disk %d, aborting\n", i);
393 unlock_all_stripes(info, sig);
394 err = -1;
395 goto exitCheck;
396 }
397 }
398
399 diskP = geo_map(-1, start, raid_disks, level, layout);
400 block_index_for_slot[-1] = diskP;
401 blocks[-1] = stripes[diskP];
402
403 diskQ = geo_map(-2, start, raid_disks, level, layout);
404 block_index_for_slot[-2] = diskQ;
405 blocks[-2] = stripes[diskQ];
406
407 if (!is_ddf(layout)) {
408 /* The syndrome-order of disks starts immediately after 'Q',
409 * but skips P */
410 diskD = diskQ;
411 for (i = 0 ; i < data_disks ; i++) {
412 diskD = diskD + 1;
413 if (diskD >= raid_disks)
414 diskD = 0;
415 if (diskD == diskP)
416 diskD += 1;
417 if (diskD >= raid_disks)
418 diskD = 0;
419 blocks[i] = stripes[diskD];
420 block_index_for_slot[i] = diskD;
421 }
422 } else {
423 /* The syndrome-order exactly follows raid-disk
424 * numbers, with ZERO in place of P and Q
425 */
426 for (i = 0 ; i < raid_disks; i++) {
427 if (i == diskP || i == diskQ) {
428 blocks[i] = zero;
429 block_index_for_slot[i] = -1;
430 } else {
431 blocks[i] = stripes[i];
432 block_index_for_slot[i] = i;
433 }
434 }
435 }
436
437 qsyndrome(p, q, (uint8_t**)blocks, syndrome_disks, chunk_size);
438
439 raid6_collect(chunk_size, p, q, stripes[diskP], stripes[diskQ], results);
440 raid6_stats(disk, results, raid_disks, chunk_size);
441
442 for(j = 0; j < (chunk_size >> CHECK_PAGE_BITS); j++) {
443 int role = disk[j];
444 if (role >= -2) {
445 int slot = block_index_for_slot[role];
446 if (slot >= 0)
447 printf("Error detected at stripe %llu, page %d: possible failed disk slot %d: %d --> %s\n",
448 start, j, role, slot, name[slot]);
449 else
450 printf("Error detected at stripe %llu, page %d: failed slot %d should be zeros\n",
451 start, j, role);
452 } else if(disk[j] == -65535) {
453 printf("Error detected at stripe %llu, page %d: disk slot unknown\n", start, j);
454 }
455 }
456
457 if(repair == AUTO_REPAIR) {
458 err = autorepair(disk, start, chunk_size,
459 name, raid_disks, syndrome_disks, blocks_page,
460 blocks, p, block_index_for_slot,
461 source, offsets);
462 if(err != 0) {
463 unlock_all_stripes(info, sig);
464 goto exitCheck;
465 }
466 }
467
468 if(repair == MANUAL_REPAIR) {
469 int failed_slot1 = -1, failed_slot2 = -1;
470 for (i = -2; i < syndrome_disks; i++) {
471 if (block_index_for_slot[i] == failed_disk1)
472 failed_slot1 = i;
473 if (block_index_for_slot[i] == failed_disk2)
474 failed_slot2 = i;
475 }
476 err = manual_repair(chunk_size, syndrome_disks,
477 failed_slot1, failed_slot2,
478 start, block_index_for_slot,
479 name, stripes, blocks, p,
480 source, offsets);
481 if(err == -1) {
482 unlock_all_stripes(info, sig);
483 goto exitCheck;
484 }
485 }
486
487 err = unlock_all_stripes(info, sig);
488 if(err != 0) {
489 goto exitCheck;
490 }
491
492 length--;
493 start++;
494 }
495
496 exitCheck:
497
498 free(stripe_buf);
499 free(stripes);
500 free(blocks-2);
501 free(blocks_page-2);
502 free(block_index_for_slot-2);
503 free(p);
504 free(q);
505 free(results);
506 free(sig);
507
508 return err;
509 }
510
511 unsigned long long getnum(char *str, char **err)
512 {
513 char *e;
514 unsigned long long rv = strtoull(str, &e, 10);
515 if (e==str || *e) {
516 *err = str;
517 return 0;
518 }
519 return rv;
520 }
521
522 int main(int argc, char *argv[])
523 {
524 /* md_device start length */
525 int *fds = NULL;
526 char *buf = NULL;
527 char **disk_name = NULL;
528 unsigned long long *offsets = NULL;
529 int raid_disks = 0;
530 int active_disks;
531 int chunk_size = 0;
532 int layout = -1;
533 int level = 6;
534 enum repair repair = NO_REPAIR;
535 int failed_disk1 = -1;
536 int failed_disk2 = -1;
537 unsigned long long start, length;
538 int i;
539 int mdfd;
540 struct mdinfo *info = NULL, *comp = NULL;
541 char *err = NULL;
542 int exit_err = 0;
543 int close_flag = 0;
544 char *prg = strrchr(argv[0], '/');
545
546 if (prg == NULL)
547 prg = argv[0];
548 else
549 prg++;
550
551 if (argc < 4) {
552 fprintf(stderr, "Usage: %s md_device start_stripe length_stripes [autorepair]\n", prg);
553 fprintf(stderr, " or: %s md_device repair stripe failed_slot_1 failed_slot_2\n", prg);
554 exit_err = 1;
555 goto exitHere;
556 }
557
558 mdfd = open(argv[1], O_RDONLY);
559 if(mdfd < 0) {
560 perror(argv[1]);
561 fprintf(stderr, "%s: cannot open %s\n", prg, argv[1]);
562 exit_err = 2;
563 goto exitHere;
564 }
565
566 info = sysfs_read(mdfd, NULL,
567 GET_LEVEL|
568 GET_LAYOUT|
569 GET_DISKS|
570 GET_STATE |
571 GET_COMPONENT|
572 GET_CHUNK|
573 GET_DEVS|
574 GET_OFFSET|
575 GET_SIZE);
576
577 if(info == NULL) {
578 fprintf(stderr, "%s: Error reading sysfs information of %s\n", prg, argv[1]);
579 exit_err = 9;
580 goto exitHere;
581 }
582
583 if(info->array.level != level) {
584 fprintf(stderr, "%s: %s not a RAID-6\n", prg, argv[1]);
585 exit_err = 3;
586 goto exitHere;
587 }
588
589 if(info->array.failed_disks > 0) {
590 fprintf(stderr, "%s: %s degraded array\n", prg, argv[1]);
591 exit_err = 8;
592 goto exitHere;
593 }
594
595 printf("layout: %d\n", info->array.layout);
596 printf("disks: %d\n", info->array.raid_disks);
597 printf("component size: %llu\n", info->component_size * 512);
598 printf("total stripes: %llu\n", (info->component_size * 512) / info->array.chunk_size);
599 printf("chunk size: %d\n", info->array.chunk_size);
600 printf("\n");
601
602 comp = info->devs;
603 for(i = 0, active_disks = 0; active_disks < info->array.raid_disks; i++) {
604 printf("disk: %d - offset: %llu - size: %llu - name: %s - slot: %d\n",
605 i, comp->data_offset * 512, comp->component_size * 512,
606 map_dev(comp->disk.major, comp->disk.minor, 0),
607 comp->disk.raid_disk);
608 if(comp->disk.raid_disk >= 0)
609 active_disks++;
610 comp = comp->next;
611 }
612 printf("\n");
613
614 close(mdfd);
615
616 raid_disks = info->array.raid_disks;
617 chunk_size = info->array.chunk_size;
618 layout = info->array.layout;
619 if (strcmp(argv[2], "repair")==0) {
620 if (argc < 6) {
621 fprintf(stderr, "For repair mode, call %s md_device repair stripe failed_slot_1 failed_slot_2\n", prg);
622 exit_err = 1;
623 goto exitHere;
624 }
625 repair = MANUAL_REPAIR;
626 start = getnum(argv[3], &err);
627 length = 1;
628 failed_disk1 = getnum(argv[4], &err);
629 failed_disk2 = getnum(argv[5], &err);
630
631 if(failed_disk1 >= info->array.raid_disks) {
632 fprintf(stderr, "%s: failed_slot_1 index is higher than number of devices in raid\n", prg);
633 exit_err = 4;
634 goto exitHere;
635 }
636 if(failed_disk2 >= info->array.raid_disks) {
637 fprintf(stderr, "%s: failed_slot_2 index is higher than number of devices in raid\n", prg);
638 exit_err = 4;
639 goto exitHere;
640 }
641 if(failed_disk1 == failed_disk2) {
642 fprintf(stderr, "%s: failed_slot_1 and failed_slot_2 are the same\n", prg);
643 exit_err = 4;
644 goto exitHere;
645 }
646 }
647 else {
648 start = getnum(argv[2], &err);
649 length = getnum(argv[3], &err);
650 if (argc >= 5 && strcmp(argv[4], "autorepair")==0)
651 repair = AUTO_REPAIR;
652 }
653
654 if (err) {
655 fprintf(stderr, "%s: Bad number: %s\n", prg, err);
656 exit_err = 4;
657 goto exitHere;
658 }
659
660 if(start > ((info->component_size * 512) / chunk_size)) {
661 start = (info->component_size * 512) / chunk_size;
662 fprintf(stderr, "%s: start beyond disks size\n", prg);
663 }
664
665 if((length == 0) ||
666 ((length + start) > ((info->component_size * 512) / chunk_size))) {
667 length = (info->component_size * 512) / chunk_size - start;
668 }
669
670 disk_name = xmalloc(raid_disks * sizeof(*disk_name));
671 fds = xmalloc(raid_disks * sizeof(*fds));
672 offsets = xcalloc(raid_disks, sizeof(*offsets));
673 buf = xmalloc(raid_disks * chunk_size);
674
675 for(i=0; i<raid_disks; i++) {
676 fds[i] = -1;
677 }
678 close_flag = 1;
679
680 comp = info->devs;
681 for (i=0, active_disks=0; active_disks<raid_disks; i++) {
682 int disk_slot = comp->disk.raid_disk;
683 if(disk_slot >= 0) {
684 disk_name[disk_slot] = map_dev(comp->disk.major, comp->disk.minor, 0);
685 offsets[disk_slot] = comp->data_offset * 512;
686 fds[disk_slot] = open(disk_name[disk_slot], O_RDWR | O_DIRECT);
687 if (fds[disk_slot] < 0) {
688 perror(disk_name[disk_slot]);
689 fprintf(stderr,"%s: cannot open %s\n", prg, disk_name[disk_slot]);
690 exit_err = 6;
691 goto exitHere;
692 }
693 active_disks++;
694 }
695 comp = comp->next;
696 }
697
698 int rv = check_stripes(info, fds, offsets,
699 raid_disks, chunk_size, level, layout,
700 start, length, disk_name, repair, failed_disk1, failed_disk2);
701 if (rv != 0) {
702 fprintf(stderr, "%s: check_stripes returned %d\n", prg, rv);
703 exit_err = 7;
704 goto exitHere;
705 }
706
707 exitHere:
708
709 if (close_flag)
710 for(i = 0; i < raid_disks; i++)
711 close(fds[i]);
712
713 free(disk_name);
714 free(fds);
715 free(offsets);
716 free(buf);
717
718 exit(exit_err);
719 }