rf_dagffrd.c revision 1.12 1 /* $NetBSD: rf_dagffrd.c,v 1.12 2004/03/05 03:22: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 (at) 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_dagffrd.c
31 *
32 * code for creating fault-free read DAGs
33 *
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: rf_dagffrd.c,v 1.12 2004/03/05 03:22: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_dagffrd.h"
48
49 /******************************************************************************
50 *
51 * General comments on DAG creation:
52 *
53 * All DAGs in this file use roll-away error recovery. Each DAG has a single
54 * commit node, usually called "Cmt." If an error occurs before the Cmt node
55 * is reached, the execution engine will halt forward execution and work
56 * backward through the graph, executing the undo functions. Assuming that
57 * each node in the graph prior to the Cmt node are undoable and atomic - or -
58 * does not make changes to permanent state, the graph will fail atomically.
59 * If an error occurs after the Cmt node executes, the engine will roll-forward
60 * through the graph, blindly executing nodes until it reaches the end.
61 * If a graph reaches the end, it is assumed to have completed successfully.
62 *
63 * A graph has only 1 Cmt node.
64 *
65 */
66
67
68 /******************************************************************************
69 *
70 * The following wrappers map the standard DAG creation interface to the
71 * DAG creation routines. Additionally, these wrappers enable experimentation
72 * with new DAG structures by providing an extra level of indirection, allowing
73 * the DAG creation routines to be replaced at this single point.
74 */
75
76 void
77 rf_CreateFaultFreeReadDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
78 RF_DagHeader_t *dag_h, void *bp,
79 RF_RaidAccessFlags_t flags,
80 RF_AllocListElem_t *allocList)
81 {
82 rf_CreateNonredundantDAG(raidPtr, asmap, dag_h, bp, flags, allocList,
83 RF_IO_TYPE_READ);
84 }
85
86
87 /******************************************************************************
88 *
89 * DAG creation code begins here
90 */
91
92 /******************************************************************************
93 *
94 * creates a DAG to perform a nonredundant read or write of data within one
95 * stripe.
96 * For reads, this DAG is as follows:
97 *
98 * /---- read ----\
99 * Header -- Block ---- read ---- Commit -- Terminate
100 * \---- read ----/
101 *
102 * For writes, this DAG is as follows:
103 *
104 * /---- write ----\
105 * Header -- Commit ---- write ---- Block -- Terminate
106 * \---- write ----/
107 *
108 * There is one disk node per stripe unit accessed, and all disk nodes are in
109 * parallel.
110 *
111 * Tricky point here: The first disk node (read or write) is created
112 * normally. Subsequent disk nodes are created by copying the first one,
113 * and modifying a few params. The "succedents" and "antecedents" fields are
114 * _not_ re-created in each node, but rather left pointing to the same array
115 * that was malloc'd when the first node was created. Thus, it's essential
116 * that when this DAG is freed, the succedents and antecedents fields be freed
117 * in ONLY ONE of the read nodes. This does not apply to the "params" field
118 * because it is recreated for each READ node.
119 *
120 * Note that normal-priority accesses do not need to be tagged with their
121 * parity stripe ID, because they will never be promoted. Hence, I've
122 * commented-out the code to do this, and marked it with UNNEEDED.
123 *
124 *****************************************************************************/
125
126 void
127 rf_CreateNonredundantDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
128 RF_DagHeader_t *dag_h, void *bp,
129 RF_RaidAccessFlags_t flags,
130 RF_AllocListElem_t *allocList,
131 RF_IoType_t type)
132 {
133 RF_DagNode_t *nodes, *diskNodes, *blockNode, *commitNode, *termNode;
134 RF_PhysDiskAddr_t *pda = asmap->physInfo;
135 int (*doFunc) (RF_DagNode_t *), (*undoFunc) (RF_DagNode_t *);
136 int i, n, totalNumNodes;
137 char *name;
138
139 n = asmap->numStripeUnitsAccessed;
140 dag_h->creator = "NonredundantDAG";
141
142 RF_ASSERT(RF_IO_IS_R_OR_W(type));
143 switch (type) {
144 case RF_IO_TYPE_READ:
145 doFunc = rf_DiskReadFunc;
146 undoFunc = rf_DiskReadUndoFunc;
147 name = "R ";
148 #if RF_DEBUG_DAG
149 if (rf_dagDebug)
150 printf("[Creating non-redundant read DAG]\n");
151 #endif
152 break;
153 case RF_IO_TYPE_WRITE:
154 doFunc = rf_DiskWriteFunc;
155 undoFunc = rf_DiskWriteUndoFunc;
156 name = "W ";
157 #if RF_DEBUG_DAG
158 if (rf_dagDebug)
159 printf("[Creating non-redundant write DAG]\n");
160 #endif
161 break;
162 default:
163 RF_PANIC();
164 }
165
166 /*
167 * For reads, the dag can not commit until the block node is reached.
168 * for writes, the dag commits immediately.
169 */
170 dag_h->numCommitNodes = 1;
171 dag_h->numCommits = 0;
172 dag_h->numSuccedents = 1;
173
174 /*
175 * Node count:
176 * 1 block node
177 * n data reads (or writes)
178 * 1 commit node
179 * 1 terminator node
180 */
181 RF_ASSERT(n > 0);
182 totalNumNodes = n + 3;
183 RF_MallocAndAdd(nodes, totalNumNodes * sizeof(RF_DagNode_t),
184 (RF_DagNode_t *), allocList);
185 i = 0;
186 diskNodes = &nodes[i];
187 i += n;
188 blockNode = &nodes[i];
189 i += 1;
190 commitNode = &nodes[i];
191 i += 1;
192 termNode = &nodes[i];
193 i += 1;
194 RF_ASSERT(i == totalNumNodes);
195
196 /* initialize nodes */
197 switch (type) {
198 case RF_IO_TYPE_READ:
199 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
200 NULL, n, 0, 0, 0, dag_h, "Nil", allocList);
201 rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
202 NULL, 1, n, 0, 0, dag_h, "Cmt", allocList);
203 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc,
204 NULL, 0, 1, 0, 0, dag_h, "Trm", allocList);
205 break;
206 case RF_IO_TYPE_WRITE:
207 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
208 NULL, 1, 0, 0, 0, dag_h, "Nil", allocList);
209 rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
210 NULL, n, 1, 0, 0, dag_h, "Cmt", allocList);
211 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc,
212 NULL, 0, n, 0, 0, dag_h, "Trm", allocList);
213 break;
214 default:
215 RF_PANIC();
216 }
217
218 for (i = 0; i < n; i++) {
219 RF_ASSERT(pda != NULL);
220 rf_InitNode(&diskNodes[i], rf_wait, RF_FALSE, doFunc, undoFunc, rf_GenericWakeupFunc,
221 1, 1, 4, 0, dag_h, name, allocList);
222 diskNodes[i].params[0].p = pda;
223 diskNodes[i].params[1].p = pda->bufPtr;
224 /* parity stripe id is not necessary */
225 diskNodes[i].params[2].v = 0;
226 diskNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0);
227 pda = pda->next;
228 }
229
230 /*
231 * Connect nodes.
232 */
233
234 /* connect hdr to block node */
235 RF_ASSERT(blockNode->numAntecedents == 0);
236 dag_h->succedents[0] = blockNode;
237
238 if (type == RF_IO_TYPE_READ) {
239 /* connecting a nonredundant read DAG */
240 RF_ASSERT(blockNode->numSuccedents == n);
241 RF_ASSERT(commitNode->numAntecedents == n);
242 for (i = 0; i < n; i++) {
243 /* connect block node to each read node */
244 RF_ASSERT(diskNodes[i].numAntecedents == 1);
245 blockNode->succedents[i] = &diskNodes[i];
246 diskNodes[i].antecedents[0] = blockNode;
247 diskNodes[i].antType[0] = rf_control;
248
249 /* connect each read node to the commit node */
250 RF_ASSERT(diskNodes[i].numSuccedents == 1);
251 diskNodes[i].succedents[0] = commitNode;
252 commitNode->antecedents[i] = &diskNodes[i];
253 commitNode->antType[i] = rf_control;
254 }
255 /* connect the commit node to the term node */
256 RF_ASSERT(commitNode->numSuccedents == 1);
257 RF_ASSERT(termNode->numAntecedents == 1);
258 RF_ASSERT(termNode->numSuccedents == 0);
259 commitNode->succedents[0] = termNode;
260 termNode->antecedents[0] = commitNode;
261 termNode->antType[0] = rf_control;
262 } else {
263 /* connecting a nonredundant write DAG */
264 /* connect the block node to the commit node */
265 RF_ASSERT(blockNode->numSuccedents == 1);
266 RF_ASSERT(commitNode->numAntecedents == 1);
267 blockNode->succedents[0] = commitNode;
268 commitNode->antecedents[0] = blockNode;
269 commitNode->antType[0] = rf_control;
270
271 RF_ASSERT(commitNode->numSuccedents == n);
272 RF_ASSERT(termNode->numAntecedents == n);
273 RF_ASSERT(termNode->numSuccedents == 0);
274 for (i = 0; i < n; i++) {
275 /* connect the commit node to each write node */
276 RF_ASSERT(diskNodes[i].numAntecedents == 1);
277 commitNode->succedents[i] = &diskNodes[i];
278 diskNodes[i].antecedents[0] = commitNode;
279 diskNodes[i].antType[0] = rf_control;
280
281 /* connect each write node to the term node */
282 RF_ASSERT(diskNodes[i].numSuccedents == 1);
283 diskNodes[i].succedents[0] = termNode;
284 termNode->antecedents[i] = &diskNodes[i];
285 termNode->antType[i] = rf_control;
286 }
287 }
288 }
289 /******************************************************************************
290 * Create a fault-free read DAG for RAID level 1
291 *
292 * Hdr -> Nil -> Rmir -> Cmt -> Trm
293 *
294 * The "Rmir" node schedules a read from the disk in the mirror pair with the
295 * shortest disk queue. the proper queue is selected at Rmir execution. this
296 * deferred mapping is unlike other archs in RAIDframe which generally fix
297 * mapping at DAG creation time.
298 *
299 * Parameters: raidPtr - description of the physical array
300 * asmap - logical & physical addresses for this access
301 * bp - buffer ptr (for holding read data)
302 * flags - general flags (e.g. disk locking)
303 * allocList - list of memory allocated in DAG creation
304 *****************************************************************************/
305
306 static void
307 CreateMirrorReadDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
308 RF_DagHeader_t *dag_h, void *bp,
309 RF_RaidAccessFlags_t flags,
310 RF_AllocListElem_t *allocList,
311 int (*readfunc) (RF_DagNode_t * node))
312 {
313 RF_DagNode_t *readNodes, *nodes, *blockNode, *commitNode, *termNode;
314 RF_PhysDiskAddr_t *data_pda = asmap->physInfo;
315 RF_PhysDiskAddr_t *parity_pda = asmap->parityInfo;
316 int i, n, totalNumNodes;
317
318 n = asmap->numStripeUnitsAccessed;
319 dag_h->creator = "RaidOneReadDAG";
320 #if RF_DEBUG_DAG
321 if (rf_dagDebug) {
322 printf("[Creating RAID level 1 read DAG]\n");
323 }
324 #endif
325 /*
326 * This dag can not commit until the commit node is reached
327 * errors prior to the commit point imply the dag has failed.
328 */
329 dag_h->numCommitNodes = 1;
330 dag_h->numCommits = 0;
331 dag_h->numSuccedents = 1;
332
333 /*
334 * Node count:
335 * n data reads
336 * 1 block node
337 * 1 commit node
338 * 1 terminator node
339 */
340 RF_ASSERT(n > 0);
341 totalNumNodes = n + 3;
342 RF_MallocAndAdd(nodes, totalNumNodes * sizeof(RF_DagNode_t),
343 (RF_DagNode_t *), allocList);
344 i = 0;
345 readNodes = &nodes[i];
346 i += n;
347 blockNode = &nodes[i];
348 i += 1;
349 commitNode = &nodes[i];
350 i += 1;
351 termNode = &nodes[i];
352 i += 1;
353 RF_ASSERT(i == totalNumNodes);
354
355 /* initialize nodes */
356 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc,
357 rf_NullNodeUndoFunc, NULL, n, 0, 0, 0, dag_h, "Nil", allocList);
358 rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc,
359 rf_NullNodeUndoFunc, NULL, 1, n, 0, 0, dag_h, "Cmt", allocList);
360 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc,
361 rf_TerminateUndoFunc, NULL, 0, 1, 0, 0, dag_h, "Trm", allocList);
362
363 for (i = 0; i < n; i++) {
364 RF_ASSERT(data_pda != NULL);
365 RF_ASSERT(parity_pda != NULL);
366 rf_InitNode(&readNodes[i], rf_wait, RF_FALSE, readfunc,
367 rf_DiskReadMirrorUndoFunc, rf_GenericWakeupFunc, 1, 1, 5, 0, dag_h,
368 "Rmir", allocList);
369 readNodes[i].params[0].p = data_pda;
370 readNodes[i].params[1].p = data_pda->bufPtr;
371 /* parity stripe id is not necessary */
372 readNodes[i].params[2].p = 0;
373 readNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0);
374 readNodes[i].params[4].p = parity_pda;
375 data_pda = data_pda->next;
376 parity_pda = parity_pda->next;
377 }
378
379 /*
380 * Connect nodes
381 */
382
383 /* connect hdr to block node */
384 RF_ASSERT(blockNode->numAntecedents == 0);
385 dag_h->succedents[0] = blockNode;
386
387 /* connect block node to read nodes */
388 RF_ASSERT(blockNode->numSuccedents == n);
389 for (i = 0; i < n; i++) {
390 RF_ASSERT(readNodes[i].numAntecedents == 1);
391 blockNode->succedents[i] = &readNodes[i];
392 readNodes[i].antecedents[0] = blockNode;
393 readNodes[i].antType[0] = rf_control;
394 }
395
396 /* connect read nodes to commit node */
397 RF_ASSERT(commitNode->numAntecedents == n);
398 for (i = 0; i < n; i++) {
399 RF_ASSERT(readNodes[i].numSuccedents == 1);
400 readNodes[i].succedents[0] = commitNode;
401 commitNode->antecedents[i] = &readNodes[i];
402 commitNode->antType[i] = rf_control;
403 }
404
405 /* connect commit node to term node */
406 RF_ASSERT(commitNode->numSuccedents == 1);
407 RF_ASSERT(termNode->numAntecedents == 1);
408 RF_ASSERT(termNode->numSuccedents == 0);
409 commitNode->succedents[0] = termNode;
410 termNode->antecedents[0] = commitNode;
411 termNode->antType[0] = rf_control;
412 }
413
414 void
415 rf_CreateMirrorIdleReadDAG(
416 RF_Raid_t * raidPtr,
417 RF_AccessStripeMap_t * asmap,
418 RF_DagHeader_t * dag_h,
419 void *bp,
420 RF_RaidAccessFlags_t flags,
421 RF_AllocListElem_t * allocList)
422 {
423 CreateMirrorReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList,
424 rf_DiskReadMirrorIdleFunc);
425 }
426
427 #if (RF_INCLUDE_CHAINDECLUSTER > 0) || (RF_INCLUDE_INTERDECLUSTER > 0)
428
429 void
430 rf_CreateMirrorPartitionReadDAG(RF_Raid_t *raidPtr,
431 RF_AccessStripeMap_t *asmap,
432 RF_DagHeader_t *dag_h, void *bp,
433 RF_RaidAccessFlags_t flags,
434 RF_AllocListElem_t *allocList)
435 {
436 CreateMirrorReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList,
437 rf_DiskReadMirrorPartitionFunc);
438 }
439 #endif
440