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