1 1.10 oster /* $NetBSD: rf_pqdeg.c,v 1.10 2023/10/15 18:15:20 oster Exp $ */ 2 1.1 oster /* 3 1.1 oster * Copyright (c) 1995 Carnegie-Mellon University. 4 1.1 oster * All rights reserved. 5 1.1 oster * 6 1.1 oster * Author: Daniel Stodolsky 7 1.1 oster * 8 1.1 oster * Permission to use, copy, modify and distribute this software and 9 1.1 oster * its documentation is hereby granted, provided that both the copyright 10 1.1 oster * notice and this permission notice appear in all copies of the 11 1.1 oster * software, derivative works or modified versions, and any portions 12 1.1 oster * thereof, and that both notices appear in supporting documentation. 13 1.1 oster * 14 1.1 oster * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 15 1.1 oster * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 16 1.1 oster * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 17 1.1 oster * 18 1.1 oster * Carnegie Mellon requests users of this software to return to 19 1.1 oster * 20 1.1 oster * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU 21 1.1 oster * School of Computer Science 22 1.1 oster * Carnegie Mellon University 23 1.1 oster * Pittsburgh PA 15213-3890 24 1.1 oster * 25 1.1 oster * any improvements or extensions that they make and grant Carnegie the 26 1.1 oster * rights to redistribute these changes. 27 1.1 oster */ 28 1.7 lukem 29 1.7 lukem #include <sys/cdefs.h> 30 1.10 oster __KERNEL_RCSID(0, "$NetBSD: rf_pqdeg.c,v 1.10 2023/10/15 18:15:20 oster Exp $"); 31 1.1 oster 32 1.1 oster #include "rf_archs.h" 33 1.1 oster 34 1.1 oster #if (RF_INCLUDE_DECL_PQ > 0) || (RF_INCLUDE_RAID6 > 0) 35 1.1 oster 36 1.6 oster #include <dev/raidframe/raidframevar.h> 37 1.6 oster 38 1.1 oster #include "rf_raid.h" 39 1.1 oster #include "rf_dag.h" 40 1.1 oster #include "rf_dagutils.h" 41 1.1 oster #include "rf_dagfuncs.h" 42 1.1 oster #include "rf_dagffrd.h" 43 1.1 oster #include "rf_dagffwr.h" 44 1.1 oster #include "rf_dagdegrd.h" 45 1.1 oster #include "rf_dagdegwr.h" 46 1.1 oster #include "rf_etimer.h" 47 1.1 oster #include "rf_pqdeg.h" 48 1.1 oster #include "rf_general.h" 49 1.1 oster #include "rf_pqdegdags.h" 50 1.1 oster #include "rf_pq.h" 51 1.1 oster 52 1.1 oster /* 53 1.1 oster Degraded mode dag functions for P+Q calculations. 54 1.1 oster 55 1.3 oster The following nomenclature is used. 56 1.1 oster 57 1.1 oster PQ_<D><P><Q>_Create{Large,Small}<Write|Read>DAG 58 1.1 oster 59 1.1 oster where <D><P><Q> are single digits representing the number of failed 60 1.1 oster data units <D> (0,1,2), parity units <P> (0,1), and Q units <Q>, effecting 61 1.1 oster the I/O. The reads have only PQ_<D><P><Q>_CreateReadDAG variants, while 62 1.1 oster the single fault writes have both large and small write versions. (Single fault 63 1.3 oster PQ is equivalent to normal mode raid 5 in many aspects. 64 1.1 oster 65 1.1 oster Some versions degenerate into the same case, and are grouped together below. 66 1.1 oster */ 67 1.1 oster 68 1.3 oster /* Reads, single failure 69 1.1 oster 70 1.1 oster we have parity, so we can do a raid 5 71 1.1 oster reconstruct read. 72 1.1 oster */ 73 1.1 oster 74 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_100_CreateReadDAG) 75 1.1 oster { 76 1.3 oster rf_CreateDegradedReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList, &rf_pRecoveryFuncs); 77 1.1 oster } 78 1.1 oster /* Reads double failure */ 79 1.1 oster 80 1.1 oster /* 81 1.1 oster Q is lost, but not parity 82 1.1 oster so we can a raid 5 reconstruct read. 83 1.1 oster */ 84 1.1 oster 85 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_101_CreateReadDAG) 86 1.1 oster { 87 1.3 oster rf_CreateDegradedReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList, &rf_pRecoveryFuncs); 88 1.1 oster } 89 1.1 oster /* 90 1.1 oster parity is lost, so we need to 91 1.1 oster do a reconstruct read and recompute 92 1.1 oster the data with Q. 93 1.1 oster */ 94 1.1 oster 95 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_110_CreateReadDAG) 96 1.1 oster { 97 1.3 oster RF_PhysDiskAddr_t *temp; 98 1.3 oster /* swap P and Q pointers to fake out the DegradedReadDAG code */ 99 1.3 oster temp = asmap->parityInfo; 100 1.3 oster asmap->parityInfo = asmap->qInfo; 101 1.3 oster asmap->qInfo = temp; 102 1.3 oster rf_CreateDegradedReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList, &rf_qRecoveryFuncs); 103 1.1 oster } 104 1.1 oster /* 105 1.1 oster Two data units are dead in this stripe, so we will need read 106 1.3 oster both P and Q to reconstruct the data. Note that only 107 1.3 oster one data unit we are reading may actually be missing. 108 1.1 oster */ 109 1.4 oster RF_CREATE_DAG_FUNC_DECL(rf_CreateDoubleDegradedReadDAG); 110 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_CreateDoubleDegradedReadDAG) 111 1.1 oster { 112 1.3 oster rf_PQ_DoubleDegRead(raidPtr, asmap, dag_h, bp, flags, allocList); 113 1.1 oster } 114 1.4 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_200_CreateReadDAG); 115 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_200_CreateReadDAG) 116 1.1 oster { 117 1.3 oster rf_CreateDoubleDegradedReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList); 118 1.1 oster } 119 1.1 oster /* Writes, single failure */ 120 1.1 oster 121 1.4 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_100_CreateWriteDAG); 122 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_100_CreateWriteDAG) 123 1.1 oster { 124 1.3 oster if (asmap->numStripeUnitsAccessed != 1 && 125 1.8 perry asmap->failedPDAs[0]->numSector != 126 1.4 oster raidPtr->Layout.sectorsPerStripeUnit) 127 1.3 oster RF_PANIC(); 128 1.8 perry rf_CommonCreateSimpleDegradedWriteDAG(raidPtr, asmap, dag_h, bp, 129 1.8 perry flags, allocList, 2, 130 1.10 oster (void (*) (RF_DagNode_t *)) rf_Degraded_100_PQFunc, 131 1.4 oster RF_FALSE); 132 1.1 oster } 133 1.1 oster /* Dead P - act like a RAID 5 small write with parity = Q */ 134 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_010_CreateSmallWriteDAG) 135 1.1 oster { 136 1.3 oster RF_PhysDiskAddr_t *temp; 137 1.3 oster /* swap P and Q pointers to fake out the DegradedReadDAG code */ 138 1.3 oster temp = asmap->parityInfo; 139 1.3 oster asmap->parityInfo = asmap->qInfo; 140 1.3 oster asmap->qInfo = temp; 141 1.8 perry rf_CommonCreateSmallWriteDAG(raidPtr, asmap, dag_h, bp, flags, 142 1.4 oster allocList, &rf_qFuncs, NULL); 143 1.1 oster } 144 1.1 oster /* Dead Q - act like a RAID 5 small write */ 145 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_001_CreateSmallWriteDAG) 146 1.1 oster { 147 1.8 perry rf_CommonCreateSmallWriteDAG(raidPtr, asmap, dag_h, bp, flags, 148 1.4 oster allocList, &rf_pFuncs, NULL); 149 1.1 oster } 150 1.1 oster /* Dead P - act like a RAID 5 large write but for Q */ 151 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_010_CreateLargeWriteDAG) 152 1.1 oster { 153 1.3 oster RF_PhysDiskAddr_t *temp; 154 1.3 oster /* swap P and Q pointers to fake out the code */ 155 1.3 oster temp = asmap->parityInfo; 156 1.3 oster asmap->parityInfo = asmap->qInfo; 157 1.3 oster asmap->qInfo = temp; 158 1.8 perry rf_CommonCreateLargeWriteDAG(raidPtr, asmap, dag_h, bp, flags, 159 1.4 oster allocList, 1, rf_RegularQFunc, RF_FALSE); 160 1.1 oster } 161 1.1 oster /* Dead Q - act like a RAID 5 large write */ 162 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_001_CreateLargeWriteDAG) 163 1.1 oster { 164 1.8 perry rf_CommonCreateLargeWriteDAG(raidPtr, asmap, dag_h, bp, flags, 165 1.4 oster allocList, 1, rf_RegularPFunc, RF_FALSE); 166 1.1 oster } 167 1.1 oster 168 1.1 oster 169 1.1 oster /* 170 1.1 oster * writes, double failure 171 1.1 oster */ 172 1.1 oster 173 1.1 oster /* 174 1.3 oster * Lost P & Q - do a nonredundant write 175 1.1 oster */ 176 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_011_CreateWriteDAG) 177 1.1 oster { 178 1.3 oster rf_CreateNonRedundantWriteDAG(raidPtr, asmap, dag_h, bp, flags, allocList, 179 1.3 oster RF_IO_TYPE_WRITE); 180 1.1 oster } 181 1.1 oster /* 182 1.1 oster In the two cases below, 183 1.1 oster A nasty case arises when the write a (strict) portion of a failed stripe unit 184 1.1 oster and parts of another su. For now, we do not support this. 185 1.1 oster */ 186 1.1 oster 187 1.1 oster /* 188 1.1 oster Lost Data and P - do a Q write. 189 1.1 oster */ 190 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_110_CreateWriteDAG) 191 1.1 oster { 192 1.3 oster RF_PhysDiskAddr_t *temp; 193 1.1 oster 194 1.3 oster if (asmap->numStripeUnitsAccessed != 1 && 195 1.3 oster asmap->failedPDAs[0]->numSector != raidPtr->Layout.sectorsPerStripeUnit) { 196 1.3 oster RF_PANIC(); 197 1.3 oster } 198 1.3 oster /* swap P and Q to fake out parity code */ 199 1.3 oster temp = asmap->parityInfo; 200 1.3 oster asmap->parityInfo = asmap->qInfo; 201 1.3 oster asmap->qInfo = temp; 202 1.3 oster rf_CommonCreateSimpleDegradedWriteDAG(raidPtr, asmap, dag_h, bp, flags, 203 1.8 perry allocList, 1, 204 1.10 oster (void (*) (RF_DagNode_t *)) rf_PQ_DegradedWriteQFunc, 205 1.4 oster RF_FALSE); 206 1.3 oster /* is the regular Q func the right one to call? */ 207 1.1 oster } 208 1.1 oster /* 209 1.1 oster Lost Data and Q - do degraded mode P write 210 1.1 oster */ 211 1.1 oster RF_CREATE_DAG_FUNC_DECL(rf_PQ_101_CreateWriteDAG) 212 1.1 oster { 213 1.3 oster if (asmap->numStripeUnitsAccessed != 1 && 214 1.3 oster asmap->failedPDAs[0]->numSector != raidPtr->Layout.sectorsPerStripeUnit) 215 1.3 oster RF_PANIC(); 216 1.3 oster rf_CommonCreateSimpleDegradedWriteDAG(raidPtr, asmap, dag_h, bp, flags, 217 1.3 oster allocList, 1, rf_RecoveryXorFunc, RF_FALSE); 218 1.1 oster } 219 1.3 oster #endif /* (RF_INCLUDE_DECL_PQ > 0) || 220 1.3 oster * (RF_INCLUDE_RAID6 > 0) */ 221