1 /* $NetBSD: rf_layout.h,v 1.16 2005/12/11 12:23:37 christos Exp $ */
3 * Copyright (c) 1995 Carnegie-Mellon University.
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.
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.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
29 /* rf_layout.h -- header file defining layout data structures
32 #ifndef _RF__RF_LAYOUT_H_
33 #define _RF__RF_LAYOUT_H_
35 #include <dev/raidframe/raidframevar.h>
37 #include "rf_alloclist.h"
39 /* enables remapping to spare location under dist sparing */
41 #define RF_DONT_REMAP 0
44 * Flags values for RF_AccessStripeMapFlags_t
46 #define RF_NO_STRIPE_LOCKS 0x0001 /* suppress stripe locks */
47 #define RF_DISTRIBUTE_SPARE 0x0002 /* distribute spare space in archs
49 #define RF_BD_DECLUSTERED 0x0004 /* declustering uses block designs */
51 /*************************************************************************
53 * this structure forms the layout component of the main Raid
54 * structure. It describes everything needed to define and perform
55 * the mapping of logical RAID addresses <-> physical disk addresses.
57 *************************************************************************/
58 struct RF_RaidLayout_s
{
59 /* configuration parameters */
60 RF_SectorCount_t sectorsPerStripeUnit
; /* number of sectors in one
62 RF_StripeCount_t SUsPerPU
; /* stripe units per parity unit */
63 RF_StripeCount_t SUsPerRU
; /* stripe units per reconstruction
66 /* redundant-but-useful info computed from the above, used in all
68 RF_StripeCount_t numStripe
; /* total number of stripes in the
70 RF_SectorCount_t dataSectorsPerStripe
;
71 RF_StripeCount_t dataStripeUnitsPerDisk
;
72 RF_StripeCount_t numDataCol
; /* number of SUs of data per stripe
73 * (name here is a la RAID4) */
74 RF_StripeCount_t numParityCol
; /* number of SUs of parity per stripe.
76 RF_StripeCount_t numParityLogCol
; /* number of SUs of parity log
77 * per stripe. Always 1 for
79 RF_StripeCount_t stripeUnitsPerDisk
;
81 const RF_LayoutSW_t
*map
; /* ptr to struct holding mapping fns and
83 void *layoutSpecificInfo
; /* ptr to a structure holding
84 * layout-specific params */
86 /*****************************************************************************************
88 * The mapping code returns a pointer to a list of AccessStripeMap structures, which
89 * describes all the mapping information about an access. The list contains one
90 * AccessStripeMap structure per stripe touched by the access. Each element in the list
91 * contains a stripe identifier and a pointer to a list of PhysDiskAddr structuress. Each
92 * element in this latter list describes the physical location of a stripe unit accessed
93 * within the corresponding stripe.
95 ****************************************************************************************/
97 #define RF_PDA_TYPE_DATA 0
98 #define RF_PDA_TYPE_PARITY 1
99 #define RF_PDA_TYPE_Q 2
101 struct RF_PhysDiskAddr_s
{
102 RF_RowCol_t col
; /* disk identifier */
103 RF_SectorNum_t startSector
; /* sector offset into the disk */
104 RF_SectorCount_t numSector
; /* number of sectors accessed */
105 int type
; /* used by higher levels: currently, data,
107 void *bufPtr
; /* pointer to buffer supplying/receiving data */
108 RF_RaidAddr_t raidAddress
; /* raid address corresponding to this
109 * physical disk address */
110 RF_PhysDiskAddr_t
*next
;
112 #define RF_MAX_FAILED_PDA RF_MAXCOL
114 struct RF_AccessStripeMap_s
{
115 RF_StripeNum_t stripeID
;/* the stripe index */
116 RF_RaidAddr_t raidAddress
; /* the starting raid address within
118 RF_RaidAddr_t endRaidAddress
; /* raid address one sector past the
119 * end of the access */
120 RF_SectorCount_t totalSectorsAccessed
; /* total num sectors
121 * identified in physInfo list */
122 RF_StripeCount_t numStripeUnitsAccessed
; /* total num elements in
124 int numDataFailed
; /* number of failed data disks accessed */
125 int numParityFailed
;/* number of failed parity disks accessed (0
127 int numQFailed
; /* number of failed Q units accessed (0 or 1) */
128 RF_AccessStripeMapFlags_t flags
; /* various flags */
129 int numFailedPDAs
; /* number of failed phys addrs */
130 RF_PhysDiskAddr_t
*failedPDAs
[RF_MAX_FAILED_PDA
]; /* array of failed phys
132 RF_PhysDiskAddr_t
*physInfo
; /* a list of PhysDiskAddr structs */
133 RF_PhysDiskAddr_t
*parityInfo
; /* list of physical addrs for the
134 * parity (P of P + Q ) */
135 RF_PhysDiskAddr_t
*qInfo
; /* list of physical addrs for the Q of
137 RF_LockReqDesc_t lockReqDesc
; /* used for stripe locking */
138 RF_AccessStripeMap_t
*next
;
141 #define RF_ASM_REDIR_LARGE_WRITE 0x00000001 /* allows large-write creation
142 * code to redirect failed
144 #define RF_ASM_BAILOUT_DAG_USED 0x00000002 /* allows us to detect
145 * recursive calls to the
146 * bailout write dag */
147 #define RF_ASM_FLAGS_LOCK_TRIED 0x00000004 /* we've acquired the lock on
148 * the first parity range in
149 * this parity stripe */
150 #define RF_ASM_FLAGS_LOCK_TRIED2 0x00000008 /* we've acquired the lock on
151 * the 2nd parity range in
152 * this parity stripe */
153 #define RF_ASM_FLAGS_FORCE_TRIED 0x00000010 /* we've done the force-recon
154 * call on this parity stripe */
155 #define RF_ASM_FLAGS_RECON_BLOCKED 0x00000020 /* we blocked recon => we must
156 * unblock it later */
158 struct RF_AccessStripeMapHeader_s
{
159 RF_StripeCount_t numStripes
; /* total number of stripes touched by
161 RF_AccessStripeMap_t
*stripeMap
; /* pointer to the actual map.
162 * Also used for making lists */
163 RF_AccessStripeMapHeader_t
*next
;
166 /* A structure to be used in a linked list to keep track of function pointers. */
167 typedef struct RF_VoidFunctionPointerListElem_s RF_VoidFunctionPointerListElem_t
;
168 struct RF_VoidFunctionPointerListElem_s
{
170 RF_VoidFunctionPointerListElem_t
*next
;
173 /* We need something to just be a linked list of anonymous pointers
175 typedef struct RF_VoidPointerListElem_s RF_VoidPointerListElem_t
;
176 struct RF_VoidPointerListElem_s
{
178 RF_VoidPointerListElem_t
*next
;
181 /* A structure to be used in a linked list to keep track of ASM Headers */
182 typedef struct RF_ASMHeaderListElem_s RF_ASMHeaderListElem_t
;
183 struct RF_ASMHeaderListElem_s
{
184 RF_AccessStripeMapHeader_t
*asmh
;
185 RF_ASMHeaderListElem_t
*next
;
188 /* A structure to keep track of all the data structures associated with
189 a failed stripe. Used for constructing the appropriate DAGs in
190 rf_SelectAlgorithm() in rf_aselect.c */
191 typedef struct RF_FailedStripe_s RF_FailedStripe_t
;
192 struct RF_FailedStripe_s
{
193 RF_VoidFunctionPointerListElem_t
*vfple
; /* linked list of pointers to DAG creation
194 functions for stripes */
195 RF_VoidFunctionPointerListElem_t
*bvfple
; /* linked list of poitners to DAG creation
196 functions for blocks */
197 RF_ASMHeaderListElem_t
*asmh_u
; /* Access Stripe Map Headers for regular
199 RF_ASMHeaderListElem_t
*asmh_b
; /* Access Stripe Map Headers used for the
201 RF_FailedStripe_t
*next
;
206 /*****************************************************************************************
208 * various routines mapping addresses in the RAID address space. These work across
209 * all layouts. DON'T PUT ANY LAYOUT-SPECIFIC CODE HERE.
211 ****************************************************************************************/
213 /* return the identifier of the stripe containing the given address */
214 #define rf_RaidAddressToStripeID(_layoutPtr_, _addr_) \
215 ( ((_addr_) / (_layoutPtr_)->sectorsPerStripeUnit) / (_layoutPtr_)->numDataCol )
217 /* return the raid address of the start of the indicates stripe ID */
218 #define rf_StripeIDToRaidAddress(_layoutPtr_, _sid_) \
219 ( ((_sid_) * (_layoutPtr_)->sectorsPerStripeUnit) * (_layoutPtr_)->numDataCol )
221 /* return the identifier of the stripe containing the given stripe unit id */
222 #define rf_StripeUnitIDToStripeID(_layoutPtr_, _addr_) \
223 ( (_addr_) / (_layoutPtr_)->numDataCol )
225 /* return the identifier of the stripe unit containing the given address */
226 #define rf_RaidAddressToStripeUnitID(_layoutPtr_, _addr_) \
227 ( ((_addr_) / (_layoutPtr_)->sectorsPerStripeUnit) )
229 /* return the RAID address of next stripe boundary beyond the given address */
230 #define rf_RaidAddressOfNextStripeBoundary(_layoutPtr_, _addr_) \
231 ( (((_addr_)/(_layoutPtr_)->dataSectorsPerStripe)+1) * (_layoutPtr_)->dataSectorsPerStripe )
233 /* return the RAID address of the start of the stripe containing the given address */
234 #define rf_RaidAddressOfPrevStripeBoundary(_layoutPtr_, _addr_) \
235 ( (((_addr_)/(_layoutPtr_)->dataSectorsPerStripe)+0) * (_layoutPtr_)->dataSectorsPerStripe )
237 /* return the RAID address of next stripe unit boundary beyond the given address */
238 #define rf_RaidAddressOfNextStripeUnitBoundary(_layoutPtr_, _addr_) \
239 ( (((_addr_)/(_layoutPtr_)->sectorsPerStripeUnit)+1L)*(_layoutPtr_)->sectorsPerStripeUnit )
241 /* return the RAID address of the start of the stripe unit containing RAID address _addr_ */
242 #define rf_RaidAddressOfPrevStripeUnitBoundary(_layoutPtr_, _addr_) \
243 ( (((_addr_)/(_layoutPtr_)->sectorsPerStripeUnit)+0)*(_layoutPtr_)->sectorsPerStripeUnit )
245 /* returns the offset into the stripe. used by RaidAddressStripeAligned */
246 #define rf_RaidAddressStripeOffset(_layoutPtr_, _addr_) \
247 ( (_addr_) % ((_layoutPtr_)->dataSectorsPerStripe) )
249 /* returns the offset into the stripe unit. */
250 #define rf_StripeUnitOffset(_layoutPtr_, _addr_) \
251 ( (_addr_) % ((_layoutPtr_)->sectorsPerStripeUnit) )
253 /* returns nonzero if the given RAID address is stripe-aligned */
254 #define rf_RaidAddressStripeAligned( __layoutPtr__, __addr__ ) \
255 ( rf_RaidAddressStripeOffset(__layoutPtr__, __addr__) == 0 )
257 /* returns nonzero if the given address is stripe-unit aligned */
258 #define rf_StripeUnitAligned( __layoutPtr__, __addr__ ) \
259 ( rf_StripeUnitOffset(__layoutPtr__, __addr__) == 0 )
261 /* convert an address expressed in RAID blocks to/from an addr expressed in bytes */
262 #define rf_RaidAddressToByte(_raidPtr_, _addr_) \
263 ( (_addr_) << ( (_raidPtr_)->logBytesPerSector ) )
265 #define rf_ByteToRaidAddress(_raidPtr_, _addr_) \
266 ( (_addr_) >> ( (_raidPtr_)->logBytesPerSector ) )
268 /* convert a raid address to/from a parity stripe ID. Conversion to raid address is easy,
269 * since we're asking for the address of the first sector in the parity stripe. Conversion to a
270 * parity stripe ID is more complex, since stripes are not contiguously allocated in
273 #define rf_RaidAddressToParityStripeID(_layoutPtr_, _addr_, _ru_num_) \
274 rf_MapStripeIDToParityStripeID( (_layoutPtr_), rf_RaidAddressToStripeID( (_layoutPtr_), (_addr_) ), (_ru_num_) )
276 #define rf_ParityStripeIDToRaidAddress(_layoutPtr_, _psid_) \
277 ( (_psid_) * (_layoutPtr_)->SUsPerPU * (_layoutPtr_)->numDataCol * (_layoutPtr_)->sectorsPerStripeUnit )
279 const RF_LayoutSW_t
*rf_GetLayout(RF_ParityConfig_t parityConfig
);
281 rf_ConfigureLayout(RF_ShutdownList_t
** listp
, RF_Raid_t
* raidPtr
,
282 RF_Config_t
* cfgPtr
);
284 rf_MapStripeIDToParityStripeID(RF_RaidLayout_t
* layoutPtr
,
285 RF_StripeNum_t stripeID
, RF_ReconUnitNum_t
* which_ru
);
287 #endif /* !_RF__RF_LAYOUT_H_ */