diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-10 18:38:19 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-08-10 18:38:19 -0400 |
| commit | 3d30701b58970425e1d45994d6cb82f828924fdd (patch) | |
| tree | 8b14cf462628bebf8548c1b8c205a674564052d1 /lib/raid6/raid6recov.c | |
| parent | 8cbd84f2dd4e52a8771b191030c374ba3e56d291 (diff) | |
| parent | fd8aa2c1811bf60ccb2d5de0579c6f62aec1772d (diff) | |
Merge branch 'for-linus' of git://neil.brown.name/md
* 'for-linus' of git://neil.brown.name/md: (24 commits)
md: clean up do_md_stop
md: fix another deadlock with removing sysfs attributes.
md: move revalidate_disk() back outside open_mutex
md/raid10: fix deadlock with unaligned read during resync
md/bitmap: separate out loading a bitmap from initialising the structures.
md/bitmap: prepare for storing write-intent-bitmap via dm-dirty-log.
md/bitmap: optimise scanning of empty bitmaps.
md/bitmap: clean up plugging calls.
md/bitmap: reduce dependence on sysfs.
md/bitmap: white space clean up and similar.
md/raid5: export raid5 unplugging interface.
md/plug: optionally use plugger to unplug an array during resync/recovery.
md/raid5: add simple plugging infrastructure.
md/raid5: export is_congested test
raid5: Don't set read-ahead when there is no queue
md: add support for raising dm events.
md: export various start/stop interfaces
md: split out md_rdev_init
md: be more careful setting MD_CHANGE_CLEAN
md/raid5: ensure we create a unique name for kmem_cache when mddev has no gendisk
...
Diffstat (limited to 'lib/raid6/raid6recov.c')
| -rw-r--r-- | lib/raid6/raid6recov.c | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/lib/raid6/raid6recov.c b/lib/raid6/raid6recov.c new file mode 100644 index 000000000000..2609f00e0d61 --- /dev/null +++ b/lib/raid6/raid6recov.c | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | /* -*- linux-c -*- ------------------------------------------------------- * | ||
| 2 | * | ||
| 3 | * Copyright 2002 H. Peter Anvin - All Rights Reserved | ||
| 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 | * Boston MA 02111-1307, USA; either version 2 of the License, or | ||
| 9 | * (at your option) any later version; incorporated herein by reference. | ||
| 10 | * | ||
| 11 | * ----------------------------------------------------------------------- */ | ||
| 12 | |||
| 13 | /* | ||
| 14 | * raid6recov.c | ||
| 15 | * | ||
| 16 | * RAID-6 data recovery in dual failure mode. In single failure mode, | ||
| 17 | * use the RAID-5 algorithm (or, in the case of Q failure, just reconstruct | ||
| 18 | * the syndrome.) | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <linux/raid/pq.h> | ||
| 22 | |||
| 23 | /* Recover two failed data blocks. */ | ||
| 24 | void raid6_2data_recov(int disks, size_t bytes, int faila, int failb, | ||
| 25 | void **ptrs) | ||
| 26 | { | ||
| 27 | u8 *p, *q, *dp, *dq; | ||
| 28 | u8 px, qx, db; | ||
| 29 | const u8 *pbmul; /* P multiplier table for B data */ | ||
| 30 | const u8 *qmul; /* Q multiplier table (for both) */ | ||
| 31 | |||
| 32 | p = (u8 *)ptrs[disks-2]; | ||
| 33 | q = (u8 *)ptrs[disks-1]; | ||
| 34 | |||
| 35 | /* Compute syndrome with zero for the missing data pages | ||
| 36 | Use the dead data pages as temporary storage for | ||
| 37 | delta p and delta q */ | ||
| 38 | dp = (u8 *)ptrs[faila]; | ||
| 39 | ptrs[faila] = (void *)raid6_empty_zero_page; | ||
| 40 | ptrs[disks-2] = dp; | ||
| 41 | dq = (u8 *)ptrs[failb]; | ||
| 42 | ptrs[failb] = (void *)raid6_empty_zero_page; | ||
| 43 | ptrs[disks-1] = dq; | ||
| 44 | |||
| 45 | raid6_call.gen_syndrome(disks, bytes, ptrs); | ||
| 46 | |||
| 47 | /* Restore pointer table */ | ||
| 48 | ptrs[faila] = dp; | ||
| 49 | ptrs[failb] = dq; | ||
| 50 | ptrs[disks-2] = p; | ||
| 51 | ptrs[disks-1] = q; | ||
| 52 | |||
| 53 | /* Now, pick the proper data tables */ | ||
| 54 | pbmul = raid6_gfmul[raid6_gfexi[failb-faila]]; | ||
| 55 | qmul = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]^raid6_gfexp[failb]]]; | ||
| 56 | |||
| 57 | /* Now do it... */ | ||
| 58 | while ( bytes-- ) { | ||
| 59 | px = *p ^ *dp; | ||
| 60 | qx = qmul[*q ^ *dq]; | ||
| 61 | *dq++ = db = pbmul[px] ^ qx; /* Reconstructed B */ | ||
| 62 | *dp++ = db ^ px; /* Reconstructed A */ | ||
| 63 | p++; q++; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | EXPORT_SYMBOL_GPL(raid6_2data_recov); | ||
| 67 | |||
| 68 | /* Recover failure of one data block plus the P block */ | ||
| 69 | void raid6_datap_recov(int disks, size_t bytes, int faila, void **ptrs) | ||
| 70 | { | ||
| 71 | u8 *p, *q, *dq; | ||
| 72 | const u8 *qmul; /* Q multiplier table */ | ||
| 73 | |||
| 74 | p = (u8 *)ptrs[disks-2]; | ||
| 75 | q = (u8 *)ptrs[disks-1]; | ||
| 76 | |||
| 77 | /* Compute syndrome with zero for the missing data page | ||
| 78 | Use the dead data page as temporary storage for delta q */ | ||
| 79 | dq = (u8 *)ptrs[faila]; | ||
| 80 | ptrs[faila] = (void *)raid6_empty_zero_page; | ||
| 81 | ptrs[disks-1] = dq; | ||
| 82 | |||
| 83 | raid6_call.gen_syndrome(disks, bytes, ptrs); | ||
| 84 | |||
| 85 | /* Restore pointer table */ | ||
| 86 | ptrs[faila] = dq; | ||
| 87 | ptrs[disks-1] = q; | ||
| 88 | |||
| 89 | /* Now, pick the proper data tables */ | ||
| 90 | qmul = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]]]; | ||
| 91 | |||
| 92 | /* Now do it... */ | ||
| 93 | while ( bytes-- ) { | ||
| 94 | *p++ ^= *dq = qmul[*q ^ *dq]; | ||
| 95 | q++; dq++; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | EXPORT_SYMBOL_GPL(raid6_datap_recov); | ||
| 99 | |||
| 100 | #ifndef __KERNEL__ | ||
| 101 | /* Testing only */ | ||
| 102 | |||
| 103 | /* Recover two failed blocks. */ | ||
| 104 | void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, void **ptrs) | ||
| 105 | { | ||
| 106 | if ( faila > failb ) { | ||
| 107 | int tmp = faila; | ||
| 108 | faila = failb; | ||
| 109 | failb = tmp; | ||
| 110 | } | ||
| 111 | |||
| 112 | if ( failb == disks-1 ) { | ||
| 113 | if ( faila == disks-2 ) { | ||
| 114 | /* P+Q failure. Just rebuild the syndrome. */ | ||
| 115 | raid6_call.gen_syndrome(disks, bytes, ptrs); | ||
| 116 | } else { | ||
| 117 | /* data+Q failure. Reconstruct data from P, | ||
| 118 | then rebuild syndrome. */ | ||
| 119 | /* NOT IMPLEMENTED - equivalent to RAID-5 */ | ||
| 120 | } | ||
| 121 | } else { | ||
| 122 | if ( failb == disks-2 ) { | ||
| 123 | /* data+P failure. */ | ||
| 124 | raid6_datap_recov(disks, bytes, faila, ptrs); | ||
| 125 | } else { | ||
| 126 | /* data+data failure. */ | ||
| 127 | raid6_2data_recov(disks, bytes, faila, failb, ptrs); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | } | ||
| 131 | |||
| 132 | #endif | ||
