rf_raid5.c revision 1.9 1 /* $NetBSD: rf_raid5.c,v 1.9 2003/12/29 02:38:18 oster Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
5 *
6 * Author: Mark Holland
7 *
8 * Permission to use, copy, modify and distribute this software and
9 * its documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
27 */
28
29 /******************************************************************************
30 *
31 * rf_raid5.c -- implements RAID Level 5
32 *
33 *****************************************************************************/
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: rf_raid5.c,v 1.9 2003/12/29 02:38:18 oster Exp $");
37
38 #include <dev/raidframe/raidframevar.h>
39
40 #include "rf_raid.h"
41 #include "rf_raid5.h"
42 #include "rf_dag.h"
43 #include "rf_dagffrd.h"
44 #include "rf_dagffwr.h"
45 #include "rf_dagdegrd.h"
46 #include "rf_dagdegwr.h"
47 #include "rf_dagutils.h"
48 #include "rf_general.h"
49 #include "rf_map.h"
50 #include "rf_utils.h"
51
52 typedef struct RF_Raid5ConfigInfo_s {
53 RF_RowCol_t **stripeIdentifier; /* filled in at config time and used
54 * by IdentifyStripe */
55 } RF_Raid5ConfigInfo_t;
56
57 int
58 rf_ConfigureRAID5(
59 RF_ShutdownList_t ** listp,
60 RF_Raid_t * raidPtr,
61 RF_Config_t * cfgPtr)
62 {
63 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
64 RF_Raid5ConfigInfo_t *info;
65 RF_RowCol_t i, j, startdisk;
66
67 /* create a RAID level 5 configuration structure */
68 RF_MallocAndAdd(info, sizeof(RF_Raid5ConfigInfo_t), (RF_Raid5ConfigInfo_t *), raidPtr->cleanupList);
69 if (info == NULL)
70 return (ENOMEM);
71 layoutPtr->layoutSpecificInfo = (void *) info;
72
73 /* the stripe identifier must identify the disks in each stripe, IN
74 * THE ORDER THAT THEY APPEAR IN THE STRIPE. */
75 info->stripeIdentifier = rf_make_2d_array(raidPtr->numCol, raidPtr->numCol, raidPtr->cleanupList);
76 if (info->stripeIdentifier == NULL)
77 return (ENOMEM);
78 startdisk = 0;
79 for (i = 0; i < raidPtr->numCol; i++) {
80 for (j = 0; j < raidPtr->numCol; j++) {
81 info->stripeIdentifier[i][j] = (startdisk + j) % raidPtr->numCol;
82 }
83 if ((--startdisk) < 0)
84 startdisk = raidPtr->numCol - 1;
85 }
86
87 /* fill in the remaining layout parameters */
88 layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
89 layoutPtr->numDataCol = raidPtr->numCol - 1;
90 layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
91 layoutPtr->numParityCol = 1;
92 layoutPtr->dataStripeUnitsPerDisk = layoutPtr->stripeUnitsPerDisk;
93
94 raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
95
96 return (0);
97 }
98
99 int
100 rf_GetDefaultNumFloatingReconBuffersRAID5(RF_Raid_t * raidPtr)
101 {
102 return (20);
103 }
104
105 RF_HeadSepLimit_t
106 rf_GetDefaultHeadSepLimitRAID5(RF_Raid_t * raidPtr)
107 {
108 return (10);
109 }
110 #if !defined(__NetBSD__) && !defined(_KERNEL)
111 /* not currently used */
112 int
113 rf_ShutdownRAID5(RF_Raid_t * raidPtr)
114 {
115 return (0);
116 }
117 #endif
118
119 void
120 rf_MapSectorRAID5(
121 RF_Raid_t * raidPtr,
122 RF_RaidAddr_t raidSector,
123 RF_RowCol_t * col,
124 RF_SectorNum_t * diskSector,
125 int remap)
126 {
127 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
128 *col = (SUID % raidPtr->numCol);
129 *diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
130 (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
131 }
132
133 void
134 rf_MapParityRAID5(
135 RF_Raid_t * raidPtr,
136 RF_RaidAddr_t raidSector,
137 RF_RowCol_t * col,
138 RF_SectorNum_t * diskSector,
139 int remap)
140 {
141 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
142
143 *col = raidPtr->Layout.numDataCol - (SUID / raidPtr->Layout.numDataCol) % raidPtr->numCol;
144 *diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
145 (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
146 }
147
148 void
149 rf_IdentifyStripeRAID5(
150 RF_Raid_t * raidPtr,
151 RF_RaidAddr_t addr,
152 RF_RowCol_t ** diskids)
153 {
154 RF_StripeNum_t stripeID = rf_RaidAddressToStripeID(&raidPtr->Layout, addr);
155 RF_Raid5ConfigInfo_t *info = (RF_Raid5ConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
156
157 *diskids = info->stripeIdentifier[stripeID % raidPtr->numCol];
158 }
159
160 void
161 rf_MapSIDToPSIDRAID5(
162 RF_RaidLayout_t * layoutPtr,
163 RF_StripeNum_t stripeID,
164 RF_StripeNum_t * psID,
165 RF_ReconUnitNum_t * which_ru)
166 {
167 *which_ru = 0;
168 *psID = stripeID;
169 }
170 /* select an algorithm for performing an access. Returns two pointers,
171 * one to a function that will return information about the DAG, and
172 * another to a function that will create the dag.
173 */
174 void
175 rf_RaidFiveDagSelect(
176 RF_Raid_t * raidPtr,
177 RF_IoType_t type,
178 RF_AccessStripeMap_t * asmap,
179 RF_VoidFuncPtr * createFunc)
180 {
181 RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
182 RF_PhysDiskAddr_t *failedPDA = NULL;
183 RF_RowCol_t fcol;
184 RF_RowStatus_t rstat;
185 int prior_recon;
186
187 RF_ASSERT(RF_IO_IS_R_OR_W(type));
188
189 if (asmap->numDataFailed + asmap->numParityFailed > 1) {
190 RF_ERRORMSG("Multiple disks failed in a single group! Aborting I/O operation.\n");
191 *createFunc = NULL;
192 return;
193 } else
194 if (asmap->numDataFailed + asmap->numParityFailed == 1) {
195
196 /* if under recon & already reconstructed, redirect
197 * the access to the spare drive and eliminate the
198 * failure indication */
199 failedPDA = asmap->failedPDAs[0];
200 fcol = failedPDA->col;
201 rstat = raidPtr->status;
202 prior_recon = (rstat == rf_rs_reconfigured) || (
203 (rstat == rf_rs_reconstructing) ?
204 rf_CheckRUReconstructed(raidPtr->reconControl->reconMap, failedPDA->startSector) : 0
205 );
206 if (prior_recon) {
207 RF_RowCol_t oc = failedPDA->col;
208 RF_SectorNum_t oo = failedPDA->startSector;
209
210 if (layoutPtr->map->flags & RF_DISTRIBUTE_SPARE) { /* redirect to dist
211 * spare space */
212
213 if (failedPDA == asmap->parityInfo) {
214
215 /* parity has failed */
216 (layoutPtr->map->MapParity) (raidPtr, failedPDA->raidAddress,
217 &failedPDA->col, &failedPDA->startSector, RF_REMAP);
218
219 if (asmap->parityInfo->next) { /* redir 2nd component,
220 * if any */
221 RF_PhysDiskAddr_t *p = asmap->parityInfo->next;
222 RF_SectorNum_t SUoffs = p->startSector % layoutPtr->sectorsPerStripeUnit;
223 p->col = failedPDA->col;
224 p->startSector = rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, failedPDA->startSector) +
225 SUoffs; /* cheating:
226 * startSector is not
227 * really a RAID address */
228 }
229 } else
230 if (asmap->parityInfo->next && failedPDA == asmap->parityInfo->next) {
231 RF_ASSERT(0); /* should not ever
232 * happen */
233 } else {
234
235 /* data has failed */
236 (layoutPtr->map->MapSector) (raidPtr, failedPDA->raidAddress,
237 &failedPDA->col, &failedPDA->startSector, RF_REMAP);
238
239 }
240
241 } else { /* redirect to dedicated spare
242 * space */
243
244 failedPDA->col = raidPtr->Disks[fcol].spareCol;
245
246 /* the parity may have two distinct
247 * components, both of which may need
248 * to be redirected */
249 if (asmap->parityInfo->next) {
250 if (failedPDA == asmap->parityInfo) {
251 failedPDA->next->col = failedPDA->col;
252 } else
253 if (failedPDA == asmap->parityInfo->next) { /* paranoid: should
254 * never occur */
255 asmap->parityInfo->col = failedPDA->col;
256 }
257 }
258 }
259
260 RF_ASSERT(failedPDA->col != -1);
261
262 if (rf_dagDebug || rf_mapDebug) {
263 printf("raid%d: Redirected type '%c' c %d o %ld -> c %d o %ld\n",
264 raidPtr->raidid, type, oc,
265 (long) oo, failedPDA->col,
266 (long) failedPDA->startSector);
267 }
268 asmap->numDataFailed = asmap->numParityFailed = 0;
269 }
270 }
271 /* all dags begin/end with block/unblock node therefore, hdrSucc &
272 * termAnt counts should always be 1 also, these counts should not be
273 * visible outside dag creation routines - manipulating the counts
274 * here should be removed */
275 if (type == RF_IO_TYPE_READ) {
276 if (asmap->numDataFailed == 0)
277 *createFunc = (RF_VoidFuncPtr) rf_CreateFaultFreeReadDAG;
278 else
279 *createFunc = (RF_VoidFuncPtr) rf_CreateRaidFiveDegradedReadDAG;
280 } else {
281
282
283 /* if mirroring, always use large writes. If the access
284 * requires two distinct parity updates, always do a small
285 * write. If the stripe contains a failure but the access
286 * does not, do a small write. The first conditional
287 * (numStripeUnitsAccessed <= numDataCol/2) uses a
288 * less-than-or-equal rather than just a less-than because
289 * when G is 3 or 4, numDataCol/2 is 1, and I want
290 * single-stripe-unit updates to use just one disk. */
291 if ((asmap->numDataFailed + asmap->numParityFailed) == 0) {
292 if (rf_suppressLocksAndLargeWrites ||
293 (((asmap->numStripeUnitsAccessed <= (layoutPtr->numDataCol / 2)) && (layoutPtr->numDataCol != 1)) ||
294 (asmap->parityInfo->next != NULL) || rf_CheckStripeForFailures(raidPtr, asmap))) {
295 *createFunc = (RF_VoidFuncPtr) rf_CreateSmallWriteDAG;
296 } else
297 *createFunc = (RF_VoidFuncPtr) rf_CreateLargeWriteDAG;
298 } else {
299 if (asmap->numParityFailed == 1)
300 *createFunc = (RF_VoidFuncPtr) rf_CreateNonRedundantWriteDAG;
301 else
302 if (asmap->numStripeUnitsAccessed != 1 && failedPDA->numSector != layoutPtr->sectorsPerStripeUnit)
303 *createFunc = NULL;
304 else
305 *createFunc = (RF_VoidFuncPtr) rf_CreateDegradedWriteDAG;
306 }
307 }
308 }
309