rf_dagfuncs.c revision 1.19 1 1.19 oster /* $NetBSD: rf_dagfuncs.c,v 1.19 2004/03/01 23:30:58 oster Exp $ */
2 1.1 oster /*
3 1.1 oster * Copyright (c) 1995 Carnegie-Mellon University.
4 1.1 oster * All rights reserved.
5 1.1 oster *
6 1.1 oster * Author: Mark Holland, William V. Courtright II
7 1.1 oster *
8 1.1 oster * Permission to use, copy, modify and distribute this software and
9 1.1 oster * its documentation is hereby granted, provided that both the copyright
10 1.1 oster * notice and this permission notice appear in all copies of the
11 1.1 oster * software, derivative works or modified versions, and any portions
12 1.1 oster * thereof, and that both notices appear in supporting documentation.
13 1.1 oster *
14 1.1 oster * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 1.1 oster * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 1.1 oster * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 1.1 oster *
18 1.1 oster * Carnegie Mellon requests users of this software to return to
19 1.1 oster *
20 1.1 oster * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 1.1 oster * School of Computer Science
22 1.1 oster * Carnegie Mellon University
23 1.1 oster * Pittsburgh PA 15213-3890
24 1.1 oster *
25 1.1 oster * any improvements or extensions that they make and grant Carnegie the
26 1.1 oster * rights to redistribute these changes.
27 1.1 oster */
28 1.1 oster
29 1.1 oster /*
30 1.1 oster * dagfuncs.c -- DAG node execution routines
31 1.1 oster *
32 1.1 oster * Rules:
33 1.1 oster * 1. Every DAG execution function must eventually cause node->status to
34 1.1 oster * get set to "good" or "bad", and "FinishNode" to be called. In the
35 1.1 oster * case of nodes that complete immediately (xor, NullNodeFunc, etc),
36 1.1 oster * the node execution function can do these two things directly. In
37 1.1 oster * the case of nodes that have to wait for some event (a disk read to
38 1.1 oster * complete, a lock to be released, etc) to occur before they can
39 1.1 oster * complete, this is typically achieved by having whatever module
40 1.1 oster * is doing the operation call GenericWakeupFunc upon completion.
41 1.1 oster * 2. DAG execution functions should check the status in the DAG header
42 1.1 oster * and NOP out their operations if the status is not "enable". However,
43 1.1 oster * execution functions that release resources must be sure to release
44 1.1 oster * them even when they NOP out the function that would use them.
45 1.1 oster * Functions that acquire resources should go ahead and acquire them
46 1.1 oster * even when they NOP, so that a downstream release node will not have
47 1.1 oster * to check to find out whether or not the acquire was suppressed.
48 1.1 oster */
49 1.8 lukem
50 1.8 lukem #include <sys/cdefs.h>
51 1.19 oster __KERNEL_RCSID(0, "$NetBSD: rf_dagfuncs.c,v 1.19 2004/03/01 23:30:58 oster Exp $");
52 1.1 oster
53 1.7 mrg #include <sys/param.h>
54 1.1 oster #include <sys/ioctl.h>
55 1.1 oster
56 1.1 oster #include "rf_archs.h"
57 1.1 oster #include "rf_raid.h"
58 1.1 oster #include "rf_dag.h"
59 1.1 oster #include "rf_layout.h"
60 1.1 oster #include "rf_etimer.h"
61 1.1 oster #include "rf_acctrace.h"
62 1.1 oster #include "rf_diskqueue.h"
63 1.1 oster #include "rf_dagfuncs.h"
64 1.1 oster #include "rf_general.h"
65 1.1 oster #include "rf_engine.h"
66 1.1 oster #include "rf_dagutils.h"
67 1.1 oster
68 1.1 oster #include "rf_kintf.h"
69 1.1 oster
70 1.1 oster #if RF_INCLUDE_PARITYLOGGING > 0
71 1.1 oster #include "rf_paritylog.h"
72 1.3 oster #endif /* RF_INCLUDE_PARITYLOGGING > 0 */
73 1.1 oster
74 1.3 oster int (*rf_DiskReadFunc) (RF_DagNode_t *);
75 1.3 oster int (*rf_DiskWriteFunc) (RF_DagNode_t *);
76 1.3 oster int (*rf_DiskReadUndoFunc) (RF_DagNode_t *);
77 1.3 oster int (*rf_DiskWriteUndoFunc) (RF_DagNode_t *);
78 1.3 oster int (*rf_DiskUnlockFunc) (RF_DagNode_t *);
79 1.3 oster int (*rf_DiskUnlockUndoFunc) (RF_DagNode_t *);
80 1.3 oster int (*rf_RegularXorUndoFunc) (RF_DagNode_t *);
81 1.3 oster int (*rf_SimpleXorUndoFunc) (RF_DagNode_t *);
82 1.3 oster int (*rf_RecoveryXorUndoFunc) (RF_DagNode_t *);
83 1.1 oster
84 1.14 oster /*****************************************************************************
85 1.1 oster * main (only) configuration routine for this module
86 1.14 oster ****************************************************************************/
87 1.3 oster int
88 1.15 oster rf_ConfigureDAGFuncs(RF_ShutdownList_t **listp)
89 1.3 oster {
90 1.14 oster RF_ASSERT(((sizeof(long) == 8) && RF_LONGSHIFT == 3) ||
91 1.14 oster ((sizeof(long) == 4) && RF_LONGSHIFT == 2));
92 1.3 oster rf_DiskReadFunc = rf_DiskReadFuncForThreads;
93 1.3 oster rf_DiskReadUndoFunc = rf_DiskUndoFunc;
94 1.3 oster rf_DiskWriteFunc = rf_DiskWriteFuncForThreads;
95 1.3 oster rf_DiskWriteUndoFunc = rf_DiskUndoFunc;
96 1.3 oster rf_DiskUnlockFunc = rf_DiskUnlockFuncForThreads;
97 1.3 oster rf_DiskUnlockUndoFunc = rf_NullNodeUndoFunc;
98 1.3 oster rf_RegularXorUndoFunc = rf_NullNodeUndoFunc;
99 1.3 oster rf_SimpleXorUndoFunc = rf_NullNodeUndoFunc;
100 1.3 oster rf_RecoveryXorUndoFunc = rf_NullNodeUndoFunc;
101 1.3 oster return (0);
102 1.1 oster }
103 1.1 oster
104 1.1 oster
105 1.1 oster
106 1.14 oster /*****************************************************************************
107 1.1 oster * the execution function associated with a terminate node
108 1.14 oster ****************************************************************************/
109 1.3 oster int
110 1.15 oster rf_TerminateFunc(RF_DagNode_t *node)
111 1.1 oster {
112 1.3 oster RF_ASSERT(node->dagHdr->numCommits == node->dagHdr->numCommitNodes);
113 1.3 oster node->status = rf_good;
114 1.3 oster return (rf_FinishNode(node, RF_THREAD_CONTEXT));
115 1.1 oster }
116 1.1 oster
117 1.3 oster int
118 1.15 oster rf_TerminateUndoFunc(RF_DagNode_t *node)
119 1.1 oster {
120 1.3 oster return (0);
121 1.1 oster }
122 1.1 oster
123 1.1 oster
124 1.15 oster /*****************************************************************************
125 1.1 oster * execution functions associated with a mirror node
126 1.1 oster *
127 1.1 oster * parameters:
128 1.1 oster *
129 1.1 oster * 0 - physical disk addres of data
130 1.1 oster * 1 - buffer for holding read data
131 1.1 oster * 2 - parity stripe ID
132 1.1 oster * 3 - flags
133 1.1 oster * 4 - physical disk address of mirror (parity)
134 1.1 oster *
135 1.15 oster ****************************************************************************/
136 1.1 oster
137 1.3 oster int
138 1.15 oster rf_DiskReadMirrorIdleFunc(RF_DagNode_t *node)
139 1.1 oster {
140 1.3 oster /* select the mirror copy with the shortest queue and fill in node
141 1.3 oster * parameters with physical disk address */
142 1.1 oster
143 1.3 oster rf_SelectMirrorDiskIdle(node);
144 1.3 oster return (rf_DiskReadFunc(node));
145 1.1 oster }
146 1.1 oster
147 1.11 oster #if (RF_INCLUDE_CHAINDECLUSTER > 0) || (RF_INCLUDE_INTERDECLUSTER > 0) || (RF_DEBUG_VALIDATE_DAG > 0)
148 1.3 oster int
149 1.15 oster rf_DiskReadMirrorPartitionFunc(RF_DagNode_t *node)
150 1.1 oster {
151 1.3 oster /* select the mirror copy with the shortest queue and fill in node
152 1.3 oster * parameters with physical disk address */
153 1.1 oster
154 1.3 oster rf_SelectMirrorDiskPartition(node);
155 1.3 oster return (rf_DiskReadFunc(node));
156 1.1 oster }
157 1.11 oster #endif
158 1.1 oster
159 1.3 oster int
160 1.15 oster rf_DiskReadMirrorUndoFunc(RF_DagNode_t *node)
161 1.1 oster {
162 1.3 oster return (0);
163 1.1 oster }
164 1.1 oster
165 1.1 oster
166 1.1 oster
167 1.1 oster #if RF_INCLUDE_PARITYLOGGING > 0
168 1.14 oster /*****************************************************************************
169 1.1 oster * the execution function associated with a parity log update node
170 1.14 oster ****************************************************************************/
171 1.3 oster int
172 1.15 oster rf_ParityLogUpdateFunc(RF_DagNode_t *node)
173 1.3 oster {
174 1.3 oster RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
175 1.3 oster caddr_t buf = (caddr_t) node->params[1].p;
176 1.3 oster RF_ParityLogData_t *logData;
177 1.19 oster #if RF_ACC_TRACE > 0
178 1.3 oster RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
179 1.3 oster RF_Etimer_t timer;
180 1.19 oster #endif
181 1.3 oster
182 1.3 oster if (node->dagHdr->status == rf_enable) {
183 1.19 oster #if RF_ACC_TRACE > 0
184 1.3 oster RF_ETIMER_START(timer);
185 1.19 oster #endif
186 1.3 oster logData = rf_CreateParityLogData(RF_UPDATE, pda, buf,
187 1.3 oster (RF_Raid_t *) (node->dagHdr->raidPtr),
188 1.3 oster node->wakeFunc, (void *) node,
189 1.3 oster node->dagHdr->tracerec, timer);
190 1.3 oster if (logData)
191 1.3 oster rf_ParityLogAppend(logData, RF_FALSE, NULL, RF_FALSE);
192 1.3 oster else {
193 1.19 oster #if RF_ACC_TRACE > 0
194 1.3 oster RF_ETIMER_STOP(timer);
195 1.3 oster RF_ETIMER_EVAL(timer);
196 1.3 oster tracerec->plog_us += RF_ETIMER_VAL_US(timer);
197 1.19 oster #endif
198 1.3 oster (node->wakeFunc) (node, ENOMEM);
199 1.3 oster }
200 1.1 oster }
201 1.3 oster return (0);
202 1.1 oster }
203 1.1 oster
204 1.1 oster
205 1.15 oster /*****************************************************************************
206 1.1 oster * the execution function associated with a parity log overwrite node
207 1.15 oster ****************************************************************************/
208 1.3 oster int
209 1.15 oster rf_ParityLogOverwriteFunc(RF_DagNode_t *node)
210 1.3 oster {
211 1.3 oster RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
212 1.3 oster caddr_t buf = (caddr_t) node->params[1].p;
213 1.3 oster RF_ParityLogData_t *logData;
214 1.19 oster #if RF_ACC_TRACE > 0
215 1.3 oster RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
216 1.3 oster RF_Etimer_t timer;
217 1.19 oster #endif
218 1.3 oster
219 1.3 oster if (node->dagHdr->status == rf_enable) {
220 1.19 oster #if RF_ACC_TRACE > 0
221 1.3 oster RF_ETIMER_START(timer);
222 1.19 oster #endif
223 1.14 oster logData = rf_CreateParityLogData(RF_OVERWRITE, pda, buf,
224 1.14 oster (RF_Raid_t *) (node->dagHdr->raidPtr),
225 1.3 oster node->wakeFunc, (void *) node, node->dagHdr->tracerec, timer);
226 1.3 oster if (logData)
227 1.3 oster rf_ParityLogAppend(logData, RF_FALSE, NULL, RF_FALSE);
228 1.3 oster else {
229 1.19 oster #if RF_ACC_TRACE > 0
230 1.3 oster RF_ETIMER_STOP(timer);
231 1.3 oster RF_ETIMER_EVAL(timer);
232 1.3 oster tracerec->plog_us += RF_ETIMER_VAL_US(timer);
233 1.19 oster #endif
234 1.3 oster (node->wakeFunc) (node, ENOMEM);
235 1.3 oster }
236 1.1 oster }
237 1.3 oster return (0);
238 1.1 oster }
239 1.1 oster
240 1.3 oster int
241 1.15 oster rf_ParityLogUpdateUndoFunc(RF_DagNode_t *node)
242 1.1 oster {
243 1.3 oster return (0);
244 1.1 oster }
245 1.1 oster
246 1.3 oster int
247 1.15 oster rf_ParityLogOverwriteUndoFunc(RF_DagNode_t *node)
248 1.1 oster {
249 1.3 oster return (0);
250 1.1 oster }
251 1.10 oster #endif /* RF_INCLUDE_PARITYLOGGING > 0 */
252 1.10 oster
253 1.14 oster /*****************************************************************************
254 1.1 oster * the execution function associated with a NOP node
255 1.14 oster ****************************************************************************/
256 1.3 oster int
257 1.15 oster rf_NullNodeFunc(RF_DagNode_t *node)
258 1.1 oster {
259 1.3 oster node->status = rf_good;
260 1.3 oster return (rf_FinishNode(node, RF_THREAD_CONTEXT));
261 1.1 oster }
262 1.1 oster
263 1.3 oster int
264 1.15 oster rf_NullNodeUndoFunc(RF_DagNode_t *node)
265 1.1 oster {
266 1.3 oster node->status = rf_undone;
267 1.3 oster return (rf_FinishNode(node, RF_THREAD_CONTEXT));
268 1.1 oster }
269 1.1 oster
270 1.1 oster
271 1.14 oster /*****************************************************************************
272 1.1 oster * the execution function associated with a disk-read node
273 1.14 oster ****************************************************************************/
274 1.3 oster int
275 1.15 oster rf_DiskReadFuncForThreads(RF_DagNode_t *node)
276 1.3 oster {
277 1.3 oster RF_DiskQueueData_t *req;
278 1.3 oster RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
279 1.3 oster caddr_t buf = (caddr_t) node->params[1].p;
280 1.3 oster RF_StripeNum_t parityStripeID = (RF_StripeNum_t) node->params[2].v;
281 1.3 oster unsigned priority = RF_EXTRACT_PRIORITY(node->params[3].v);
282 1.3 oster unsigned which_ru = RF_EXTRACT_RU(node->params[3].v);
283 1.3 oster RF_IoType_t iotype = (node->dagHdr->status == rf_enable) ? RF_IO_TYPE_READ : RF_IO_TYPE_NOP;
284 1.13 oster RF_DiskQueue_t *dqs = ((RF_Raid_t *) (node->dagHdr->raidPtr))->Queues;
285 1.3 oster void *b_proc = NULL;
286 1.1 oster
287 1.3 oster if (node->dagHdr->bp)
288 1.3 oster b_proc = (void *) ((struct buf *) node->dagHdr->bp)->b_proc;
289 1.1 oster
290 1.3 oster req = rf_CreateDiskQueueData(iotype, pda->startSector, pda->numSector,
291 1.3 oster buf, parityStripeID, which_ru,
292 1.3 oster (int (*) (void *, int)) node->wakeFunc,
293 1.19 oster node, NULL,
294 1.19 oster #if RF_ACC_TRACE > 0
295 1.19 oster node->dagHdr->tracerec,
296 1.19 oster #else
297 1.19 oster NULL,
298 1.19 oster #endif
299 1.18 oster (void *) (node->dagHdr->raidPtr), 0, b_proc);
300 1.3 oster if (!req) {
301 1.3 oster (node->wakeFunc) (node, ENOMEM);
302 1.3 oster } else {
303 1.3 oster node->dagFuncData = (void *) req;
304 1.13 oster rf_DiskIOEnqueue(&(dqs[pda->col]), req, priority);
305 1.3 oster }
306 1.3 oster return (0);
307 1.1 oster }
308 1.1 oster
309 1.1 oster
310 1.14 oster /*****************************************************************************
311 1.1 oster * the execution function associated with a disk-write node
312 1.14 oster ****************************************************************************/
313 1.3 oster int
314 1.15 oster rf_DiskWriteFuncForThreads(RF_DagNode_t *node)
315 1.3 oster {
316 1.3 oster RF_DiskQueueData_t *req;
317 1.3 oster RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
318 1.3 oster caddr_t buf = (caddr_t) node->params[1].p;
319 1.3 oster RF_StripeNum_t parityStripeID = (RF_StripeNum_t) node->params[2].v;
320 1.3 oster unsigned priority = RF_EXTRACT_PRIORITY(node->params[3].v);
321 1.3 oster unsigned which_ru = RF_EXTRACT_RU(node->params[3].v);
322 1.3 oster RF_IoType_t iotype = (node->dagHdr->status == rf_enable) ? RF_IO_TYPE_WRITE : RF_IO_TYPE_NOP;
323 1.13 oster RF_DiskQueue_t *dqs = ((RF_Raid_t *) (node->dagHdr->raidPtr))->Queues;
324 1.3 oster void *b_proc = NULL;
325 1.1 oster
326 1.3 oster if (node->dagHdr->bp)
327 1.3 oster b_proc = (void *) ((struct buf *) node->dagHdr->bp)->b_proc;
328 1.1 oster
329 1.3 oster /* normal processing (rollaway or forward recovery) begins here */
330 1.3 oster req = rf_CreateDiskQueueData(iotype, pda->startSector, pda->numSector,
331 1.3 oster buf, parityStripeID, which_ru,
332 1.3 oster (int (*) (void *, int)) node->wakeFunc,
333 1.3 oster (void *) node, NULL,
334 1.19 oster #if RF_ACC_TRACE > 0
335 1.3 oster node->dagHdr->tracerec,
336 1.19 oster #else
337 1.19 oster NULL,
338 1.19 oster #endif
339 1.3 oster (void *) (node->dagHdr->raidPtr),
340 1.18 oster 0, b_proc);
341 1.3 oster
342 1.3 oster if (!req) {
343 1.3 oster (node->wakeFunc) (node, ENOMEM);
344 1.3 oster } else {
345 1.3 oster node->dagFuncData = (void *) req;
346 1.13 oster rf_DiskIOEnqueue(&(dqs[pda->col]), req, priority);
347 1.3 oster }
348 1.3 oster
349 1.3 oster return (0);
350 1.1 oster }
351 1.14 oster /*****************************************************************************
352 1.1 oster * the undo function for disk nodes
353 1.1 oster * Note: this is not a proper undo of a write node, only locks are released.
354 1.1 oster * old data is not restored to disk!
355 1.14 oster ****************************************************************************/
356 1.3 oster int
357 1.15 oster rf_DiskUndoFunc(RF_DagNode_t *node)
358 1.3 oster {
359 1.3 oster RF_DiskQueueData_t *req;
360 1.3 oster RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
361 1.13 oster RF_DiskQueue_t *dqs = ((RF_Raid_t *) (node->dagHdr->raidPtr))->Queues;
362 1.3 oster
363 1.3 oster req = rf_CreateDiskQueueData(RF_IO_TYPE_NOP,
364 1.3 oster 0L, 0, NULL, 0L, 0,
365 1.3 oster (int (*) (void *, int)) node->wakeFunc,
366 1.3 oster (void *) node,
367 1.19 oster NULL,
368 1.19 oster #if RF_ACC_TRACE > 0
369 1.19 oster node->dagHdr->tracerec,
370 1.19 oster #else
371 1.19 oster NULL,
372 1.19 oster #endif
373 1.3 oster (void *) (node->dagHdr->raidPtr),
374 1.3 oster RF_UNLOCK_DISK_QUEUE, NULL);
375 1.3 oster if (!req)
376 1.3 oster (node->wakeFunc) (node, ENOMEM);
377 1.3 oster else {
378 1.3 oster node->dagFuncData = (void *) req;
379 1.13 oster rf_DiskIOEnqueue(&(dqs[pda->col]), req, RF_IO_NORMAL_PRIORITY);
380 1.3 oster }
381 1.1 oster
382 1.3 oster return (0);
383 1.1 oster }
384 1.14 oster /*****************************************************************************
385 1.1 oster * the execution function associated with an "unlock disk queue" node
386 1.14 oster ****************************************************************************/
387 1.3 oster int
388 1.15 oster rf_DiskUnlockFuncForThreads(RF_DagNode_t *node)
389 1.3 oster {
390 1.3 oster RF_DiskQueueData_t *req;
391 1.3 oster RF_PhysDiskAddr_t *pda = (RF_PhysDiskAddr_t *) node->params[0].p;
392 1.13 oster RF_DiskQueue_t *dqs = ((RF_Raid_t *) (node->dagHdr->raidPtr))->Queues;
393 1.3 oster
394 1.3 oster req = rf_CreateDiskQueueData(RF_IO_TYPE_NOP,
395 1.3 oster 0L, 0, NULL, 0L, 0,
396 1.3 oster (int (*) (void *, int)) node->wakeFunc,
397 1.3 oster (void *) node,
398 1.19 oster NULL,
399 1.19 oster #if RF_ACC_TRACE > 0
400 1.19 oster node->dagHdr->tracerec,
401 1.19 oster #else
402 1.19 oster NULL,
403 1.19 oster #endif
404 1.3 oster (void *) (node->dagHdr->raidPtr),
405 1.3 oster RF_UNLOCK_DISK_QUEUE, NULL);
406 1.3 oster if (!req)
407 1.3 oster (node->wakeFunc) (node, ENOMEM);
408 1.3 oster else {
409 1.3 oster node->dagFuncData = (void *) req;
410 1.13 oster rf_DiskIOEnqueue(&(dqs[pda->col]), req, RF_IO_NORMAL_PRIORITY);
411 1.3 oster }
412 1.1 oster
413 1.3 oster return (0);
414 1.1 oster }
415 1.14 oster /*****************************************************************************
416 1.14 oster * Callback routine for DiskRead and DiskWrite nodes. When the disk
417 1.14 oster * op completes, the routine is called to set the node status and
418 1.14 oster * inform the execution engine that the node has fired.
419 1.14 oster ****************************************************************************/
420 1.3 oster int
421 1.15 oster rf_GenericWakeupFunc(RF_DagNode_t *node, int status)
422 1.3 oster {
423 1.15 oster
424 1.3 oster switch (node->status) {
425 1.3 oster case rf_bwd1:
426 1.3 oster node->status = rf_bwd2;
427 1.3 oster if (node->dagFuncData)
428 1.3 oster rf_FreeDiskQueueData((RF_DiskQueueData_t *) node->dagFuncData);
429 1.3 oster return (rf_DiskWriteFuncForThreads(node));
430 1.3 oster case rf_fired:
431 1.3 oster if (status)
432 1.3 oster node->status = rf_bad;
433 1.3 oster else
434 1.3 oster node->status = rf_good;
435 1.3 oster break;
436 1.3 oster case rf_recover:
437 1.3 oster /* probably should never reach this case */
438 1.3 oster if (status)
439 1.3 oster node->status = rf_panic;
440 1.3 oster else
441 1.3 oster node->status = rf_undone;
442 1.3 oster break;
443 1.3 oster default:
444 1.4 oster printf("rf_GenericWakeupFunc:");
445 1.4 oster printf("node->status is %d,", node->status);
446 1.4 oster printf("status is %d \n", status);
447 1.3 oster RF_PANIC();
448 1.3 oster break;
449 1.3 oster }
450 1.3 oster if (node->dagFuncData)
451 1.3 oster rf_FreeDiskQueueData((RF_DiskQueueData_t *) node->dagFuncData);
452 1.3 oster return (rf_FinishNode(node, RF_INTR_CONTEXT));
453 1.1 oster }
454 1.1 oster
455 1.1 oster
456 1.14 oster /*****************************************************************************
457 1.14 oster * there are three distinct types of xor nodes:
458 1.14 oster
459 1.14 oster * A "regular xor" is used in the fault-free case where the access
460 1.14 oster * spans a complete stripe unit. It assumes that the result buffer is
461 1.14 oster * one full stripe unit in size, and uses the stripe-unit-offset
462 1.14 oster * values that it computes from the PDAs to determine where within the
463 1.14 oster * stripe unit to XOR each argument buffer.
464 1.14 oster *
465 1.14 oster * A "simple xor" is used in the fault-free case where the access
466 1.14 oster * touches only a portion of one (or two, in some cases) stripe
467 1.14 oster * unit(s). It assumes that all the argument buffers are of the same
468 1.14 oster * size and have the same stripe unit offset.
469 1.14 oster *
470 1.14 oster * A "recovery xor" is used in the degraded-mode case. It's similar
471 1.14 oster * to the regular xor function except that it takes the failed PDA as
472 1.14 oster * an additional parameter, and uses it to determine what portions of
473 1.14 oster * the argument buffers need to be xor'd into the result buffer, and
474 1.14 oster * where in the result buffer they should go.
475 1.14 oster ****************************************************************************/
476 1.1 oster
477 1.1 oster /* xor the params together and store the result in the result field.
478 1.14 oster * assume the result field points to a buffer that is the size of one
479 1.14 oster * SU, and use the pda params to determine where within the buffer to
480 1.14 oster * XOR the input buffers. */
481 1.3 oster int
482 1.15 oster rf_RegularXorFunc(RF_DagNode_t *node)
483 1.3 oster {
484 1.3 oster RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[node->numParams - 1].p;
485 1.19 oster #if RF_ACC_TRACE > 0
486 1.3 oster RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
487 1.3 oster RF_Etimer_t timer;
488 1.19 oster #endif
489 1.3 oster int i, retcode;
490 1.1 oster
491 1.3 oster retcode = 0;
492 1.3 oster if (node->dagHdr->status == rf_enable) {
493 1.3 oster /* don't do the XOR if the input is the same as the output */
494 1.19 oster #if RF_ACC_TRACE > 0
495 1.3 oster RF_ETIMER_START(timer);
496 1.19 oster #endif
497 1.3 oster for (i = 0; i < node->numParams - 1; i += 2)
498 1.3 oster if (node->params[i + 1].p != node->results[0]) {
499 1.3 oster retcode = rf_XorIntoBuffer(raidPtr, (RF_PhysDiskAddr_t *) node->params[i].p,
500 1.17 oster (char *) node->params[i + 1].p, (char *) node->results[0]);
501 1.3 oster }
502 1.19 oster #if RF_ACC_TRACE > 0
503 1.3 oster RF_ETIMER_STOP(timer);
504 1.3 oster RF_ETIMER_EVAL(timer);
505 1.3 oster tracerec->xor_us += RF_ETIMER_VAL_US(timer);
506 1.19 oster #endif
507 1.3 oster }
508 1.3 oster return (rf_GenericWakeupFunc(node, retcode)); /* call wake func
509 1.3 oster * explicitly since no
510 1.3 oster * I/O in this node */
511 1.1 oster }
512 1.1 oster /* xor the inputs into the result buffer, ignoring placement issues */
513 1.3 oster int
514 1.15 oster rf_SimpleXorFunc(RF_DagNode_t *node)
515 1.3 oster {
516 1.3 oster RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[node->numParams - 1].p;
517 1.3 oster int i, retcode = 0;
518 1.19 oster #if RF_ACC_TRACE > 0
519 1.3 oster RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
520 1.3 oster RF_Etimer_t timer;
521 1.19 oster #endif
522 1.1 oster
523 1.3 oster if (node->dagHdr->status == rf_enable) {
524 1.19 oster #if RF_ACC_TRACE > 0
525 1.3 oster RF_ETIMER_START(timer);
526 1.19 oster #endif
527 1.3 oster /* don't do the XOR if the input is the same as the output */
528 1.3 oster for (i = 0; i < node->numParams - 1; i += 2)
529 1.3 oster if (node->params[i + 1].p != node->results[0]) {
530 1.3 oster retcode = rf_bxor((char *) node->params[i + 1].p, (char *) node->results[0],
531 1.17 oster rf_RaidAddressToByte(raidPtr, ((RF_PhysDiskAddr_t *) node->params[i].p)->numSector));
532 1.3 oster }
533 1.19 oster #if RF_ACC_TRACE > 0
534 1.3 oster RF_ETIMER_STOP(timer);
535 1.3 oster RF_ETIMER_EVAL(timer);
536 1.3 oster tracerec->xor_us += RF_ETIMER_VAL_US(timer);
537 1.19 oster #endif
538 1.3 oster }
539 1.3 oster return (rf_GenericWakeupFunc(node, retcode)); /* call wake func
540 1.3 oster * explicitly since no
541 1.3 oster * I/O in this node */
542 1.1 oster }
543 1.14 oster /* this xor is used by the degraded-mode dag functions to recover lost
544 1.14 oster * data. the second-to-last parameter is the PDA for the failed
545 1.14 oster * portion of the access. the code here looks at this PDA and assumes
546 1.14 oster * that the xor target buffer is equal in size to the number of
547 1.14 oster * sectors in the failed PDA. It then uses the other PDAs in the
548 1.14 oster * parameter list to determine where within the target buffer the
549 1.14 oster * corresponding data should be xored. */
550 1.3 oster int
551 1.15 oster rf_RecoveryXorFunc(RF_DagNode_t *node)
552 1.3 oster {
553 1.3 oster RF_Raid_t *raidPtr = (RF_Raid_t *) node->params[node->numParams - 1].p;
554 1.3 oster RF_RaidLayout_t *layoutPtr = (RF_RaidLayout_t *) & raidPtr->Layout;
555 1.3 oster RF_PhysDiskAddr_t *failedPDA = (RF_PhysDiskAddr_t *) node->params[node->numParams - 2].p;
556 1.3 oster int i, retcode = 0;
557 1.3 oster RF_PhysDiskAddr_t *pda;
558 1.3 oster int suoffset, failedSUOffset = rf_StripeUnitOffset(layoutPtr, failedPDA->startSector);
559 1.3 oster char *srcbuf, *destbuf;
560 1.19 oster #if RF_ACC_TRACE > 0
561 1.3 oster RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;
562 1.3 oster RF_Etimer_t timer;
563 1.19 oster #endif
564 1.1 oster
565 1.3 oster if (node->dagHdr->status == rf_enable) {
566 1.19 oster #if RF_ACC_TRACE > 0
567 1.3 oster RF_ETIMER_START(timer);
568 1.19 oster #endif
569 1.3 oster for (i = 0; i < node->numParams - 2; i += 2)
570 1.3 oster if (node->params[i + 1].p != node->results[0]) {
571 1.3 oster pda = (RF_PhysDiskAddr_t *) node->params[i].p;
572 1.3 oster srcbuf = (char *) node->params[i + 1].p;
573 1.3 oster suoffset = rf_StripeUnitOffset(layoutPtr, pda->startSector);
574 1.3 oster destbuf = ((char *) node->results[0]) + rf_RaidAddressToByte(raidPtr, suoffset - failedSUOffset);
575 1.17 oster retcode = rf_bxor(srcbuf, destbuf, rf_RaidAddressToByte(raidPtr, pda->numSector));
576 1.3 oster }
577 1.19 oster #if RF_ACC_TRACE > 0
578 1.3 oster RF_ETIMER_STOP(timer);
579 1.3 oster RF_ETIMER_EVAL(timer);
580 1.3 oster tracerec->xor_us += RF_ETIMER_VAL_US(timer);
581 1.19 oster #endif
582 1.3 oster }
583 1.3 oster return (rf_GenericWakeupFunc(node, retcode));
584 1.1 oster }
585 1.14 oster /*****************************************************************************
586 1.14 oster * The next three functions are utilities used by the above
587 1.14 oster * xor-execution functions.
588 1.14 oster ****************************************************************************/
589 1.1 oster
590 1.1 oster
591 1.1 oster /*
592 1.14 oster * this is just a glorified buffer xor. targbuf points to a buffer
593 1.14 oster * that is one full stripe unit in size. srcbuf points to a buffer
594 1.14 oster * that may be less than 1 SU, but never more. When the access
595 1.14 oster * described by pda is one SU in size (which by implication means it's
596 1.14 oster * SU-aligned), all that happens is (targbuf) <- (srcbuf ^ targbuf).
597 1.14 oster * When the access is less than one SU in size the XOR occurs on only
598 1.14 oster * the portion of targbuf identified in the pda. */
599 1.1 oster
600 1.3 oster int
601 1.15 oster rf_XorIntoBuffer(RF_Raid_t *raidPtr, RF_PhysDiskAddr_t *pda,
602 1.17 oster char *srcbuf, char *targbuf)
603 1.3 oster {
604 1.3 oster char *targptr;
605 1.3 oster int sectPerSU = raidPtr->Layout.sectorsPerStripeUnit;
606 1.3 oster int SUOffset = pda->startSector % sectPerSU;
607 1.3 oster int length, retcode = 0;
608 1.3 oster
609 1.3 oster RF_ASSERT(pda->numSector <= sectPerSU);
610 1.3 oster
611 1.3 oster targptr = targbuf + rf_RaidAddressToByte(raidPtr, SUOffset);
612 1.3 oster length = rf_RaidAddressToByte(raidPtr, pda->numSector);
613 1.17 oster retcode = rf_bxor(srcbuf, targptr, length);
614 1.3 oster return (retcode);
615 1.1 oster }
616 1.14 oster /* it really should be the case that the buffer pointers (returned by
617 1.14 oster * malloc) are aligned to the natural word size of the machine, so
618 1.14 oster * this is the only case we optimize for. The length should always be
619 1.14 oster * a multiple of the sector size, so there should be no problem with
620 1.14 oster * leftover bytes at the end. */
621 1.3 oster int
622 1.17 oster rf_bxor(char *src, char *dest, int len)
623 1.3 oster {
624 1.3 oster unsigned mask = sizeof(long) - 1, retcode = 0;
625 1.3 oster
626 1.14 oster if (!(((unsigned long) src) & mask) &&
627 1.14 oster !(((unsigned long) dest) & mask) && !(len & mask)) {
628 1.14 oster retcode = rf_longword_bxor((unsigned long *) src,
629 1.14 oster (unsigned long *) dest,
630 1.17 oster len >> RF_LONGSHIFT);
631 1.3 oster } else {
632 1.3 oster RF_ASSERT(0);
633 1.3 oster }
634 1.3 oster return (retcode);
635 1.1 oster }
636 1.1 oster
637 1.14 oster /* When XORing in kernel mode, we need to map each user page to kernel
638 1.14 oster * space before we can access it. We don't want to assume anything
639 1.14 oster * about which input buffers are in kernel/user space, nor about their
640 1.14 oster * alignment, so in each loop we compute the maximum number of bytes
641 1.14 oster * that we can xor without crossing any page boundaries, and do only
642 1.15 oster * this many bytes before the next remap.
643 1.15 oster *
644 1.15 oster * len - is in longwords
645 1.15 oster */
646 1.3 oster int
647 1.17 oster rf_longword_bxor(unsigned long *src, unsigned long *dest, int len)
648 1.3 oster {
649 1.6 augustss unsigned long *end = src + len;
650 1.6 augustss unsigned long d0, d1, d2, d3, s0, s1, s2, s3; /* temps */
651 1.14 oster unsigned long *pg_src, *pg_dest; /* per-page source/dest pointers */
652 1.3 oster int longs_this_time;/* # longwords to xor in the current iteration */
653 1.3 oster
654 1.16 oster pg_src = src;
655 1.16 oster pg_dest = dest;
656 1.3 oster if (!pg_src || !pg_dest)
657 1.3 oster return (EFAULT);
658 1.3 oster
659 1.3 oster while (len >= 4) {
660 1.3 oster longs_this_time = RF_MIN(len, RF_MIN(RF_BLIP(pg_src), RF_BLIP(pg_dest)) >> RF_LONGSHIFT); /* note len in longwords */
661 1.3 oster src += longs_this_time;
662 1.3 oster dest += longs_this_time;
663 1.3 oster len -= longs_this_time;
664 1.3 oster while (longs_this_time >= 4) {
665 1.3 oster d0 = pg_dest[0];
666 1.3 oster d1 = pg_dest[1];
667 1.3 oster d2 = pg_dest[2];
668 1.3 oster d3 = pg_dest[3];
669 1.3 oster s0 = pg_src[0];
670 1.3 oster s1 = pg_src[1];
671 1.3 oster s2 = pg_src[2];
672 1.3 oster s3 = pg_src[3];
673 1.3 oster pg_dest[0] = d0 ^ s0;
674 1.3 oster pg_dest[1] = d1 ^ s1;
675 1.3 oster pg_dest[2] = d2 ^ s2;
676 1.3 oster pg_dest[3] = d3 ^ s3;
677 1.3 oster pg_src += 4;
678 1.3 oster pg_dest += 4;
679 1.3 oster longs_this_time -= 4;
680 1.3 oster }
681 1.3 oster while (longs_this_time > 0) { /* cannot cross any page
682 1.3 oster * boundaries here */
683 1.3 oster *pg_dest++ ^= *pg_src++;
684 1.3 oster longs_this_time--;
685 1.3 oster }
686 1.3 oster
687 1.3 oster /* either we're done, or we've reached a page boundary on one
688 1.3 oster * (or possibly both) of the pointers */
689 1.3 oster if (len) {
690 1.3 oster if (RF_PAGE_ALIGNED(src))
691 1.16 oster pg_src = src;
692 1.3 oster if (RF_PAGE_ALIGNED(dest))
693 1.16 oster pg_dest = dest;
694 1.3 oster if (!pg_src || !pg_dest)
695 1.3 oster return (EFAULT);
696 1.3 oster }
697 1.3 oster }
698 1.3 oster while (src < end) {
699 1.3 oster *pg_dest++ ^= *pg_src++;
700 1.3 oster src++;
701 1.3 oster dest++;
702 1.3 oster len--;
703 1.3 oster if (RF_PAGE_ALIGNED(src))
704 1.16 oster pg_src = src;
705 1.3 oster if (RF_PAGE_ALIGNED(dest))
706 1.16 oster pg_dest = dest;
707 1.3 oster }
708 1.3 oster RF_ASSERT(len == 0);
709 1.3 oster return (0);
710 1.1 oster }
711 1.1 oster
712 1.9 oster #if 0
713 1.1 oster /*
714 1.1 oster dst = a ^ b ^ c;
715 1.1 oster a may equal dst
716 1.1 oster see comment above longword_bxor
717 1.15 oster len is length in longwords
718 1.1 oster */
719 1.3 oster int
720 1.15 oster rf_longword_bxor3(unsigned long *dst, unsigned long *a, unsigned long *b,
721 1.15 oster unsigned long *c, int len, void *bp)
722 1.3 oster {
723 1.3 oster unsigned long a0, a1, a2, a3, b0, b1, b2, b3;
724 1.6 augustss unsigned long *pg_a, *pg_b, *pg_c, *pg_dst; /* per-page source/dest
725 1.3 oster * pointers */
726 1.3 oster int longs_this_time;/* # longs to xor in the current iteration */
727 1.3 oster char dst_is_a = 0;
728 1.3 oster
729 1.16 oster pg_a = a;
730 1.16 oster pg_b = b;
731 1.16 oster pg_c = c;
732 1.3 oster if (a == dst) {
733 1.3 oster pg_dst = pg_a;
734 1.3 oster dst_is_a = 1;
735 1.3 oster } else {
736 1.16 oster pg_dst = dst;
737 1.3 oster }
738 1.3 oster
739 1.3 oster /* align dest to cache line. Can't cross a pg boundary on dst here. */
740 1.3 oster while ((((unsigned long) pg_dst) & 0x1f)) {
741 1.3 oster *pg_dst++ = *pg_a++ ^ *pg_b++ ^ *pg_c++;
742 1.3 oster dst++;
743 1.3 oster a++;
744 1.3 oster b++;
745 1.3 oster c++;
746 1.3 oster if (RF_PAGE_ALIGNED(a)) {
747 1.16 oster pg_a = a;
748 1.3 oster if (!pg_a)
749 1.3 oster return (EFAULT);
750 1.3 oster }
751 1.3 oster if (RF_PAGE_ALIGNED(b)) {
752 1.16 oster pg_b = a;
753 1.3 oster if (!pg_b)
754 1.3 oster return (EFAULT);
755 1.3 oster }
756 1.3 oster if (RF_PAGE_ALIGNED(c)) {
757 1.16 oster pg_c = a;
758 1.3 oster if (!pg_c)
759 1.3 oster return (EFAULT);
760 1.3 oster }
761 1.3 oster len--;
762 1.3 oster }
763 1.3 oster
764 1.3 oster while (len > 4) {
765 1.3 oster longs_this_time = RF_MIN(len, RF_MIN(RF_BLIP(a), RF_MIN(RF_BLIP(b), RF_MIN(RF_BLIP(c), RF_BLIP(dst)))) >> RF_LONGSHIFT);
766 1.3 oster a += longs_this_time;
767 1.3 oster b += longs_this_time;
768 1.3 oster c += longs_this_time;
769 1.3 oster dst += longs_this_time;
770 1.3 oster len -= longs_this_time;
771 1.3 oster while (longs_this_time >= 4) {
772 1.3 oster a0 = pg_a[0];
773 1.3 oster longs_this_time -= 4;
774 1.3 oster
775 1.3 oster a1 = pg_a[1];
776 1.3 oster a2 = pg_a[2];
777 1.3 oster
778 1.3 oster a3 = pg_a[3];
779 1.3 oster pg_a += 4;
780 1.3 oster
781 1.3 oster b0 = pg_b[0];
782 1.3 oster b1 = pg_b[1];
783 1.3 oster
784 1.3 oster b2 = pg_b[2];
785 1.3 oster b3 = pg_b[3];
786 1.3 oster /* start dual issue */
787 1.3 oster a0 ^= b0;
788 1.3 oster b0 = pg_c[0];
789 1.3 oster
790 1.3 oster pg_b += 4;
791 1.3 oster a1 ^= b1;
792 1.3 oster
793 1.3 oster a2 ^= b2;
794 1.3 oster a3 ^= b3;
795 1.3 oster
796 1.3 oster b1 = pg_c[1];
797 1.3 oster a0 ^= b0;
798 1.3 oster
799 1.3 oster b2 = pg_c[2];
800 1.3 oster a1 ^= b1;
801 1.3 oster
802 1.3 oster b3 = pg_c[3];
803 1.3 oster a2 ^= b2;
804 1.3 oster
805 1.3 oster pg_dst[0] = a0;
806 1.3 oster a3 ^= b3;
807 1.3 oster pg_dst[1] = a1;
808 1.3 oster pg_c += 4;
809 1.3 oster pg_dst[2] = a2;
810 1.3 oster pg_dst[3] = a3;
811 1.3 oster pg_dst += 4;
812 1.3 oster }
813 1.3 oster while (longs_this_time > 0) { /* cannot cross any page
814 1.3 oster * boundaries here */
815 1.3 oster *pg_dst++ = *pg_a++ ^ *pg_b++ ^ *pg_c++;
816 1.3 oster longs_this_time--;
817 1.3 oster }
818 1.3 oster
819 1.3 oster if (len) {
820 1.3 oster if (RF_PAGE_ALIGNED(a)) {
821 1.16 oster pg_a = a;
822 1.3 oster if (!pg_a)
823 1.3 oster return (EFAULT);
824 1.3 oster if (dst_is_a)
825 1.3 oster pg_dst = pg_a;
826 1.3 oster }
827 1.3 oster if (RF_PAGE_ALIGNED(b)) {
828 1.16 oster pg_b = b;
829 1.3 oster if (!pg_b)
830 1.3 oster return (EFAULT);
831 1.3 oster }
832 1.3 oster if (RF_PAGE_ALIGNED(c)) {
833 1.16 oster pg_c = c;
834 1.3 oster if (!pg_c)
835 1.3 oster return (EFAULT);
836 1.3 oster }
837 1.3 oster if (!dst_is_a)
838 1.3 oster if (RF_PAGE_ALIGNED(dst)) {
839 1.16 oster pg_dst = dst;
840 1.3 oster if (!pg_dst)
841 1.3 oster return (EFAULT);
842 1.3 oster }
843 1.3 oster }
844 1.3 oster }
845 1.3 oster while (len) {
846 1.3 oster *pg_dst++ = *pg_a++ ^ *pg_b++ ^ *pg_c++;
847 1.3 oster dst++;
848 1.3 oster a++;
849 1.3 oster b++;
850 1.3 oster c++;
851 1.3 oster if (RF_PAGE_ALIGNED(a)) {
852 1.16 oster pg_a = a;
853 1.3 oster if (!pg_a)
854 1.3 oster return (EFAULT);
855 1.3 oster if (dst_is_a)
856 1.3 oster pg_dst = pg_a;
857 1.3 oster }
858 1.3 oster if (RF_PAGE_ALIGNED(b)) {
859 1.16 oster pg_b = b;
860 1.3 oster if (!pg_b)
861 1.3 oster return (EFAULT);
862 1.3 oster }
863 1.3 oster if (RF_PAGE_ALIGNED(c)) {
864 1.16 oster pg_c = c;
865 1.3 oster if (!pg_c)
866 1.3 oster return (EFAULT);
867 1.3 oster }
868 1.3 oster if (!dst_is_a)
869 1.3 oster if (RF_PAGE_ALIGNED(dst)) {
870 1.16 oster pg_dst = dst;
871 1.3 oster if (!pg_dst)
872 1.3 oster return (EFAULT);
873 1.3 oster }
874 1.3 oster len--;
875 1.3 oster }
876 1.3 oster return (0);
877 1.3 oster }
878 1.3 oster
879 1.3 oster int
880 1.15 oster rf_bxor3(unsigned char *dst, unsigned char *a, unsigned char *b,
881 1.15 oster unsigned char *c, unsigned long len, void *bp)
882 1.1 oster {
883 1.3 oster RF_ASSERT(((RF_UL(dst) | RF_UL(a) | RF_UL(b) | RF_UL(c) | len) & 0x7) == 0);
884 1.1 oster
885 1.3 oster return (rf_longword_bxor3((unsigned long *) dst, (unsigned long *) a,
886 1.3 oster (unsigned long *) b, (unsigned long *) c, len >> RF_LONGSHIFT, bp));
887 1.1 oster }
888 1.9 oster #endif
889