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