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