rf_raid5_rotatedspare.c revision 1.1 1 /* $NetBSD: rf_raid5_rotatedspare.c,v 1.1 1998/11/13 04:20:33 oster Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
5 *
6 * Author: Khalil Amiri
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_rotated_spare.c -- implements RAID Level 5 with rotated sparing
32 *
33 **************************************************************************/
34
35 /* :
36 * Log: rf_raid5_rotatedspare.c,v
37 * Revision 1.22 1996/07/31 16:56:18 jimz
38 * dataBytesPerStripe, sectorsPerDisk init arch-indep.
39 *
40 * Revision 1.21 1996/07/29 14:05:12 jimz
41 * fix numPUs/numRUs confusion (everything is now numRUs)
42 * clean up some commenting, return values
43 *
44 * Revision 1.20 1996/07/18 22:57:14 jimz
45 * port simulator to AIX
46 *
47 * Revision 1.19 1996/07/13 00:00:59 jimz
48 * sanitized generalized reconstruction architecture
49 * cleaned up head sep, rbuf problems
50 *
51 * Revision 1.18 1996/06/19 17:53:48 jimz
52 * move GetNumSparePUs, InstallSpareTable ops into layout switch
53 *
54 * Revision 1.17 1996/06/11 08:54:27 jimz
55 * improved error-checking at configuration time
56 *
57 * Revision 1.16 1996/06/10 11:55:47 jimz
58 * Straightened out some per-array/not-per-array distinctions, fixed
59 * a couple bugs related to confusion. Added shutdown lists. Removed
60 * layout shutdown function (now subsumed by shutdown lists).
61 *
62 * Revision 1.15 1996/06/07 22:26:27 jimz
63 * type-ify which_ru (RF_ReconUnitNum_t)
64 *
65 * Revision 1.14 1996/06/07 21:33:04 jimz
66 * begin using consistent types for sector numbers,
67 * stripe numbers, row+col numbers, recon unit numbers
68 *
69 * Revision 1.13 1996/06/03 23:28:26 jimz
70 * more bugfixes
71 * check in tree to sync for IPDS runs with current bugfixes
72 * there still may be a problem with threads in the script test
73 * getting I/Os stuck- not trivially reproducible (runs ~50 times
74 * in a row without getting stuck)
75 *
76 * Revision 1.12 1996/06/02 17:31:48 jimz
77 * Moved a lot of global stuff into array structure, where it belongs.
78 * Fixed up paritylogging, pss modules in this manner. Some general
79 * code cleanup. Removed lots of dead code, some dead files.
80 *
81 * Revision 1.11 1996/05/31 22:26:54 jimz
82 * fix a lot of mapping problems, memory allocation problems
83 * found some weird lock issues, fixed 'em
84 * more code cleanup
85 *
86 * Revision 1.10 1996/05/27 18:56:37 jimz
87 * more code cleanup
88 * better typing
89 * compiles in all 3 environments
90 *
91 * Revision 1.9 1996/05/24 01:59:45 jimz
92 * another checkpoint in code cleanup for release
93 * time to sync kernel tree
94 *
95 * Revision 1.8 1996/05/23 00:33:23 jimz
96 * code cleanup: move all debug decls to rf_options.c, all extern
97 * debug decls to rf_options.h, all debug vars preceded by rf_
98 *
99 * Revision 1.7 1996/05/18 19:51:34 jimz
100 * major code cleanup- fix syntax, make some types consistent,
101 * add prototypes, clean out dead code, et cetera
102 *
103 * Revision 1.6 1996/05/03 19:48:36 wvcii
104 * removed include of rf_redstripe.h
105 *
106 * Revision 1.5 1995/12/12 18:10:06 jimz
107 * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
108 * fix 80-column brain damage in comments
109 *
110 * Revision 1.4 1995/12/06 15:05:53 root
111 * added copyright info
112 *
113 * Revision 1.3 1995/11/19 21:26:29 amiri
114 * Added an assert to make sure numCol >= 3
115 *
116 * Revision 1.2 1995/11/17 19:03:18 wvcii
117 * added prototyping to MapParity
118 *
119 */
120
121 #include "rf_raid.h"
122 #include "rf_raid5.h"
123 #include "rf_dag.h"
124 #include "rf_dagutils.h"
125 #include "rf_dagfuncs.h"
126 #include "rf_threadid.h"
127 #include "rf_general.h"
128 #include "rf_utils.h"
129 #include "rf_raid5_rotatedspare.h"
130
131 typedef struct RF_Raid5RSConfigInfo_s {
132 RF_RowCol_t **stripeIdentifier; /* filled in at config time & used by IdentifyStripe */
133 } RF_Raid5RSConfigInfo_t;
134
135 int rf_ConfigureRAID5_RS(
136 RF_ShutdownList_t **listp,
137 RF_Raid_t *raidPtr,
138 RF_Config_t *cfgPtr)
139 {
140 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
141 RF_Raid5RSConfigInfo_t *info;
142 RF_RowCol_t i, j, startdisk;
143
144 /* create a RAID level 5 configuration structure */
145 RF_MallocAndAdd(info, sizeof(RF_Raid5RSConfigInfo_t), (RF_Raid5RSConfigInfo_t *), raidPtr->cleanupList);
146 if (info == NULL)
147 return(ENOMEM);
148 layoutPtr->layoutSpecificInfo = (void *) info;
149
150 RF_ASSERT(raidPtr->numRow == 1);
151 RF_ASSERT(raidPtr->numCol >= 3);
152
153 /* the stripe identifier must identify the disks in each stripe,
154 * IN THE ORDER THAT THEY APPEAR IN THE STRIPE.
155 */
156 info->stripeIdentifier = rf_make_2d_array(raidPtr->numCol, raidPtr->numCol, raidPtr->cleanupList);
157 if (info->stripeIdentifier == NULL)
158 return(ENOMEM);
159 startdisk = 0;
160 for (i=0; i<raidPtr->numCol; i++) {
161 for (j=0; j<raidPtr->numCol; j++) {
162 info->stripeIdentifier[i][j] = (startdisk + j) % raidPtr->numCol;
163 }
164 if ((--startdisk) < 0) startdisk = raidPtr->numCol-1;
165 }
166
167 /* fill in the remaining layout parameters */
168 layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
169 layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
170 layoutPtr->numDataCol = raidPtr->numCol-2;
171 layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
172 layoutPtr->numParityCol = 1;
173 layoutPtr->dataStripeUnitsPerDisk = layoutPtr->stripeUnitsPerDisk;
174 raidPtr->sectorsPerDisk = layoutPtr->stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit;
175
176 raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
177
178 return(0);
179 }
180
181 RF_ReconUnitCount_t rf_GetNumSpareRUsRAID5_RS(raidPtr)
182 RF_Raid_t *raidPtr;
183 {
184 return ( raidPtr->Layout.stripeUnitsPerDisk / raidPtr->numCol );
185 }
186
187 void rf_MapSectorRAID5_RS(
188 RF_Raid_t *raidPtr,
189 RF_RaidAddr_t raidSector,
190 RF_RowCol_t *row,
191 RF_RowCol_t *col,
192 RF_SectorNum_t *diskSector,
193 int remap)
194 {
195 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
196
197 *row = 0;
198 if (remap) {
199 *col = raidPtr->numCol-1-(1+SUID/raidPtr->Layout.numDataCol)%raidPtr->numCol;
200 *col = (*col+1)%raidPtr->numCol; /*spare unit is rotated with parity; line above maps to parity */
201 }
202 else {
203 *col = ( SUID + (SUID/raidPtr->Layout.numDataCol) ) % raidPtr->numCol;
204 }
205 *diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
206 (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
207 }
208
209 void rf_MapParityRAID5_RS(
210 RF_Raid_t *raidPtr,
211 RF_RaidAddr_t raidSector,
212 RF_RowCol_t *row,
213 RF_RowCol_t *col,
214 RF_SectorNum_t *diskSector,
215 int remap)
216 {
217 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
218
219 *row = 0;
220 *col = raidPtr->numCol-1-(1+SUID/raidPtr->Layout.numDataCol)%raidPtr->numCol;
221 *diskSector =(SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
222 (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
223 if (remap)
224 *col = (*col+1)%raidPtr->numCol;
225 }
226
227 void rf_IdentifyStripeRAID5_RS(
228 RF_Raid_t *raidPtr,
229 RF_RaidAddr_t addr,
230 RF_RowCol_t **diskids,
231 RF_RowCol_t *outRow)
232 {
233 RF_StripeNum_t stripeID = rf_RaidAddressToStripeID(&raidPtr->Layout, addr);
234 RF_Raid5RSConfigInfo_t *info = (RF_Raid5RSConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
235 *outRow = 0;
236 *diskids = info->stripeIdentifier[ stripeID % raidPtr->numCol ];
237
238 }
239
240 void rf_MapSIDToPSIDRAID5_RS(
241 RF_RaidLayout_t *layoutPtr,
242 RF_StripeNum_t stripeID,
243 RF_StripeNum_t *psID,
244 RF_ReconUnitNum_t *which_ru)
245 {
246 *which_ru = 0;
247 *psID = stripeID;
248 }
249
250