rf_reconutil.c revision 1.32
1/* $NetBSD: rf_reconutil.c,v 1.32 2011/05/02 01:07:24 mrg Exp $ */ 2/* 3 * Copyright (c) 1995 Carnegie-Mellon University. 4 * All rights reserved. 5 * 6 * Author: Mark Holland 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 * rf_reconutil.c -- reconstruction utilities 31 ********************************************/ 32 33#include <sys/cdefs.h> 34__KERNEL_RCSID(0, "$NetBSD: rf_reconutil.c,v 1.32 2011/05/02 01:07:24 mrg Exp $"); 35 36#include <dev/raidframe/raidframevar.h> 37 38#include "rf_raid.h" 39#include "rf_desc.h" 40#include "rf_reconutil.h" 41#include "rf_reconbuffer.h" 42#include "rf_general.h" 43#include "rf_decluster.h" 44#include "rf_raid5_rotatedspare.h" 45#include "rf_interdecluster.h" 46#include "rf_chaindecluster.h" 47 48/******************************************************************* 49 * allocates/frees the reconstruction control information structures 50 *******************************************************************/ 51 52/* fcol - failed column 53 * scol - identifies which spare we are using 54 */ 55 56RF_ReconCtrl_t * 57rf_MakeReconControl(RF_RaidReconDesc_t *reconDesc, 58 RF_RowCol_t fcol, RF_RowCol_t scol) 59{ 60 RF_Raid_t *raidPtr = reconDesc->raidPtr; 61 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout; 62 RF_ReconUnitCount_t RUsPerPU = layoutPtr->SUsPerPU / layoutPtr->SUsPerRU; 63 RF_ReconUnitCount_t numSpareRUs; 64 RF_ReconCtrl_t *reconCtrlPtr; 65 RF_ReconBuffer_t *rbuf; 66 const RF_LayoutSW_t *lp; 67#if (RF_INCLUDE_PARITY_DECLUSTERING_DS > 0) 68 int retcode; 69#endif 70 RF_RowCol_t i; 71 72 lp = raidPtr->Layout.map; 73 74 /* make and zero the global reconstruction structure and the per-disk 75 * structure */ 76 RF_Malloc(reconCtrlPtr, sizeof(RF_ReconCtrl_t), (RF_ReconCtrl_t *)); 77 78 /* note: this zeros the perDiskInfo */ 79 RF_Malloc(reconCtrlPtr->perDiskInfo, raidPtr->numCol * 80 sizeof(RF_PerDiskReconCtrl_t), (RF_PerDiskReconCtrl_t *)); 81 reconCtrlPtr->reconDesc = reconDesc; 82 reconCtrlPtr->fcol = fcol; 83 reconCtrlPtr->spareCol = scol; 84 reconCtrlPtr->lastPSID = layoutPtr->numStripe / layoutPtr->SUsPerPU; 85 reconCtrlPtr->percentComplete = 0; 86 reconCtrlPtr->error = 0; 87 reconCtrlPtr->pending_writes = 0; 88 89 /* initialize each per-disk recon information structure */ 90 for (i = 0; i < raidPtr->numCol; i++) { 91 reconCtrlPtr->perDiskInfo[i].reconCtrl = reconCtrlPtr; 92 reconCtrlPtr->perDiskInfo[i].col = i; 93 /* make it appear as if we just finished an RU */ 94 reconCtrlPtr->perDiskInfo[i].curPSID = -1; 95 reconCtrlPtr->perDiskInfo[i].ru_count = RUsPerPU - 1; 96 } 97 98 /* Get the number of spare units per disk and the sparemap in case 99 * spare is distributed */ 100 101 if (lp->GetNumSpareRUs) { 102 numSpareRUs = lp->GetNumSpareRUs(raidPtr); 103 } else { 104 numSpareRUs = 0; 105 } 106 107#if (RF_INCLUDE_PARITY_DECLUSTERING_DS > 0) 108 /* 109 * Not all distributed sparing archs need dynamic mappings 110 */ 111 if (lp->InstallSpareTable) { 112 retcode = rf_InstallSpareTable(raidPtr, 0, fcol); 113 if (retcode) { 114 RF_PANIC(); /* XXX fix this */ 115 } 116 } 117#endif 118 /* make the reconstruction map */ 119 reconCtrlPtr->reconMap = rf_MakeReconMap(raidPtr, (int) (layoutPtr->SUsPerRU * layoutPtr->sectorsPerStripeUnit), 120 raidPtr->sectorsPerDisk, numSpareRUs); 121 122 /* make the per-disk reconstruction buffers */ 123 for (i = 0; i < raidPtr->numCol; i++) { 124 reconCtrlPtr->perDiskInfo[i].rbuf = (i == fcol) ? NULL : rf_MakeReconBuffer(raidPtr, i, RF_RBUF_TYPE_EXCLUSIVE); 125 } 126 127 /* initialize the event queue */ 128 rf_init_mutex2(reconCtrlPtr->eq_mutex, IPL_VM); 129 rf_init_cond2(reconCtrlPtr->eq_cv, "rfevq"); 130 131 reconCtrlPtr->eventQueue = NULL; 132 reconCtrlPtr->eq_count = 0; 133 134 /* make the floating recon buffers and append them to the free list */ 135 rf_mutex_init(&reconCtrlPtr->rb_mutex); 136 137 reconCtrlPtr->fullBufferList = NULL; 138 reconCtrlPtr->floatingRbufs = NULL; 139 reconCtrlPtr->committedRbufs = NULL; 140 for (i = 0; i < raidPtr->numFloatingReconBufs; i++) { 141 rbuf = rf_MakeReconBuffer(raidPtr, fcol, 142 RF_RBUF_TYPE_FLOATING); 143 rbuf->next = reconCtrlPtr->floatingRbufs; 144 reconCtrlPtr->floatingRbufs = rbuf; 145 } 146 147 /* create the parity stripe status table */ 148 reconCtrlPtr->pssTable = rf_MakeParityStripeStatusTable(raidPtr); 149 150 /* set the initial min head sep counter val */ 151 reconCtrlPtr->minHeadSepCounter = 0; 152 153 return (reconCtrlPtr); 154} 155 156void 157rf_FreeReconControl(RF_Raid_t *raidPtr) 158{ 159 RF_ReconCtrl_t *reconCtrlPtr = raidPtr->reconControl; 160 RF_ReconBuffer_t *t; 161 RF_ReconUnitNum_t i; 162 163 RF_ASSERT(reconCtrlPtr); 164 for (i = 0; i < raidPtr->numCol; i++) 165 if (reconCtrlPtr->perDiskInfo[i].rbuf) 166 rf_FreeReconBuffer(reconCtrlPtr->perDiskInfo[i].rbuf); 167 168 t = reconCtrlPtr->floatingRbufs; 169 while (t) { 170 reconCtrlPtr->floatingRbufs = t->next; 171 rf_FreeReconBuffer(t); 172 t = reconCtrlPtr->floatingRbufs; 173 } 174 175 rf_destroy_mutex2(reconCtrlPtr->eq_mutex); 176 rf_destroy_cond2(reconCtrlPtr->eq_cv); 177 178 rf_FreeReconMap(reconCtrlPtr->reconMap); 179 rf_FreeParityStripeStatusTable(raidPtr, reconCtrlPtr->pssTable); 180 RF_Free(reconCtrlPtr->perDiskInfo, 181 raidPtr->numCol * sizeof(RF_PerDiskReconCtrl_t)); 182 RF_Free(reconCtrlPtr, sizeof(*reconCtrlPtr)); 183} 184 185 186/****************************************************************************** 187 * computes the default head separation limit 188 *****************************************************************************/ 189RF_HeadSepLimit_t 190rf_GetDefaultHeadSepLimit(RF_Raid_t *raidPtr) 191{ 192 RF_HeadSepLimit_t hsl; 193 const RF_LayoutSW_t *lp; 194 195 lp = raidPtr->Layout.map; 196 if (lp->GetDefaultHeadSepLimit == NULL) 197 return (-1); 198 hsl = lp->GetDefaultHeadSepLimit(raidPtr); 199 return (hsl); 200} 201 202 203/****************************************************************************** 204 * computes the default number of floating recon buffers 205 *****************************************************************************/ 206int 207rf_GetDefaultNumFloatingReconBuffers(RF_Raid_t *raidPtr) 208{ 209 const RF_LayoutSW_t *lp; 210 int nrb; 211 212 lp = raidPtr->Layout.map; 213 if (lp->GetDefaultNumFloatingReconBuffers == NULL) 214 return (3 * raidPtr->numCol); 215 nrb = lp->GetDefaultNumFloatingReconBuffers(raidPtr); 216 return (nrb); 217} 218 219 220/****************************************************************************** 221 * creates and initializes a reconstruction buffer 222 *****************************************************************************/ 223RF_ReconBuffer_t * 224rf_MakeReconBuffer(RF_Raid_t *raidPtr, RF_RowCol_t col, RF_RbufType_t type) 225{ 226 RF_RaidLayout_t *layoutPtr = &raidPtr->Layout; 227 RF_ReconBuffer_t *t; 228 u_int recon_buffer_size = rf_RaidAddressToByte(raidPtr, layoutPtr->SUsPerRU * layoutPtr->sectorsPerStripeUnit); 229 230 t = pool_get(&rf_pools.reconbuffer, PR_WAITOK); 231 RF_Malloc(t->buffer, recon_buffer_size, (void *)); 232 t->raidPtr = raidPtr; 233 t->col = col; 234 t->priority = RF_IO_RECON_PRIORITY; 235 t->type = type; 236 t->pssPtr = NULL; 237 t->next = NULL; 238 return (t); 239} 240/****************************************************************************** 241 * frees a reconstruction buffer 242 *****************************************************************************/ 243void 244rf_FreeReconBuffer(RF_ReconBuffer_t *rbuf) 245{ 246 RF_Raid_t *raidPtr = rbuf->raidPtr; 247 u_int recon_buffer_size; 248 249 recon_buffer_size = rf_RaidAddressToByte(raidPtr, raidPtr->Layout.SUsPerRU * raidPtr->Layout.sectorsPerStripeUnit); 250 251 RF_Free(rbuf->buffer, recon_buffer_size); 252 pool_put(&rf_pools.reconbuffer, rbuf); 253} 254 255#if RF_DEBUG_RECON 256XXXX IF you use this, you really want to fix the locking in here. 257/****************************************************************************** 258 * debug only: sanity check the number of floating recon bufs in use 259 *****************************************************************************/ 260void 261rf_CheckFloatingRbufCount(RF_Raid_t *raidPtr, int dolock) 262{ 263 RF_ReconParityStripeStatus_t *p; 264 RF_PSStatusHeader_t *pssTable; 265 RF_ReconBuffer_t *rbuf; 266 int i, j, sum = 0; 267 268 if (dolock) 269 RF_LOCK_MUTEX(raidPtr->reconControl->rb_mutex); 270 pssTable = raidPtr->reconControl->pssTable; 271 272 for (i = 0; i < raidPtr->pssTableSize; i++) { 273 RF_LOCK_MUTEX(pssTable[i].mutex); 274 for (p = pssTable[i].chain; p; p = p->next) { 275 rbuf = (RF_ReconBuffer_t *) p->rbuf; 276 if (rbuf && rbuf->type == RF_RBUF_TYPE_FLOATING) 277 sum++; 278 279 rbuf = (RF_ReconBuffer_t *) p->writeRbuf; 280 if (rbuf && rbuf->type == RF_RBUF_TYPE_FLOATING) 281 sum++; 282 283 for (j = 0; j < p->xorBufCount; j++) { 284 rbuf = (RF_ReconBuffer_t *) p->rbufsForXor[j]; 285 RF_ASSERT(rbuf); 286 if (rbuf->type == RF_RBUF_TYPE_FLOATING) 287 sum++; 288 } 289 } 290 RF_UNLOCK_MUTEX(pssTable[i].mutex); 291 } 292 293 for (rbuf = raidPtr->reconControl->floatingRbufs; rbuf; 294 rbuf = rbuf->next) { 295 if (rbuf->type == RF_RBUF_TYPE_FLOATING) 296 sum++; 297 } 298 for (rbuf = raidPtr->reconControl->committedRbufs; rbuf; 299 rbuf = rbuf->next) { 300 if (rbuf->type == RF_RBUF_TYPE_FLOATING) 301 sum++; 302 } 303 for (rbuf = raidPtr->reconControl->fullBufferList; rbuf; 304 rbuf = rbuf->next) { 305 if (rbuf->type == RF_RBUF_TYPE_FLOATING) 306 sum++; 307 } 308 RF_ASSERT(sum == raidPtr->numFloatingReconBufs); 309 310 if (dolock) 311 RF_UNLOCK_MUTEX(raidPtr->reconControl->rb_mutex); 312} 313#endif 314 315