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