xref: /netbsd/sys/dev/raidframe/rf_layout.h (revision bf9ec67e)
1 /*	$NetBSD: rf_layout.h,v 1.7 2001/10/05 15:41:23 oster 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 <dev/raidframe/raidframevar.h>
36 #include "rf_archs.h"
37 #include "rf_alloclist.h"
38 
39 /* enables remapping to spare location under dist sparing */
40 #define RF_REMAP       1
41 #define RF_DONT_REMAP  0
42 
43 /*
44  * Flags values for RF_AccessStripeMapFlags_t
45  */
46 #define RF_NO_STRIPE_LOCKS   0x0001	/* suppress stripe locks */
47 #define RF_DISTRIBUTE_SPARE  0x0002	/* distribute spare space in archs
48 					 * that support it */
49 #define RF_BD_DECLUSTERED    0x0004	/* declustering uses block designs */
50 
51 /*************************************************************************
52  *
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.
56  *
57  *************************************************************************/
58 struct RF_RaidLayout_s {
59 	/* configuration parameters */
60 	RF_SectorCount_t sectorsPerStripeUnit;	/* number of sectors in one
61 						 * stripe unit */
62 	RF_StripeCount_t SUsPerPU;	/* stripe units per parity unit */
63 	RF_StripeCount_t SUsPerRU;	/* stripe units per reconstruction
64 					 * unit */
65 
66 	/* redundant-but-useful info computed from the above, used in all
67 	 * layouts */
68 	RF_StripeCount_t numStripe;	/* total number of stripes in the
69 					 * array */
70 	RF_SectorCount_t dataSectorsPerStripe;
71 	RF_StripeCount_t dataStripeUnitsPerDisk;
72 	u_int   bytesPerStripeUnit;
73 	u_int   dataBytesPerStripe;
74 	RF_StripeCount_t numDataCol;	/* number of SUs of data per stripe
75 					 * (name here is a la RAID4) */
76 	RF_StripeCount_t numParityCol;	/* number of SUs of parity per stripe.
77 					 * Always 1 for now */
78 	RF_StripeCount_t numParityLogCol;	/* number of SUs of parity log
79 						 * per stripe.  Always 1 for
80 						 * now */
81 	RF_StripeCount_t stripeUnitsPerDisk;
82 
83 	RF_LayoutSW_t *map;	/* ptr to struct holding mapping fns and
84 				 * information */
85 	void   *layoutSpecificInfo;	/* ptr to a structure holding
86 					 * layout-specific params */
87 };
88 /*****************************************************************************************
89  *
90  * The mapping code returns a pointer to a list of AccessStripeMap structures, which
91  * describes all the mapping information about an access.  The list contains one
92  * AccessStripeMap structure per stripe touched by the access.  Each element in the list
93  * contains a stripe identifier and a pointer to a list of PhysDiskAddr structuress.  Each
94  * element in this latter list describes the physical location of a stripe unit accessed
95  * within the corresponding stripe.
96  *
97  ****************************************************************************************/
98 
99 #define RF_PDA_TYPE_DATA   0
100 #define RF_PDA_TYPE_PARITY 1
101 #define RF_PDA_TYPE_Q      2
102 
103 struct RF_PhysDiskAddr_s {
104 	RF_RowCol_t row, col;	/* disk identifier */
105 	RF_SectorNum_t startSector;	/* sector offset into the disk */
106 	RF_SectorCount_t numSector;	/* number of sectors accessed */
107 	int     type;		/* used by higher levels: currently, data,
108 				 * parity, or q */
109 	caddr_t bufPtr;		/* pointer to buffer supplying/receiving data */
110 	RF_RaidAddr_t raidAddress;	/* raid address corresponding to this
111 					 * physical disk address */
112 	RF_PhysDiskAddr_t *next;
113 };
114 #define RF_MAX_FAILED_PDA RF_MAXCOL
115 
116 struct RF_AccessStripeMap_s {
117 	RF_StripeNum_t stripeID;/* the stripe index */
118 	RF_RaidAddr_t raidAddress;	/* the starting raid address within
119 					 * this stripe */
120 	RF_RaidAddr_t endRaidAddress;	/* raid address one sector past the
121 					 * end of the access */
122 	RF_SectorCount_t totalSectorsAccessed;	/* total num sectors
123 						 * identified in physInfo list */
124 	RF_StripeCount_t numStripeUnitsAccessed;	/* total num elements in
125 							 * physInfo list */
126 	int     numDataFailed;	/* number of failed data disks accessed */
127 	int     numParityFailed;/* number of failed parity disks accessed (0
128 				 * or 1) */
129 	int     numQFailed;	/* number of failed Q units accessed (0 or 1) */
130 	RF_AccessStripeMapFlags_t flags;	/* various flags */
131 	int     numFailedPDAs;	/* number of failed phys addrs */
132 	RF_PhysDiskAddr_t *failedPDAs[RF_MAX_FAILED_PDA];	/* array of failed phys
133 								 * addrs */
134 	RF_PhysDiskAddr_t *physInfo;	/* a list of PhysDiskAddr structs */
135 	RF_PhysDiskAddr_t *parityInfo;	/* list of physical addrs for the
136 					 * parity (P of P + Q ) */
137 	RF_PhysDiskAddr_t *qInfo;	/* list of physical addrs for the Q of
138 					 * P + Q */
139 	RF_LockReqDesc_t lockReqDesc;	/* used for stripe locking */
140 	RF_RowCol_t origRow;	/* the original row:  we may redirect the acc
141 				 * to a different row */
142 	RF_AccessStripeMap_t *next;
143 };
144 /* flag values */
145 #define RF_ASM_REDIR_LARGE_WRITE   0x00000001	/* allows large-write creation
146 						 * code to redirect failed
147 						 * accs */
148 #define RF_ASM_BAILOUT_DAG_USED    0x00000002	/* allows us to detect
149 						 * recursive calls to the
150 						 * bailout write dag */
151 #define RF_ASM_FLAGS_LOCK_TRIED    0x00000004	/* we've acquired the lock on
152 						 * the first parity range in
153 						 * this parity stripe */
154 #define RF_ASM_FLAGS_LOCK_TRIED2   0x00000008	/* we've acquired the lock on
155 						 * the 2nd   parity range in
156 						 * this parity stripe */
157 #define RF_ASM_FLAGS_FORCE_TRIED   0x00000010	/* we've done the force-recon
158 						 * call on this parity stripe */
159 #define RF_ASM_FLAGS_RECON_BLOCKED 0x00000020	/* we blocked recon => we must
160 						 * unblock it later */
161 
162 struct RF_AccessStripeMapHeader_s {
163 	RF_StripeCount_t numStripes;	/* total number of stripes touched by
164 					 * this acc */
165 	RF_AccessStripeMap_t *stripeMap;	/* pointer to the actual map.
166 						 * Also used for making lists */
167 	RF_AccessStripeMapHeader_t *next;
168 };
169 /*****************************************************************************************
170  *
171  * various routines mapping addresses in the RAID address space.  These work across
172  * all layouts.  DON'T PUT ANY LAYOUT-SPECIFIC CODE HERE.
173  *
174  ****************************************************************************************/
175 
176 /* return the identifier of the stripe containing the given address */
177 #define rf_RaidAddressToStripeID(_layoutPtr_, _addr_) \
178   ( ((_addr_) / (_layoutPtr_)->sectorsPerStripeUnit) / (_layoutPtr_)->numDataCol )
179 
180 /* return the raid address of the start of the indicates stripe ID */
181 #define rf_StripeIDToRaidAddress(_layoutPtr_, _sid_) \
182   ( ((_sid_) * (_layoutPtr_)->sectorsPerStripeUnit) * (_layoutPtr_)->numDataCol )
183 
184 /* return the identifier of the stripe containing the given stripe unit id */
185 #define rf_StripeUnitIDToStripeID(_layoutPtr_, _addr_) \
186   ( (_addr_) / (_layoutPtr_)->numDataCol )
187 
188 /* return the identifier of the stripe unit containing the given address */
189 #define rf_RaidAddressToStripeUnitID(_layoutPtr_, _addr_) \
190   ( ((_addr_) / (_layoutPtr_)->sectorsPerStripeUnit) )
191 
192 /* return the RAID address of next stripe boundary beyond the given address */
193 #define rf_RaidAddressOfNextStripeBoundary(_layoutPtr_, _addr_) \
194   ( (((_addr_)/(_layoutPtr_)->dataSectorsPerStripe)+1) * (_layoutPtr_)->dataSectorsPerStripe )
195 
196 /* return the RAID address of the start of the stripe containing the given address */
197 #define rf_RaidAddressOfPrevStripeBoundary(_layoutPtr_, _addr_) \
198   ( (((_addr_)/(_layoutPtr_)->dataSectorsPerStripe)+0) * (_layoutPtr_)->dataSectorsPerStripe )
199 
200 /* return the RAID address of next stripe unit boundary beyond the given address */
201 #define rf_RaidAddressOfNextStripeUnitBoundary(_layoutPtr_, _addr_) \
202   ( (((_addr_)/(_layoutPtr_)->sectorsPerStripeUnit)+1L)*(_layoutPtr_)->sectorsPerStripeUnit )
203 
204 /* return the RAID address of the start of the stripe unit containing RAID address _addr_ */
205 #define rf_RaidAddressOfPrevStripeUnitBoundary(_layoutPtr_, _addr_) \
206   ( (((_addr_)/(_layoutPtr_)->sectorsPerStripeUnit)+0)*(_layoutPtr_)->sectorsPerStripeUnit )
207 
208 /* returns the offset into the stripe.  used by RaidAddressStripeAligned */
209 #define rf_RaidAddressStripeOffset(_layoutPtr_, _addr_) \
210   ( (_addr_) % ((_layoutPtr_)->dataSectorsPerStripe) )
211 
212 /* returns the offset into the stripe unit.  */
213 #define rf_StripeUnitOffset(_layoutPtr_, _addr_) \
214   ( (_addr_) % ((_layoutPtr_)->sectorsPerStripeUnit) )
215 
216 /* returns nonzero if the given RAID address is stripe-aligned */
217 #define rf_RaidAddressStripeAligned( __layoutPtr__, __addr__ ) \
218   ( rf_RaidAddressStripeOffset(__layoutPtr__, __addr__) == 0 )
219 
220 /* returns nonzero if the given address is stripe-unit aligned */
221 #define rf_StripeUnitAligned( __layoutPtr__, __addr__ ) \
222   ( rf_StripeUnitOffset(__layoutPtr__, __addr__) == 0 )
223 
224 /* convert an address expressed in RAID blocks to/from an addr expressed in bytes */
225 #define rf_RaidAddressToByte(_raidPtr_, _addr_) \
226   ( (_addr_) << ( (_raidPtr_)->logBytesPerSector ) )
227 
228 #define rf_ByteToRaidAddress(_raidPtr_, _addr_) \
229   ( (_addr_) >> ( (_raidPtr_)->logBytesPerSector ) )
230 
231 /* convert a raid address to/from a parity stripe ID.  Conversion to raid address is easy,
232  * since we're asking for the address of the first sector in the parity stripe.  Conversion to a
233  * parity stripe ID is more complex, since stripes are not contiguously allocated in
234  * parity stripes.
235  */
236 #define rf_RaidAddressToParityStripeID(_layoutPtr_, _addr_, _ru_num_) \
237   rf_MapStripeIDToParityStripeID( (_layoutPtr_), rf_RaidAddressToStripeID( (_layoutPtr_), (_addr_) ), (_ru_num_) )
238 
239 #define rf_ParityStripeIDToRaidAddress(_layoutPtr_, _psid_) \
240   ( (_psid_) * (_layoutPtr_)->SUsPerPU * (_layoutPtr_)->numDataCol * (_layoutPtr_)->sectorsPerStripeUnit )
241 
242 RF_LayoutSW_t *rf_GetLayout(RF_ParityConfig_t parityConfig);
243 int
244 rf_ConfigureLayout(RF_ShutdownList_t ** listp, RF_Raid_t * raidPtr,
245     RF_Config_t * cfgPtr);
246 RF_StripeNum_t
247 rf_MapStripeIDToParityStripeID(RF_RaidLayout_t * layoutPtr,
248     RF_StripeNum_t stripeID, RF_ReconUnitNum_t * which_ru);
249 
250 #endif				/* !_RF__RF_LAYOUT_H_ */
251