rf_raid4.c revision 1.1 1 /* $NetBSD: rf_raid4.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: Rachad Youssef
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_raid4.c -- implements RAID Level 4
32 *
33 ***************************************/
34
35 /*
36 * :
37 * Log: rf_raid4.c,v
38 * Revision 1.24 1996/07/31 16:56:18 jimz
39 * dataBytesPerStripe, sectorsPerDisk init arch-indep.
40 *
41 * Revision 1.23 1996/07/18 22:57:14 jimz
42 * port simulator to AIX
43 *
44 * Revision 1.22 1996/07/13 00:00:59 jimz
45 * sanitized generalized reconstruction architecture
46 * cleaned up head sep, rbuf problems
47 *
48 * Revision 1.21 1996/06/11 08:54:27 jimz
49 * improved error-checking at configuration time
50 *
51 * Revision 1.20 1996/06/10 11:55:47 jimz
52 * Straightened out some per-array/not-per-array distinctions, fixed
53 * a couple bugs related to confusion. Added shutdown lists. Removed
54 * layout shutdown function (now subsumed by shutdown lists).
55 *
56 * Revision 1.19 1996/06/07 22:26:27 jimz
57 * type-ify which_ru (RF_ReconUnitNum_t)
58 *
59 * Revision 1.18 1996/06/07 21:33:04 jimz
60 * begin using consistent types for sector numbers,
61 * stripe numbers, row+col numbers, recon unit numbers
62 *
63 * Revision 1.17 1996/06/03 23:28:26 jimz
64 * more bugfixes
65 * check in tree to sync for IPDS runs with current bugfixes
66 * there still may be a problem with threads in the script test
67 * getting I/Os stuck- not trivially reproducible (runs ~50 times
68 * in a row without getting stuck)
69 *
70 * Revision 1.16 1996/05/31 22:26:54 jimz
71 * fix a lot of mapping problems, memory allocation problems
72 * found some weird lock issues, fixed 'em
73 * more code cleanup
74 *
75 * Revision 1.15 1996/05/27 18:56:37 jimz
76 * more code cleanup
77 * better typing
78 * compiles in all 3 environments
79 *
80 * Revision 1.14 1996/05/24 01:59:45 jimz
81 * another checkpoint in code cleanup for release
82 * time to sync kernel tree
83 *
84 * Revision 1.13 1996/05/23 00:33:23 jimz
85 * code cleanup: move all debug decls to rf_options.c, all extern
86 * debug decls to rf_options.h, all debug vars preceded by rf_
87 *
88 * Revision 1.12 1996/05/18 19:51:34 jimz
89 * major code cleanup- fix syntax, make some types consistent,
90 * add prototypes, clean out dead code, et cetera
91 *
92 * Revision 1.11 1996/05/03 19:39:41 wvcii
93 * added includes for dag library
94 *
95 * Revision 1.10 1995/12/12 18:10:06 jimz
96 * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
97 * fix 80-column brain damage in comments
98 *
99 * Revision 1.9 1995/12/06 15:02:46 root
100 * added copyright info
101 *
102 * Revision 1.8 1995/11/17 18:57:32 wvcii
103 * added prototyping to MapParity
104 *
105 * Revision 1.7 1995/06/23 13:38:58 robby
106 * updeated to prototypes in rf_layout.h
107 *
108 */
109
110 #include "rf_raid.h"
111 #include "rf_dag.h"
112 #include "rf_dagutils.h"
113 #include "rf_dagfuncs.h"
114 #include "rf_dagffrd.h"
115 #include "rf_dagffwr.h"
116 #include "rf_dagdegrd.h"
117 #include "rf_dagdegwr.h"
118 #include "rf_threadid.h"
119 #include "rf_raid4.h"
120 #include "rf_general.h"
121
122 typedef struct RF_Raid4ConfigInfo_s {
123 RF_RowCol_t *stripeIdentifier; /* filled in at config time & used by IdentifyStripe */
124 } RF_Raid4ConfigInfo_t;
125
126
127
128 int rf_ConfigureRAID4(
129 RF_ShutdownList_t **listp,
130 RF_Raid_t *raidPtr,
131 RF_Config_t *cfgPtr)
132 {
133 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
134 RF_Raid4ConfigInfo_t *info;
135 int i;
136
137 /* create a RAID level 4 configuration structure ... */
138 RF_MallocAndAdd(info, sizeof(RF_Raid4ConfigInfo_t), (RF_Raid4ConfigInfo_t *), raidPtr->cleanupList);
139 if (info == NULL)
140 return(ENOMEM);
141 layoutPtr->layoutSpecificInfo = (void *) info;
142
143 /* ... and fill it in. */
144 RF_MallocAndAdd(info->stripeIdentifier, raidPtr->numCol * sizeof(RF_RowCol_t), (RF_RowCol_t *), raidPtr->cleanupList);
145 if (info->stripeIdentifier == NULL)
146 return(ENOMEM);
147 for (i=0; i<raidPtr->numCol; i++)
148 info->stripeIdentifier[i] = i;
149
150 RF_ASSERT(raidPtr->numRow == 1);
151
152 /* fill in the remaining layout parameters */
153 layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk;
154 layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
155 layoutPtr->numDataCol = raidPtr->numCol-1;
156 layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
157 layoutPtr->numParityCol = 1;
158 raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
159
160 return(0);
161 }
162
163 int rf_GetDefaultNumFloatingReconBuffersRAID4(RF_Raid_t *raidPtr)
164 {
165 return(20);
166 }
167
168 RF_HeadSepLimit_t rf_GetDefaultHeadSepLimitRAID4(RF_Raid_t *raidPtr)
169 {
170 return(20);
171 }
172
173 void rf_MapSectorRAID4(
174 RF_Raid_t *raidPtr,
175 RF_RaidAddr_t raidSector,
176 RF_RowCol_t *row,
177 RF_RowCol_t *col,
178 RF_SectorNum_t *diskSector,
179 int remap)
180 {
181 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
182 *row = 0;
183 *col = SUID % raidPtr->Layout.numDataCol;
184 *diskSector = (SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
185 (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
186 }
187
188 void rf_MapParityRAID4(
189 RF_Raid_t *raidPtr,
190 RF_RaidAddr_t raidSector,
191 RF_RowCol_t *row,
192 RF_RowCol_t *col,
193 RF_SectorNum_t *diskSector,
194 int remap)
195 {
196 RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
197
198 *row = 0;
199 *col = raidPtr->Layout.numDataCol;
200 *diskSector =(SUID / (raidPtr->Layout.numDataCol)) * raidPtr->Layout.sectorsPerStripeUnit +
201 (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
202 }
203
204 void rf_IdentifyStripeRAID4(
205 RF_Raid_t *raidPtr,
206 RF_RaidAddr_t addr,
207 RF_RowCol_t **diskids,
208 RF_RowCol_t *outRow)
209 {
210 RF_Raid4ConfigInfo_t *info = raidPtr->Layout.layoutSpecificInfo;
211
212 *outRow = 0;
213 *diskids = info->stripeIdentifier;
214 }
215
216 void rf_MapSIDToPSIDRAID4(
217 RF_RaidLayout_t *layoutPtr,
218 RF_StripeNum_t stripeID,
219 RF_StripeNum_t *psID,
220 RF_ReconUnitNum_t *which_ru)
221 {
222 *which_ru = 0;
223 *psID = stripeID;
224 }
225