Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

H. Peter Anvin and committed by
Linus Torvalds
66c811e9 98ec302b

+68 -47
+68 -47
drivers/md/raid6test/test.c
··· 1 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 6 - * it under the terms of the GNU General Public License as published by 7 - * the Free Software Foundation, Inc., 53 Temple Place Ste 330, 8 - * Bostom MA 02111-1307, USA; either version 2 of the License, or 9 - * (at your option) any later version; incorporated herein by reference. 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. 10 8 * 11 9 * ----------------------------------------------------------------------- */ 12 10 ··· 28 30 char data[NDISKS][PAGE_SIZE]; 29 31 char recovi[PAGE_SIZE], recovj[PAGE_SIZE]; 30 32 31 - void makedata(void) 33 + static void makedata(void) 32 34 { 33 35 int i, j; 34 36 35 - for ( i = 0 ; i < NDISKS ; i++ ) { 36 - for ( j = 0 ; j < PAGE_SIZE ; j++ ) { 37 + for (i = 0; i < NDISKS; i++) { 38 + for (j = 0; j < PAGE_SIZE; j++) 37 39 data[i][j] = rand(); 38 - } 40 + 39 41 dataptrs[i] = data[i]; 40 42 } 41 43 } 42 44 45 + static char disk_type(int d) 46 + { 47 + switch (d) { 48 + case NDISKS-2: 49 + return 'P'; 50 + case NDISKS-1: 51 + return 'Q'; 52 + default: 53 + return 'D'; 54 + } 55 + } 56 + 57 + static int test_disks(int i, int j) 58 + { 59 + int erra, errb; 60 + 61 + memset(recovi, 0xf0, PAGE_SIZE); 62 + memset(recovj, 0xba, PAGE_SIZE); 63 + 64 + dataptrs[i] = recovi; 65 + dataptrs[j] = recovj; 66 + 67 + raid6_dual_recov(NDISKS, PAGE_SIZE, i, j, (void **)&dataptrs); 68 + 69 + erra = memcmp(data[i], recovi, PAGE_SIZE); 70 + errb = memcmp(data[j], recovj, PAGE_SIZE); 71 + 72 + if (i < NDISKS-2 && j == NDISKS-1) { 73 + /* We don't implement the DQ failure scenario, since it's 74 + equivalent to a RAID-5 failure (XOR, then recompute Q) */ 75 + erra = errb = 0; 76 + } else { 77 + printf("algo=%-8s faila=%3d(%c) failb=%3d(%c) %s\n", 78 + raid6_call.name, 79 + i, disk_type(i), 80 + j, disk_type(j), 81 + (!erra && !errb) ? "OK" : 82 + !erra ? "ERRB" : 83 + !errb ? "ERRA" : "ERRAB"); 84 + } 85 + 86 + dataptrs[i] = data[i]; 87 + dataptrs[j] = data[j]; 88 + 89 + return erra || errb; 90 + } 91 + 43 92 int main(int argc, char *argv[]) 44 93 { 45 - const struct raid6_calls * const * algo; 94 + const struct raid6_calls *const *algo; 46 95 int i, j; 47 - int erra, errb; 96 + int err = 0; 48 97 49 98 makedata(); 50 99 51 - for ( algo = raid6_algos ; *algo ; algo++ ) { 52 - if ( !(*algo)->valid || (*algo)->valid() ) { 100 + for (algo = raid6_algos; *algo; algo++) { 101 + if (!(*algo)->valid || (*algo)->valid()) { 53 102 raid6_call = **algo; 54 103 55 104 /* Nuke syndromes */ 56 105 memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE); 57 106 58 107 /* Generate assumed good syndrome */ 59 - raid6_call.gen_syndrome(NDISKS, PAGE_SIZE, (void **)&dataptrs); 108 + raid6_call.gen_syndrome(NDISKS, PAGE_SIZE, 109 + (void **)&dataptrs); 60 110 61 - for ( i = 0 ; i < NDISKS-1 ; i++ ) { 62 - for ( j = i+1 ; j < NDISKS ; j++ ) { 63 - memset(recovi, 0xf0, PAGE_SIZE); 64 - memset(recovj, 0xba, PAGE_SIZE); 65 - 66 - dataptrs[i] = recovi; 67 - dataptrs[j] = recovj; 68 - 69 - raid6_dual_recov(NDISKS, PAGE_SIZE, i, j, (void **)&dataptrs); 70 - 71 - erra = memcmp(data[i], recovi, PAGE_SIZE); 72 - errb = memcmp(data[j], recovj, PAGE_SIZE); 73 - 74 - if ( i < NDISKS-2 && j == NDISKS-1 ) { 75 - /* We don't implement the DQ failure scenario, since it's 76 - equivalent to a RAID-5 failure (XOR, then recompute Q) */ 77 - } else { 78 - printf("algo=%-8s faila=%3d(%c) failb=%3d(%c) %s\n", 79 - raid6_call.name, 80 - i, (i==NDISKS-2)?'P':'D', 81 - j, (j==NDISKS-1)?'Q':(j==NDISKS-2)?'P':'D', 82 - (!erra && !errb) ? "OK" : 83 - !erra ? "ERRB" : 84 - !errb ? "ERRA" : 85 - "ERRAB"); 86 - } 87 - 88 - dataptrs[i] = data[i]; 89 - dataptrs[j] = data[j]; 90 - } 91 - } 111 + for (i = 0; i < NDISKS-1; i++) 112 + for (j = i+1; j < NDISKS; j++) 113 + err += test_disks(i, j); 92 114 } 93 115 printf("\n"); 94 116 } ··· 117 99 /* Pick the best algorithm test */ 118 100 raid6_select_algo(); 119 101 120 - return 0; 102 + if (err) 103 + printf("\n*** ERRORS FOUND ***\n"); 104 + 105 + return err; 121 106 }