rf_dagffrd.c revision 1.10 1 /* $NetBSD: rf_dagffrd.c,v 1.10 2003/12/30 21:59:03 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.10 2003/12/30 21:59:03 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_dagDebug)
149 printf("[Creating non-redundant read DAG]\n");
150 break;
151 case RF_IO_TYPE_WRITE:
152 doFunc = rf_DiskWriteFunc;
153 undoFunc = rf_DiskWriteUndoFunc;
154 name = "W ";
155 if (rf_dagDebug)
156 printf("[Creating non-redundant write DAG]\n");
157 break;
158 default:
159 RF_PANIC();
160 }
161
162 /*
163 * For reads, the dag can not commit until the block node is reached.
164 * for writes, the dag commits immediately.
165 */
166 dag_h->numCommitNodes = 1;
167 dag_h->numCommits = 0;
168 dag_h->numSuccedents = 1;
169
170 /*
171 * Node count:
172 * 1 block node
173 * n data reads (or writes)
174 * 1 commit node
175 * 1 terminator node
176 */
177 RF_ASSERT(n > 0);
178 totalNumNodes = n + 3;
179 RF_MallocAndAdd(nodes, totalNumNodes * sizeof(RF_DagNode_t),
180 (RF_DagNode_t *), allocList);
181 i = 0;
182 diskNodes = &nodes[i];
183 i += n;
184 blockNode = &nodes[i];
185 i += 1;
186 commitNode = &nodes[i];
187 i += 1;
188 termNode = &nodes[i];
189 i += 1;
190 RF_ASSERT(i == totalNumNodes);
191
192 /* initialize nodes */
193 switch (type) {
194 case RF_IO_TYPE_READ:
195 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
196 NULL, n, 0, 0, 0, dag_h, "Nil", allocList);
197 rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
198 NULL, 1, n, 0, 0, dag_h, "Cmt", allocList);
199 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc,
200 NULL, 0, 1, 0, 0, dag_h, "Trm", allocList);
201 break;
202 case RF_IO_TYPE_WRITE:
203 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
204 NULL, 1, 0, 0, 0, dag_h, "Nil", allocList);
205 rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc, rf_NullNodeUndoFunc,
206 NULL, n, 1, 0, 0, dag_h, "Cmt", allocList);
207 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc, rf_TerminateUndoFunc,
208 NULL, 0, n, 0, 0, dag_h, "Trm", allocList);
209 break;
210 default:
211 RF_PANIC();
212 }
213
214 for (i = 0; i < n; i++) {
215 RF_ASSERT(pda != NULL);
216 rf_InitNode(&diskNodes[i], rf_wait, RF_FALSE, doFunc, undoFunc, rf_GenericWakeupFunc,
217 1, 1, 4, 0, dag_h, name, allocList);
218 diskNodes[i].params[0].p = pda;
219 diskNodes[i].params[1].p = pda->bufPtr;
220 /* parity stripe id is not necessary */
221 diskNodes[i].params[2].v = 0;
222 diskNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, 0);
223 pda = pda->next;
224 }
225
226 /*
227 * Connect nodes.
228 */
229
230 /* connect hdr to block node */
231 RF_ASSERT(blockNode->numAntecedents == 0);
232 dag_h->succedents[0] = blockNode;
233
234 if (type == RF_IO_TYPE_READ) {
235 /* connecting a nonredundant read DAG */
236 RF_ASSERT(blockNode->numSuccedents == n);
237 RF_ASSERT(commitNode->numAntecedents == n);
238 for (i = 0; i < n; i++) {
239 /* connect block node to each read node */
240 RF_ASSERT(diskNodes[i].numAntecedents == 1);
241 blockNode->succedents[i] = &diskNodes[i];
242 diskNodes[i].antecedents[0] = blockNode;
243 diskNodes[i].antType[0] = rf_control;
244
245 /* connect each read node to the commit node */
246 RF_ASSERT(diskNodes[i].numSuccedents == 1);
247 diskNodes[i].succedents[0] = commitNode;
248 commitNode->antecedents[i] = &diskNodes[i];
249 commitNode->antType[i] = rf_control;
250 }
251 /* connect the commit node to the term node */
252 RF_ASSERT(commitNode->numSuccedents == 1);
253 RF_ASSERT(termNode->numAntecedents == 1);
254 RF_ASSERT(termNode->numSuccedents == 0);
255 commitNode->succedents[0] = termNode;
256 termNode->antecedents[0] = commitNode;
257 termNode->antType[0] = rf_control;
258 } else {
259 /* connecting a nonredundant write DAG */
260 /* connect the block node to the commit node */
261 RF_ASSERT(blockNode->numSuccedents == 1);
262 RF_ASSERT(commitNode->numAntecedents == 1);
263 blockNode->succedents[0] = commitNode;
264 commitNode->antecedents[0] = blockNode;
265 commitNode->antType[0] = rf_control;
266
267 RF_ASSERT(commitNode->numSuccedents == n);
268 RF_ASSERT(termNode->numAntecedents == n);
269 RF_ASSERT(termNode->numSuccedents == 0);
270 for (i = 0; i < n; i++) {
271 /* connect the commit node to each write node */
272 RF_ASSERT(diskNodes[i].numAntecedents == 1);
273 commitNode->succedents[i] = &diskNodes[i];
274 diskNodes[i].antecedents[0] = commitNode;
275 diskNodes[i].antType[0] = rf_control;
276
277 /* connect each write node to the term node */
278 RF_ASSERT(diskNodes[i].numSuccedents == 1);
279 diskNodes[i].succedents[0] = termNode;
280 termNode->antecedents[i] = &diskNodes[i];
281 termNode->antType[i] = rf_control;
282 }
283 }
284 }
285 /******************************************************************************
286 * Create a fault-free read DAG for RAID level 1
287 *
288 * Hdr -> Nil -> Rmir -> Cmt -> Trm
289 *
290 * The "Rmir" node schedules a read from the disk in the mirror pair with the
291 * shortest disk queue. the proper queue is selected at Rmir execution. this
292 * deferred mapping is unlike other archs in RAIDframe which generally fix
293 * mapping at DAG creation time.
294 *
295 * Parameters: raidPtr - description of the physical array
296 * asmap - logical & physical addresses for this access
297 * bp - buffer ptr (for holding read data)
298 * flags - general flags (e.g. disk locking)
299 * allocList - list of memory allocated in DAG creation
300 *****************************************************************************/
301
302 static void
303 CreateMirrorReadDAG(RF_Raid_t *raidPtr, RF_AccessStripeMap_t *asmap,
304 RF_DagHeader_t *dag_h, void *bp,
305 RF_RaidAccessFlags_t flags,
306 RF_AllocListElem_t *allocList,
307 int (*readfunc) (RF_DagNode_t * node))
308 {
309 RF_DagNode_t *readNodes, *nodes, *blockNode, *commitNode, *termNode;
310 RF_PhysDiskAddr_t *data_pda = asmap->physInfo;
311 RF_PhysDiskAddr_t *parity_pda = asmap->parityInfo;
312 int i, n, totalNumNodes;
313
314 n = asmap->numStripeUnitsAccessed;
315 dag_h->creator = "RaidOneReadDAG";
316 if (rf_dagDebug) {
317 printf("[Creating RAID level 1 read DAG]\n");
318 }
319 /*
320 * This dag can not commit until the commit node is reached
321 * errors prior to the commit point imply the dag has failed.
322 */
323 dag_h->numCommitNodes = 1;
324 dag_h->numCommits = 0;
325 dag_h->numSuccedents = 1;
326
327 /*
328 * Node count:
329 * n data reads
330 * 1 block node
331 * 1 commit node
332 * 1 terminator node
333 */
334 RF_ASSERT(n > 0);
335 totalNumNodes = n + 3;
336 RF_MallocAndAdd(nodes, totalNumNodes * sizeof(RF_DagNode_t),
337 (RF_DagNode_t *), allocList);
338 i = 0;
339 readNodes = &nodes[i];
340 i += n;
341 blockNode = &nodes[i];
342 i += 1;
343 commitNode = &nodes[i];
344 i += 1;
345 termNode = &nodes[i];
346 i += 1;
347 RF_ASSERT(i == totalNumNodes);
348
349 /* initialize nodes */
350 rf_InitNode(blockNode, rf_wait, RF_FALSE, rf_NullNodeFunc,
351 rf_NullNodeUndoFunc, NULL, n, 0, 0, 0, dag_h, "Nil", allocList);
352 rf_InitNode(commitNode, rf_wait, RF_TRUE, rf_NullNodeFunc,
353 rf_NullNodeUndoFunc, NULL, 1, n, 0, 0, dag_h, "Cmt", allocList);
354 rf_InitNode(termNode, rf_wait, RF_FALSE, rf_TerminateFunc,
355 rf_TerminateUndoFunc, NULL, 0, 1, 0, 0, dag_h, "Trm", allocList);
356
357 for (i = 0; i < n; i++) {
358 RF_ASSERT(data_pda != NULL);
359 RF_ASSERT(parity_pda != NULL);
360 rf_InitNode(&readNodes[i], rf_wait, RF_FALSE, readfunc,
361 rf_DiskReadMirrorUndoFunc, rf_GenericWakeupFunc, 1, 1, 5, 0, dag_h,
362 "Rmir", allocList);
363 readNodes[i].params[0].p = data_pda;
364 readNodes[i].params[1].p = data_pda->bufPtr;
365 /* parity stripe id is not necessary */
366 readNodes[i].params[2].p = 0;
367 readNodes[i].params[3].v = RF_CREATE_PARAM3(RF_IO_NORMAL_PRIORITY, 0, 0, 0);
368 readNodes[i].params[4].p = parity_pda;
369 data_pda = data_pda->next;
370 parity_pda = parity_pda->next;
371 }
372
373 /*
374 * Connect nodes
375 */
376
377 /* connect hdr to block node */
378 RF_ASSERT(blockNode->numAntecedents == 0);
379 dag_h->succedents[0] = blockNode;
380
381 /* connect block node to read nodes */
382 RF_ASSERT(blockNode->numSuccedents == n);
383 for (i = 0; i < n; i++) {
384 RF_ASSERT(readNodes[i].numAntecedents == 1);
385 blockNode->succedents[i] = &readNodes[i];
386 readNodes[i].antecedents[0] = blockNode;
387 readNodes[i].antType[0] = rf_control;
388 }
389
390 /* connect read nodes to commit node */
391 RF_ASSERT(commitNode->numAntecedents == n);
392 for (i = 0; i < n; i++) {
393 RF_ASSERT(readNodes[i].numSuccedents == 1);
394 readNodes[i].succedents[0] = commitNode;
395 commitNode->antecedents[i] = &readNodes[i];
396 commitNode->antType[i] = rf_control;
397 }
398
399 /* connect commit node to term node */
400 RF_ASSERT(commitNode->numSuccedents == 1);
401 RF_ASSERT(termNode->numAntecedents == 1);
402 RF_ASSERT(termNode->numSuccedents == 0);
403 commitNode->succedents[0] = termNode;
404 termNode->antecedents[0] = commitNode;
405 termNode->antType[0] = rf_control;
406 }
407
408 void
409 rf_CreateMirrorIdleReadDAG(
410 RF_Raid_t * raidPtr,
411 RF_AccessStripeMap_t * asmap,
412 RF_DagHeader_t * dag_h,
413 void *bp,
414 RF_RaidAccessFlags_t flags,
415 RF_AllocListElem_t * allocList)
416 {
417 CreateMirrorReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList,
418 rf_DiskReadMirrorIdleFunc);
419 }
420
421 #if (RF_INCLUDE_CHAINDECLUSTER > 0) || (RF_INCLUDE_INTERDECLUSTER > 0)
422
423 void
424 rf_CreateMirrorPartitionReadDAG(RF_Raid_t *raidPtr,
425 RF_AccessStripeMap_t *asmap,
426 RF_DagHeader_t *dag_h, void *bp,
427 RF_RaidAccessFlags_t flags,
428 RF_AllocListElem_t *allocList)
429 {
430 CreateMirrorReadDAG(raidPtr, asmap, dag_h, bp, flags, allocList,
431 rf_DiskReadMirrorPartitionFunc);
432 }
433 #endif
434