Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* -*- linux-c -*- ------------------------------------------------------- * |
| 2 | * |
H. Peter Anvin | 66c811e | 2008-02-06 01:39:48 -0800 | [diff] [blame] | 3 | * Copyright 2002-2007 H. Peter Anvin - All Rights Reserved |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
H. Peter Anvin | 66c811e | 2008-02-06 01:39:48 -0800 | [diff] [blame] | 5 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 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 Williams | f701d58 | 2009-03-31 15:09:39 +1100 | [diff] [blame] | 20 | #include <linux/raid/pq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #define NDISKS 16 /* Including P and Q */ |
| 23 | |
Gayatri Kammela | 099b548 | 2016-09-26 14:37:38 -0700 | [diff] [blame] | 24 | const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | struct raid6_calls raid6_call; |
| 26 | |
| 27 | char *dataptrs[NDISKS]; |
Gayatri Kammela | 099b548 | 2016-09-26 14:37:38 -0700 | [diff] [blame] | 28 | char data[NDISKS][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); |
| 29 | char recovi[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); |
| 30 | char recovj[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Markus Stockhausen | 7e92e1d | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 32 | static void makedata(int start, int stop) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | { |
| 34 | int i, j; |
| 35 | |
Markus Stockhausen | 7e92e1d | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 36 | for (i = start; i <= stop; i++) { |
H. Peter Anvin | 66c811e | 2008-02-06 01:39:48 -0800 | [diff] [blame] | 37 | for (j = 0; j < PAGE_SIZE; j++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | data[i][j] = rand(); |
H. Peter Anvin | 66c811e | 2008-02-06 01:39:48 -0800 | [diff] [blame] | 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | dataptrs[i] = data[i]; |
| 41 | } |
| 42 | } |
| 43 | |
H. Peter Anvin | 66c811e | 2008-02-06 01:39:48 -0800 | [diff] [blame] | 44 | static 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 | |
| 56 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | int main(int argc, char *argv[]) |
| 92 | { |
H. Peter Anvin | 66c811e | 2008-02-06 01:39:48 -0800 | [diff] [blame] | 93 | const struct raid6_calls *const *algo; |
Jim Kukunas | 2dbf708 | 2012-05-22 13:54:23 +1000 | [diff] [blame] | 94 | const struct raid6_recov_calls *const *ra; |
Markus Stockhausen | 7e92e1d | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 95 | int i, j, p1, p2; |
H. Peter Anvin | 66c811e | 2008-02-06 01:39:48 -0800 | [diff] [blame] | 96 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Markus Stockhausen | 7e92e1d | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 98 | makedata(0, NDISKS-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Jim Kukunas | 2dbf708 | 2012-05-22 13:54:23 +1000 | [diff] [blame] | 100 | for (ra = raid6_recov_algos; *ra; ra++) { |
| 101 | if ((*ra)->valid && !(*ra)->valid()) |
| 102 | continue; |
Markus Stockhausen | 7e92e1d | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 103 | |
Jim Kukunas | 2dbf708 | 2012-05-22 13:54:23 +1000 | [diff] [blame] | 104 | raid6_2data_recov = (*ra)->data2; |
| 105 | raid6_datap_recov = (*ra)->datap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Jim Kukunas | 2dbf708 | 2012-05-22 13:54:23 +1000 | [diff] [blame] | 107 | printf("using recovery %s\n", (*ra)->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Jim Kukunas | 2dbf708 | 2012-05-22 13:54:23 +1000 | [diff] [blame] | 109 | for (algo = raid6_algos; *algo; algo++) { |
Markus Stockhausen | 7e92e1d | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 110 | if ((*algo)->valid && !(*algo)->valid()) |
| 111 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Markus Stockhausen | 7e92e1d | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 113 | raid6_call = **algo; |
Jim Kukunas | 2dbf708 | 2012-05-22 13:54:23 +1000 | [diff] [blame] | 114 | |
Markus Stockhausen | 7e92e1d | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 115 | /* Nuke syndromes */ |
| 116 | memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE); |
Jim Kukunas | 2dbf708 | 2012-05-22 13:54:23 +1000 | [diff] [blame] | 117 | |
Markus Stockhausen | 7e92e1d | 2014-12-15 12:57:04 +1100 | [diff] [blame] | 118 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | printf("\n"); |
| 146 | } |
| 147 | |
| 148 | printf("\n"); |
| 149 | /* Pick the best algorithm test */ |
| 150 | raid6_select_algo(); |
| 151 | |
H. Peter Anvin | 66c811e | 2008-02-06 01:39:48 -0800 | [diff] [blame] | 152 | if (err) |
| 153 | printf("\n*** ERRORS FOUND ***\n"); |
| 154 | |
| 155 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |