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