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