rf_layout.h revision 1.3.8.1 1 1.3.8.1 bouyer /* $NetBSD: rf_layout.h,v 1.3.8.1 2000/11/20 11:42:55 bouyer 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 /* rf_layout.h -- header file defining layout data structures
30 1.1 oster */
31 1.1 oster
32 1.1 oster #ifndef _RF__RF_LAYOUT_H_
33 1.1 oster #define _RF__RF_LAYOUT_H_
34 1.1 oster
35 1.1 oster #include "rf_types.h"
36 1.1 oster #include "rf_archs.h"
37 1.1 oster #include "rf_alloclist.h"
38 1.1 oster
39 1.2 oster #ifndef _KERNEL
40 1.2 oster #include <stdio.h>
41 1.2 oster #endif
42 1.2 oster
43 1.1 oster /*****************************************************************************************
44 1.1 oster *
45 1.1 oster * This structure identifies all layout-specific operations and parameters.
46 1.3 oster *
47 1.1 oster ****************************************************************************************/
48 1.1 oster
49 1.1 oster typedef struct RF_LayoutSW_s {
50 1.3 oster RF_ParityConfig_t parityConfig;
51 1.3.8.1 bouyer const char *configName;
52 1.1 oster
53 1.2 oster #ifndef _KERNEL
54 1.3 oster /* layout-specific parsing */
55 1.3 oster int (*MakeLayoutSpecific) (FILE * fp, RF_Config_t * cfgPtr, void *arg);
56 1.3 oster void *makeLayoutSpecificArg;
57 1.3 oster #endif /* !KERNEL */
58 1.1 oster
59 1.1 oster #if RF_UTILITY == 0
60 1.3 oster /* initialization routine */
61 1.3 oster int (*Configure) (RF_ShutdownList_t ** shutdownListp, RF_Raid_t * raidPtr, RF_Config_t * cfgPtr);
62 1.1 oster
63 1.3 oster /* routine to map RAID sector address -> physical (row, col, offset) */
64 1.3 oster void (*MapSector) (RF_Raid_t * raidPtr, RF_RaidAddr_t raidSector,
65 1.3 oster RF_RowCol_t * row, RF_RowCol_t * col, RF_SectorNum_t * diskSector, int remap);
66 1.3 oster
67 1.3 oster /* routine to map RAID sector address -> physical (r,c,o) of parity
68 1.3 oster * unit */
69 1.3 oster void (*MapParity) (RF_Raid_t * raidPtr, RF_RaidAddr_t raidSector,
70 1.3 oster RF_RowCol_t * row, RF_RowCol_t * col, RF_SectorNum_t * diskSector, int remap);
71 1.3 oster
72 1.3 oster /* routine to map RAID sector address -> physical (r,c,o) of Q unit */
73 1.3 oster void (*MapQ) (RF_Raid_t * raidPtr, RF_RaidAddr_t raidSector, RF_RowCol_t * row,
74 1.3 oster RF_RowCol_t * col, RF_SectorNum_t * diskSector, int remap);
75 1.3 oster
76 1.3 oster /* routine to identify the disks comprising a stripe */
77 1.3 oster void (*IdentifyStripe) (RF_Raid_t * raidPtr, RF_RaidAddr_t addr,
78 1.3 oster RF_RowCol_t ** diskids, RF_RowCol_t * outRow);
79 1.3 oster
80 1.3 oster /* routine to select a dag */
81 1.3 oster void (*SelectionFunc) (RF_Raid_t * raidPtr, RF_IoType_t type,
82 1.3 oster RF_AccessStripeMap_t * asmap,
83 1.3 oster RF_VoidFuncPtr *);
84 1.1 oster #if 0
85 1.3 oster void (**createFunc) (RF_Raid_t *,
86 1.3 oster RF_AccessStripeMap_t *,
87 1.3 oster RF_DagHeader_t *, void *,
88 1.3 oster RF_RaidAccessFlags_t,
89 1.3 oster /**INDENT** Warning@88: Extra ) */
90 1.3 oster RF_AllocListElem_t *));
91 1.3 oster
92 1.1 oster #endif
93 1.1 oster
94 1.3 oster /* map a stripe ID to a parity stripe ID. This is typically the
95 1.3 oster * identity mapping */
96 1.3 oster void (*MapSIDToPSID) (RF_RaidLayout_t * layoutPtr, RF_StripeNum_t stripeID,
97 1.3 oster RF_StripeNum_t * psID, RF_ReconUnitNum_t * which_ru);
98 1.3 oster
99 1.3 oster /* get default head separation limit (may be NULL) */
100 1.3 oster RF_HeadSepLimit_t(*GetDefaultHeadSepLimit) (RF_Raid_t * raidPtr);
101 1.3 oster
102 1.3 oster /* get default num recon buffers (may be NULL) */
103 1.3 oster int (*GetDefaultNumFloatingReconBuffers) (RF_Raid_t * raidPtr);
104 1.3 oster
105 1.3 oster /* get number of spare recon units (may be NULL) */
106 1.3 oster RF_ReconUnitCount_t(*GetNumSpareRUs) (RF_Raid_t * raidPtr);
107 1.3 oster
108 1.3 oster /* spare table installation (may be NULL) */
109 1.3 oster int (*InstallSpareTable) (RF_Raid_t * raidPtr, RF_RowCol_t frow, RF_RowCol_t fcol);
110 1.3 oster
111 1.3 oster /* recon buffer submission function */
112 1.3 oster int (*SubmitReconBuffer) (RF_ReconBuffer_t * rbuf, int keep_it,
113 1.3 oster int use_committed);
114 1.3 oster
115 1.3 oster /*
116 1.3 oster * verify that parity information for a stripe is correct
117 1.3 oster * see rf_parityscan.h for return vals
118 1.3 oster */
119 1.3 oster int (*VerifyParity) (RF_Raid_t * raidPtr, RF_RaidAddr_t raidAddr,
120 1.3 oster RF_PhysDiskAddr_t * parityPDA, int correct_it, RF_RaidAccessFlags_t flags);
121 1.3 oster
122 1.3 oster /* number of faults tolerated by this mapping */
123 1.3 oster int faultsTolerated;
124 1.3 oster
125 1.3 oster /* states to step through in an access. Must end with "LastState". The
126 1.3 oster * default is DefaultStates in rf_layout.c */
127 1.3 oster RF_AccessState_t *states;
128 1.3 oster
129 1.3 oster RF_AccessStripeMapFlags_t flags;
130 1.3 oster #endif /* RF_UTILITY == 0 */
131 1.3 oster } RF_LayoutSW_t;
132 1.1 oster /* enables remapping to spare location under dist sparing */
133 1.1 oster #define RF_REMAP 1
134 1.1 oster #define RF_DONT_REMAP 0
135 1.1 oster
136 1.1 oster /*
137 1.1 oster * Flags values for RF_AccessStripeMapFlags_t
138 1.1 oster */
139 1.3 oster #define RF_NO_STRIPE_LOCKS 0x0001 /* suppress stripe locks */
140 1.3 oster #define RF_DISTRIBUTE_SPARE 0x0002 /* distribute spare space in archs
141 1.3 oster * that support it */
142 1.3 oster #define RF_BD_DECLUSTERED 0x0004 /* declustering uses block designs */
143 1.1 oster
144 1.1 oster /*************************************************************************
145 1.1 oster *
146 1.1 oster * this structure forms the layout component of the main Raid
147 1.1 oster * structure. It describes everything needed to define and perform
148 1.1 oster * the mapping of logical RAID addresses <-> physical disk addresses.
149 1.3 oster *
150 1.1 oster *************************************************************************/
151 1.1 oster struct RF_RaidLayout_s {
152 1.3 oster /* configuration parameters */
153 1.3 oster RF_SectorCount_t sectorsPerStripeUnit; /* number of sectors in one
154 1.3 oster * stripe unit */
155 1.3 oster RF_StripeCount_t SUsPerPU; /* stripe units per parity unit */
156 1.3 oster RF_StripeCount_t SUsPerRU; /* stripe units per reconstruction
157 1.3 oster * unit */
158 1.3 oster
159 1.3 oster /* redundant-but-useful info computed from the above, used in all
160 1.3 oster * layouts */
161 1.3 oster RF_StripeCount_t numStripe; /* total number of stripes in the
162 1.3 oster * array */
163 1.3 oster RF_SectorCount_t dataSectorsPerStripe;
164 1.3 oster RF_StripeCount_t dataStripeUnitsPerDisk;
165 1.3 oster u_int bytesPerStripeUnit;
166 1.3 oster u_int dataBytesPerStripe;
167 1.3 oster RF_StripeCount_t numDataCol; /* number of SUs of data per stripe
168 1.3 oster * (name here is a la RAID4) */
169 1.3 oster RF_StripeCount_t numParityCol; /* number of SUs of parity per stripe.
170 1.3 oster * Always 1 for now */
171 1.3 oster RF_StripeCount_t numParityLogCol; /* number of SUs of parity log
172 1.3 oster * per stripe. Always 1 for
173 1.3 oster * now */
174 1.3 oster RF_StripeCount_t stripeUnitsPerDisk;
175 1.3 oster
176 1.3 oster RF_LayoutSW_t *map; /* ptr to struct holding mapping fns and
177 1.3 oster * information */
178 1.3 oster void *layoutSpecificInfo; /* ptr to a structure holding
179 1.3 oster * layout-specific params */
180 1.1 oster };
181 1.1 oster /*****************************************************************************************
182 1.1 oster *
183 1.1 oster * The mapping code returns a pointer to a list of AccessStripeMap structures, which
184 1.1 oster * describes all the mapping information about an access. The list contains one
185 1.1 oster * AccessStripeMap structure per stripe touched by the access. Each element in the list
186 1.1 oster * contains a stripe identifier and a pointer to a list of PhysDiskAddr structuress. Each
187 1.1 oster * element in this latter list describes the physical location of a stripe unit accessed
188 1.1 oster * within the corresponding stripe.
189 1.3 oster *
190 1.1 oster ****************************************************************************************/
191 1.1 oster
192 1.1 oster #define RF_PDA_TYPE_DATA 0
193 1.1 oster #define RF_PDA_TYPE_PARITY 1
194 1.1 oster #define RF_PDA_TYPE_Q 2
195 1.1 oster
196 1.1 oster struct RF_PhysDiskAddr_s {
197 1.3 oster RF_RowCol_t row, col; /* disk identifier */
198 1.3 oster RF_SectorNum_t startSector; /* sector offset into the disk */
199 1.3 oster RF_SectorCount_t numSector; /* number of sectors accessed */
200 1.3 oster int type; /* used by higher levels: currently, data,
201 1.3 oster * parity, or q */
202 1.3 oster caddr_t bufPtr; /* pointer to buffer supplying/receiving data */
203 1.3 oster RF_RaidAddr_t raidAddress; /* raid address corresponding to this
204 1.3 oster * physical disk address */
205 1.3 oster RF_PhysDiskAddr_t *next;
206 1.1 oster };
207 1.1 oster #define RF_MAX_FAILED_PDA RF_MAXCOL
208 1.1 oster
209 1.1 oster struct RF_AccessStripeMap_s {
210 1.3 oster RF_StripeNum_t stripeID;/* the stripe index */
211 1.3 oster RF_RaidAddr_t raidAddress; /* the starting raid address within
212 1.3 oster * this stripe */
213 1.3 oster RF_RaidAddr_t endRaidAddress; /* raid address one sector past the
214 1.3 oster * end of the access */
215 1.3 oster RF_SectorCount_t totalSectorsAccessed; /* total num sectors
216 1.3 oster * identified in physInfo list */
217 1.3 oster RF_StripeCount_t numStripeUnitsAccessed; /* total num elements in
218 1.3 oster * physInfo list */
219 1.3 oster int numDataFailed; /* number of failed data disks accessed */
220 1.3 oster int numParityFailed;/* number of failed parity disks accessed (0
221 1.3 oster * or 1) */
222 1.3 oster int numQFailed; /* number of failed Q units accessed (0 or 1) */
223 1.3 oster RF_AccessStripeMapFlags_t flags; /* various flags */
224 1.1 oster #if 0
225 1.3 oster RF_PhysDiskAddr_t *failedPDA; /* points to the PDA that has failed */
226 1.3 oster RF_PhysDiskAddr_t *failedPDAtwo; /* points to the second PDA
227 1.3 oster * that has failed, if any */
228 1.1 oster #else
229 1.3 oster int numFailedPDAs; /* number of failed phys addrs */
230 1.3 oster RF_PhysDiskAddr_t *failedPDAs[RF_MAX_FAILED_PDA]; /* array of failed phys
231 1.3 oster * addrs */
232 1.1 oster #endif
233 1.3 oster RF_PhysDiskAddr_t *physInfo; /* a list of PhysDiskAddr structs */
234 1.3 oster RF_PhysDiskAddr_t *parityInfo; /* list of physical addrs for the
235 1.3 oster * parity (P of P + Q ) */
236 1.3 oster RF_PhysDiskAddr_t *qInfo; /* list of physical addrs for the Q of
237 1.3 oster * P + Q */
238 1.3 oster RF_LockReqDesc_t lockReqDesc; /* used for stripe locking */
239 1.3 oster RF_RowCol_t origRow; /* the original row: we may redirect the acc
240 1.3 oster * to a different row */
241 1.3 oster RF_AccessStripeMap_t *next;
242 1.1 oster };
243 1.1 oster /* flag values */
244 1.3 oster #define RF_ASM_REDIR_LARGE_WRITE 0x00000001 /* allows large-write creation
245 1.3 oster * code to redirect failed
246 1.3 oster * accs */
247 1.3 oster #define RF_ASM_BAILOUT_DAG_USED 0x00000002 /* allows us to detect
248 1.3 oster * recursive calls to the
249 1.3 oster * bailout write dag */
250 1.3 oster #define RF_ASM_FLAGS_LOCK_TRIED 0x00000004 /* we've acquired the lock on
251 1.3 oster * the first parity range in
252 1.3 oster * this parity stripe */
253 1.3 oster #define RF_ASM_FLAGS_LOCK_TRIED2 0x00000008 /* we've acquired the lock on
254 1.3 oster * the 2nd parity range in
255 1.3 oster * this parity stripe */
256 1.3 oster #define RF_ASM_FLAGS_FORCE_TRIED 0x00000010 /* we've done the force-recon
257 1.3 oster * call on this parity stripe */
258 1.3 oster #define RF_ASM_FLAGS_RECON_BLOCKED 0x00000020 /* we blocked recon => we must
259 1.3 oster * unblock it later */
260 1.1 oster
261 1.1 oster struct RF_AccessStripeMapHeader_s {
262 1.3 oster RF_StripeCount_t numStripes; /* total number of stripes touched by
263 1.3 oster * this acc */
264 1.3 oster RF_AccessStripeMap_t *stripeMap; /* pointer to the actual map.
265 1.3 oster * Also used for making lists */
266 1.3 oster RF_AccessStripeMapHeader_t *next;
267 1.1 oster };
268 1.1 oster /*****************************************************************************************
269 1.1 oster *
270 1.1 oster * various routines mapping addresses in the RAID address space. These work across
271 1.1 oster * all layouts. DON'T PUT ANY LAYOUT-SPECIFIC CODE HERE.
272 1.1 oster *
273 1.1 oster ****************************************************************************************/
274 1.1 oster
275 1.1 oster /* return the identifier of the stripe containing the given address */
276 1.1 oster #define rf_RaidAddressToStripeID(_layoutPtr_, _addr_) \
277 1.1 oster ( ((_addr_) / (_layoutPtr_)->sectorsPerStripeUnit) / (_layoutPtr_)->numDataCol )
278 1.1 oster
279 1.1 oster /* return the raid address of the start of the indicates stripe ID */
280 1.1 oster #define rf_StripeIDToRaidAddress(_layoutPtr_, _sid_) \
281 1.1 oster ( ((_sid_) * (_layoutPtr_)->sectorsPerStripeUnit) * (_layoutPtr_)->numDataCol )
282 1.1 oster
283 1.1 oster /* return the identifier of the stripe containing the given stripe unit id */
284 1.1 oster #define rf_StripeUnitIDToStripeID(_layoutPtr_, _addr_) \
285 1.1 oster ( (_addr_) / (_layoutPtr_)->numDataCol )
286 1.1 oster
287 1.1 oster /* return the identifier of the stripe unit containing the given address */
288 1.1 oster #define rf_RaidAddressToStripeUnitID(_layoutPtr_, _addr_) \
289 1.1 oster ( ((_addr_) / (_layoutPtr_)->sectorsPerStripeUnit) )
290 1.1 oster
291 1.1 oster /* return the RAID address of next stripe boundary beyond the given address */
292 1.1 oster #define rf_RaidAddressOfNextStripeBoundary(_layoutPtr_, _addr_) \
293 1.1 oster ( (((_addr_)/(_layoutPtr_)->dataSectorsPerStripe)+1) * (_layoutPtr_)->dataSectorsPerStripe )
294 1.1 oster
295 1.1 oster /* return the RAID address of the start of the stripe containing the given address */
296 1.1 oster #define rf_RaidAddressOfPrevStripeBoundary(_layoutPtr_, _addr_) \
297 1.1 oster ( (((_addr_)/(_layoutPtr_)->dataSectorsPerStripe)+0) * (_layoutPtr_)->dataSectorsPerStripe )
298 1.1 oster
299 1.1 oster /* return the RAID address of next stripe unit boundary beyond the given address */
300 1.1 oster #define rf_RaidAddressOfNextStripeUnitBoundary(_layoutPtr_, _addr_) \
301 1.1 oster ( (((_addr_)/(_layoutPtr_)->sectorsPerStripeUnit)+1L)*(_layoutPtr_)->sectorsPerStripeUnit )
302 1.1 oster
303 1.1 oster /* return the RAID address of the start of the stripe unit containing RAID address _addr_ */
304 1.1 oster #define rf_RaidAddressOfPrevStripeUnitBoundary(_layoutPtr_, _addr_) \
305 1.1 oster ( (((_addr_)/(_layoutPtr_)->sectorsPerStripeUnit)+0)*(_layoutPtr_)->sectorsPerStripeUnit )
306 1.1 oster
307 1.1 oster /* returns the offset into the stripe. used by RaidAddressStripeAligned */
308 1.1 oster #define rf_RaidAddressStripeOffset(_layoutPtr_, _addr_) \
309 1.1 oster ( (_addr_) % ((_layoutPtr_)->dataSectorsPerStripe) )
310 1.1 oster
311 1.1 oster /* returns the offset into the stripe unit. */
312 1.1 oster #define rf_StripeUnitOffset(_layoutPtr_, _addr_) \
313 1.1 oster ( (_addr_) % ((_layoutPtr_)->sectorsPerStripeUnit) )
314 1.1 oster
315 1.1 oster /* returns nonzero if the given RAID address is stripe-aligned */
316 1.1 oster #define rf_RaidAddressStripeAligned( __layoutPtr__, __addr__ ) \
317 1.1 oster ( rf_RaidAddressStripeOffset(__layoutPtr__, __addr__) == 0 )
318 1.1 oster
319 1.1 oster /* returns nonzero if the given address is stripe-unit aligned */
320 1.1 oster #define rf_StripeUnitAligned( __layoutPtr__, __addr__ ) \
321 1.1 oster ( rf_StripeUnitOffset(__layoutPtr__, __addr__) == 0 )
322 1.1 oster
323 1.1 oster /* convert an address expressed in RAID blocks to/from an addr expressed in bytes */
324 1.1 oster #define rf_RaidAddressToByte(_raidPtr_, _addr_) \
325 1.1 oster ( (_addr_) << ( (_raidPtr_)->logBytesPerSector ) )
326 1.1 oster
327 1.1 oster #define rf_ByteToRaidAddress(_raidPtr_, _addr_) \
328 1.1 oster ( (_addr_) >> ( (_raidPtr_)->logBytesPerSector ) )
329 1.1 oster
330 1.1 oster /* convert a raid address to/from a parity stripe ID. Conversion to raid address is easy,
331 1.1 oster * since we're asking for the address of the first sector in the parity stripe. Conversion to a
332 1.1 oster * parity stripe ID is more complex, since stripes are not contiguously allocated in
333 1.1 oster * parity stripes.
334 1.1 oster */
335 1.1 oster #define rf_RaidAddressToParityStripeID(_layoutPtr_, _addr_, _ru_num_) \
336 1.1 oster rf_MapStripeIDToParityStripeID( (_layoutPtr_), rf_RaidAddressToStripeID( (_layoutPtr_), (_addr_) ), (_ru_num_) )
337 1.1 oster
338 1.1 oster #define rf_ParityStripeIDToRaidAddress(_layoutPtr_, _psid_) \
339 1.1 oster ( (_psid_) * (_layoutPtr_)->SUsPerPU * (_layoutPtr_)->numDataCol * (_layoutPtr_)->sectorsPerStripeUnit )
340 1.1 oster
341 1.1 oster RF_LayoutSW_t *rf_GetLayout(RF_ParityConfig_t parityConfig);
342 1.3 oster int
343 1.3 oster rf_ConfigureLayout(RF_ShutdownList_t ** listp, RF_Raid_t * raidPtr,
344 1.3 oster RF_Config_t * cfgPtr);
345 1.3 oster RF_StripeNum_t
346 1.3 oster rf_MapStripeIDToParityStripeID(RF_RaidLayout_t * layoutPtr,
347 1.3 oster RF_StripeNum_t stripeID, RF_ReconUnitNum_t * which_ru);
348 1.1 oster
349 1.3 oster #endif /* !_RF__RF_LAYOUT_H_ */
350