2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2006-2009 Neil Brown <neilb@suse.de>
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.
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.
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
22 * Email: <neilb@suse.de>
28 /* To restripe, we read from old geometry to a buffer, and
29 * read from buffer to new geometry.
30 * When reading, we might have missing devices and so could need
32 * When writing, we need to create correct parity and Q.
36 int geo_map(int block
, unsigned long long stripe
, int raid_disks
,
37 int level
, int layout
)
39 /* On the given stripe, find which disk in the array will have
40 * block numbered 'block'.
41 * '-1' means the parity block.
42 * '-2' means the Q syndrome.
46 /* layout is not relevant for raid0 and raid4 */
51 switch(level
*100 + layout
) {
54 case 500 + ALGORITHM_PARITY_N
:
55 /* raid 4 isn't messed around by parity blocks */
57 return raid_disks
-1; /* parity block */
59 case 500 + ALGORITHM_LEFT_ASYMMETRIC
:
60 pd
= (raid_disks
-1) - stripe
% raid_disks
;
61 if (block
== -1) return pd
;
66 case 500 + ALGORITHM_RIGHT_ASYMMETRIC
:
67 pd
= stripe
% raid_disks
;
68 if (block
== -1) return pd
;
73 case 500 + ALGORITHM_LEFT_SYMMETRIC
:
74 pd
= (raid_disks
- 1) - stripe
% raid_disks
;
75 if (block
== -1) return pd
;
76 return (pd
+ 1 + block
) % raid_disks
;
78 case 500 + ALGORITHM_RIGHT_SYMMETRIC
:
79 pd
= stripe
% raid_disks
;
80 if (block
== -1) return pd
;
81 return (pd
+ 1 + block
) % raid_disks
;
83 case 500 + ALGORITHM_PARITY_0
:
86 case 600 + ALGORITHM_PARITY_N_6
:
88 return raid_disks
- 1;
90 return raid_disks
- 2; /* parity block */
92 case 600 + ALGORITHM_LEFT_ASYMMETRIC_6
:
94 return raid_disks
- 1;
96 pd
= (raid_disks
-1) - stripe
% raid_disks
;
97 if (block
== -1) return pd
;
102 case 600 + ALGORITHM_RIGHT_ASYMMETRIC_6
:
104 return raid_disks
- 1;
106 pd
= stripe
% raid_disks
;
107 if (block
== -1) return pd
;
112 case 600 + ALGORITHM_LEFT_SYMMETRIC_6
:
114 return raid_disks
- 1;
116 pd
= (raid_disks
- 1) - stripe
% raid_disks
;
117 if (block
== -1) return pd
;
118 return (pd
+ 1 + block
) % raid_disks
;
120 case 600 + ALGORITHM_RIGHT_SYMMETRIC_6
:
122 return raid_disks
- 1;
124 pd
= stripe
% raid_disks
;
125 if (block
== -1) return pd
;
126 return (pd
+ 1 + block
) % raid_disks
;
128 case 600 + ALGORITHM_PARITY_0_6
:
130 return raid_disks
- 1;
133 case 600 + ALGORITHM_PARITY_0
:
140 case 600 + ALGORITHM_LEFT_ASYMMETRIC
:
141 pd
= raid_disks
- 1 - (stripe
% raid_disks
);
142 if (block
== -1) return pd
;
143 if (block
== -2) return (pd
+1) % raid_disks
;
144 if (pd
== raid_disks
- 1)
150 case 600 + ALGORITHM_ROTATING_ZERO_RESTART
:
151 /* Different order for calculating Q, otherwize same as ... */
152 case 600 + ALGORITHM_RIGHT_ASYMMETRIC
:
153 pd
= stripe
% raid_disks
;
154 if (block
== -1) return pd
;
155 if (block
== -2) return (pd
+1) % raid_disks
;
156 if (pd
== raid_disks
- 1)
162 case 600 + ALGORITHM_LEFT_SYMMETRIC
:
163 pd
= raid_disks
- 1 - (stripe
% raid_disks
);
164 if (block
== -1) return pd
;
165 if (block
== -2) return (pd
+1) % raid_disks
;
166 return (pd
+ 2 + block
) % raid_disks
;
168 case 600 + ALGORITHM_RIGHT_SYMMETRIC
:
169 pd
= stripe
% raid_disks
;
170 if (block
== -1) return pd
;
171 if (block
== -2) return (pd
+1) % raid_disks
;
172 return (pd
+ 2 + block
) % raid_disks
;
174 case 600 + ALGORITHM_ROTATING_N_RESTART
:
175 /* Same a left_asymmetric, by first stripe is
176 * D D D P Q rather than
179 pd
= raid_disks
- 1 - ((stripe
+ 1) % raid_disks
);
180 if (block
== -1) return pd
;
181 if (block
== -2) return (pd
+1) % raid_disks
;
182 if (pd
== raid_disks
- 1)
188 case 600 + ALGORITHM_ROTATING_N_CONTINUE
:
189 /* Same as left_symmetric but Q is before P */
190 pd
= raid_disks
- 1 - (stripe
% raid_disks
);
191 if (block
== -1) return pd
;
192 if (block
== -2) return (pd
+raid_disks
-1) % raid_disks
;
193 return (pd
+ 1 + block
) % raid_disks
;
197 static int is_ddf(int layout
)
203 case ALGORITHM_ROTATING_N_CONTINUE
:
204 case ALGORITHM_ROTATING_N_RESTART
:
205 case ALGORITHM_ROTATING_ZERO_RESTART
:
210 void xor_blocks(char *target
, char **sources
, int disks
, int size
)
213 /* Amazingly inefficient... */
214 for (i
=0; i
<size
; i
++) {
216 for (j
=0 ; j
<disks
; j
++)
222 void qsyndrome(uint8_t *p
, uint8_t *q
, uint8_t **sources
, int disks
, int size
)
225 uint8_t wq0
, wp0
, wd0
, w10
, w20
;
226 for ( d
= 0; d
< size
; d
++) {
227 wq0
= wp0
= sources
[disks
-1][d
];
228 for ( z
= disks
-2 ; z
>= 0 ; z
-- ) {
231 w20
= (wq0
&0x80) ? 0xff : 0x00;
232 w10
= (wq0
<< 1) & 0xff;
243 * The following was taken from linux/drivers/md/mktables.c, and modified
244 * to create in-memory tables rather than C code
246 static uint8_t gfmul(uint8_t a
, uint8_t b
)
253 a
= (a
<< 1) ^ (a
& 0x80 ? 0x1d : 0);
260 static uint8_t gfpow(uint8_t a
, int b
)
278 int tables_ready
= 0;
279 uint8_t raid6_gfmul
[256][256];
280 uint8_t raid6_gfexp
[256];
281 uint8_t raid6_gfinv
[256];
282 uint8_t raid6_gfexi
[256];
283 uint8_t raid6_gflog
[256];
284 uint8_t raid6_gfilog
[256];
285 void make_tables(void)
291 /* Compute multiplication table */
292 for (i
= 0; i
< 256; i
++)
293 for (j
= 0; j
< 256; j
++)
294 raid6_gfmul
[i
][j
] = gfmul(i
, j
);
296 /* Compute power-of-2 table (exponent) */
298 for (i
= 0; i
< 256; i
++) {
302 v
= 0; /* For entry 255, not a real entry */
305 /* Compute inverse table x^-1 == x^254 */
306 for (i
= 0; i
< 256; i
++)
307 raid6_gfinv
[i
] = gfpow(i
, 254);
309 /* Compute inv(2^x + 1) (exponent-xor-inverse) table */
310 for (i
= 0; i
< 256; i
++)
311 raid6_gfexi
[i
] = raid6_gfinv
[raid6_gfexp
[i
] ^ 1];
313 /* Compute log and inverse log */
314 /* Modified code from:
315 * http://web.eecs.utk.edu/~plank/plank/papers/CS-96-332.html
319 raid6_gfilog
[255] = 0;
321 for (log
= 0; log
< 255; log
++) {
322 raid6_gflog
[b
] = (uint8_t) log
;
323 raid6_gfilog
[log
] = (uint8_t) b
;
325 if (b
& 256) b
= b
^ 0435;
334 void ensure_zero_has_size(int chunk_size
)
336 if (zero
== NULL
|| chunk_size
> zero_size
) {
339 zero
= xcalloc(1, chunk_size
);
340 zero_size
= chunk_size
;
344 /* Following was taken from linux/drivers/md/raid6recov.c */
346 /* Recover two failed data blocks. */
347 void raid6_2data_recov(int disks
, size_t bytes
, int faila
, int failb
,
350 uint8_t *p
, *q
, *dp
, *dq
;
352 const uint8_t *pbmul
; /* P multiplier table for B data */
353 const uint8_t *qmul
; /* Q multiplier table (for both) */
358 /* Compute syndrome with zero for the missing data pages
359 Use the dead data pages as temporary storage for
360 delta p and delta q */
366 qsyndrome(dp
, dq
, ptrs
, disks
-2, bytes
);
368 /* Restore pointer table */
372 /* Now, pick the proper data tables */
373 pbmul
= raid6_gfmul
[raid6_gfexi
[failb
-faila
]];
374 qmul
= raid6_gfmul
[raid6_gfinv
[raid6_gfexp
[faila
]^raid6_gfexp
[failb
]]];
380 *dq
++ = db
= pbmul
[px
] ^ qx
; /* Reconstructed B */
381 *dp
++ = db
^ px
; /* Reconstructed A */
386 /* Recover failure of one data block plus the P block */
387 void raid6_datap_recov(int disks
, size_t bytes
, int faila
, uint8_t **ptrs
)
390 const uint8_t *qmul
; /* Q multiplier table */
395 /* Compute syndrome with zero for the missing data page
396 Use the dead data page as temporary storage for delta q */
400 qsyndrome(p
, dq
, ptrs
, disks
-2, bytes
);
402 /* Restore pointer table */
405 /* Now, pick the proper data tables */
406 qmul
= raid6_gfmul
[raid6_gfinv
[raid6_gfexp
[faila
]]];
410 *p
++ ^= *dq
= qmul
[*q
^ *dq
];
415 /* Try to find out if a specific disk has a problem */
416 int raid6_check_disks(int data_disks
, int start
, int chunk_size
,
417 int level
, int layout
, int diskP
, int diskQ
,
418 char *p
, char *q
, char **stripes
)
423 int curr_broken_disk
= -1;
424 int prev_broken_disk
= -1;
425 int broken_status
= 0;
427 for(i
= 0; i
< chunk_size
; i
++) {
428 Px
= (uint8_t)stripes
[diskP
][i
] ^ (uint8_t)p
[i
];
429 Qx
= (uint8_t)stripes
[diskQ
][i
] ^ (uint8_t)q
[i
];
431 if((Px
!= 0) && (Qx
== 0))
432 curr_broken_disk
= diskP
;
434 if((Px
== 0) && (Qx
!= 0))
435 curr_broken_disk
= diskQ
;
437 if((Px
!= 0) && (Qx
!= 0)) {
438 data_id
= (raid6_gflog
[Qx
] - raid6_gflog
[Px
]);
439 if(data_id
< 0) data_id
+= 255;
440 diskD
= geo_map(data_id
, start
/chunk_size
,
441 data_disks
+ 2, level
, layout
);
442 curr_broken_disk
= diskD
;
445 if((Px
== 0) && (Qx
== 0))
446 curr_broken_disk
= curr_broken_disk
;
448 if(curr_broken_disk
>= data_disks
+ 2)
451 switch(broken_status
) {
453 if(curr_broken_disk
!= -1) {
454 prev_broken_disk
= curr_broken_disk
;
460 if(curr_broken_disk
!= prev_broken_disk
)
466 curr_broken_disk
= prev_broken_disk
= -2;
471 return curr_broken_disk
;
474 /*******************************************************************************
475 * Function: save_stripes
477 * Function reads data (only data without P and Q) from array and writes
478 * it to buf and opcjonaly to backup files
480 * source : A list of 'fds' of the active disks.
482 * offsets : A list of offsets on disk belonging
483 * to the array [bytes]
484 * raid_disks : geometry: number of disks in the array
485 * chunk_size : geometry: chunk size [bytes]
486 * level : geometry: RAID level
487 * layout : geometry: layout
488 * nwrites : number of backup files
489 * dest : A list of 'fds' for mirrored targets
490 * (e.g. backup files). They are already seeked to right
491 * (write) location. If NULL, data will be wrote
493 * start : start address of data to read (must be stripe-aligned)
495 * length - : length of data to read (must be stripe-aligned)
497 * buf : buffer for data. It is large enough to hold
498 * one stripe. It is stripe aligned
502 ******************************************************************************/
503 int save_stripes(int *source
, unsigned long long *offsets
,
504 int raid_disks
, int chunk_size
, int level
, int layout
,
505 int nwrites
, int *dest
,
506 unsigned long long start
, unsigned long long length
,
510 int data_disks
= raid_disks
- (level
== 0 ? 0 : level
<=5 ? 1 : 2);
513 unsigned long long length_test
;
517 ensure_zero_has_size(chunk_size
);
519 len
= data_disks
* chunk_size
;
520 length_test
= length
/ len
;
523 if (length
!= length_test
) {
524 dprintf("Error: save_stripes(): Data are not alligned. EXIT\n");
525 dprintf("\tArea for saving stripes (length) = %llu\n", length
);
526 dprintf("\tWork step (len) = %i\n", len
);
527 dprintf("\tExpected save area (length_test) = %llu\n",
534 int fdisk
[3], fblock
[3];
535 for (disk
= 0; disk
< raid_disks
; disk
++) {
536 unsigned long long offset
;
539 offset
= (start
/chunk_size
/data_disks
)*chunk_size
;
540 dnum
= geo_map(disk
< data_disks
? disk
: data_disks
- disk
- 1,
541 start
/chunk_size
/data_disks
,
542 raid_disks
, level
, layout
);
543 if (dnum
< 0) abort();
544 if (source
[dnum
] < 0 ||
545 lseek64(source
[dnum
], offsets
[dnum
]+offset
, 0) < 0 ||
546 read(source
[dnum
], buf
+disk
* chunk_size
, chunk_size
)
549 fdisk
[failed
] = dnum
;
550 fblock
[failed
] = disk
;
554 if (failed
== 0 || fblock
[0] >= data_disks
)
555 /* all data disks are good */
557 else if (failed
== 1 || fblock
[1] >= data_disks
+1) {
558 /* one failed data disk and good parity */
559 char *bufs
[data_disks
];
560 for (i
=0; i
< data_disks
; i
++)
562 bufs
[i
] = buf
+ data_disks
*chunk_size
;
564 bufs
[i
] = buf
+ i
*chunk_size
;
566 xor_blocks(buf
+ fblock
[0]*chunk_size
,
567 bufs
, data_disks
, chunk_size
);
568 } else if (failed
> 2 || level
!= 6)
569 /* too much failure */
572 /* RAID6 computations needed. */
573 uint8_t *bufs
[data_disks
+4];
576 disk
= geo_map(-1, start
/chunk_size
/data_disks
,
577 raid_disks
, level
, layout
);
578 qdisk
= geo_map(-2, start
/chunk_size
/data_disks
,
579 raid_disks
, level
, layout
);
580 if (is_ddf(layout
)) {
581 /* q over 'raid_disks' blocks, in device order.
582 * 'p' and 'q' get to be all zero
584 for (i
= 0; i
< raid_disks
; i
++)
586 for (i
= 0; i
< data_disks
; i
++) {
587 int dnum
= geo_map(i
,
588 start
/chunk_size
/data_disks
,
589 raid_disks
, level
, layout
);
591 /* i is the logical block number, so is index to 'buf'.
592 * dnum is physical disk number
593 * and thus the syndrome number.
596 bufs
[snum
] = (uint8_t*)buf
+ chunk_size
* i
;
598 syndrome_disks
= raid_disks
;
600 /* for md, q is over 'data_disks' blocks,
601 * starting immediately after 'q'
602 * Note that for the '_6' variety, the p block
603 * makes a hole that we need to be careful of.
607 for (j
= 0; j
< raid_disks
; j
++) {
608 int dnum
= (qdisk
+ 1 + j
) % raid_disks
;
609 if (dnum
== disk
|| dnum
== qdisk
)
611 for (i
= 0; i
< data_disks
; i
++)
613 start
/chunk_size
/data_disks
,
614 raid_disks
, level
, layout
) == dnum
)
616 /* i is the logical block number, so is index to 'buf'.
617 * dnum is physical disk number
618 * snum is syndrome disk for which 0 is immediately after Q
620 bufs
[snum
] = (uint8_t*)buf
+ chunk_size
* i
;
629 syndrome_disks
= data_disks
;
632 /* Place P and Q blocks at end of bufs */
633 bufs
[syndrome_disks
] = (uint8_t*)buf
+ chunk_size
* data_disks
;
634 bufs
[syndrome_disks
+1] = (uint8_t*)buf
+ chunk_size
* (data_disks
+1);
636 if (fblock
[1] == data_disks
)
637 /* One data failed, and parity failed */
638 raid6_datap_recov(syndrome_disks
+2, chunk_size
,
641 if (fdisk
[0] > fdisk
[1]) {
646 /* Two data blocks failed, P,Q OK */
647 raid6_2data_recov(syndrome_disks
+2, chunk_size
,
648 fdisk
[0], fdisk
[1], bufs
);
652 for (i
= 0; i
< nwrites
; i
++)
653 if (write(dest
[i
], buf
, len
) != len
)
656 /* build next stripe in buffer */
667 * A list of 'fds' of the active disks. Some may be '-1' for not-available.
668 * A geometry: raid_disks, chunk_size, level, layout
669 * An 'fd' to read from. It is already seeked to the right (Read) location.
670 * A start and length.
671 * The length must be a multiple of the stripe size.
673 * We build a full stripe in memory and then write it out.
674 * We assume that there are enough working devices.
676 int restore_stripes(int *dest
, unsigned long long *offsets
,
677 int raid_disks
, int chunk_size
, int level
, int layout
,
678 int source
, unsigned long long read_offset
,
679 unsigned long long start
, unsigned long long length
,
683 char **stripes
= xmalloc(raid_disks
* sizeof(char*));
684 char **blocks
= xmalloc(raid_disks
* sizeof(char*));
688 int data_disks
= raid_disks
- (level
== 0 ? 0 : level
<= 5 ? 1 : 2);
690 if (posix_memalign((void**)&stripe_buf
, 4096, raid_disks
* chunk_size
))
693 if (zero
== NULL
|| chunk_size
> zero_size
) {
696 zero
= xcalloc(1, chunk_size
);
697 zero_size
= chunk_size
;
700 if (stripe_buf
== NULL
|| stripes
== NULL
|| blocks
== NULL
705 for (i
= 0; i
< raid_disks
; i
++)
706 stripes
[i
] = stripe_buf
+ i
* chunk_size
;
708 unsigned int len
= data_disks
* chunk_size
;
709 unsigned long long offset
;
716 for (i
= 0; i
< data_disks
; i
++) {
717 int disk
= geo_map(i
, start
/chunk_size
/data_disks
,
718 raid_disks
, level
, layout
);
719 if (src_buf
== NULL
) {
721 if (lseek64(source
, read_offset
, 0) !=
722 (off64_t
)read_offset
) {
728 chunk_size
) != chunk_size
) {
733 /* read from input buffer */
734 memcpy(stripes
[disk
],
735 src_buf
+ read_offset
,
738 read_offset
+= chunk_size
;
740 /* We have the data, now do the parity */
741 offset
= (start
/chunk_size
/data_disks
) * chunk_size
;
745 disk
= geo_map(-1, start
/chunk_size
/data_disks
,
746 raid_disks
, level
, layout
);
747 for (i
= 0; i
< data_disks
; i
++)
748 blocks
[i
] = stripes
[(disk
+1+i
) % raid_disks
];
749 xor_blocks(stripes
[disk
], blocks
, data_disks
, chunk_size
);
752 disk
= geo_map(-1, start
/chunk_size
/data_disks
,
753 raid_disks
, level
, layout
);
754 qdisk
= geo_map(-2, start
/chunk_size
/data_disks
,
755 raid_disks
, level
, layout
);
756 if (is_ddf(layout
)) {
757 /* q over 'raid_disks' blocks, in device order.
758 * 'p' and 'q' get to be all zero
760 for (i
= 0; i
< raid_disks
; i
++)
761 if (i
== disk
|| i
== qdisk
)
762 blocks
[i
] = (char*)zero
;
764 blocks
[i
] = stripes
[i
];
765 syndrome_disks
= raid_disks
;
767 /* for md, q is over 'data_disks' blocks,
768 * starting immediately after 'q'
770 for (i
= 0; i
< data_disks
; i
++)
771 blocks
[i
] = stripes
[(qdisk
+1+i
) % raid_disks
];
773 syndrome_disks
= data_disks
;
775 qsyndrome((uint8_t*)stripes
[disk
],
776 (uint8_t*)stripes
[qdisk
],
778 syndrome_disks
, chunk_size
);
781 for (i
=0; i
< raid_disks
; i
++)
784 offsets
[i
]+offset
, 0) < 0) {
788 if (write(dest
[i
], stripes
[i
],
789 chunk_size
) != chunk_size
) {
808 int test_stripes(int *source
, unsigned long long *offsets
,
809 int raid_disks
, int chunk_size
, int level
, int layout
,
810 unsigned long long start
, unsigned long long length
)
812 /* ready the data and p (and q) blocks, and check we got them right */
813 char *stripe_buf
= xmalloc(raid_disks
* chunk_size
);
814 char **stripes
= xmalloc(raid_disks
* sizeof(char*));
815 char **blocks
= xmalloc(raid_disks
* sizeof(char*));
816 char *p
= xmalloc(chunk_size
);
817 char *q
= xmalloc(chunk_size
);
821 int data_disks
= raid_disks
- (level
== 5 ? 1: 2);
826 for ( i
= 0 ; i
< raid_disks
; i
++)
827 stripes
[i
] = stripe_buf
+ i
* chunk_size
;
832 for (i
= 0 ; i
< raid_disks
; i
++) {
833 lseek64(source
[i
], offsets
[i
]+start
, 0);
834 read(source
[i
], stripes
[i
], chunk_size
);
836 for (i
= 0 ; i
< data_disks
; i
++) {
837 int disk
= geo_map(i
, start
/chunk_size
, raid_disks
,
839 blocks
[i
] = stripes
[disk
];
840 printf("%d->%d\n", i
, disk
);
844 qsyndrome(p
, q
, (uint8_t**)blocks
, data_disks
, chunk_size
);
845 diskP
= geo_map(-1, start
/chunk_size
, raid_disks
,
847 if (memcmp(p
, stripes
[diskP
], chunk_size
) != 0) {
848 printf("P(%d) wrong at %llu\n", diskP
,
851 diskQ
= geo_map(-2, start
/chunk_size
, raid_disks
,
853 if (memcmp(q
, stripes
[diskQ
], chunk_size
) != 0) {
854 printf("Q(%d) wrong at %llu\n", diskQ
,
857 disk
= raid6_check_disks(data_disks
, start
, chunk_size
,
858 level
, layout
, diskP
, diskQ
,
861 printf("Possible failed disk: %d\n", disk
);
864 printf("Failure detected, but disk unknown\n");
868 length
-= chunk_size
;
874 unsigned long long getnum(char *str
, char **err
)
877 unsigned long long rv
= strtoull(str
, &e
, 10);
885 main(int argc
, char *argv
[])
887 /* save/restore file raid_disks chunk_size level layout start length devices...
894 unsigned long long *offsets
;
895 int raid_disks
, chunk_size
, level
, layout
;
896 unsigned long long start
, length
;
901 fprintf(stderr
, "Usage: test_stripe save/restore file raid_disks"
902 " chunk_size level layout start length devices...\n");
905 if (strcmp(argv
[1], "save")==0)
907 else if (strcmp(argv
[1], "restore") == 0)
909 else if (strcmp(argv
[1], "test") == 0)
912 fprintf(stderr
, "test_stripe: must give 'save' or 'restore'.\n");
917 raid_disks
= getnum(argv
[3], &err
);
918 chunk_size
= getnum(argv
[4], &err
);
919 level
= getnum(argv
[5], &err
);
920 layout
= getnum(argv
[6], &err
);
921 start
= getnum(argv
[7], &err
);
922 length
= getnum(argv
[8], &err
);
924 fprintf(stderr
, "test_stripe: Bad number: %s\n", err
);
927 if (argc
!= raid_disks
+ 9) {
928 fprintf(stderr
, "test_stripe: wrong number of devices: want %d found %d\n",
932 fds
= xmalloc(raid_disks
* sizeof(*fds
));
933 offsets
= xcalloc(raid_disks
, sizeof(*offsets
));
935 storefd
= open(file
, O_RDWR
);
938 fprintf(stderr
, "test_stripe: could not open %s.\n", file
);
941 for (i
=0; i
<raid_disks
; i
++) {
943 p
= strchr(argv
[9+i
], ':');
947 offsets
[i
] = atoll(p
) * 512;
950 fds
[i
] = open(argv
[9+i
], O_RDWR
);
953 fprintf(stderr
,"test_stripe: cannot open %s.\n", argv
[9+i
]);
958 buf
= xmalloc(raid_disks
* chunk_size
);
961 int rv
= save_stripes(fds
, offsets
,
962 raid_disks
, chunk_size
, level
, layout
,
967 "test_stripe: save_stripes returned %d\n", rv
);
970 } else if (save
== 2) {
971 int rv
= test_stripes(fds
, offsets
,
972 raid_disks
, chunk_size
, level
, layout
,
976 "test_stripe: test_stripes returned %d\n", rv
);
980 int rv
= restore_stripes(fds
, offsets
,
981 raid_disks
, chunk_size
, level
, layout
,
983 start
, length
, NULL
);
986 "test_stripe: restore_stripes returned %d\n",