rf_map.c revision 1.1 1 1.1 oster /* $NetBSD: rf_map.c,v 1.1 1998/11/13 04:20:31 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: Mark Holland
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.1 oster
29 1.1 oster /**************************************************************************
30 1.1 oster *
31 1.1 oster * map.c -- main code for mapping RAID addresses to physical disk addresses
32 1.1 oster *
33 1.1 oster **************************************************************************/
34 1.1 oster
35 1.1 oster /*
36 1.1 oster * :
37 1.1 oster * Log: rf_map.c,v
38 1.1 oster * Revision 1.53 1996/11/05 21:10:40 jimz
39 1.1 oster * failed pda generalization
40 1.1 oster *
41 1.1 oster * Revision 1.52 1996/08/20 19:58:39 jimz
42 1.1 oster * initialize numParityFailed and numQFailed to 0 in MarkFailuresInASMList
43 1.1 oster *
44 1.1 oster * Revision 1.51 1996/08/19 22:26:31 jimz
45 1.1 oster * add Chang's bugfixes for double-disk failures in MarkFailuresInASMList
46 1.1 oster *
47 1.1 oster * Revision 1.50 1996/08/19 21:38:06 jimz
48 1.1 oster * stripeOffset was uninitialized in CheckStripeForFailures
49 1.1 oster *
50 1.1 oster * Revision 1.49 1996/07/31 15:34:56 jimz
51 1.1 oster * evenodd changes; bugfixes for double-degraded archs, generalize
52 1.1 oster * some formerly PQ-only functions
53 1.1 oster *
54 1.1 oster * Revision 1.48 1996/07/27 23:36:08 jimz
55 1.1 oster * Solaris port of simulator
56 1.1 oster *
57 1.1 oster * Revision 1.47 1996/07/22 19:52:16 jimz
58 1.1 oster * switched node params to RF_DagParam_t, a union of
59 1.1 oster * a 64-bit int and a void *, for better portability
60 1.1 oster * attempted hpux port, but failed partway through for
61 1.1 oster * lack of a single C compiler capable of compiling all
62 1.1 oster * source files
63 1.1 oster *
64 1.1 oster * Revision 1.46 1996/06/10 12:50:57 jimz
65 1.1 oster * Add counters to freelists to track number of allocations, frees,
66 1.1 oster * grows, max size, etc. Adjust a couple sets of PRIME params based
67 1.1 oster * on the results.
68 1.1 oster *
69 1.1 oster * Revision 1.45 1996/06/10 11:55:47 jimz
70 1.1 oster * Straightened out some per-array/not-per-array distinctions, fixed
71 1.1 oster * a couple bugs related to confusion. Added shutdown lists. Removed
72 1.1 oster * layout shutdown function (now subsumed by shutdown lists).
73 1.1 oster *
74 1.1 oster * Revision 1.44 1996/06/09 02:36:46 jimz
75 1.1 oster * lots of little crufty cleanup- fixup whitespace
76 1.1 oster * issues, comment #ifdefs, improve typing in some
77 1.1 oster * places (esp size-related)
78 1.1 oster *
79 1.1 oster * Revision 1.43 1996/06/07 21:33:04 jimz
80 1.1 oster * begin using consistent types for sector numbers,
81 1.1 oster * stripe numbers, row+col numbers, recon unit numbers
82 1.1 oster *
83 1.1 oster * Revision 1.42 1996/06/05 18:06:02 jimz
84 1.1 oster * Major code cleanup. The Great Renaming is now done.
85 1.1 oster * Better modularity. Better typing. Fixed a bunch of
86 1.1 oster * synchronization bugs. Made a lot of global stuff
87 1.1 oster * per-desc or per-array. Removed dead code.
88 1.1 oster *
89 1.1 oster * Revision 1.41 1996/06/03 23:28:26 jimz
90 1.1 oster * more bugfixes
91 1.1 oster * check in tree to sync for IPDS runs with current bugfixes
92 1.1 oster * there still may be a problem with threads in the script test
93 1.1 oster * getting I/Os stuck- not trivially reproducible (runs ~50 times
94 1.1 oster * in a row without getting stuck)
95 1.1 oster *
96 1.1 oster * Revision 1.40 1996/05/31 22:26:54 jimz
97 1.1 oster * fix a lot of mapping problems, memory allocation problems
98 1.1 oster * found some weird lock issues, fixed 'em
99 1.1 oster * more code cleanup
100 1.1 oster *
101 1.1 oster * Revision 1.39 1996/05/30 23:22:16 jimz
102 1.1 oster * bugfixes of serialization, timing problems
103 1.1 oster * more cleanup
104 1.1 oster *
105 1.1 oster * Revision 1.38 1996/05/30 11:29:41 jimz
106 1.1 oster * Numerous bug fixes. Stripe lock release code disagreed with the taking code
107 1.1 oster * about when stripes should be locked (I made it consistent: no parity, no lock)
108 1.1 oster * There was a lot of extra serialization of I/Os which I've removed- a lot of
109 1.1 oster * it was to calculate values for the cache code, which is no longer with us.
110 1.1 oster * More types, function, macro cleanup. Added code to properly quiesce the array
111 1.1 oster * on shutdown. Made a lot of stuff array-specific which was (bogusly) general
112 1.1 oster * before. Fixed memory allocation, freeing bugs.
113 1.1 oster *
114 1.1 oster * Revision 1.37 1996/05/27 18:56:37 jimz
115 1.1 oster * more code cleanup
116 1.1 oster * better typing
117 1.1 oster * compiles in all 3 environments
118 1.1 oster *
119 1.1 oster * Revision 1.36 1996/05/23 21:46:35 jimz
120 1.1 oster * checkpoint in code cleanup (release prep)
121 1.1 oster * lots of types, function names have been fixed
122 1.1 oster *
123 1.1 oster * Revision 1.35 1996/05/23 00:33:23 jimz
124 1.1 oster * code cleanup: move all debug decls to rf_options.c, all extern
125 1.1 oster * debug decls to rf_options.h, all debug vars preceded by rf_
126 1.1 oster *
127 1.1 oster * Revision 1.34 1996/05/20 16:14:45 jimz
128 1.1 oster * switch to rf_{mutex,cond}_{init,destroy}
129 1.1 oster *
130 1.1 oster * Revision 1.33 1996/05/18 19:51:34 jimz
131 1.1 oster * major code cleanup- fix syntax, make some types consistent,
132 1.1 oster * add prototypes, clean out dead code, et cetera
133 1.1 oster *
134 1.1 oster * Revision 1.32 1996/05/17 00:51:47 jimz
135 1.1 oster * reformat for readability
136 1.1 oster *
137 1.1 oster * Revision 1.31 1996/05/16 23:06:26 jimz
138 1.1 oster * convert asmhdr to use RF_FREELIST stuff
139 1.1 oster *
140 1.1 oster * Revision 1.30 1996/05/16 19:09:42 jimz
141 1.1 oster * grow init asm freelist to 32
142 1.1 oster *
143 1.1 oster * Revision 1.29 1996/05/16 15:27:55 jimz
144 1.1 oster * prime freelist pumps for asm and pda lists
145 1.1 oster *
146 1.1 oster * Revision 1.28 1996/05/02 14:58:35 jimz
147 1.1 oster * legibility cleanup
148 1.1 oster *
149 1.1 oster * Revision 1.27 1995/12/12 18:10:06 jimz
150 1.1 oster * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
151 1.1 oster * fix 80-column brain damage in comments
152 1.1 oster *
153 1.1 oster * Revision 1.26 1995/12/01 19:25:06 root
154 1.1 oster * added copyright info
155 1.1 oster *
156 1.1 oster * Revision 1.25 1995/11/17 19:01:57 wvcii
157 1.1 oster * added call to MapQ in two fault tolerant case
158 1.1 oster *
159 1.1 oster * Revision 1.24 1995/11/17 15:10:53 wvcii
160 1.1 oster * fixed bug in ASMCheckStatus - ASSERT was using disk sector addresses
161 1.1 oster * rather than raidAddress
162 1.1 oster *
163 1.1 oster * Revision 1.23 1995/07/26 03:26:51 robby
164 1.1 oster * map the allocation and freeing routines for some stuff non-static
165 1.1 oster *
166 1.1 oster * Revision 1.22 1995/06/28 09:33:45 holland
167 1.1 oster * bug fixes related to dist sparing and multiple-row arrays
168 1.1 oster *
169 1.1 oster * Revision 1.21 1995/06/28 04:51:08 holland
170 1.1 oster * added some asserts against zero-length accesses
171 1.1 oster *
172 1.1 oster * Revision 1.20 1995/06/23 13:40:06 robby
173 1.1 oster * updeated to prototypes in rf_layout.h
174 1.1 oster *
175 1.1 oster */
176 1.1 oster
177 1.1 oster #include "rf_types.h"
178 1.1 oster #include "rf_threadstuff.h"
179 1.1 oster #include "rf_raid.h"
180 1.1 oster #include "rf_general.h"
181 1.1 oster #include "rf_map.h"
182 1.1 oster #include "rf_freelist.h"
183 1.1 oster #include "rf_shutdown.h"
184 1.1 oster #include "rf_sys.h"
185 1.1 oster
186 1.1 oster static void rf_FreePDAList(RF_PhysDiskAddr_t *start, RF_PhysDiskAddr_t *end, int count);
187 1.1 oster static void rf_FreeASMList(RF_AccessStripeMap_t *start, RF_AccessStripeMap_t *end,
188 1.1 oster int count);
189 1.1 oster
190 1.1 oster /*****************************************************************************************
191 1.1 oster *
192 1.1 oster * MapAccess -- main 1st order mapping routine.
193 1.1 oster *
194 1.1 oster * Maps an access in the RAID address space to the corresponding set of physical disk
195 1.1 oster * addresses. The result is returned as a list of AccessStripeMap structures, one per
196 1.1 oster * stripe accessed. Each ASM structure contains a pointer to a list of PhysDiskAddr
197 1.1 oster * structures, which describe the physical locations touched by the user access. Note
198 1.1 oster * that this routine returns only static mapping information, i.e. the list of physical
199 1.1 oster * addresses returned does not necessarily identify the set of physical locations that
200 1.1 oster * will actually be read or written.
201 1.1 oster *
202 1.1 oster * The routine also maps the parity. The physical disk location returned always
203 1.1 oster * indicates the entire parity unit, even when only a subset of it is being accessed.
204 1.1 oster * This is because an access that is not stripe unit aligned but that spans a stripe
205 1.1 oster * unit boundary may require access two distinct portions of the parity unit, and we
206 1.1 oster * can't yet tell which portion(s) we'll actually need. We leave it up to the algorithm
207 1.1 oster * selection code to decide what subset of the parity unit to access.
208 1.1 oster *
209 1.1 oster * Note that addresses in the RAID address space must always be maintained as
210 1.1 oster * longs, instead of ints.
211 1.1 oster *
212 1.1 oster * This routine returns NULL if numBlocks is 0
213 1.1 oster *
214 1.1 oster ****************************************************************************************/
215 1.1 oster
216 1.1 oster RF_AccessStripeMapHeader_t *rf_MapAccess(raidPtr, raidAddress, numBlocks, buffer, remap)
217 1.1 oster RF_Raid_t *raidPtr;
218 1.1 oster RF_RaidAddr_t raidAddress; /* starting address in RAID address space */
219 1.1 oster RF_SectorCount_t numBlocks; /* number of blocks in RAID address space to access */
220 1.1 oster caddr_t buffer; /* buffer to supply/receive data */
221 1.1 oster int remap; /* 1 => remap addresses to spare space */
222 1.1 oster {
223 1.1 oster RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout);
224 1.1 oster RF_AccessStripeMapHeader_t *asm_hdr = NULL;
225 1.1 oster RF_AccessStripeMap_t *asm_list = NULL, *asm_p = NULL;
226 1.1 oster int faultsTolerated = layoutPtr->map->faultsTolerated;
227 1.1 oster RF_RaidAddr_t startAddress = raidAddress; /* we'll change raidAddress along the way */
228 1.1 oster RF_RaidAddr_t endAddress = raidAddress + numBlocks;
229 1.1 oster RF_RaidDisk_t **disks = raidPtr->Disks;
230 1.1 oster
231 1.1 oster RF_PhysDiskAddr_t *pda_p, *pda_q;
232 1.1 oster RF_StripeCount_t numStripes = 0;
233 1.1 oster RF_RaidAddr_t stripeRealEndAddress, stripeEndAddress, nextStripeUnitAddress;
234 1.1 oster RF_RaidAddr_t startAddrWithinStripe, lastRaidAddr;
235 1.1 oster RF_StripeCount_t totStripes;
236 1.1 oster RF_StripeNum_t stripeID, lastSID, SUID, lastSUID;
237 1.1 oster RF_AccessStripeMap_t *asmList, *t_asm;
238 1.1 oster RF_PhysDiskAddr_t *pdaList, *t_pda;
239 1.1 oster
240 1.1 oster /* allocate all the ASMs and PDAs up front */
241 1.1 oster lastRaidAddr = raidAddress + numBlocks - 1 ;
242 1.1 oster stripeID = rf_RaidAddressToStripeID(layoutPtr, raidAddress);
243 1.1 oster lastSID = rf_RaidAddressToStripeID(layoutPtr, lastRaidAddr);
244 1.1 oster totStripes = lastSID - stripeID + 1;
245 1.1 oster SUID = rf_RaidAddressToStripeUnitID(layoutPtr, raidAddress);
246 1.1 oster lastSUID = rf_RaidAddressToStripeUnitID(layoutPtr, lastRaidAddr);
247 1.1 oster
248 1.1 oster asmList = rf_AllocASMList(totStripes);
249 1.1 oster pdaList = rf_AllocPDAList(lastSUID - SUID + 1 + faultsTolerated * totStripes); /* may also need pda(s) per stripe for parity */
250 1.1 oster
251 1.1 oster if (raidAddress+numBlocks > raidPtr->totalSectors) {
252 1.1 oster RF_ERRORMSG1("Unable to map access because offset (%d) was invalid\n",
253 1.1 oster (int)raidAddress);
254 1.1 oster return(NULL);
255 1.1 oster }
256 1.1 oster
257 1.1 oster if (rf_mapDebug)
258 1.1 oster rf_PrintRaidAddressInfo(raidPtr, raidAddress, numBlocks);
259 1.1 oster for (; raidAddress < endAddress; ) {
260 1.1 oster /* make the next stripe structure */
261 1.1 oster RF_ASSERT(asmList);
262 1.1 oster t_asm = asmList;
263 1.1 oster asmList = asmList->next;
264 1.1 oster bzero((char *)t_asm, sizeof(RF_AccessStripeMap_t));
265 1.1 oster if (!asm_p)
266 1.1 oster asm_list = asm_p = t_asm;
267 1.1 oster else {
268 1.1 oster asm_p->next = t_asm;
269 1.1 oster asm_p = asm_p->next;
270 1.1 oster }
271 1.1 oster numStripes++;
272 1.1 oster
273 1.1 oster /* map SUs from current location to the end of the stripe */
274 1.1 oster asm_p->stripeID = /*rf_RaidAddressToStripeID(layoutPtr, raidAddress)*/ stripeID++;
275 1.1 oster stripeRealEndAddress = rf_RaidAddressOfNextStripeBoundary(layoutPtr, raidAddress);
276 1.1 oster stripeEndAddress = RF_MIN(endAddress,stripeRealEndAddress );
277 1.1 oster asm_p->raidAddress = raidAddress;
278 1.1 oster asm_p->endRaidAddress = stripeEndAddress;
279 1.1 oster
280 1.1 oster /* map each stripe unit in the stripe */
281 1.1 oster pda_p = NULL;
282 1.1 oster startAddrWithinStripe = raidAddress; /* Raid addr of start of portion of access that is within this stripe */
283 1.1 oster for (; raidAddress < stripeEndAddress; ) {
284 1.1 oster RF_ASSERT(pdaList);
285 1.1 oster t_pda = pdaList;
286 1.1 oster pdaList = pdaList->next;
287 1.1 oster bzero((char *)t_pda, sizeof(RF_PhysDiskAddr_t));
288 1.1 oster if (!pda_p)
289 1.1 oster asm_p->physInfo = pda_p = t_pda;
290 1.1 oster else {
291 1.1 oster pda_p->next = t_pda;
292 1.1 oster pda_p = pda_p->next;
293 1.1 oster }
294 1.1 oster
295 1.1 oster pda_p->type = RF_PDA_TYPE_DATA;
296 1.1 oster (layoutPtr->map->MapSector)(raidPtr, raidAddress, &(pda_p->row), &(pda_p->col), &(pda_p->startSector), remap);
297 1.1 oster
298 1.1 oster /* mark any failures we find. failedPDA is don't-care if there is more than one failure */
299 1.1 oster pda_p->raidAddress = raidAddress; /* the RAID address corresponding to this physical disk address */
300 1.1 oster nextStripeUnitAddress = rf_RaidAddressOfNextStripeUnitBoundary(layoutPtr, raidAddress);
301 1.1 oster pda_p->numSector = RF_MIN(endAddress, nextStripeUnitAddress) - raidAddress;
302 1.1 oster RF_ASSERT(pda_p->numSector != 0);
303 1.1 oster rf_ASMCheckStatus(raidPtr,pda_p,asm_p,disks,0);
304 1.1 oster pda_p->bufPtr = buffer + rf_RaidAddressToByte(raidPtr, (raidAddress - startAddress));
305 1.1 oster asm_p->totalSectorsAccessed += pda_p->numSector;
306 1.1 oster asm_p->numStripeUnitsAccessed++;
307 1.1 oster asm_p->origRow = pda_p->row; /* redundant but harmless to do this in every loop iteration */
308 1.1 oster
309 1.1 oster raidAddress = RF_MIN(endAddress, nextStripeUnitAddress);
310 1.1 oster }
311 1.1 oster
312 1.1 oster /* Map the parity. At this stage, the startSector and numSector fields
313 1.1 oster * for the parity unit are always set to indicate the entire parity unit.
314 1.1 oster * We may modify this after mapping the data portion.
315 1.1 oster */
316 1.1 oster switch (faultsTolerated)
317 1.1 oster {
318 1.1 oster case 0:
319 1.1 oster break;
320 1.1 oster case 1: /* single fault tolerant */
321 1.1 oster RF_ASSERT(pdaList);
322 1.1 oster t_pda = pdaList;
323 1.1 oster pdaList = pdaList->next;
324 1.1 oster bzero((char *)t_pda, sizeof(RF_PhysDiskAddr_t));
325 1.1 oster pda_p = asm_p->parityInfo = t_pda;
326 1.1 oster pda_p->type = RF_PDA_TYPE_PARITY;
327 1.1 oster (layoutPtr->map->MapParity)(raidPtr, rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe),
328 1.1 oster &(pda_p->row), &(pda_p->col), &(pda_p->startSector), remap);
329 1.1 oster pda_p->numSector = layoutPtr->sectorsPerStripeUnit;
330 1.1 oster /* raidAddr may be needed to find unit to redirect to */
331 1.1 oster pda_p->raidAddress = rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe);
332 1.1 oster rf_ASMCheckStatus(raidPtr,pda_p,asm_p,disks,1);
333 1.1 oster rf_ASMParityAdjust(asm_p->parityInfo,startAddrWithinStripe,endAddress,layoutPtr,asm_p);
334 1.1 oster
335 1.1 oster break;
336 1.1 oster case 2: /* two fault tolerant */
337 1.1 oster RF_ASSERT(pdaList && pdaList->next);
338 1.1 oster t_pda = pdaList;
339 1.1 oster pdaList = pdaList->next;
340 1.1 oster bzero((char *)t_pda, sizeof(RF_PhysDiskAddr_t));
341 1.1 oster pda_p = asm_p->parityInfo = t_pda;
342 1.1 oster pda_p->type = RF_PDA_TYPE_PARITY;
343 1.1 oster t_pda = pdaList;
344 1.1 oster pdaList = pdaList->next;
345 1.1 oster bzero((char *)t_pda, sizeof(RF_PhysDiskAddr_t));
346 1.1 oster pda_q = asm_p->qInfo = t_pda;
347 1.1 oster pda_q->type = RF_PDA_TYPE_Q;
348 1.1 oster (layoutPtr->map->MapParity)(raidPtr, rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe),
349 1.1 oster &(pda_p->row), &(pda_p->col), &(pda_p->startSector), remap);
350 1.1 oster (layoutPtr->map->MapQ)(raidPtr, rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe),
351 1.1 oster &(pda_q->row), &(pda_q->col), &(pda_q->startSector), remap);
352 1.1 oster pda_q->numSector = pda_p->numSector = layoutPtr->sectorsPerStripeUnit;
353 1.1 oster /* raidAddr may be needed to find unit to redirect to */
354 1.1 oster pda_p->raidAddress = rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe);
355 1.1 oster pda_q->raidAddress = rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, startAddrWithinStripe);
356 1.1 oster /* failure mode stuff */
357 1.1 oster rf_ASMCheckStatus(raidPtr,pda_p,asm_p,disks,1);
358 1.1 oster rf_ASMCheckStatus(raidPtr,pda_q,asm_p,disks,1);
359 1.1 oster rf_ASMParityAdjust(asm_p->parityInfo,startAddrWithinStripe,endAddress,layoutPtr,asm_p);
360 1.1 oster rf_ASMParityAdjust(asm_p->qInfo,startAddrWithinStripe,endAddress,layoutPtr,asm_p);
361 1.1 oster break;
362 1.1 oster }
363 1.1 oster }
364 1.1 oster RF_ASSERT(asmList == NULL && pdaList == NULL);
365 1.1 oster /* make the header structure */
366 1.1 oster asm_hdr = rf_AllocAccessStripeMapHeader();
367 1.1 oster RF_ASSERT(numStripes == totStripes);
368 1.1 oster asm_hdr->numStripes = numStripes;
369 1.1 oster asm_hdr->stripeMap = asm_list;
370 1.1 oster
371 1.1 oster if (rf_mapDebug)
372 1.1 oster rf_PrintAccessStripeMap(asm_hdr);
373 1.1 oster return(asm_hdr);
374 1.1 oster }
375 1.1 oster
376 1.1 oster /*****************************************************************************************
377 1.1 oster * This routine walks through an ASM list and marks the PDAs that have failed.
378 1.1 oster * It's called only when a disk failure causes an in-flight DAG to fail.
379 1.1 oster * The parity may consist of two components, but we want to use only one failedPDA
380 1.1 oster * pointer. Thus we set failedPDA to point to the first parity component, and rely
381 1.1 oster * on the rest of the code to do the right thing with this.
382 1.1 oster ****************************************************************************************/
383 1.1 oster
384 1.1 oster void rf_MarkFailuresInASMList(raidPtr, asm_h)
385 1.1 oster RF_Raid_t *raidPtr;
386 1.1 oster RF_AccessStripeMapHeader_t *asm_h;
387 1.1 oster {
388 1.1 oster RF_RaidDisk_t **disks = raidPtr->Disks;
389 1.1 oster RF_AccessStripeMap_t *asmap;
390 1.1 oster RF_PhysDiskAddr_t *pda;
391 1.1 oster
392 1.1 oster for (asmap = asm_h->stripeMap; asmap; asmap = asmap->next) {
393 1.1 oster asmap->numDataFailed = asmap->numParityFailed = asmap->numQFailed = 0;
394 1.1 oster asmap->numFailedPDAs = 0;
395 1.1 oster bzero((char *)asmap->failedPDAs,
396 1.1 oster RF_MAX_FAILED_PDA*sizeof(RF_PhysDiskAddr_t *));
397 1.1 oster for (pda = asmap->physInfo; pda; pda=pda->next) {
398 1.1 oster if (RF_DEAD_DISK(disks[pda->row][pda->col].status)) {
399 1.1 oster printf("DEAD DISK BOGUSLY DETECTED!!\n");
400 1.1 oster asmap->numDataFailed++;
401 1.1 oster asmap->failedPDAs[asmap->numFailedPDAs] = pda;
402 1.1 oster asmap->numFailedPDAs++;
403 1.1 oster }
404 1.1 oster }
405 1.1 oster pda = asmap->parityInfo;
406 1.1 oster if (pda && RF_DEAD_DISK(disks[pda->row][pda->col].status)) {
407 1.1 oster asmap->numParityFailed++;
408 1.1 oster asmap->failedPDAs[asmap->numFailedPDAs] = pda;
409 1.1 oster asmap->numFailedPDAs++;
410 1.1 oster }
411 1.1 oster pda = asmap->qInfo;
412 1.1 oster if (pda && RF_DEAD_DISK(disks[pda->row][pda->col].status)) {
413 1.1 oster asmap->numQFailed++;
414 1.1 oster asmap->failedPDAs[asmap->numFailedPDAs] = pda;
415 1.1 oster asmap->numFailedPDAs++;
416 1.1 oster }
417 1.1 oster }
418 1.1 oster }
419 1.1 oster
420 1.1 oster /*****************************************************************************************
421 1.1 oster *
422 1.1 oster * DuplicateASM -- duplicates an ASM and returns the new one
423 1.1 oster *
424 1.1 oster ****************************************************************************************/
425 1.1 oster RF_AccessStripeMap_t *rf_DuplicateASM(asmap)
426 1.1 oster RF_AccessStripeMap_t *asmap;
427 1.1 oster {
428 1.1 oster RF_AccessStripeMap_t *new_asm;
429 1.1 oster RF_PhysDiskAddr_t *pda, *new_pda, *t_pda;
430 1.1 oster
431 1.1 oster new_pda = NULL;
432 1.1 oster new_asm = rf_AllocAccessStripeMapComponent();
433 1.1 oster bcopy((char *)asmap, (char *)new_asm, sizeof(RF_AccessStripeMap_t));
434 1.1 oster new_asm->numFailedPDAs = 0; /* ??? */
435 1.1 oster new_asm->failedPDAs[0] = NULL;
436 1.1 oster new_asm->physInfo = NULL;
437 1.1 oster new_asm->parityInfo = NULL;
438 1.1 oster new_asm->next = NULL;
439 1.1 oster
440 1.1 oster for (pda = asmap->physInfo; pda; pda=pda->next) { /* copy the physInfo list */
441 1.1 oster t_pda = rf_AllocPhysDiskAddr();
442 1.1 oster bcopy((char *)pda, (char *)t_pda, sizeof(RF_PhysDiskAddr_t));
443 1.1 oster t_pda->next = NULL;
444 1.1 oster if (!new_asm->physInfo) {new_asm->physInfo = t_pda; new_pda = t_pda;}
445 1.1 oster else {new_pda->next = t_pda; new_pda = new_pda->next;}
446 1.1 oster if (pda == asmap->failedPDAs[0])
447 1.1 oster new_asm->failedPDAs[0] = t_pda;
448 1.1 oster }
449 1.1 oster for (pda = asmap->parityInfo; pda; pda=pda->next) { /* copy the parityInfo list */
450 1.1 oster t_pda = rf_AllocPhysDiskAddr();
451 1.1 oster bcopy((char *)pda, (char *)t_pda, sizeof(RF_PhysDiskAddr_t));
452 1.1 oster t_pda->next = NULL;
453 1.1 oster if (!new_asm->parityInfo) {new_asm->parityInfo = t_pda; new_pda = t_pda;}
454 1.1 oster else {new_pda->next = t_pda; new_pda = new_pda->next;}
455 1.1 oster if (pda == asmap->failedPDAs[0])
456 1.1 oster new_asm->failedPDAs[0] = t_pda;
457 1.1 oster }
458 1.1 oster return(new_asm);
459 1.1 oster }
460 1.1 oster
461 1.1 oster /*****************************************************************************************
462 1.1 oster *
463 1.1 oster * DuplicatePDA -- duplicates a PDA and returns the new one
464 1.1 oster *
465 1.1 oster ****************************************************************************************/
466 1.1 oster RF_PhysDiskAddr_t *rf_DuplicatePDA(pda)
467 1.1 oster RF_PhysDiskAddr_t *pda;
468 1.1 oster {
469 1.1 oster RF_PhysDiskAddr_t *new;
470 1.1 oster
471 1.1 oster new = rf_AllocPhysDiskAddr();
472 1.1 oster bcopy((char *)pda, (char *)new, sizeof(RF_PhysDiskAddr_t));
473 1.1 oster return(new);
474 1.1 oster }
475 1.1 oster
476 1.1 oster /*****************************************************************************************
477 1.1 oster *
478 1.1 oster * routines to allocate and free list elements. All allocation routines zero the
479 1.1 oster * structure before returning it.
480 1.1 oster *
481 1.1 oster * FreePhysDiskAddr is static. It should never be called directly, because
482 1.1 oster * FreeAccessStripeMap takes care of freeing the PhysDiskAddr list.
483 1.1 oster *
484 1.1 oster ****************************************************************************************/
485 1.1 oster
486 1.1 oster static RF_FreeList_t *rf_asmhdr_freelist;
487 1.1 oster #define RF_MAX_FREE_ASMHDR 128
488 1.1 oster #define RF_ASMHDR_INC 16
489 1.1 oster #define RF_ASMHDR_INITIAL 32
490 1.1 oster
491 1.1 oster static RF_FreeList_t *rf_asm_freelist;
492 1.1 oster #define RF_MAX_FREE_ASM 192
493 1.1 oster #define RF_ASM_INC 24
494 1.1 oster #define RF_ASM_INITIAL 64
495 1.1 oster
496 1.1 oster static RF_FreeList_t *rf_pda_freelist;
497 1.1 oster #define RF_MAX_FREE_PDA 192
498 1.1 oster #define RF_PDA_INC 24
499 1.1 oster #define RF_PDA_INITIAL 64
500 1.1 oster
501 1.1 oster /* called at shutdown time. So far, all that is necessary is to release all the free lists */
502 1.1 oster static void rf_ShutdownMapModule(void *);
503 1.1 oster static void rf_ShutdownMapModule(ignored)
504 1.1 oster void *ignored;
505 1.1 oster {
506 1.1 oster RF_FREELIST_DESTROY(rf_asmhdr_freelist,next,(RF_AccessStripeMapHeader_t *));
507 1.1 oster RF_FREELIST_DESTROY(rf_pda_freelist,next,(RF_PhysDiskAddr_t *));
508 1.1 oster RF_FREELIST_DESTROY(rf_asm_freelist,next,(RF_AccessStripeMap_t *));
509 1.1 oster }
510 1.1 oster
511 1.1 oster int rf_ConfigureMapModule(listp)
512 1.1 oster RF_ShutdownList_t **listp;
513 1.1 oster {
514 1.1 oster int rc;
515 1.1 oster
516 1.1 oster RF_FREELIST_CREATE(rf_asmhdr_freelist, RF_MAX_FREE_ASMHDR,
517 1.1 oster RF_ASMHDR_INC, sizeof(RF_AccessStripeMapHeader_t));
518 1.1 oster if (rf_asmhdr_freelist == NULL) {
519 1.1 oster return(ENOMEM);
520 1.1 oster }
521 1.1 oster RF_FREELIST_CREATE(rf_asm_freelist, RF_MAX_FREE_ASM,
522 1.1 oster RF_ASM_INC, sizeof(RF_AccessStripeMap_t));
523 1.1 oster if (rf_asm_freelist == NULL) {
524 1.1 oster RF_FREELIST_DESTROY(rf_asmhdr_freelist,next,(RF_AccessStripeMapHeader_t *));
525 1.1 oster return(ENOMEM);
526 1.1 oster }
527 1.1 oster RF_FREELIST_CREATE(rf_pda_freelist, RF_MAX_FREE_PDA,
528 1.1 oster RF_PDA_INC, sizeof(RF_PhysDiskAddr_t));
529 1.1 oster if (rf_pda_freelist == NULL) {
530 1.1 oster RF_FREELIST_DESTROY(rf_asmhdr_freelist,next,(RF_AccessStripeMapHeader_t *));
531 1.1 oster RF_FREELIST_DESTROY(rf_pda_freelist,next,(RF_PhysDiskAddr_t *));
532 1.1 oster return(ENOMEM);
533 1.1 oster }
534 1.1 oster
535 1.1 oster rc = rf_ShutdownCreate(listp, rf_ShutdownMapModule, NULL);
536 1.1 oster if (rc) {
537 1.1 oster RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n", __FILE__,
538 1.1 oster __LINE__, rc);
539 1.1 oster rf_ShutdownMapModule(NULL);
540 1.1 oster return(rc);
541 1.1 oster }
542 1.1 oster
543 1.1 oster RF_FREELIST_PRIME(rf_asmhdr_freelist, RF_ASMHDR_INITIAL,next,
544 1.1 oster (RF_AccessStripeMapHeader_t *));
545 1.1 oster RF_FREELIST_PRIME(rf_asm_freelist, RF_ASM_INITIAL,next,
546 1.1 oster (RF_AccessStripeMap_t *));
547 1.1 oster RF_FREELIST_PRIME(rf_pda_freelist, RF_PDA_INITIAL,next,
548 1.1 oster (RF_PhysDiskAddr_t *));
549 1.1 oster
550 1.1 oster return(0);
551 1.1 oster }
552 1.1 oster
553 1.1 oster RF_AccessStripeMapHeader_t *rf_AllocAccessStripeMapHeader()
554 1.1 oster {
555 1.1 oster RF_AccessStripeMapHeader_t *p;
556 1.1 oster
557 1.1 oster RF_FREELIST_GET(rf_asmhdr_freelist,p,next,(RF_AccessStripeMapHeader_t *));
558 1.1 oster bzero((char *)p, sizeof(RF_AccessStripeMapHeader_t));
559 1.1 oster
560 1.1 oster return(p);
561 1.1 oster }
562 1.1 oster
563 1.1 oster
564 1.1 oster void rf_FreeAccessStripeMapHeader(p)
565 1.1 oster RF_AccessStripeMapHeader_t *p;
566 1.1 oster {
567 1.1 oster RF_FREELIST_FREE(rf_asmhdr_freelist,p,next);
568 1.1 oster }
569 1.1 oster
570 1.1 oster RF_PhysDiskAddr_t *rf_AllocPhysDiskAddr()
571 1.1 oster {
572 1.1 oster RF_PhysDiskAddr_t *p;
573 1.1 oster
574 1.1 oster RF_FREELIST_GET(rf_pda_freelist,p,next,(RF_PhysDiskAddr_t *));
575 1.1 oster bzero((char *)p, sizeof(RF_PhysDiskAddr_t));
576 1.1 oster
577 1.1 oster return(p);
578 1.1 oster }
579 1.1 oster
580 1.1 oster /* allocates a list of PDAs, locking the free list only once
581 1.1 oster * when we have to call calloc, we do it one component at a time to simplify
582 1.1 oster * the process of freeing the list at program shutdown. This should not be
583 1.1 oster * much of a performance hit, because it should be very infrequently executed.
584 1.1 oster */
585 1.1 oster RF_PhysDiskAddr_t *rf_AllocPDAList(count)
586 1.1 oster int count;
587 1.1 oster {
588 1.1 oster RF_PhysDiskAddr_t *p = NULL;
589 1.1 oster
590 1.1 oster RF_FREELIST_GET_N(rf_pda_freelist,p,next,(RF_PhysDiskAddr_t *),count);
591 1.1 oster return(p);
592 1.1 oster }
593 1.1 oster
594 1.1 oster void rf_FreePhysDiskAddr(p)
595 1.1 oster RF_PhysDiskAddr_t *p;
596 1.1 oster {
597 1.1 oster RF_FREELIST_FREE(rf_pda_freelist,p,next);
598 1.1 oster }
599 1.1 oster
600 1.1 oster static void rf_FreePDAList(l_start, l_end, count)
601 1.1 oster RF_PhysDiskAddr_t *l_start, *l_end; /* pointers to start and end of list */
602 1.1 oster int count; /* number of elements in list */
603 1.1 oster {
604 1.1 oster RF_FREELIST_FREE_N(rf_pda_freelist,l_start,next,(RF_PhysDiskAddr_t *),count);
605 1.1 oster }
606 1.1 oster
607 1.1 oster RF_AccessStripeMap_t *rf_AllocAccessStripeMapComponent()
608 1.1 oster {
609 1.1 oster RF_AccessStripeMap_t *p;
610 1.1 oster
611 1.1 oster RF_FREELIST_GET(rf_asm_freelist,p,next,(RF_AccessStripeMap_t *));
612 1.1 oster bzero((char *)p, sizeof(RF_AccessStripeMap_t));
613 1.1 oster
614 1.1 oster return(p);
615 1.1 oster }
616 1.1 oster
617 1.1 oster /* this is essentially identical to AllocPDAList. I should combine the two.
618 1.1 oster * when we have to call calloc, we do it one component at a time to simplify
619 1.1 oster * the process of freeing the list at program shutdown. This should not be
620 1.1 oster * much of a performance hit, because it should be very infrequently executed.
621 1.1 oster */
622 1.1 oster RF_AccessStripeMap_t *rf_AllocASMList(count)
623 1.1 oster int count;
624 1.1 oster {
625 1.1 oster RF_AccessStripeMap_t *p = NULL;
626 1.1 oster
627 1.1 oster RF_FREELIST_GET_N(rf_asm_freelist,p,next,(RF_AccessStripeMap_t *),count);
628 1.1 oster return(p);
629 1.1 oster }
630 1.1 oster
631 1.1 oster void rf_FreeAccessStripeMapComponent(p)
632 1.1 oster RF_AccessStripeMap_t *p;
633 1.1 oster {
634 1.1 oster RF_FREELIST_FREE(rf_asm_freelist,p,next);
635 1.1 oster }
636 1.1 oster
637 1.1 oster static void rf_FreeASMList(l_start, l_end, count)
638 1.1 oster RF_AccessStripeMap_t *l_start, *l_end;
639 1.1 oster int count;
640 1.1 oster {
641 1.1 oster RF_FREELIST_FREE_N(rf_asm_freelist,l_start,next,(RF_AccessStripeMap_t *),count);
642 1.1 oster }
643 1.1 oster
644 1.1 oster void rf_FreeAccessStripeMap(hdr)
645 1.1 oster RF_AccessStripeMapHeader_t *hdr;
646 1.1 oster {
647 1.1 oster RF_AccessStripeMap_t *p, *pt = NULL;
648 1.1 oster RF_PhysDiskAddr_t *pdp, *trailer, *pdaList = NULL, *pdaEnd = NULL;
649 1.1 oster int count = 0, t, asm_count = 0;
650 1.1 oster
651 1.1 oster for (p = hdr->stripeMap; p; p=p->next) {
652 1.1 oster
653 1.1 oster /* link the 3 pda lists into the accumulating pda list */
654 1.1 oster
655 1.1 oster if (!pdaList) pdaList = p->qInfo; else pdaEnd->next = p->qInfo;
656 1.1 oster for (trailer=NULL,pdp=p->qInfo; pdp; ) {trailer = pdp; pdp=pdp->next; count++;}
657 1.1 oster if (trailer) pdaEnd = trailer;
658 1.1 oster
659 1.1 oster if (!pdaList) pdaList = p->parityInfo; else pdaEnd->next = p->parityInfo;
660 1.1 oster for (trailer=NULL,pdp=p->parityInfo; pdp; ) {trailer = pdp; pdp=pdp->next; count++;}
661 1.1 oster if (trailer) pdaEnd = trailer;
662 1.1 oster
663 1.1 oster if (!pdaList) pdaList = p->physInfo; else pdaEnd->next = p->physInfo;
664 1.1 oster for (trailer=NULL,pdp=p->physInfo; pdp; ) {trailer = pdp; pdp=pdp->next; count++;}
665 1.1 oster if (trailer) pdaEnd = trailer;
666 1.1 oster
667 1.1 oster pt = p;
668 1.1 oster asm_count++;
669 1.1 oster }
670 1.1 oster
671 1.1 oster /* debug only */
672 1.1 oster for (t=0,pdp=pdaList; pdp; pdp=pdp->next)
673 1.1 oster t++;
674 1.1 oster RF_ASSERT(t == count);
675 1.1 oster
676 1.1 oster if (pdaList)
677 1.1 oster rf_FreePDAList(pdaList, pdaEnd, count);
678 1.1 oster rf_FreeASMList(hdr->stripeMap, pt, asm_count);
679 1.1 oster rf_FreeAccessStripeMapHeader(hdr);
680 1.1 oster }
681 1.1 oster
682 1.1 oster /* We can't use the large write optimization if there are any failures in the stripe.
683 1.1 oster * In the declustered layout, there is no way to immediately determine what disks
684 1.1 oster * constitute a stripe, so we actually have to hunt through the stripe looking for failures.
685 1.1 oster * The reason we map the parity instead of just using asm->parityInfo->col is because
686 1.1 oster * the latter may have been already redirected to a spare drive, which would
687 1.1 oster * mess up the computation of the stripe offset.
688 1.1 oster *
689 1.1 oster * ASSUMES AT MOST ONE FAILURE IN THE STRIPE.
690 1.1 oster */
691 1.1 oster int rf_CheckStripeForFailures(raidPtr, asmap)
692 1.1 oster RF_Raid_t *raidPtr;
693 1.1 oster RF_AccessStripeMap_t *asmap;
694 1.1 oster {
695 1.1 oster RF_RowCol_t trow, tcol, prow, pcol, *diskids, row, i;
696 1.1 oster RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
697 1.1 oster RF_StripeCount_t stripeOffset;
698 1.1 oster int numFailures;
699 1.1 oster RF_RaidAddr_t sosAddr;
700 1.1 oster RF_SectorNum_t diskOffset, poffset;
701 1.1 oster RF_RowCol_t testrow;
702 1.1 oster
703 1.1 oster /* quick out in the fault-free case. */
704 1.1 oster RF_LOCK_MUTEX(raidPtr->mutex);
705 1.1 oster numFailures = raidPtr->numFailures;
706 1.1 oster RF_UNLOCK_MUTEX(raidPtr->mutex);
707 1.1 oster if (numFailures == 0) return(0);
708 1.1 oster
709 1.1 oster sosAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, asmap->raidAddress);
710 1.1 oster row = asmap->physInfo->row;
711 1.1 oster (layoutPtr->map->IdentifyStripe)(raidPtr, asmap->raidAddress, &diskids, &testrow);
712 1.1 oster (layoutPtr->map->MapParity)(raidPtr, asmap->raidAddress, &prow, &pcol, &poffset, 0); /* get pcol */
713 1.1 oster
714 1.1 oster /* this need not be true if we've redirected the access to a spare in another row
715 1.1 oster RF_ASSERT(row == testrow);
716 1.1 oster */
717 1.1 oster stripeOffset = 0;
718 1.1 oster for (i=0; i<layoutPtr->numDataCol+layoutPtr->numParityCol; i++) {
719 1.1 oster if (diskids[i] != pcol) {
720 1.1 oster if (RF_DEAD_DISK(raidPtr->Disks[testrow][diskids[i]].status)) {
721 1.1 oster if (raidPtr->status[testrow] != rf_rs_reconstructing)
722 1.1 oster return(1);
723 1.1 oster RF_ASSERT(raidPtr->reconControl[testrow]->fcol == diskids[i]);
724 1.1 oster layoutPtr->map->MapSector(raidPtr,
725 1.1 oster sosAddr + stripeOffset * layoutPtr->sectorsPerStripeUnit,
726 1.1 oster &trow, &tcol, &diskOffset, 0);
727 1.1 oster RF_ASSERT( (trow == testrow) && (tcol == diskids[i]) );
728 1.1 oster if (!rf_CheckRUReconstructed(raidPtr->reconControl[testrow]->reconMap, diskOffset))
729 1.1 oster return(1);
730 1.1 oster asmap->flags |= RF_ASM_REDIR_LARGE_WRITE;
731 1.1 oster return(0);
732 1.1 oster }
733 1.1 oster stripeOffset++;
734 1.1 oster }
735 1.1 oster }
736 1.1 oster return(0);
737 1.1 oster }
738 1.1 oster
739 1.1 oster /*
740 1.1 oster return the number of failed data units in the stripe.
741 1.1 oster */
742 1.1 oster
743 1.1 oster int rf_NumFailedDataUnitsInStripe(raidPtr, asmap)
744 1.1 oster RF_Raid_t *raidPtr;
745 1.1 oster RF_AccessStripeMap_t *asmap;
746 1.1 oster {
747 1.1 oster RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
748 1.1 oster RF_RowCol_t trow, tcol, row, i;
749 1.1 oster RF_SectorNum_t diskOffset;
750 1.1 oster RF_RaidAddr_t sosAddr;
751 1.1 oster int numFailures;
752 1.1 oster
753 1.1 oster /* quick out in the fault-free case. */
754 1.1 oster RF_LOCK_MUTEX(raidPtr->mutex);
755 1.1 oster numFailures = raidPtr->numFailures;
756 1.1 oster RF_UNLOCK_MUTEX(raidPtr->mutex);
757 1.1 oster if (numFailures == 0) return(0);
758 1.1 oster numFailures = 0;
759 1.1 oster
760 1.1 oster sosAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, asmap->raidAddress);
761 1.1 oster row = asmap->physInfo->row;
762 1.1 oster for (i=0; i<layoutPtr->numDataCol; i++)
763 1.1 oster {
764 1.1 oster (layoutPtr->map->MapSector)(raidPtr, sosAddr + i * layoutPtr->sectorsPerStripeUnit,
765 1.1 oster &trow, &tcol, &diskOffset, 0);
766 1.1 oster if (RF_DEAD_DISK(raidPtr->Disks[trow][tcol].status))
767 1.1 oster numFailures++;
768 1.1 oster }
769 1.1 oster
770 1.1 oster return numFailures;
771 1.1 oster }
772 1.1 oster
773 1.1 oster
774 1.1 oster /*****************************************************************************************
775 1.1 oster *
776 1.1 oster * debug routines
777 1.1 oster *
778 1.1 oster ****************************************************************************************/
779 1.1 oster
780 1.1 oster void rf_PrintAccessStripeMap(asm_h)
781 1.1 oster RF_AccessStripeMapHeader_t *asm_h;
782 1.1 oster {
783 1.1 oster rf_PrintFullAccessStripeMap(asm_h, 0);
784 1.1 oster }
785 1.1 oster
786 1.1 oster void rf_PrintFullAccessStripeMap(asm_h, prbuf)
787 1.1 oster RF_AccessStripeMapHeader_t *asm_h;
788 1.1 oster int prbuf; /* flag to print buffer pointers */
789 1.1 oster {
790 1.1 oster int i;
791 1.1 oster RF_AccessStripeMap_t *asmap = asm_h->stripeMap;
792 1.1 oster RF_PhysDiskAddr_t *p;
793 1.1 oster printf("%d stripes total\n", (int)asm_h->numStripes);
794 1.1 oster for (; asmap; asmap = asmap->next) {
795 1.1 oster /* printf("Num failures: %d\n",asmap->numDataFailed); */
796 1.1 oster /* printf("Num sectors: %d\n",(int)asmap->totalSectorsAccessed); */
797 1.1 oster printf("Stripe %d (%d sectors), failures: %d data, %d parity: ",
798 1.1 oster (int) asmap->stripeID,
799 1.1 oster (int) asmap->totalSectorsAccessed,
800 1.1 oster (int) asmap->numDataFailed,
801 1.1 oster (int) asmap->numParityFailed);
802 1.1 oster if (asmap->parityInfo) {
803 1.1 oster printf("Parity [r%d c%d s%d-%d", asmap->parityInfo->row, asmap->parityInfo->col,
804 1.1 oster (int)asmap->parityInfo->startSector,
805 1.1 oster (int)(asmap->parityInfo->startSector +
806 1.1 oster asmap->parityInfo->numSector - 1));
807 1.1 oster if (prbuf) printf(" b0x%lx",(unsigned long) asmap->parityInfo->bufPtr);
808 1.1 oster if (asmap->parityInfo->next) {
809 1.1 oster printf(", r%d c%d s%d-%d", asmap->parityInfo->next->row,
810 1.1 oster asmap->parityInfo->next->col,
811 1.1 oster (int) asmap->parityInfo->next->startSector,
812 1.1 oster (int)(asmap->parityInfo->next->startSector +
813 1.1 oster asmap->parityInfo->next->numSector - 1));
814 1.1 oster if (prbuf) printf(" b0x%lx",(unsigned long) asmap->parityInfo->next->bufPtr);
815 1.1 oster RF_ASSERT(asmap->parityInfo->next->next == NULL);
816 1.1 oster }
817 1.1 oster printf("]\n\t");
818 1.1 oster }
819 1.1 oster for (i=0,p=asmap->physInfo; p; p=p->next,i++) {
820 1.1 oster printf("SU r%d c%d s%d-%d ", p->row, p->col, (int)p->startSector,
821 1.1 oster (int)(p->startSector + p->numSector - 1));
822 1.1 oster if (prbuf) printf("b0x%lx ", (unsigned long) p->bufPtr);
823 1.1 oster if (i && !(i&1)) printf("\n\t");
824 1.1 oster }
825 1.1 oster printf("\n");
826 1.1 oster p = asm_h->stripeMap->failedPDAs[0];
827 1.1 oster if (asm_h->stripeMap->numDataFailed + asm_h->stripeMap->numParityFailed > 1) printf("[multiple failures]\n");
828 1.1 oster else if (asm_h->stripeMap->numDataFailed + asm_h->stripeMap->numParityFailed > 0)
829 1.1 oster printf("\t[Failed PDA: r%d c%d s%d-%d]\n",p->row, p->col,
830 1.1 oster (int)p->startSector, (int)(p->startSector + p->numSector-1));
831 1.1 oster }
832 1.1 oster }
833 1.1 oster
834 1.1 oster void rf_PrintRaidAddressInfo(raidPtr, raidAddr, numBlocks)
835 1.1 oster RF_Raid_t *raidPtr;
836 1.1 oster RF_RaidAddr_t raidAddr;
837 1.1 oster RF_SectorCount_t numBlocks;
838 1.1 oster {
839 1.1 oster RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
840 1.1 oster RF_RaidAddr_t ra, sosAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, raidAddr);
841 1.1 oster
842 1.1 oster printf("Raid addrs of SU boundaries from start of stripe to end of access:\n\t");
843 1.1 oster for (ra = sosAddr; ra <= raidAddr + numBlocks; ra += layoutPtr->sectorsPerStripeUnit) {
844 1.1 oster printf("%d (0x%x), ",(int)ra, (int)ra);
845 1.1 oster }
846 1.1 oster printf("\n");
847 1.1 oster printf("Offset into stripe unit: %d (0x%x)\n",
848 1.1 oster (int)(raidAddr % layoutPtr->sectorsPerStripeUnit),
849 1.1 oster (int)(raidAddr % layoutPtr->sectorsPerStripeUnit));
850 1.1 oster }
851 1.1 oster
852 1.1 oster /*
853 1.1 oster given a parity descriptor and the starting address within a stripe,
854 1.1 oster range restrict the parity descriptor to touch only the correct stuff.
855 1.1 oster */
856 1.1 oster void rf_ASMParityAdjust(
857 1.1 oster RF_PhysDiskAddr_t *toAdjust,
858 1.1 oster RF_StripeNum_t startAddrWithinStripe,
859 1.1 oster RF_SectorNum_t endAddress,
860 1.1 oster RF_RaidLayout_t *layoutPtr,
861 1.1 oster RF_AccessStripeMap_t *asm_p)
862 1.1 oster {
863 1.1 oster RF_PhysDiskAddr_t *new_pda;
864 1.1 oster
865 1.1 oster /* when we're accessing only a portion of one stripe unit, we want the parity descriptor
866 1.1 oster * to identify only the chunk of parity associated with the data. When the access spans
867 1.1 oster * exactly one stripe unit boundary and is less than a stripe unit in size, it uses two disjoint
868 1.1 oster * regions of the parity unit. When an access spans more than one stripe unit boundary, it
869 1.1 oster * uses all of the parity unit.
870 1.1 oster *
871 1.1 oster * To better handle the case where stripe units are small, we may eventually want to change
872 1.1 oster * the 2nd case so that if the SU size is below some threshold, we just read/write the whole
873 1.1 oster * thing instead of breaking it up into two accesses.
874 1.1 oster */
875 1.1 oster if (asm_p->numStripeUnitsAccessed == 1)
876 1.1 oster {
877 1.1 oster int x = (startAddrWithinStripe % layoutPtr->sectorsPerStripeUnit);
878 1.1 oster toAdjust->startSector += x;
879 1.1 oster toAdjust->raidAddress += x;
880 1.1 oster toAdjust->numSector = asm_p->physInfo->numSector;
881 1.1 oster RF_ASSERT(toAdjust->numSector != 0);
882 1.1 oster }
883 1.1 oster else
884 1.1 oster if (asm_p->numStripeUnitsAccessed == 2 && asm_p->totalSectorsAccessed < layoutPtr->sectorsPerStripeUnit)
885 1.1 oster {
886 1.1 oster int x = (startAddrWithinStripe % layoutPtr->sectorsPerStripeUnit);
887 1.1 oster
888 1.1 oster /* create a second pda and copy the parity map info into it */
889 1.1 oster RF_ASSERT(toAdjust->next == NULL);
890 1.1 oster new_pda = toAdjust->next = rf_AllocPhysDiskAddr();
891 1.1 oster *new_pda = *toAdjust; /* structure assignment */
892 1.1 oster new_pda->next = NULL;
893 1.1 oster
894 1.1 oster /* adjust the start sector & number of blocks for the first parity pda */
895 1.1 oster toAdjust->startSector += x;
896 1.1 oster toAdjust->raidAddress += x;
897 1.1 oster toAdjust->numSector = rf_RaidAddressOfNextStripeUnitBoundary(layoutPtr, startAddrWithinStripe) - startAddrWithinStripe;
898 1.1 oster RF_ASSERT(toAdjust->numSector != 0);
899 1.1 oster
900 1.1 oster /* adjust the second pda */
901 1.1 oster new_pda->numSector = endAddress - rf_RaidAddressOfPrevStripeUnitBoundary(layoutPtr, endAddress);
902 1.1 oster /*new_pda->raidAddress = rf_RaidAddressOfNextStripeUnitBoundary(layoutPtr, toAdjust->raidAddress);*/
903 1.1 oster RF_ASSERT(new_pda->numSector != 0);
904 1.1 oster }
905 1.1 oster }
906 1.1 oster
907 1.1 oster /*
908 1.1 oster Check if a disk has been spared or failed. If spared,
909 1.1 oster redirect the I/O.
910 1.1 oster If it has been failed, record it in the asm pointer.
911 1.1 oster Fourth arg is whether data or parity.
912 1.1 oster */
913 1.1 oster void rf_ASMCheckStatus(
914 1.1 oster RF_Raid_t *raidPtr,
915 1.1 oster RF_PhysDiskAddr_t *pda_p,
916 1.1 oster RF_AccessStripeMap_t *asm_p,
917 1.1 oster RF_RaidDisk_t **disks,
918 1.1 oster int parity)
919 1.1 oster {
920 1.1 oster RF_DiskStatus_t dstatus;
921 1.1 oster RF_RowCol_t frow, fcol;
922 1.1 oster
923 1.1 oster dstatus = disks[pda_p->row][pda_p->col].status;
924 1.1 oster
925 1.1 oster if (dstatus == rf_ds_spared) {
926 1.1 oster /* if the disk has been spared, redirect access to the spare */
927 1.1 oster frow = pda_p->row; fcol = pda_p->col;
928 1.1 oster pda_p->row = disks[frow][fcol].spareRow;
929 1.1 oster pda_p->col = disks[frow][fcol].spareCol;
930 1.1 oster }
931 1.1 oster else if (dstatus == rf_ds_dist_spared) {
932 1.1 oster /* ditto if disk has been spared to dist spare space */
933 1.1 oster RF_RowCol_t or = pda_p->row, oc=pda_p->col;
934 1.1 oster RF_SectorNum_t oo = pda_p->startSector;
935 1.1 oster
936 1.1 oster if (pda_p -> type == RF_PDA_TYPE_DATA)
937 1.1 oster raidPtr->Layout.map->MapSector(raidPtr, pda_p->raidAddress, &pda_p->row, &pda_p->col, &pda_p->startSector, RF_REMAP);
938 1.1 oster else
939 1.1 oster raidPtr->Layout.map->MapParity(raidPtr, pda_p->raidAddress, &pda_p->row, &pda_p->col, &pda_p->startSector, RF_REMAP);
940 1.1 oster
941 1.1 oster if (rf_mapDebug) {
942 1.1 oster printf("Redirected r %d c %d o %d -> r%d c %d o %d\n",or,oc,(int)oo,
943 1.1 oster pda_p->row,pda_p->col,(int)pda_p->startSector);
944 1.1 oster }
945 1.1 oster } else if (RF_DEAD_DISK(dstatus)) {
946 1.1 oster /* if the disk is inaccessible, mark the failure */
947 1.1 oster if (parity)
948 1.1 oster asm_p->numParityFailed++;
949 1.1 oster else {
950 1.1 oster asm_p->numDataFailed++;
951 1.1 oster #if 0
952 1.1 oster /* XXX Do we really want this spewing out on the console? GO */
953 1.1 oster printf("DATA_FAILED!\n");
954 1.1 oster #endif
955 1.1 oster }
956 1.1 oster asm_p->failedPDAs[asm_p->numFailedPDAs] = pda_p;
957 1.1 oster asm_p->numFailedPDAs++;
958 1.1 oster #if 0
959 1.1 oster switch (asm_p->numParityFailed + asm_p->numDataFailed)
960 1.1 oster {
961 1.1 oster case 1:
962 1.1 oster asm_p->failedPDAs[0] = pda_p;
963 1.1 oster break;
964 1.1 oster case 2:
965 1.1 oster asm_p->failedPDAs[1] = pda_p;
966 1.1 oster default:
967 1.1 oster break;
968 1.1 oster }
969 1.1 oster #endif
970 1.1 oster }
971 1.1 oster /* the redirected access should never span a stripe unit boundary */
972 1.1 oster RF_ASSERT(rf_RaidAddressToStripeUnitID(&raidPtr->Layout,pda_p->raidAddress) ==
973 1.1 oster rf_RaidAddressToStripeUnitID(&raidPtr->Layout,pda_p->raidAddress + pda_p->numSector -1));
974 1.1 oster RF_ASSERT(pda_p->col != -1);
975 1.1 oster }
976