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