blob: b07f4d8e6b033f8030ea715d5f78e16db37859f2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* -*- linux-c -*- ------------------------------------------------------- *
2 *
H. Peter Anvin66c811e2008-02-06 01:39:48 -08003 * Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
H. Peter Anvin66c811e2008-02-06 01:39:48 -08005 * This file is part of the Linux kernel, and is made available under
6 * the terms of the GNU General Public License version 2 or (at your
7 * option) any later version; incorporated herein by reference.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * ----------------------------------------------------------------------- */
10
11/*
12 * raid6test.c
13 *
14 * Test RAID-6 recovery with various algorithms
15 */
16
17#include <stdlib.h>
18#include <stdio.h>
19#include <string.h>
Dan Williamsf701d582009-03-31 15:09:39 +110020#include <linux/raid/pq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#define NDISKS 16 /* Including P and Q */
23
Gayatri Kammela099b5482016-09-26 14:37:38 -070024const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070025struct raid6_calls raid6_call;
26
27char *dataptrs[NDISKS];
Gayatri Kammela099b5482016-09-26 14:37:38 -070028char data[NDISKS][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
29char recovi[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
30char recovj[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +110032static void makedata(int start, int stop)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
34 int i, j;
35
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +110036 for (i = start; i <= stop; i++) {
H. Peter Anvin66c811e2008-02-06 01:39:48 -080037 for (j = 0; j < PAGE_SIZE; j++)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 data[i][j] = rand();
H. Peter Anvin66c811e2008-02-06 01:39:48 -080039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 dataptrs[i] = data[i];
41 }
42}
43
H. Peter Anvin66c811e2008-02-06 01:39:48 -080044static char disk_type(int d)
45{
46 switch (d) {
47 case NDISKS-2:
48 return 'P';
49 case NDISKS-1:
50 return 'Q';
51 default:
52 return 'D';
53 }
54}
55
56static int test_disks(int i, int j)
57{
58 int erra, errb;
59
60 memset(recovi, 0xf0, PAGE_SIZE);
61 memset(recovj, 0xba, PAGE_SIZE);
62
63 dataptrs[i] = recovi;
64 dataptrs[j] = recovj;
65
66 raid6_dual_recov(NDISKS, PAGE_SIZE, i, j, (void **)&dataptrs);
67
68 erra = memcmp(data[i], recovi, PAGE_SIZE);
69 errb = memcmp(data[j], recovj, PAGE_SIZE);
70
71 if (i < NDISKS-2 && j == NDISKS-1) {
72 /* We don't implement the DQ failure scenario, since it's
73 equivalent to a RAID-5 failure (XOR, then recompute Q) */
74 erra = errb = 0;
75 } else {
76 printf("algo=%-8s faila=%3d(%c) failb=%3d(%c) %s\n",
77 raid6_call.name,
78 i, disk_type(i),
79 j, disk_type(j),
80 (!erra && !errb) ? "OK" :
81 !erra ? "ERRB" :
82 !errb ? "ERRA" : "ERRAB");
83 }
84
85 dataptrs[i] = data[i];
86 dataptrs[j] = data[j];
87
88 return erra || errb;
89}
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091int main(int argc, char *argv[])
92{
H. Peter Anvin66c811e2008-02-06 01:39:48 -080093 const struct raid6_calls *const *algo;
Jim Kukunas2dbf7082012-05-22 13:54:23 +100094 const struct raid6_recov_calls *const *ra;
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +110095 int i, j, p1, p2;
H. Peter Anvin66c811e2008-02-06 01:39:48 -080096 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +110098 makedata(0, NDISKS-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Jim Kukunas2dbf7082012-05-22 13:54:23 +1000100 for (ra = raid6_recov_algos; *ra; ra++) {
101 if ((*ra)->valid && !(*ra)->valid())
102 continue;
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +1100103
Jim Kukunas2dbf7082012-05-22 13:54:23 +1000104 raid6_2data_recov = (*ra)->data2;
105 raid6_datap_recov = (*ra)->datap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Jim Kukunas2dbf7082012-05-22 13:54:23 +1000107 printf("using recovery %s\n", (*ra)->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Jim Kukunas2dbf7082012-05-22 13:54:23 +1000109 for (algo = raid6_algos; *algo; algo++) {
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +1100110 if ((*algo)->valid && !(*algo)->valid())
111 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +1100113 raid6_call = **algo;
Jim Kukunas2dbf7082012-05-22 13:54:23 +1000114
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +1100115 /* Nuke syndromes */
116 memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE);
Jim Kukunas2dbf7082012-05-22 13:54:23 +1000117
Markus Stockhausen7e92e1d2014-12-15 12:57:04 +1100118 /* Generate assumed good syndrome */
119 raid6_call.gen_syndrome(NDISKS, PAGE_SIZE,
120 (void **)&dataptrs);
121
122 for (i = 0; i < NDISKS-1; i++)
123 for (j = i+1; j < NDISKS; j++)
124 err += test_disks(i, j);
125
126 if (!raid6_call.xor_syndrome)
127 continue;
128
129 for (p1 = 0; p1 < NDISKS-2; p1++)
130 for (p2 = p1; p2 < NDISKS-2; p2++) {
131
132 /* Simulate rmw run */
133 raid6_call.xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
134 (void **)&dataptrs);
135 makedata(p1, p2);
136 raid6_call.xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
137 (void **)&dataptrs);
138
139 for (i = 0; i < NDISKS-1; i++)
140 for (j = i+1; j < NDISKS; j++)
141 err += test_disks(i, j);
142 }
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
145 printf("\n");
146 }
147
148 printf("\n");
149 /* Pick the best algorithm test */
150 raid6_select_algo();
151
H. Peter Anvin66c811e2008-02-06 01:39:48 -0800152 if (err)
153 printf("\n*** ERRORS FOUND ***\n");
154
155 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}