xref: /netbsd-src/sys/dev/raidframe/rf_interdecluster.c (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1 /*	$NetBSD: rf_interdecluster.c,v 1.5 2001/01/26 05:09:13 oster Exp $	*/
2 /*
3  * Copyright (c) 1995 Carnegie-Mellon University.
4  * All rights reserved.
5  *
6  * Author: Khalil Amiri
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 /************************************************************
30  *
31  * rf_interdecluster.c -- implements interleaved declustering
32  *
33  ************************************************************/
34 
35 #include "rf_archs.h"
36 
37 #if RF_INCLUDE_INTERDECLUSTER > 0
38 
39 #include "rf_types.h"
40 #include "rf_raid.h"
41 #include "rf_interdecluster.h"
42 #include "rf_dag.h"
43 #include "rf_dagutils.h"
44 #include "rf_dagfuncs.h"
45 #include "rf_general.h"
46 #include "rf_utils.h"
47 #include "rf_dagffrd.h"
48 #include "rf_dagdegrd.h"
49 #include "rf_dagffwr.h"
50 #include "rf_dagdegwr.h"
51 
52 typedef struct RF_InterdeclusterConfigInfo_s {
53 	RF_RowCol_t **stripeIdentifier;	/* filled in at config time and used
54 					 * by IdentifyStripe */
55 	RF_StripeCount_t numSparingRegions;
56 	RF_StripeCount_t stripeUnitsPerSparingRegion;
57 	RF_SectorNum_t mirrorStripeOffset;
58 }       RF_InterdeclusterConfigInfo_t;
59 
60 int
61 rf_ConfigureInterDecluster(
62     RF_ShutdownList_t ** listp,
63     RF_Raid_t * raidPtr,
64     RF_Config_t * cfgPtr)
65 {
66 	RF_RaidLayout_t *layoutPtr = &raidPtr->Layout;
67 	RF_StripeCount_t num_used_stripeUnitsPerDisk;
68 	RF_InterdeclusterConfigInfo_t *info;
69 	RF_RowCol_t i, tmp, SUs_per_region;
70 
71 	/* create an Interleaved Declustering configuration structure */
72 	RF_MallocAndAdd(info, sizeof(RF_InterdeclusterConfigInfo_t), (RF_InterdeclusterConfigInfo_t *),
73 	    raidPtr->cleanupList);
74 	if (info == NULL)
75 		return (ENOMEM);
76 	layoutPtr->layoutSpecificInfo = (void *) info;
77 
78 	/* fill in the config structure.  */
79 	SUs_per_region = raidPtr->numCol * (raidPtr->numCol - 1);
80 	info->stripeIdentifier = rf_make_2d_array(SUs_per_region, 2, raidPtr->cleanupList);
81 	if (info->stripeIdentifier == NULL)
82 		return (ENOMEM);
83 	for (i = 0; i < SUs_per_region; i++) {
84 		info->stripeIdentifier[i][0] = i / (raidPtr->numCol - 1);
85 		tmp = i / raidPtr->numCol;
86 		info->stripeIdentifier[i][1] = (i + 1 + tmp) % raidPtr->numCol;
87 	}
88 
89 	/* no spare tables */
90 	RF_ASSERT(raidPtr->numRow == 1);
91 
92 	/* fill in the remaining layout parameters */
93 
94 	/* total number of stripes should a multiple of 2*numCol: Each sparing
95 	 * region consists of 2*numCol stripes: n-1 primary copy, n-1
96 	 * secondary copy and 2 for spare .. */
97 	num_used_stripeUnitsPerDisk = layoutPtr->stripeUnitsPerDisk - (layoutPtr->stripeUnitsPerDisk %
98 	    (2 * raidPtr->numCol));
99 	info->numSparingRegions = num_used_stripeUnitsPerDisk / (2 * raidPtr->numCol);
100 	/* this is in fact the number of stripe units (that are primary data
101 	 * copies) in the sparing region */
102 	info->stripeUnitsPerSparingRegion = raidPtr->numCol * (raidPtr->numCol - 1);
103 	info->mirrorStripeOffset = info->numSparingRegions * (raidPtr->numCol + 1);
104 	layoutPtr->numStripe = info->numSparingRegions * info->stripeUnitsPerSparingRegion;
105 	layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector;
106 	layoutPtr->numDataCol = 1;
107 	layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit;
108 	layoutPtr->numParityCol = 1;
109 
110 	layoutPtr->dataStripeUnitsPerDisk = num_used_stripeUnitsPerDisk;
111 
112 	raidPtr->sectorsPerDisk =
113 	    num_used_stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit;
114 
115 	raidPtr->totalSectors =
116 	    (layoutPtr->numStripe) * layoutPtr->sectorsPerStripeUnit;
117 
118 	layoutPtr->stripeUnitsPerDisk = raidPtr->sectorsPerDisk / layoutPtr->sectorsPerStripeUnit;
119 
120 	return (0);
121 }
122 
123 int
124 rf_GetDefaultNumFloatingReconBuffersInterDecluster(RF_Raid_t * raidPtr)
125 {
126 	return (30);
127 }
128 
129 RF_HeadSepLimit_t
130 rf_GetDefaultHeadSepLimitInterDecluster(RF_Raid_t * raidPtr)
131 {
132 	return (raidPtr->sectorsPerDisk);
133 }
134 
135 RF_ReconUnitCount_t
136 rf_GetNumSpareRUsInterDecluster(
137     RF_Raid_t * raidPtr)
138 {
139 	RF_InterdeclusterConfigInfo_t *info = (RF_InterdeclusterConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
140 
141 	return (2 * ((RF_ReconUnitCount_t) info->numSparingRegions));
142 	/* the layout uses two stripe units per disk as spare within each
143 	 * sparing region */
144 }
145 /* Maps to the primary copy of the data, i.e. the first mirror pair */
146 void
147 rf_MapSectorInterDecluster(
148     RF_Raid_t * raidPtr,
149     RF_RaidAddr_t raidSector,
150     RF_RowCol_t * row,
151     RF_RowCol_t * col,
152     RF_SectorNum_t * diskSector,
153     int remap)
154 {
155 	RF_InterdeclusterConfigInfo_t *info = (RF_InterdeclusterConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
156 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
157 	RF_StripeNum_t su_offset_into_disk, mirror_su_offset_into_disk;
158 	RF_StripeNum_t sparing_region_id, index_within_region;
159 	int     col_before_remap;
160 
161 	*row = 0;
162 	sparing_region_id = SUID / info->stripeUnitsPerSparingRegion;
163 	index_within_region = SUID % info->stripeUnitsPerSparingRegion;
164 	su_offset_into_disk = index_within_region % (raidPtr->numCol - 1);
165 	mirror_su_offset_into_disk = index_within_region / raidPtr->numCol;
166 	col_before_remap = index_within_region / (raidPtr->numCol - 1);
167 
168 	if (!remap) {
169 		*col = col_before_remap;;
170 		*diskSector = (su_offset_into_disk + ((raidPtr->numCol - 1) * sparing_region_id)) *
171 		    raidPtr->Layout.sectorsPerStripeUnit;
172 		*diskSector += (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
173 	} else {
174 		/* remap sector to spare space... */
175 		*diskSector = sparing_region_id * (raidPtr->numCol + 1) * raidPtr->Layout.sectorsPerStripeUnit;
176 		*diskSector += (raidPtr->numCol - 1) * raidPtr->Layout.sectorsPerStripeUnit;
177 		*diskSector += (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
178 		*col = (index_within_region + 1 + mirror_su_offset_into_disk) % raidPtr->numCol;
179 		*col = (*col + 1) % raidPtr->numCol;
180 		if (*col == col_before_remap)
181 			*col = (*col + 1) % raidPtr->numCol;
182 	}
183 }
184 /* Maps to the second copy of the mirror pair. */
185 void
186 rf_MapParityInterDecluster(
187     RF_Raid_t * raidPtr,
188     RF_RaidAddr_t raidSector,
189     RF_RowCol_t * row,
190     RF_RowCol_t * col,
191     RF_SectorNum_t * diskSector,
192     int remap)
193 {
194 	RF_InterdeclusterConfigInfo_t *info = (RF_InterdeclusterConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
195 	RF_StripeNum_t sparing_region_id, index_within_region, mirror_su_offset_into_disk;
196 	RF_StripeNum_t SUID = raidSector / raidPtr->Layout.sectorsPerStripeUnit;
197 	int     col_before_remap;
198 
199 	sparing_region_id = SUID / info->stripeUnitsPerSparingRegion;
200 	index_within_region = SUID % info->stripeUnitsPerSparingRegion;
201 	mirror_su_offset_into_disk = index_within_region / raidPtr->numCol;
202 	col_before_remap = (index_within_region + 1 + mirror_su_offset_into_disk) % raidPtr->numCol;
203 
204 	*row = 0;
205 	if (!remap) {
206 		*col = col_before_remap;
207 		*diskSector = info->mirrorStripeOffset * raidPtr->Layout.sectorsPerStripeUnit;
208 		*diskSector += sparing_region_id * (raidPtr->numCol - 1) * raidPtr->Layout.sectorsPerStripeUnit;
209 		*diskSector += mirror_su_offset_into_disk * raidPtr->Layout.sectorsPerStripeUnit;
210 		*diskSector += (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
211 	} else {
212 		/* remap parity to spare space ... */
213 		*diskSector = sparing_region_id * (raidPtr->numCol + 1) * raidPtr->Layout.sectorsPerStripeUnit;
214 		*diskSector += (raidPtr->numCol) * raidPtr->Layout.sectorsPerStripeUnit;
215 		*diskSector += (raidSector % raidPtr->Layout.sectorsPerStripeUnit);
216 		*col = index_within_region / (raidPtr->numCol - 1);
217 		*col = (*col + 1) % raidPtr->numCol;
218 		if (*col == col_before_remap)
219 			*col = (*col + 1) % raidPtr->numCol;
220 	}
221 }
222 
223 void
224 rf_IdentifyStripeInterDecluster(
225     RF_Raid_t * raidPtr,
226     RF_RaidAddr_t addr,
227     RF_RowCol_t ** diskids,
228     RF_RowCol_t * outRow)
229 {
230 	RF_InterdeclusterConfigInfo_t *info = (RF_InterdeclusterConfigInfo_t *) raidPtr->Layout.layoutSpecificInfo;
231 	RF_StripeNum_t SUID;
232 
233 	SUID = addr / raidPtr->Layout.sectorsPerStripeUnit;
234 	SUID = SUID % info->stripeUnitsPerSparingRegion;
235 
236 	*outRow = 0;
237 	*diskids = info->stripeIdentifier[SUID];
238 }
239 
240 void
241 rf_MapSIDToPSIDInterDecluster(
242     RF_RaidLayout_t * layoutPtr,
243     RF_StripeNum_t stripeID,
244     RF_StripeNum_t * psID,
245     RF_ReconUnitNum_t * which_ru)
246 {
247 	*which_ru = 0;
248 	*psID = stripeID;
249 }
250 /******************************************************************************
251  * select a graph to perform a single-stripe access
252  *
253  * Parameters:  raidPtr    - description of the physical array
254  *              type       - type of operation (read or write) requested
255  *              asmap      - logical & physical addresses for this access
256  *              createFunc - name of function to use to create the graph
257  *****************************************************************************/
258 
259 void
260 rf_RAIDIDagSelect(
261     RF_Raid_t * raidPtr,
262     RF_IoType_t type,
263     RF_AccessStripeMap_t * asmap,
264     RF_VoidFuncPtr * createFunc)
265 {
266 	RF_ASSERT(RF_IO_IS_R_OR_W(type));
267 
268 	if (asmap->numDataFailed + asmap->numParityFailed > 1) {
269 		RF_ERRORMSG("Multiple disks failed in a single group!  Aborting I/O operation.\n");
270 		*createFunc = NULL;
271 		return;
272 	}
273 	*createFunc = (type == RF_IO_TYPE_READ) ? (RF_VoidFuncPtr) rf_CreateFaultFreeReadDAG : (RF_VoidFuncPtr) rf_CreateRaidOneWriteDAG;
274 	if (type == RF_IO_TYPE_READ) {
275 		if (asmap->numDataFailed == 0)
276 			*createFunc = (RF_VoidFuncPtr) rf_CreateMirrorPartitionReadDAG;
277 		else
278 			*createFunc = (RF_VoidFuncPtr) rf_CreateRaidOneDegradedReadDAG;
279 	} else
280 		*createFunc = (RF_VoidFuncPtr) rf_CreateRaidOneWriteDAG;
281 }
282 #endif /* RF_INCLUDE_INTERDECLUSTER > 0 */
283