aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/raid6test
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-02-06 04:39:48 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-06 13:41:18 -0500
commit66c811e99322767bad5db4368de93aac604f02a2 (patch)
tree01b8c89165660ef0787d23af49d603242ef6ffdf /drivers/md/raid6test
parent98ec302be52cc8a9cc0f3072126367273dbaf865 (diff)
md: raid6: clean up the style of raid6test/test.c
Clean up the coding style in raid6test/test.c. Break it apart into subfunctions to make the code more readable. Signed-off-by: H. Peter Anvin <hpa@zytor.com> Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/md/raid6test')
-rw-r--r--drivers/md/raid6test/test.c117
1 files changed, 69 insertions, 48 deletions
diff --git a/drivers/md/raid6test/test.c b/drivers/md/raid6test/test.c
index 0d5cd57accd7..559cc41b2585 100644
--- a/drivers/md/raid6test/test.c
+++ b/drivers/md/raid6test/test.c
@@ -1,12 +1,10 @@
1/* -*- linux-c -*- ------------------------------------------------------- * 1/* -*- linux-c -*- ------------------------------------------------------- *
2 * 2 *
3 * Copyright 2002 H. Peter Anvin - All Rights Reserved 3 * Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This file is part of the Linux kernel, and is made available under
6 * it under the terms of the GNU General Public License as published by 6 * the terms of the GNU General Public License version 2 or (at your
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330, 7 * option) any later version; incorporated herein by reference.
8 * Bostom MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 * 8 *
11 * ----------------------------------------------------------------------- */ 9 * ----------------------------------------------------------------------- */
12 10
@@ -30,67 +28,87 @@ char *dataptrs[NDISKS];
30char data[NDISKS][PAGE_SIZE]; 28char data[NDISKS][PAGE_SIZE];
31char recovi[PAGE_SIZE], recovj[PAGE_SIZE]; 29char recovi[PAGE_SIZE], recovj[PAGE_SIZE];
32 30
33void makedata(void) 31static void makedata(void)
34{ 32{
35 int i, j; 33 int i, j;
36 34
37 for ( i = 0 ; i < NDISKS ; i++ ) { 35 for (i = 0; i < NDISKS; i++) {
38 for ( j = 0 ; j < PAGE_SIZE ; j++ ) { 36 for (j = 0; j < PAGE_SIZE; j++)
39 data[i][j] = rand(); 37 data[i][j] = rand();
40 } 38
41 dataptrs[i] = data[i]; 39 dataptrs[i] = data[i];
42 } 40 }
43} 41}
44 42
43static char disk_type(int d)
44{
45 switch (d) {
46 case NDISKS-2:
47 return 'P';
48 case NDISKS-1:
49 return 'Q';
50 default:
51 return 'D';
52 }
53}
54
55static int test_disks(int i, int j)
56{
57 int erra, errb;
58
59 memset(recovi, 0xf0, PAGE_SIZE);
60 memset(recovj, 0xba, PAGE_SIZE);
61
62 dataptrs[i] = recovi;
63 dataptrs[j] = recovj;
64
65 raid6_dual_recov(NDISKS, PAGE_SIZE, i, j, (void **)&dataptrs);
66
67 erra = memcmp(data[i], recovi, PAGE_SIZE);
68 errb = memcmp(data[j], recovj, PAGE_SIZE);
69
70 if (i < NDISKS-2 && j == NDISKS-1) {
71 /* We don't implement the DQ failure scenario, since it's
72 equivalent to a RAID-5 failure (XOR, then recompute Q) */
73 erra = errb = 0;
74 } else {
75 printf("algo=%-8s faila=%3d(%c) failb=%3d(%c) %s\n",
76 raid6_call.name,
77 i, disk_type(i),
78 j, disk_type(j),
79 (!erra && !errb) ? "OK" :
80 !erra ? "ERRB" :
81 !errb ? "ERRA" : "ERRAB");
82 }
83
84 dataptrs[i] = data[i];
85 dataptrs[j] = data[j];
86
87 return erra || errb;
88}
89
45int main(int argc, char *argv[]) 90int main(int argc, char *argv[])
46{ 91{
47 const struct raid6_calls * const * algo; 92 const struct raid6_calls *const *algo;
48 int i, j; 93 int i, j;
49 int erra, errb; 94 int err = 0;
50 95
51 makedata(); 96 makedata();
52 97
53 for ( algo = raid6_algos ; *algo ; algo++ ) { 98 for (algo = raid6_algos; *algo; algo++) {
54 if ( !(*algo)->valid || (*algo)->valid() ) { 99 if (!(*algo)->valid || (*algo)->valid()) {
55 raid6_call = **algo; 100 raid6_call = **algo;
56 101
57 /* Nuke syndromes */ 102 /* Nuke syndromes */
58 memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE); 103 memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE);
59 104
60 /* Generate assumed good syndrome */ 105 /* Generate assumed good syndrome */
61 raid6_call.gen_syndrome(NDISKS, PAGE_SIZE, (void **)&dataptrs); 106 raid6_call.gen_syndrome(NDISKS, PAGE_SIZE,
62 107 (void **)&dataptrs);
63 for ( i = 0 ; i < NDISKS-1 ; i++ ) { 108
64 for ( j = i+1 ; j < NDISKS ; j++ ) { 109 for (i = 0; i < NDISKS-1; i++)
65 memset(recovi, 0xf0, PAGE_SIZE); 110 for (j = i+1; j < NDISKS; j++)
66 memset(recovj, 0xba, PAGE_SIZE); 111 err += test_disks(i, j);
67
68 dataptrs[i] = recovi;
69 dataptrs[j] = recovj;
70
71 raid6_dual_recov(NDISKS, PAGE_SIZE, i, j, (void **)&dataptrs);
72
73 erra = memcmp(data[i], recovi, PAGE_SIZE);
74 errb = memcmp(data[j], recovj, PAGE_SIZE);
75
76 if ( i < NDISKS-2 && j == NDISKS-1 ) {
77 /* We don't implement the DQ failure scenario, since it's
78 equivalent to a RAID-5 failure (XOR, then recompute Q) */
79 } else {
80 printf("algo=%-8s faila=%3d(%c) failb=%3d(%c) %s\n",
81 raid6_call.name,
82 i, (i==NDISKS-2)?'P':'D',
83 j, (j==NDISKS-1)?'Q':(j==NDISKS-2)?'P':'D',
84 (!erra && !errb) ? "OK" :
85 !erra ? "ERRB" :
86 !errb ? "ERRA" :
87 "ERRAB");
88 }
89
90 dataptrs[i] = data[i];
91 dataptrs[j] = data[j];
92 }
93 }
94 } 112 }
95 printf("\n"); 113 printf("\n");
96 } 114 }
@@ -99,5 +117,8 @@ int main(int argc, char *argv[])
99 /* Pick the best algorithm test */ 117 /* Pick the best algorithm test */
100 raid6_select_algo(); 118 raid6_select_algo();
101 119
102 return 0; 120 if (err)
121 printf("\n*** ERRORS FOUND ***\n");
122
123 return err;
103} 124}