rf_dagdegwr.c revision 1.13
1/* $NetBSD: rf_dagdegwr.c,v 1.13 2003/12/29 03:33:47 oster Exp $ */ 2/* 3 * Copyright (c) 1995 Carnegie-Mellon University. 4 * All rights reserved. 5 * 6 * Author: Mark Holland, Daniel Stodolsky, William V. Courtright II 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_dagdegwr.c 31 * 32 * code for creating degraded write DAGs 33 * 34 */ 35 36#include <sys/cdefs.h> 37__KERNEL_RCSID(0, "$NetBSD: rf_dagdegwr.c,v 1.13 2003/12/29 03:33:47 oster Exp $"); 38 39#include <dev/raidframe/raidframevar.h> 40 41#include "rf_raid.h" 42#include "rf_dag.h" 43#include "rf_dagutils.h" 44#include "rf_dagfuncs.h" 45#include "rf_debugMem.h" 46#include "rf_general.h" 47#include "rf_dagdegwr.h" 48 49 50/****************************************************************************** 51 * 52 * General comments on DAG creation: 53 * 54 * All DAGs in this file use roll-away error recovery. Each DAG has a single 55 * commit node, usually called "Cmt." If an error occurs before the Cmt node 56 * is reached, the execution engine will halt forward execution and work 57 * backward through the graph, executing the undo functions. Assuming that 58 * each node in the graph prior to the Cmt node are undoable and atomic - or - 59 * does not make changes to permanent state, the graph will fail atomically. 60 * If an error occurs after the Cmt node executes, the engine will roll-forward 61 * through the graph, blindly executing nodes until it reaches the end. 62 * If a graph reaches the end, it is assumed to have completed successfully. 63 * 64 * A graph has only 1 Cmt node. 65 * 66 */ 67 68 69/****************************************************************************** 70 * 71 * The following wrappers map the standard DAG creation interface to the 72 * DAG creation routines. Additionally, these wrappers enable experimentation 73 * with new DAG structures by providing an extra level of indirection, allowing 74 * the DAG creation routines to be replaced at this single point. 75 */ 76 77static 78RF_CREATE_DAG_FUNC_DECL(rf_CreateSimpleDegradedWriteDAG) 79{ 80 rf_CommonCreateSimpleDegradedWriteDAG(raidPtr, asmap, dag_h, bp, 81 flags, allocList, 1, rf_RecoveryXorFunc, RF_TRUE); 82} 83 84void 85rf_CreateDegradedWriteDAG(raidPtr, asmap, dag_h, bp, flags, allocList) 86 RF_Raid_t *raidPtr; 87 RF_AccessStripeMap_t *asmap; 88 RF_DagHeader_t *dag_h; 89 void *bp; 90 RF_RaidAccessFlags_t flags; 91 RF_AllocListElem_t *allocList; 92{ 93 94 RF_ASSERT(asmap->numDataFailed == 1); 95 dag_h->creator = "DegradedWriteDAG"; 96 97 /* 98 * if the access writes only a portion of the failed unit, and also 99 * writes some portion of at least one surviving unit, we create two 100 * DAGs, one for the failed component and one for the non-failed 101 * component, and do them sequentially. Note that the fact that we're 102 * accessing only a portion of the failed unit indicates that the 103 * access either starts or ends in the failed unit, and hence we need 104 * create only two dags. This is inefficient in that the same data or 105 * parity can get read and written twice using this structure. I need 106 * to fix this to do the access all at once. 107 */ 108 RF_ASSERT(!(asmap->numStripeUnitsAccessed != 1 && 109 asmap->failedPDAs[0]->numSector != 110 raidPtr->Layout.sectorsPerStripeUnit)); 111 rf_CreateSimpleDegradedWriteDAG(raidPtr, asmap, dag_h, bp, flags, 112 allocList); 113} 114 115 116 117/****************************************************************************** 118 * 119 * DAG creation code begins here 120 */ 121 122 123 124/****************************************************************************** 125 * 126 * CommonCreateSimpleDegradedWriteDAG -- creates a DAG to do a degraded-mode 127 * write, which is as follows 128 * 129 * / {Wnq} --\ 130 * hdr -> blockNode -> Rod -> Xor -> Cmt -> Wnp ----> unblock -> term 131 * \ {Rod} / \ Wnd ---/ 132 * \ {Wnd} -/ 133 * 134 * commit nodes: Xor, Wnd 135 * 136 * IMPORTANT: 137 * This DAG generator does not work for double-degraded archs since it does not 138 * generate Q 139 * 140 * This dag is essentially identical to the large-write dag, except that the 141 * write to the failed data unit is suppressed. 142 * 143 * IMPORTANT: this dag does not work in the case where the access writes only 144 * a portion of the failed unit, and also writes some portion of at least one 145 * surviving SU. this case is handled in CreateDegradedWriteDAG above. 146 * 147 * The block & unblock nodes are leftovers from a previous version. They 148 * do nothing, but I haven't deleted them because it would be a tremendous 149 * effort to put them back in. 150 * 151 * This dag is used whenever a one of the data units in a write has failed. 152 * If it is the parity unit that failed, the nonredundant write dag (below) 153 * is used. 154 *****************************************************************************/ 155 156void 157rf_CommonCreateSimpleDegradedWriteDAG(raidPtr, asmap, dag_h, bp, flags, 158 allocList, nfaults, redFunc, allowBufferRecycle) 159 RF_Raid_t *raidPtr; 160 RF_AccessStripeMap_t *asmap; 161 RF_DagHeader_t *dag_h; 162 void *bp; 163 RF_RaidAccessFlags_t flags; 164 RF_AllocListElem_t *allocList; 165 int nfaults; 166 int (*redFunc) (RF_DagNode_t *); 167 int allowBufferRecycle; 168{ 169 int nNodes, nRrdNodes, nWndNodes, nXorBufs, i, j, paramNum, 170 rdnodesFaked; 171 RF_DagNode_t *blockNode, *unblockNode, *wnpNode, *wnqNode, *termNode; 172 RF_DagNode_t *nodes, *wndNodes, *rrdNodes, *xorNode, *commitNode; 173 RF_SectorCount_t sectorsPerSU; 174 RF_ReconUnitNum_t which_ru; 175 char *xorTargetBuf = NULL; /* the target buffer for the XOR 176 * operation */ 177 char *overlappingPDAs;/* a temporary array of flags */ 178 RF_AccessStripeMapHeader_t *new_asm_h[2]; 179 RF_PhysDiskAddr_t *pda, *parityPDA; 180 RF_StripeNum_t parityStripeID; 181 RF_PhysDiskAddr_t *failedPDA; 182 RF_RaidLayout_t *layoutPtr; 183 184 layoutPtr = &(raidPtr->Layout); 185 parityStripeID = rf_RaidAddressToParityStripeID(layoutPtr, asmap->raidAddress, 186 &which_ru); 187 sectorsPerSU = layoutPtr->sectorsPerStripeUnit; 188 /* failedPDA points to the pda within the asm that targets the failed 189 * disk */ 190 failedPDA = asmap->failedPDAs[0]; 191 192 if (rf_dagDebug) 193 printf("[Creating degraded-write DAG]\n"); 194 195 RF_ASSERT(asmap->numDataFailed == 1); 196 dag_h->creator = "SimpleDegradedWriteDAG"; 197 198 /* 199 * Generate two ASMs identifying the surviving data 200 * we need in order to recover the lost data. 201 */ 202 /* overlappingPDAs array must be zero'd */ 203 RF_Malloc(overlappingPDAs, asmap->numStripeUnitsAccessed * sizeof(char), (char *)); 204 rf_GenerateFailedAccessASMs(raidPtr, asmap, failedPDA, dag_h, new_asm_h, 205 &nXorBufs, NULL, overlappingPDAs, allocList); 206 207 /* create all the nodes at once */ 208 nWndNodes = asmap->numStripeUnitsAccessed - 1; /* no access is 209 * generated for the 210 * failed pda */ 211 212 nRrdNodes = ((new_asm_h[0]) ? new_asm_h[0]->stripeMap->numStripeUnitsAccessed : 0) + 213 ((new_asm_h[1]) ? new_asm_h[1]->stripeMap->numStripeUnitsAccessed : 0); 214 /* 215 * XXX 216 * 217 * There's a bug with a complete stripe overwrite- that means 0 reads 218 * of old data, and the rest of the DAG generation code doesn't like 219 * that. A release is coming, and I don't wanna risk breaking a critical 220 * DAG generator, so here's what I'm gonna do- if there's no read nodes, 221 * I'm gonna fake there being a read node, and I'm gonna swap in a 222 * no-op node in its place (to make all the link-up code happy). 223 * This should be fixed at some point. --jimz 224 */ 225 if (nRrdNodes == 0) { 226 nRrdNodes = 1; 227 rdnodesFaked = 1; 228 } else { 229 rdnodesFaked = 0; 230 } 231 /* lock, unlock, xor, Wnd, Rrd, W(nfaults) */ 232 nNodes = 5 + nfaults + nWndNodes + nRrdNodes; 233 RF_MallocAndAdd(nodes, nNodes * sizeof(RF_DagNode_t), 234 (RF_DagNode_t *), allocList); 235 i = 0; 236 blockNode = &nodes[i]; 237 i += 1; 238 commitNode = &nodes[i]; 239 i += 1; 240 unblockNode = &nodes[i]; 241 i += 1; 242 termNode = &nodes[i]; 243 i += 1; 244 xorNode = &nodes[i]; 245 i += 1; 246 wnpNode = &nodes[i]; 247 i += 1; 248 wndNodes = &nodes[i]; 249 i += nWndNodes; 250 rrdNodes = &nodes[i]; 251 i += nRrdNodes; 252 if (nfaults == 2) { 253 wnqNode = &nodes[i]; 254 i += 1; 255 } else { 256 wnqNode = NULL; 257 } 258 RF_ASSERT(i == nNodes); 259 260 /* this dag can not commit until all rrd and xor Nodes have completed */ 261 dag_h->numCommitNodes = 1; 262 dag_h->numCommits = 0; 263 dag_h->numSuccedents = 1; 264 265 RF_ASSERT(nRrdNodes > 0); 266 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, 267 NULL, nRrdNodes, 0, 0, 0, dag_h, "Nil", allocList); 268 rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc, 269 NULL, nWndNodes + nfaults, 1, 0, 0, dag_h, "Cmt", allocList); 270 rf_InitNode(unblockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, 271 NULL, 1, nWndNodes + nfaults, 0, 0, dag_h, "Nil", allocList); 272 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc, 273 NULL, 0, 1, 0, 0, dag_h, "Trm", allocList); 274 rf_InitNode(xorNode, rf_wait, RF_FALSE, redFunc, rf_NullNodeUndoFunc, NULL, 1, 275 nRrdNodes, 2 * nXorBufs + 2, nfaults, dag_h, "Xrc", allocList); 276 277 /* 278 * Fill in the Rrd nodes. If any of the rrd buffers are the same size as 279 * the failed buffer, save a pointer to it so we can use it as the target 280 * of the XOR. The pdas in the rrd nodes have been range-restricted, so if 281 * a buffer is the same size as the failed buffer, it must also be at the 282 * same alignment within the SU. 283 */ 284 i = 0; 285 if (new_asm_h[0]) { 286 for (i = 0, pda = new_asm_h[0]->stripeMap->physInfo; 287 i < new_asm_h[0]->stripeMap->numStripeUnitsAccessed; 288 i++, pda = pda->next) { 289 rf_InitNode(&rrdNodes[i], rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc, 290 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Rrd", allocList); 291 RF_ASSERT(pda); 292 rrdNodes[i].params[0].p = pda; 293 rrdNodes[i].params[1].p = pda->bufPtr; 294 rrdNodes[i].params[2].v = parityStripeID; 295 rrdNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru); 296 } 297 } 298 /* i now equals the number of stripe units accessed in new_asm_h[0] */ 299 if (new_asm_h[1]) { 300 for (j = 0, pda = new_asm_h[1]->stripeMap->physInfo; 301 j < new_asm_h[1]->stripeMap->numStripeUnitsAccessed; 302 j++, pda = pda->next) { 303 rf_InitNode(&rrdNodes[i + j], rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc, 304 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Rrd", allocList); 305 RF_ASSERT(pda); 306 rrdNodes[i + j].params[0].p = pda; 307 rrdNodes[i + j].params[1].p = pda->bufPtr; 308 rrdNodes[i + j].params[2].v = parityStripeID; 309 rrdNodes[i + j].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru); 310 if (allowBufferRecycle && (pda->numSector == failedPDA->numSector)) 311 xorTargetBuf = pda->bufPtr; 312 } 313 } 314 if (rdnodesFaked) { 315 /* 316 * This is where we'll init that fake noop read node 317 * (XXX should the wakeup func be different?) 318 */ 319 rf_InitNode(&rrdNodes[0], rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, 320 NULL, 1, 1, 0, 0, dag_h, "RrN", allocList); 321 } 322 /* 323 * Make a PDA for the parity unit. The parity PDA should start at 324 * the same offset into the SU as the failed PDA. 325 */ 326 /* Danner comment: I don't think this copy is really necessary. We are 327 * in one of two cases here. (1) The entire failed unit is written. 328 * Then asmap->parityInfo will describe the entire parity. (2) We are 329 * only writing a subset of the failed unit and nothing else. Then the 330 * asmap->parityInfo describes the failed unit and the copy can also 331 * be avoided. */ 332 333 RF_MallocAndAdd(parityPDA, sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList); 334 parityPDA->col = asmap->parityInfo->col; 335 parityPDA->startSector = ((asmap->parityInfo->startSector / sectorsPerSU) 336 * sectorsPerSU) + (failedPDA->startSector % sectorsPerSU); 337 parityPDA->numSector = failedPDA->numSector; 338 339 if (!xorTargetBuf) { 340 RF_MallocAndAdd(xorTargetBuf, 341 rf_RaidAddressToByte(raidPtr, failedPDA->numSector), (char *), allocList); 342 } 343 /* init the Wnp node */ 344 rf_InitNode(wnpNode, rf_wait, RF_FALSE, rf_DiskWriteFunc, rf_DiskWriteUndoFunc, 345 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Wnp", allocList); 346 wnpNode->params[0].p = parityPDA; 347 wnpNode->params[1].p = xorTargetBuf; 348 wnpNode->params[2].v = parityStripeID; 349 wnpNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru); 350 351 /* fill in the Wnq Node */ 352 if (nfaults == 2) { 353 { 354 RF_MallocAndAdd(parityPDA, sizeof(RF_PhysDiskAddr_t), 355 (RF_PhysDiskAddr_t *), allocList); 356 parityPDA->col = asmap->qInfo->col; 357 parityPDA->startSector = ((asmap->qInfo->startSector / sectorsPerSU) 358 * sectorsPerSU) + (failedPDA->startSector % sectorsPerSU); 359 parityPDA->numSector = failedPDA->numSector; 360 361 rf_InitNode(wnqNode, rf_wait, RF_FALSE, rf_DiskWriteFunc, rf_DiskWriteUndoFunc, 362 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Wnq", allocList); 363 wnqNode->params[0].p = parityPDA; 364 RF_MallocAndAdd(xorNode->results[1], 365 rf_RaidAddressToByte(raidPtr, failedPDA->numSector), (char *), allocList); 366 wnqNode->params[1].p = xorNode->results[1]; 367 wnqNode->params[2].v = parityStripeID; 368 wnqNode->params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru); 369 } 370 } 371 /* fill in the Wnd nodes */ 372 for (pda = asmap->physInfo, i = 0; i < nWndNodes; i++, pda = pda->next) { 373 if (pda == failedPDA) { 374 i--; 375 continue; 376 } 377 rf_InitNode(&wndNodes[i], rf_wait, RF_FALSE, rf_DiskWriteFunc, rf_DiskWriteUndoFunc, 378 rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, "Wnd", allocList); 379 RF_ASSERT(pda); 380 wndNodes[i].params[0].p = pda; 381 wndNodes[i].params[1].p = pda->bufPtr; 382 wndNodes[i].params[2].v = parityStripeID; 383 wndNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru); 384 } 385 386 /* fill in the results of the xor node */ 387 xorNode->results[0] = xorTargetBuf; 388 389 /* fill in the params of the xor node */ 390 391 paramNum = 0; 392 if (rdnodesFaked == 0) { 393 for (i = 0; i < nRrdNodes; i++) { 394 /* all the Rrd nodes need to be xored together */ 395 xorNode->params[paramNum++] = rrdNodes[i].params[0]; 396 xorNode->params[paramNum++] = rrdNodes[i].params[1]; 397 } 398 } 399 for (i = 0; i < nWndNodes; i++) { 400 /* any Wnd nodes that overlap the failed access need to be 401 * xored in */ 402 if (overlappingPDAs[i]) { 403 RF_MallocAndAdd(pda, sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList); 404 memcpy((char *) pda, (char *) wndNodes[i].params[0].p, sizeof(RF_PhysDiskAddr_t)); 405 rf_RangeRestrictPDA(raidPtr, failedPDA, pda, RF_RESTRICT_DOBUFFER, 0); 406 xorNode->params[paramNum++].p = pda; 407 xorNode->params[paramNum++].p = pda->bufPtr; 408 } 409 } 410 RF_Free(overlappingPDAs, asmap->numStripeUnitsAccessed * sizeof(char)); 411 412 /* 413 * Install the failed PDA into the xor param list so that the 414 * new data gets xor'd in. 415 */ 416 xorNode->params[paramNum++].p = failedPDA; 417 xorNode->params[paramNum++].p = failedPDA->bufPtr; 418 419 /* 420 * The last 2 params to the recovery xor node are always the failed 421 * PDA and the raidPtr. install the failedPDA even though we have just 422 * done so above. This allows us to use the same XOR function for both 423 * degraded reads and degraded writes. 424 */ 425 xorNode->params[paramNum++].p = failedPDA; 426 xorNode->params[paramNum++].p = raidPtr; 427 RF_ASSERT(paramNum == 2 * nXorBufs + 2); 428 429 /* 430 * Code to link nodes begins here 431 */ 432 433 /* link header to block node */ 434 RF_ASSERT(blockNode->numAntecedents == 0); 435 dag_h->succedents[0] = blockNode; 436 437 /* link block node to rd nodes */ 438 RF_ASSERT(blockNode->numSuccedents == nRrdNodes); 439 for (i = 0; i < nRrdNodes; i++) { 440 RF_ASSERT(rrdNodes[i].numAntecedents == 1); 441 blockNode->succedents[i] = &rrdNodes[i]; 442 rrdNodes[i].antecedents[0] = blockNode; 443 rrdNodes[i].antType[0] = rf_control; 444 } 445 446 /* link read nodes to xor node */ 447 RF_ASSERT(xorNode->numAntecedents == nRrdNodes); 448 for (i = 0; i < nRrdNodes; i++) { 449 RF_ASSERT(rrdNodes[i].numSuccedents == 1); 450 rrdNodes[i].succedents[0] = xorNode; 451 xorNode->antecedents[i] = &rrdNodes[i]; 452 xorNode->antType[i] = rf_trueData; 453 } 454 455 /* link xor node to commit node */ 456 RF_ASSERT(xorNode->numSuccedents == 1); 457 RF_ASSERT(commitNode->numAntecedents == 1); 458 xorNode->succedents[0] = commitNode; 459 commitNode->antecedents[0] = xorNode; 460 commitNode->antType[0] = rf_control; 461 462 /* link commit node to wnd nodes */ 463 RF_ASSERT(commitNode->numSuccedents == nfaults + nWndNodes); 464 for (i = 0; i < nWndNodes; i++) { 465 RF_ASSERT(wndNodes[i].numAntecedents == 1); 466 commitNode->succedents[i] = &wndNodes[i]; 467 wndNodes[i].antecedents[0] = commitNode; 468 wndNodes[i].antType[0] = rf_control; 469 } 470 471 /* link the commit node to wnp, wnq nodes */ 472 RF_ASSERT(wnpNode->numAntecedents == 1); 473 commitNode->succedents[nWndNodes] = wnpNode; 474 wnpNode->antecedents[0] = commitNode; 475 wnpNode->antType[0] = rf_control; 476 if (nfaults == 2) { 477 RF_ASSERT(wnqNode->numAntecedents == 1); 478 commitNode->succedents[nWndNodes + 1] = wnqNode; 479 wnqNode->antecedents[0] = commitNode; 480 wnqNode->antType[0] = rf_control; 481 } 482 /* link write new data nodes to unblock node */ 483 RF_ASSERT(unblockNode->numAntecedents == (nWndNodes + nfaults)); 484 for (i = 0; i < nWndNodes; i++) { 485 RF_ASSERT(wndNodes[i].numSuccedents == 1); 486 wndNodes[i].succedents[0] = unblockNode; 487 unblockNode->antecedents[i] = &wndNodes[i]; 488 unblockNode->antType[i] = rf_control; 489 } 490 491 /* link write new parity node to unblock node */ 492 RF_ASSERT(wnpNode->numSuccedents == 1); 493 wnpNode->succedents[0] = unblockNode; 494 unblockNode->antecedents[nWndNodes] = wnpNode; 495 unblockNode->antType[nWndNodes] = rf_control; 496 497 /* link write new q node to unblock node */ 498 if (nfaults == 2) { 499 RF_ASSERT(wnqNode->numSuccedents == 1); 500 wnqNode->succedents[0] = unblockNode; 501 unblockNode->antecedents[nWndNodes + 1] = wnqNode; 502 unblockNode->antType[nWndNodes + 1] = rf_control; 503 } 504 /* link unblock node to term node */ 505 RF_ASSERT(unblockNode->numSuccedents == 1); 506 RF_ASSERT(termNode->numAntecedents == 1); 507 RF_ASSERT(termNode->numSuccedents == 0); 508 unblockNode->succedents[0] = termNode; 509 termNode->antecedents[0] = unblockNode; 510 termNode->antType[0] = rf_control; 511} 512#define CONS_PDA(if,start,num) \ 513 pda_p->col = asmap->if->col; \ 514 pda_p->startSector = ((asmap->if->startSector / secPerSU) * secPerSU) + start; \ 515 pda_p->numSector = num; \ 516 pda_p->next = NULL; \ 517 RF_MallocAndAdd(pda_p->bufPtr,rf_RaidAddressToByte(raidPtr,num),(char *), allocList) 518#if (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_EVENODD > 0) 519void 520rf_WriteGenerateFailedAccessASMs( 521 RF_Raid_t * raidPtr, 522 RF_AccessStripeMap_t * asmap, 523 RF_PhysDiskAddr_t ** pdap, 524 int *nNodep, 525 RF_PhysDiskAddr_t ** pqpdap, 526 int *nPQNodep, 527 RF_AllocListElem_t * allocList) 528{ 529 RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout); 530 int PDAPerDisk, i; 531 RF_SectorCount_t secPerSU = layoutPtr->sectorsPerStripeUnit; 532 int numDataCol = layoutPtr->numDataCol; 533 int state; 534 unsigned napdas; 535 RF_SectorNum_t fone_start, fone_end, ftwo_start = 0, ftwo_end; 536 RF_PhysDiskAddr_t *fone = asmap->failedPDAs[0], *ftwo = asmap->failedPDAs[1]; 537 RF_PhysDiskAddr_t *pda_p; 538 RF_RaidAddr_t sosAddr; 539 540 /* determine how many pda's we will have to generate per unaccess 541 * stripe. If there is only one failed data unit, it is one; if two, 542 * possibly two, depending wether they overlap. */ 543 544 fone_start = rf_StripeUnitOffset(layoutPtr, fone->startSector); 545 fone_end = fone_start + fone->numSector; 546 547 if (asmap->numDataFailed == 1) { 548 PDAPerDisk = 1; 549 state = 1; 550 RF_MallocAndAdd(*pqpdap, 2 * sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList); 551 pda_p = *pqpdap; 552 /* build p */ 553 CONS_PDA(parityInfo, fone_start, fone->numSector); 554 pda_p->type = RF_PDA_TYPE_PARITY; 555 pda_p++; 556 /* build q */ 557 CONS_PDA(qInfo, fone_start, fone->numSector); 558 pda_p->type = RF_PDA_TYPE_Q; 559 } else { 560 ftwo_start = rf_StripeUnitOffset(layoutPtr, ftwo->startSector); 561 ftwo_end = ftwo_start + ftwo->numSector; 562 if (fone->numSector + ftwo->numSector > secPerSU) { 563 PDAPerDisk = 1; 564 state = 2; 565 RF_MallocAndAdd(*pqpdap, 2 * sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList); 566 pda_p = *pqpdap; 567 CONS_PDA(parityInfo, 0, secPerSU); 568 pda_p->type = RF_PDA_TYPE_PARITY; 569 pda_p++; 570 CONS_PDA(qInfo, 0, secPerSU); 571 pda_p->type = RF_PDA_TYPE_Q; 572 } else { 573 PDAPerDisk = 2; 574 state = 3; 575 /* four of them, fone, then ftwo */ 576 RF_MallocAndAdd(*pqpdap, 4 * sizeof(RF_PhysDiskAddr_t), (RF_PhysDiskAddr_t *), allocList); 577 pda_p = *pqpdap; 578 CONS_PDA(parityInfo, fone_start, fone->numSector); 579 pda_p->type = RF_PDA_TYPE_PARITY; 580 pda_p++; 581 CONS_PDA(qInfo, fone_start, fone->numSector); 582 pda_p->type = RF_PDA_TYPE_Q; 583 pda_p++; 584 CONS_PDA(parityInfo, ftwo_start, ftwo->numSector); 585 pda_p->type = RF_PDA_TYPE_PARITY; 586 pda_p++; 587 CONS_PDA(qInfo, ftwo_start, ftwo->numSector); 588 pda_p->type = RF_PDA_TYPE_Q; 589 } 590 } 591 /* figure out number of nonaccessed pda */ 592 napdas = PDAPerDisk * (numDataCol - 2); 593 *nPQNodep = PDAPerDisk; 594 595 *nNodep = napdas; 596 if (napdas == 0) 597 return; /* short circuit */ 598 599 /* allocate up our list of pda's */ 600 601 RF_MallocAndAdd(pda_p, napdas * sizeof(RF_PhysDiskAddr_t), 602 (RF_PhysDiskAddr_t *), allocList); 603 *pdap = pda_p; 604 605 /* linkem together */ 606 for (i = 0; i < (napdas - 1); i++) 607 pda_p[i].next = pda_p + (i + 1); 608 609 sosAddr = rf_RaidAddressOfPrevStripeBoundary(layoutPtr, asmap->raidAddress); 610 for (i = 0; i < numDataCol; i++) { 611 if ((pda_p - (*pdap)) == napdas) 612 continue; 613 pda_p->type = RF_PDA_TYPE_DATA; 614 pda_p->raidAddress = sosAddr + (i * secPerSU); 615 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0); 616 /* skip over dead disks */ 617 if (RF_DEAD_DISK(raidPtr->Disks[pda_p->col].status)) 618 continue; 619 switch (state) { 620 case 1: /* fone */ 621 pda_p->numSector = fone->numSector; 622 pda_p->raidAddress += fone_start; 623 pda_p->startSector += fone_start; 624 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList); 625 break; 626 case 2: /* full stripe */ 627 pda_p->numSector = secPerSU; 628 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, secPerSU), (char *), allocList); 629 break; 630 case 3: /* two slabs */ 631 pda_p->numSector = fone->numSector; 632 pda_p->raidAddress += fone_start; 633 pda_p->startSector += fone_start; 634 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList); 635 pda_p++; 636 pda_p->type = RF_PDA_TYPE_DATA; 637 pda_p->raidAddress = sosAddr + (i * secPerSU); 638 (raidPtr->Layout.map->MapSector) (raidPtr, pda_p->raidAddress, &(pda_p->col), &(pda_p->startSector), 0); 639 pda_p->numSector = ftwo->numSector; 640 pda_p->raidAddress += ftwo_start; 641 pda_p->startSector += ftwo_start; 642 RF_MallocAndAdd(pda_p->bufPtr, rf_RaidAddressToByte(raidPtr, pda_p->numSector), (char *), allocList); 643 break; 644 default: 645 RF_PANIC(); 646 } 647 pda_p++; 648 } 649 650 RF_ASSERT(pda_p - *pdap == napdas); 651 return; 652} 653#define DISK_NODE_PDA(node) ((node)->params[0].p) 654 655#define DISK_NODE_PARAMS(_node_,_p_) \ 656 (_node_).params[0].p = _p_ ; \ 657 (_node_).params[1].p = (_p_)->bufPtr; \ 658 (_node_).params[2].v = parityStripeID; \ 659 (_node_).params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, which_ru) 660 661void 662rf_DoubleDegSmallWrite( 663 RF_Raid_t * raidPtr, 664 RF_AccessStripeMap_t * asmap, 665 RF_DagHeader_t * dag_h, 666 void *bp, 667 RF_RaidAccessFlags_t flags, 668 RF_AllocListElem_t * allocList, 669 char *redundantReadNodeName, 670 char *redundantWriteNodeName, 671 char *recoveryNodeName, 672 int (*recovFunc) (RF_DagNode_t *)) 673{ 674 RF_RaidLayout_t *layoutPtr = &(raidPtr->Layout); 675 RF_DagNode_t *nodes, *wudNodes, *rrdNodes, *recoveryNode, *blockNode, 676 *unblockNode, *rpNodes, *rqNodes, *wpNodes, *wqNodes, *termNode; 677 RF_PhysDiskAddr_t *pda, *pqPDAs; 678 RF_PhysDiskAddr_t *npdas; 679 int nWriteNodes, nNodes, nReadNodes, nRrdNodes, nWudNodes, i; 680 RF_ReconUnitNum_t which_ru; 681 int nPQNodes; 682 RF_StripeNum_t parityStripeID = rf_RaidAddressToParityStripeID(layoutPtr, asmap->raidAddress, &which_ru); 683 684 /* simple small write case - First part looks like a reconstruct-read 685 * of the failed data units. Then a write of all data units not 686 * failed. */ 687 688 689 /* Hdr | ------Block- / / \ Rrd Rrd ... Rrd Rp Rq \ \ 690 * / -------PQ----- / \ \ Wud Wp WQ \ | / 691 * --Unblock- | T 692 * 693 * Rrd = read recovery data (potentially none) Wud = write user data 694 * (not incl. failed disks) Wp = Write P (could be two) Wq = Write Q 695 * (could be two) 696 * 697 */ 698 699 rf_WriteGenerateFailedAccessASMs(raidPtr, asmap, &npdas, &nRrdNodes, &pqPDAs, &nPQNodes, allocList); 700 701 RF_ASSERT(asmap->numDataFailed == 1); 702 703 nWudNodes = asmap->numStripeUnitsAccessed - (asmap->numDataFailed); 704 nReadNodes = nRrdNodes + 2 * nPQNodes; 705 nWriteNodes = nWudNodes + 2 * nPQNodes; 706 nNodes = 4 + nReadNodes + nWriteNodes; 707 708 RF_MallocAndAdd(nodes, nNodes * sizeof(RF_DagNode_t), (RF_DagNode_t *), allocList); 709 blockNode = nodes; 710 unblockNode = blockNode + 1; 711 termNode = unblockNode + 1; 712 recoveryNode = termNode + 1; 713 rrdNodes = recoveryNode + 1; 714 rpNodes = rrdNodes + nRrdNodes; 715 rqNodes = rpNodes + nPQNodes; 716 wudNodes = rqNodes + nPQNodes; 717 wpNodes = wudNodes + nWudNodes; 718 wqNodes = wpNodes + nPQNodes; 719 720 dag_h->creator = "PQ_DDSimpleSmallWrite"; 721 dag_h->numSuccedents = 1; 722 dag_h->succedents[0] = blockNode; 723 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc, NULL, 0, 1, 0, 0, dag_h, "Trm", allocList); 724 termNode->antecedents[0] = unblockNode; 725 termNode->antType[0] = rf_control; 726 727 /* init the block and unblock nodes */ 728 /* The block node has all the read nodes as successors */ 729 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, nReadNodes, 0, 0, 0, dag_h, "Nil", allocList); 730 for (i = 0; i < nReadNodes; i++) 731 blockNode->succedents[i] = rrdNodes + i; 732 733 /* The unblock node has all the writes as successors */ 734 rf_InitNode(unblockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc, NULL, 1, nWriteNodes, 0, 0, dag_h, "Nil", allocList); 735 for (i = 0; i < nWriteNodes; i++) { 736 unblockNode->antecedents[i] = wudNodes + i; 737 unblockNode->antType[i] = rf_control; 738 } 739 unblockNode->succedents[0] = termNode; 740 741#define INIT_READ_NODE(node,name) \ 742 rf_InitNode(node, rf_wait, RF_FALSE, rf_DiskReadFunc, rf_DiskReadUndoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, name, allocList); \ 743 (node)->succedents[0] = recoveryNode; \ 744 (node)->antecedents[0] = blockNode; \ 745 (node)->antType[0] = rf_control; 746 747 /* build the read nodes */ 748 pda = npdas; 749 for (i = 0; i < nRrdNodes; i++, pda = pda->next) { 750 INIT_READ_NODE(rrdNodes + i, "rrd"); 751 DISK_NODE_PARAMS(rrdNodes[i], pda); 752 } 753 754 /* read redundancy pdas */ 755 pda = pqPDAs; 756 INIT_READ_NODE(rpNodes, "Rp"); 757 RF_ASSERT(pda); 758 DISK_NODE_PARAMS(rpNodes[0], pda); 759 pda++; 760 INIT_READ_NODE(rqNodes, redundantReadNodeName); 761 RF_ASSERT(pda); 762 DISK_NODE_PARAMS(rqNodes[0], pda); 763 if (nPQNodes == 2) { 764 pda++; 765 INIT_READ_NODE(rpNodes + 1, "Rp"); 766 RF_ASSERT(pda); 767 DISK_NODE_PARAMS(rpNodes[1], pda); 768 pda++; 769 INIT_READ_NODE(rqNodes + 1, redundantReadNodeName); 770 RF_ASSERT(pda); 771 DISK_NODE_PARAMS(rqNodes[1], pda); 772 } 773 /* the recovery node has all reads as precedessors and all writes as 774 * successors. It generates a result for every write P or write Q 775 * node. As parameters, it takes a pda per read and a pda per stripe 776 * of user data written. It also takes as the last params the raidPtr 777 * and asm. For results, it takes PDA for P & Q. */ 778 779 780 rf_InitNode(recoveryNode, rf_wait, RF_FALSE, recovFunc, rf_NullNodeUndoFunc, NULL, 781 nWriteNodes, /* succesors */ 782 nReadNodes, /* preds */ 783 nReadNodes + nWudNodes + 3, /* params */ 784 2 * nPQNodes, /* results */ 785 dag_h, recoveryNodeName, allocList); 786 787 788 789 for (i = 0; i < nReadNodes; i++) { 790 recoveryNode->antecedents[i] = rrdNodes + i; 791 recoveryNode->antType[i] = rf_control; 792 recoveryNode->params[i].p = DISK_NODE_PDA(rrdNodes + i); 793 } 794 for (i = 0; i < nWudNodes; i++) { 795 recoveryNode->succedents[i] = wudNodes + i; 796 } 797 recoveryNode->params[nReadNodes + nWudNodes].p = asmap->failedPDAs[0]; 798 recoveryNode->params[nReadNodes + nWudNodes + 1].p = raidPtr; 799 recoveryNode->params[nReadNodes + nWudNodes + 2].p = asmap; 800 801 for (; i < nWriteNodes; i++) 802 recoveryNode->succedents[i] = wudNodes + i; 803 804 pda = pqPDAs; 805 recoveryNode->results[0] = pda; 806 pda++; 807 recoveryNode->results[1] = pda; 808 if (nPQNodes == 2) { 809 pda++; 810 recoveryNode->results[2] = pda; 811 pda++; 812 recoveryNode->results[3] = pda; 813 } 814 /* fill writes */ 815#define INIT_WRITE_NODE(node,name) \ 816 rf_InitNode(node, rf_wait, RF_FALSE, rf_DiskWriteFunc, rf_DiskWriteUndoFunc, rf_GenericWakeupFunc, 1, 1, 4, 0, dag_h, name, allocList); \ 817 (node)->succedents[0] = unblockNode; \ 818 (node)->antecedents[0] = recoveryNode; \ 819 (node)->antType[0] = rf_control; 820 821 pda = asmap->physInfo; 822 for (i = 0; i < nWudNodes; i++) { 823 INIT_WRITE_NODE(wudNodes + i, "Wd"); 824 DISK_NODE_PARAMS(wudNodes[i], pda); 825 recoveryNode->params[nReadNodes + i].p = DISK_NODE_PDA(wudNodes + i); 826 pda = pda->next; 827 } 828 /* write redundancy pdas */ 829 pda = pqPDAs; 830 INIT_WRITE_NODE(wpNodes, "Wp"); 831 RF_ASSERT(pda); 832 DISK_NODE_PARAMS(wpNodes[0], pda); 833 pda++; 834 INIT_WRITE_NODE(wqNodes, "Wq"); 835 RF_ASSERT(pda); 836 DISK_NODE_PARAMS(wqNodes[0], pda); 837 if (nPQNodes == 2) { 838 pda++; 839 INIT_WRITE_NODE(wpNodes + 1, "Wp"); 840 RF_ASSERT(pda); 841 DISK_NODE_PARAMS(wpNodes[1], pda); 842 pda++; 843 INIT_WRITE_NODE(wqNodes + 1, "Wq"); 844 RF_ASSERT(pda); 845 DISK_NODE_PARAMS(wqNodes[1], pda); 846 } 847} 848#endif /* (RF_INCLUDE_PQ > 0) || (RF_INCLUDE_EVENODD > 0) */ 849