Linux Audio

Check our new training course

Loading...
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/* -*- linux-c -*- ------------------------------------------------------- *
  3 *
  4 *   Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
  5 *
 
 
 
 
  6 * ----------------------------------------------------------------------- */
  7
  8/*
  9 * raid6test.c
 10 *
 11 * Test RAID-6 recovery with various algorithms
 12 */
 13
 14#include <stdlib.h>
 15#include <stdio.h>
 16#include <string.h>
 17#include <linux/raid/pq.h>
 18
 19#define NDISKS		16	/* Including P and Q */
 20
 21const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
 22struct raid6_calls raid6_call;
 23
 24char *dataptrs[NDISKS];
 25char data[NDISKS][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
 26char recovi[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
 27char recovj[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
 28
 29static void makedata(int start, int stop)
 30{
 31	int i, j;
 32
 33	for (i = start; i <= stop; i++) {
 34		for (j = 0; j < PAGE_SIZE; j++)
 35			data[i][j] = rand();
 36
 37		dataptrs[i] = data[i];
 38	}
 39}
 40
 41static char disk_type(int d)
 42{
 43	switch (d) {
 44	case NDISKS-2:
 45		return 'P';
 46	case NDISKS-1:
 47		return 'Q';
 48	default:
 49		return 'D';
 50	}
 51}
 52
 53static int test_disks(int i, int j)
 54{
 55	int erra, errb;
 56
 57	memset(recovi, 0xf0, PAGE_SIZE);
 58	memset(recovj, 0xba, PAGE_SIZE);
 59
 60	dataptrs[i] = recovi;
 61	dataptrs[j] = recovj;
 62
 63	raid6_dual_recov(NDISKS, PAGE_SIZE, i, j, (void **)&dataptrs);
 64
 65	erra = memcmp(data[i], recovi, PAGE_SIZE);
 66	errb = memcmp(data[j], recovj, PAGE_SIZE);
 67
 68	if (i < NDISKS-2 && j == NDISKS-1) {
 69		/* We don't implement the DQ failure scenario, since it's
 70		   equivalent to a RAID-5 failure (XOR, then recompute Q) */
 71		erra = errb = 0;
 72	} else {
 73		printf("algo=%-8s  faila=%3d(%c)  failb=%3d(%c)  %s\n",
 74		       raid6_call.name,
 75		       i, disk_type(i),
 76		       j, disk_type(j),
 77		       (!erra && !errb) ? "OK" :
 78		       !erra ? "ERRB" :
 79		       !errb ? "ERRA" : "ERRAB");
 80	}
 81
 82	dataptrs[i] = data[i];
 83	dataptrs[j] = data[j];
 84
 85	return erra || errb;
 86}
 87
 88int main(int argc, char *argv[])
 89{
 90	const struct raid6_calls *const *algo;
 91	const struct raid6_recov_calls *const *ra;
 92	int i, j, p1, p2;
 93	int err = 0;
 94
 95	makedata(0, NDISKS-1);
 96
 97	for (ra = raid6_recov_algos; *ra; ra++) {
 98		if ((*ra)->valid  && !(*ra)->valid())
 99			continue;
100
101		raid6_2data_recov = (*ra)->data2;
102		raid6_datap_recov = (*ra)->datap;
103
104		printf("using recovery %s\n", (*ra)->name);
105
106		for (algo = raid6_algos; *algo; algo++) {
107			if ((*algo)->valid && !(*algo)->valid())
108				continue;
109
110			raid6_call = **algo;
111
112			/* Nuke syndromes */
113			memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE);
114
115			/* Generate assumed good syndrome */
116			raid6_call.gen_syndrome(NDISKS, PAGE_SIZE,
117						(void **)&dataptrs);
118
119			for (i = 0; i < NDISKS-1; i++)
120				for (j = i+1; j < NDISKS; j++)
121					err += test_disks(i, j);
122
123			if (!raid6_call.xor_syndrome)
124				continue;
125
126			for (p1 = 0; p1 < NDISKS-2; p1++)
127				for (p2 = p1; p2 < NDISKS-2; p2++) {
128
129					/* Simulate rmw run */
130					raid6_call.xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
131								(void **)&dataptrs);
132					makedata(p1, p2);
133					raid6_call.xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
134                                                                (void **)&dataptrs);
135
136					for (i = 0; i < NDISKS-1; i++)
137						for (j = i+1; j < NDISKS; j++)
138							err += test_disks(i, j);
139				}
140
141		}
142		printf("\n");
143	}
144
145	printf("\n");
146	/* Pick the best algorithm test */
147	raid6_select_algo();
148
149	if (err)
150		printf("\n*** ERRORS FOUND ***\n");
151
152	return err;
153}
v4.6
 
  1/* -*- linux-c -*- ------------------------------------------------------- *
  2 *
  3 *   Copyright 2002-2007 H. Peter Anvin - All Rights Reserved
  4 *
  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.
  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>
 20#include <linux/raid/pq.h>
 21
 22#define NDISKS		16	/* Including P and Q */
 23
 24const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256)));
 25struct raid6_calls raid6_call;
 26
 27char *dataptrs[NDISKS];
 28char data[NDISKS][PAGE_SIZE];
 29char recovi[PAGE_SIZE], recovj[PAGE_SIZE];
 
 30
 31static void makedata(int start, int stop)
 32{
 33	int i, j;
 34
 35	for (i = start; i <= stop; i++) {
 36		for (j = 0; j < PAGE_SIZE; j++)
 37			data[i][j] = rand();
 38
 39		dataptrs[i] = data[i];
 40	}
 41}
 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
 90int main(int argc, char *argv[])
 91{
 92	const struct raid6_calls *const *algo;
 93	const struct raid6_recov_calls *const *ra;
 94	int i, j, p1, p2;
 95	int err = 0;
 96
 97	makedata(0, NDISKS-1);
 98
 99	for (ra = raid6_recov_algos; *ra; ra++) {
100		if ((*ra)->valid  && !(*ra)->valid())
101			continue;
102
103		raid6_2data_recov = (*ra)->data2;
104		raid6_datap_recov = (*ra)->datap;
105
106		printf("using recovery %s\n", (*ra)->name);
107
108		for (algo = raid6_algos; *algo; algo++) {
109			if ((*algo)->valid && !(*algo)->valid())
110				continue;
111
112			raid6_call = **algo;
113
114			/* Nuke syndromes */
115			memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE);
116
117			/* Generate assumed good syndrome */
118			raid6_call.gen_syndrome(NDISKS, PAGE_SIZE,
119						(void **)&dataptrs);
120
121			for (i = 0; i < NDISKS-1; i++)
122				for (j = i+1; j < NDISKS; j++)
123					err += test_disks(i, j);
124
125			if (!raid6_call.xor_syndrome)
126				continue;
127
128			for (p1 = 0; p1 < NDISKS-2; p1++)
129				for (p2 = p1; p2 < NDISKS-2; p2++) {
130
131					/* Simulate rmw run */
132					raid6_call.xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
133								(void **)&dataptrs);
134					makedata(p1, p2);
135					raid6_call.xor_syndrome(NDISKS, p1, p2, PAGE_SIZE,
136                                                                (void **)&dataptrs);
137
138					for (i = 0; i < NDISKS-1; i++)
139						for (j = i+1; j < NDISKS; j++)
140							err += test_disks(i, j);
141				}
142
143		}
144		printf("\n");
145	}
146
147	printf("\n");
148	/* Pick the best algorithm test */
149	raid6_select_algo();
150
151	if (err)
152		printf("\n*** ERRORS FOUND ***\n");
153
154	return err;
155}