rf_diskqueue.c revision 1.2 1 1.2 oster /* $NetBSD: rf_diskqueue.c,v 1.2 1998/12/03 14:58:24 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
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 *
31 1.1 oster * rf_diskqueue.c -- higher-level disk queue code
32 1.1 oster *
33 1.1 oster * the routines here are a generic wrapper around the actual queueing
34 1.1 oster * routines. The code here implements thread scheduling, synchronization,
35 1.1 oster * and locking ops (see below) on top of the lower-level queueing code.
36 1.1 oster *
37 1.1 oster * to support atomic RMW, we implement "locking operations". When a locking op
38 1.1 oster * is dispatched to the lower levels of the driver, the queue is locked, and no further
39 1.1 oster * I/Os are dispatched until the queue receives & completes a corresponding "unlocking
40 1.1 oster * operation". This code relies on the higher layers to guarantee that a locking
41 1.1 oster * op will always be eventually followed by an unlocking op. The model is that
42 1.1 oster * the higher layers are structured so locking and unlocking ops occur in pairs, i.e.
43 1.1 oster * an unlocking op cannot be generated until after a locking op reports completion.
44 1.1 oster * There is no good way to check to see that an unlocking op "corresponds" to the
45 1.1 oster * op that currently has the queue locked, so we make no such attempt. Since by
46 1.1 oster * definition there can be only one locking op outstanding on a disk, this should
47 1.1 oster * not be a problem.
48 1.1 oster *
49 1.1 oster * In the kernel, we allow multiple I/Os to be concurrently dispatched to the disk
50 1.1 oster * driver. In order to support locking ops in this environment, when we decide to
51 1.1 oster * do a locking op, we stop dispatching new I/Os and wait until all dispatched I/Os
52 1.1 oster * have completed before dispatching the locking op.
53 1.1 oster *
54 1.1 oster * Unfortunately, the code is different in the 3 different operating states
55 1.1 oster * (user level, kernel, simulator). In the kernel, I/O is non-blocking, and
56 1.1 oster * we have no disk threads to dispatch for us. Therefore, we have to dispatch
57 1.1 oster * new I/Os to the scsi driver at the time of enqueue, and also at the time
58 1.1 oster * of completion. At user level, I/O is blocking, and so only the disk threads
59 1.1 oster * may dispatch I/Os. Thus at user level, all we can do at enqueue time is
60 1.1 oster * enqueue and wake up the disk thread to do the dispatch.
61 1.1 oster *
62 1.1 oster ***************************************************************************************/
63 1.1 oster
64 1.1 oster /*
65 1.1 oster * :
66 1.1 oster *
67 1.1 oster * Log: rf_diskqueue.c,v
68 1.1 oster * Revision 1.50 1996/08/07 21:08:38 jimz
69 1.1 oster * b_proc -> kb_proc
70 1.1 oster *
71 1.1 oster * Revision 1.49 1996/07/05 20:36:14 jimz
72 1.1 oster * make rf_ConfigureDiskQueueSystem return 0
73 1.1 oster *
74 1.1 oster * Revision 1.48 1996/06/18 20:53:11 jimz
75 1.1 oster * fix up disk queueing (remove configure routine,
76 1.1 oster * add shutdown list arg to create routines)
77 1.1 oster *
78 1.1 oster * Revision 1.47 1996/06/14 14:16:36 jimz
79 1.1 oster * fix handling of bogus queue type
80 1.1 oster *
81 1.1 oster * Revision 1.46 1996/06/13 20:41:44 jimz
82 1.1 oster * add scan, cscan, random queueing
83 1.1 oster *
84 1.1 oster * Revision 1.45 1996/06/11 01:27:50 jimz
85 1.1 oster * Fixed bug where diskthread shutdown would crash or hang. This
86 1.1 oster * turned out to be two distinct bugs:
87 1.1 oster * (1) [crash] The thread shutdown code wasn't properly waiting for
88 1.1 oster * all the diskthreads to complete. This caused diskthreads that were
89 1.1 oster * exiting+cleaning up to unlock a destroyed mutex.
90 1.1 oster * (2) [hang] TerminateDiskQueues wasn't locking, and DiskIODequeue
91 1.1 oster * only checked for termination _after_ a wakeup if the queues were
92 1.1 oster * empty. This was a race where the termination wakeup could be lost
93 1.1 oster * by the dequeueing thread, and the system would hang waiting for the
94 1.1 oster * thread to exit, while the thread waited for an I/O or a signal to
95 1.1 oster * check the termination flag.
96 1.1 oster *
97 1.1 oster * Revision 1.44 1996/06/10 11:55:47 jimz
98 1.1 oster * Straightened out some per-array/not-per-array distinctions, fixed
99 1.1 oster * a couple bugs related to confusion. Added shutdown lists. Removed
100 1.1 oster * layout shutdown function (now subsumed by shutdown lists).
101 1.1 oster *
102 1.1 oster * Revision 1.43 1996/06/09 02:36:46 jimz
103 1.1 oster * lots of little crufty cleanup- fixup whitespace
104 1.1 oster * issues, comment #ifdefs, improve typing in some
105 1.1 oster * places (esp size-related)
106 1.1 oster *
107 1.1 oster * Revision 1.42 1996/06/07 22:26:27 jimz
108 1.1 oster * type-ify which_ru (RF_ReconUnitNum_t)
109 1.1 oster *
110 1.1 oster * Revision 1.41 1996/06/07 21:33:04 jimz
111 1.1 oster * begin using consistent types for sector numbers,
112 1.1 oster * stripe numbers, row+col numbers, recon unit numbers
113 1.1 oster *
114 1.1 oster * Revision 1.40 1996/06/06 17:28:04 jimz
115 1.1 oster * track sector number of last I/O dequeued
116 1.1 oster *
117 1.1 oster * Revision 1.39 1996/06/06 01:14:13 jimz
118 1.1 oster * fix crashing bug when tracerec is NULL (ie, from copyback)
119 1.1 oster * initialize req->queue
120 1.1 oster *
121 1.1 oster * Revision 1.38 1996/06/05 19:38:32 jimz
122 1.1 oster * fixed up disk queueing types config
123 1.1 oster * added sstf disk queueing
124 1.1 oster * fixed exit bug on diskthreads (ref-ing bad mem)
125 1.1 oster *
126 1.1 oster * Revision 1.37 1996/06/05 18:06:02 jimz
127 1.1 oster * Major code cleanup. The Great Renaming is now done.
128 1.1 oster * Better modularity. Better typing. Fixed a bunch of
129 1.1 oster * synchronization bugs. Made a lot of global stuff
130 1.1 oster * per-desc or per-array. Removed dead code.
131 1.1 oster *
132 1.1 oster * Revision 1.36 1996/05/30 23:22:16 jimz
133 1.1 oster * bugfixes of serialization, timing problems
134 1.1 oster * more cleanup
135 1.1 oster *
136 1.1 oster * Revision 1.35 1996/05/30 12:59:18 jimz
137 1.1 oster * make etimer happier, more portable
138 1.1 oster *
139 1.1 oster * Revision 1.34 1996/05/30 11:29:41 jimz
140 1.1 oster * Numerous bug fixes. Stripe lock release code disagreed with the taking code
141 1.1 oster * about when stripes should be locked (I made it consistent: no parity, no lock)
142 1.1 oster * There was a lot of extra serialization of I/Os which I've removed- a lot of
143 1.1 oster * it was to calculate values for the cache code, which is no longer with us.
144 1.1 oster * More types, function, macro cleanup. Added code to properly quiesce the array
145 1.1 oster * on shutdown. Made a lot of stuff array-specific which was (bogusly) general
146 1.1 oster * before. Fixed memory allocation, freeing bugs.
147 1.1 oster *
148 1.1 oster * Revision 1.33 1996/05/27 18:56:37 jimz
149 1.1 oster * more code cleanup
150 1.1 oster * better typing
151 1.1 oster * compiles in all 3 environments
152 1.1 oster *
153 1.1 oster * Revision 1.32 1996/05/24 22:17:04 jimz
154 1.1 oster * continue code + namespace cleanup
155 1.1 oster * typed a bunch of flags
156 1.1 oster *
157 1.1 oster * Revision 1.31 1996/05/24 01:59:45 jimz
158 1.1 oster * another checkpoint in code cleanup for release
159 1.1 oster * time to sync kernel tree
160 1.1 oster *
161 1.1 oster * Revision 1.30 1996/05/23 21:46:35 jimz
162 1.1 oster * checkpoint in code cleanup (release prep)
163 1.1 oster * lots of types, function names have been fixed
164 1.1 oster *
165 1.1 oster * Revision 1.29 1996/05/23 00:33:23 jimz
166 1.1 oster * code cleanup: move all debug decls to rf_options.c, all extern
167 1.1 oster * debug decls to rf_options.h, all debug vars preceded by rf_
168 1.1 oster *
169 1.1 oster * Revision 1.28 1996/05/20 16:14:29 jimz
170 1.1 oster * switch to rf_{mutex,cond}_{init,destroy}
171 1.1 oster *
172 1.1 oster * Revision 1.27 1996/05/18 19:51:34 jimz
173 1.1 oster * major code cleanup- fix syntax, make some types consistent,
174 1.1 oster * add prototypes, clean out dead code, et cetera
175 1.1 oster *
176 1.1 oster * Revision 1.26 1996/05/16 19:21:49 wvcii
177 1.1 oster * fixed typo in init_dqd
178 1.1 oster *
179 1.1 oster * Revision 1.25 1996/05/16 16:02:51 jimz
180 1.1 oster * switch to RF_FREELIST stuff for DiskQueueData
181 1.1 oster *
182 1.1 oster * Revision 1.24 1996/05/10 16:24:14 jimz
183 1.1 oster * new cvscan function names
184 1.1 oster *
185 1.1 oster * Revision 1.23 1996/05/01 16:27:54 jimz
186 1.1 oster * don't use ccmn bp management
187 1.1 oster *
188 1.1 oster * Revision 1.22 1995/12/12 18:10:06 jimz
189 1.1 oster * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT
190 1.1 oster * fix 80-column brain damage in comments
191 1.1 oster *
192 1.1 oster * Revision 1.21 1995/12/01 15:59:59 root
193 1.1 oster * added copyright info
194 1.1 oster *
195 1.1 oster * Revision 1.20 1995/11/07 16:27:20 wvcii
196 1.1 oster * added Peek() function to diskqueuesw
197 1.1 oster * non-locking accesses are never blocked (assume clients enforce proper
198 1.1 oster * respect for lock acquisition)
199 1.1 oster *
200 1.1 oster * Revision 1.19 1995/10/05 18:56:52 jimz
201 1.1 oster * fix req handling in IOComplete
202 1.1 oster *
203 1.1 oster * Revision 1.18 1995/10/04 20:13:50 wvcii
204 1.1 oster * added asserts to monitor numOutstanding queueLength
205 1.1 oster *
206 1.1 oster * Revision 1.17 1995/10/04 07:43:52 wvcii
207 1.1 oster * queue->numOutstanding now valid for user & sim
208 1.1 oster * added queue->queueLength
209 1.1 oster * user tested & verified, sim untested
210 1.1 oster *
211 1.1 oster * Revision 1.16 1995/09/12 00:21:19 wvcii
212 1.1 oster * added support for tracing disk queue time
213 1.1 oster *
214 1.1 oster */
215 1.1 oster
216 1.1 oster #include "rf_types.h"
217 1.1 oster #include "rf_threadstuff.h"
218 1.1 oster #include "rf_threadid.h"
219 1.1 oster #include "rf_raid.h"
220 1.1 oster #include "rf_diskqueue.h"
221 1.1 oster #include "rf_alloclist.h"
222 1.1 oster #include "rf_acctrace.h"
223 1.1 oster #include "rf_etimer.h"
224 1.1 oster #include "rf_configure.h"
225 1.1 oster #include "rf_general.h"
226 1.1 oster #include "rf_freelist.h"
227 1.1 oster #include "rf_debugprint.h"
228 1.1 oster #include "rf_shutdown.h"
229 1.1 oster #include "rf_cvscan.h"
230 1.1 oster #include "rf_sstf.h"
231 1.1 oster #include "rf_fifo.h"
232 1.1 oster
233 1.1 oster #ifdef SIMULATE
234 1.1 oster #include "rf_diskevent.h"
235 1.1 oster #endif /* SIMULATE */
236 1.1 oster
237 1.1 oster #if !defined(__NetBSD__)
238 1.1 oster extern struct buf *ubc_bufget();
239 1.1 oster #endif
240 1.1 oster
241 1.1 oster static int init_dqd(RF_DiskQueueData_t *);
242 1.1 oster static void clean_dqd(RF_DiskQueueData_t *);
243 1.1 oster static void rf_ShutdownDiskQueueSystem(void *);
244 1.1 oster /* From rf_kintf.c */
245 1.1 oster int rf_DispatchKernelIO(RF_DiskQueue_t *,RF_DiskQueueData_t *);
246 1.1 oster
247 1.1 oster
248 1.1 oster #define Dprintf1(s,a) if (rf_queueDebug) rf_debug_printf(s,(void *)((unsigned long)a),NULL,NULL,NULL,NULL,NULL,NULL,NULL)
249 1.1 oster #define Dprintf2(s,a,b) if (rf_queueDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),NULL,NULL,NULL,NULL,NULL,NULL)
250 1.1 oster #define Dprintf3(s,a,b,c) if (rf_queueDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),(void *)((unsigned long)c),NULL,NULL,NULL,NULL,NULL)
251 1.1 oster #define Dprintf4(s,a,b,c,d) if (rf_queueDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),(void *)((unsigned long)c),(void *)((unsigned long)d),NULL,NULL,NULL,NULL)
252 1.1 oster #define Dprintf5(s,a,b,c,d,e) if (rf_queueDebug) rf_debug_printf(s,(void *)((unsigned long)a),(void *)((unsigned long)b),(void *)((unsigned long)c),(void *)((unsigned long)d),(void *)((unsigned long)e),NULL,NULL,NULL)
253 1.1 oster
254 1.1 oster #if !defined(KERNEL) && !defined(SIMULATE)
255 1.1 oster
256 1.1 oster /* queue must be locked before invoking this */
257 1.1 oster #define SIGNAL_DISK_QUEUE(_q_,_wh_) \
258 1.1 oster { \
259 1.1 oster if ( (_q_)->numWaiting > 0) { \
260 1.1 oster (_q_)->numWaiting--; \
261 1.1 oster RF_SIGNAL_COND( ((_q_)->cond) ); \
262 1.1 oster } \
263 1.1 oster }
264 1.1 oster
265 1.1 oster /* queue must be locked before invoking this */
266 1.1 oster #define WAIT_DISK_QUEUE(_q_,_wh_) \
267 1.1 oster { \
268 1.1 oster (_q_)->numWaiting++; \
269 1.1 oster RF_WAIT_COND( ((_q_)->cond), ((_q_)->mutex) ); \
270 1.1 oster }
271 1.1 oster
272 1.1 oster #else /* !defined(KERNEL) && !defined(SIMULATE) */
273 1.1 oster
274 1.1 oster #define SIGNAL_DISK_QUEUE(_q_,_wh_)
275 1.1 oster #define WAIT_DISK_QUEUE(_q_,_wh_)
276 1.1 oster
277 1.1 oster #endif /* !defined(KERNEL) && !defined(SIMULATE) */
278 1.1 oster
279 1.1 oster /*****************************************************************************************
280 1.1 oster *
281 1.1 oster * the disk queue switch defines all the functions used in the different queueing
282 1.1 oster * disciplines
283 1.1 oster * queue ID, init routine, enqueue routine, dequeue routine
284 1.1 oster *
285 1.1 oster ****************************************************************************************/
286 1.1 oster
287 1.1 oster static RF_DiskQueueSW_t diskqueuesw[] = {
288 1.1 oster {"fifo", /* FIFO */
289 1.1 oster rf_FifoCreate,
290 1.1 oster rf_FifoEnqueue,
291 1.1 oster rf_FifoDequeue,
292 1.1 oster rf_FifoPeek,
293 1.1 oster rf_FifoPromote},
294 1.1 oster
295 1.1 oster {"cvscan", /* cvscan */
296 1.1 oster rf_CvscanCreate,
297 1.1 oster rf_CvscanEnqueue,
298 1.1 oster rf_CvscanDequeue,
299 1.1 oster rf_CvscanPeek,
300 1.1 oster rf_CvscanPromote },
301 1.1 oster
302 1.1 oster {"sstf", /* shortest seek time first */
303 1.1 oster rf_SstfCreate,
304 1.1 oster rf_SstfEnqueue,
305 1.1 oster rf_SstfDequeue,
306 1.1 oster rf_SstfPeek,
307 1.1 oster rf_SstfPromote},
308 1.1 oster
309 1.1 oster {"scan", /* SCAN (two-way elevator) */
310 1.1 oster rf_ScanCreate,
311 1.1 oster rf_SstfEnqueue,
312 1.1 oster rf_ScanDequeue,
313 1.1 oster rf_ScanPeek,
314 1.1 oster rf_SstfPromote},
315 1.1 oster
316 1.1 oster {"cscan", /* CSCAN (one-way elevator) */
317 1.1 oster rf_CscanCreate,
318 1.1 oster rf_SstfEnqueue,
319 1.1 oster rf_CscanDequeue,
320 1.1 oster rf_CscanPeek,
321 1.1 oster rf_SstfPromote},
322 1.1 oster
323 1.1 oster #if !defined(KERNEL) && RF_INCLUDE_QUEUE_RANDOM > 0
324 1.1 oster /* to make a point to Chris :-> */
325 1.1 oster {"random", /* random */
326 1.1 oster rf_FifoCreate,
327 1.1 oster rf_FifoEnqueue,
328 1.1 oster rf_RandomDequeue,
329 1.1 oster rf_RandomPeek,
330 1.1 oster rf_FifoPromote},
331 1.1 oster #endif /* !KERNEL && RF_INCLUDE_QUEUE_RANDOM > 0 */
332 1.1 oster };
333 1.1 oster #define NUM_DISK_QUEUE_TYPES (sizeof(diskqueuesw)/sizeof(RF_DiskQueueSW_t))
334 1.1 oster
335 1.1 oster static RF_FreeList_t *rf_dqd_freelist;
336 1.1 oster
337 1.1 oster #define RF_MAX_FREE_DQD 256
338 1.1 oster #define RF_DQD_INC 16
339 1.1 oster #define RF_DQD_INITIAL 64
340 1.1 oster
341 1.1 oster #ifdef __NetBSD__
342 1.1 oster #ifdef _KERNEL
343 1.1 oster #include <sys/buf.h>
344 1.1 oster #endif
345 1.1 oster #endif
346 1.1 oster
347 1.1 oster static int init_dqd(dqd)
348 1.1 oster RF_DiskQueueData_t *dqd;
349 1.1 oster {
350 1.1 oster #ifdef KERNEL
351 1.1 oster #ifdef __NetBSD__
352 1.1 oster /* XXX not sure if the following malloc is appropriate... probably not quite... */
353 1.1 oster dqd->bp = (struct buf *) malloc( sizeof(struct buf), M_DEVBUF, M_NOWAIT);
354 1.1 oster memset(dqd->bp,0,sizeof(struct buf)); /* if you don't do it, nobody else will.. */
355 1.1 oster /* XXX */
356 1.1 oster /* printf("NEED TO IMPLEMENT THIS BETTER!\n"); */
357 1.1 oster #else
358 1.1 oster dqd->bp = ubc_bufget();
359 1.1 oster #endif
360 1.1 oster if (dqd->bp == NULL) {
361 1.1 oster return(ENOMEM);
362 1.1 oster }
363 1.1 oster #endif /* KERNEL */
364 1.1 oster return(0);
365 1.1 oster }
366 1.1 oster
367 1.1 oster static void clean_dqd(dqd)
368 1.1 oster RF_DiskQueueData_t *dqd;
369 1.1 oster {
370 1.1 oster #ifdef KERNEL
371 1.1 oster #ifdef __NetBSD__
372 1.1 oster /* printf("NEED TO IMPLEMENT THIS BETTER(2)!\n"); */
373 1.1 oster /* XXX ? */
374 1.1 oster free( dqd->bp, M_DEVBUF );
375 1.1 oster #else
376 1.1 oster ubc_buffree(dqd->bp);
377 1.1 oster #endif
378 1.1 oster
379 1.1 oster #endif /* KERNEL */
380 1.1 oster }
381 1.1 oster
382 1.1 oster /* configures a single disk queue */
383 1.1 oster static int config_disk_queue(
384 1.1 oster RF_Raid_t *raidPtr,
385 1.1 oster RF_DiskQueue_t *diskqueue,
386 1.1 oster RF_RowCol_t r, /* row & col -- debug only. BZZT not any more... */
387 1.1 oster RF_RowCol_t c,
388 1.1 oster RF_DiskQueueSW_t *p,
389 1.1 oster RF_SectorCount_t sectPerDisk,
390 1.1 oster dev_t dev,
391 1.1 oster int maxOutstanding,
392 1.1 oster RF_ShutdownList_t **listp,
393 1.1 oster RF_AllocListElem_t *clList)
394 1.1 oster {
395 1.1 oster int rc;
396 1.1 oster
397 1.1 oster diskqueue->row = r;
398 1.1 oster diskqueue->col = c;
399 1.1 oster diskqueue->qPtr = p;
400 1.1 oster diskqueue->qHdr = (p->Create)(sectPerDisk, clList, listp);
401 1.1 oster diskqueue->dev = dev;
402 1.1 oster diskqueue->numOutstanding = 0;
403 1.1 oster diskqueue->queueLength = 0;
404 1.1 oster diskqueue->maxOutstanding = maxOutstanding;
405 1.1 oster diskqueue->curPriority = RF_IO_NORMAL_PRIORITY;
406 1.1 oster diskqueue->nextLockingOp = NULL;
407 1.1 oster diskqueue->unlockingOp = NULL;
408 1.1 oster diskqueue->numWaiting=0;
409 1.1 oster diskqueue->flags = 0;
410 1.1 oster diskqueue->raidPtr = raidPtr;
411 1.1 oster #if defined(__NetBSD__) && defined(_KERNEL)
412 1.1 oster diskqueue->rf_cinfo = &raidPtr->raid_cinfo[r][c];
413 1.1 oster #endif
414 1.1 oster rc = rf_create_managed_mutex(listp, &diskqueue->mutex);
415 1.1 oster if (rc) {
416 1.1 oster RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
417 1.1 oster __LINE__, rc);
418 1.1 oster return(rc);
419 1.1 oster }
420 1.1 oster rc = rf_create_managed_cond(listp, &diskqueue->cond);
421 1.1 oster if (rc) {
422 1.1 oster RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n", __FILE__,
423 1.1 oster __LINE__, rc);
424 1.1 oster return(rc);
425 1.1 oster }
426 1.1 oster return(0);
427 1.1 oster }
428 1.1 oster
429 1.1 oster static void rf_ShutdownDiskQueueSystem(ignored)
430 1.1 oster void *ignored;
431 1.1 oster {
432 1.1 oster RF_FREELIST_DESTROY_CLEAN(rf_dqd_freelist,next,(RF_DiskQueueData_t *),clean_dqd);
433 1.1 oster }
434 1.1 oster
435 1.1 oster int rf_ConfigureDiskQueueSystem(listp)
436 1.1 oster RF_ShutdownList_t **listp;
437 1.1 oster {
438 1.1 oster int rc;
439 1.1 oster
440 1.1 oster RF_FREELIST_CREATE(rf_dqd_freelist, RF_MAX_FREE_DQD,
441 1.1 oster RF_DQD_INC, sizeof(RF_DiskQueueData_t));
442 1.1 oster if (rf_dqd_freelist == NULL)
443 1.1 oster return(ENOMEM);
444 1.1 oster rc = rf_ShutdownCreate(listp, rf_ShutdownDiskQueueSystem, NULL);
445 1.1 oster if (rc) {
446 1.1 oster RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n",
447 1.1 oster __FILE__, __LINE__, rc);
448 1.1 oster rf_ShutdownDiskQueueSystem(NULL);
449 1.1 oster return(rc);
450 1.1 oster }
451 1.1 oster RF_FREELIST_PRIME_INIT(rf_dqd_freelist, RF_DQD_INITIAL,next,
452 1.1 oster (RF_DiskQueueData_t *),init_dqd);
453 1.1 oster return(0);
454 1.1 oster }
455 1.1 oster
456 1.1 oster #ifndef KERNEL
457 1.1 oster /* this is called prior to shutdown to wakeup everyone waiting on a disk queue
458 1.1 oster * and tell them to exit
459 1.1 oster */
460 1.1 oster void rf_TerminateDiskQueues(raidPtr)
461 1.1 oster RF_Raid_t *raidPtr;
462 1.1 oster {
463 1.1 oster RF_RowCol_t r, c;
464 1.1 oster
465 1.1 oster raidPtr->terminate_disk_queues = 1;
466 1.1 oster for (r=0; r<raidPtr->numRow; r++) {
467 1.1 oster for (c=0; c<raidPtr->numCol + ((r==0) ? raidPtr->numSpare : 0); c++) {
468 1.1 oster RF_LOCK_QUEUE_MUTEX(&raidPtr->Queues[r][c], "TerminateDiskQueues");
469 1.1 oster RF_BROADCAST_COND(raidPtr->Queues[r][c].cond);
470 1.1 oster RF_UNLOCK_QUEUE_MUTEX(&raidPtr->Queues[r][c], "TerminateDiskQueues");
471 1.1 oster }
472 1.1 oster }
473 1.1 oster }
474 1.1 oster #endif /* !KERNEL */
475 1.1 oster
476 1.1 oster int rf_ConfigureDiskQueues(
477 1.1 oster RF_ShutdownList_t **listp,
478 1.1 oster RF_Raid_t *raidPtr,
479 1.1 oster RF_Config_t *cfgPtr)
480 1.1 oster {
481 1.1 oster RF_DiskQueue_t **diskQueues, *spareQueues;
482 1.1 oster RF_DiskQueueSW_t *p;
483 1.1 oster RF_RowCol_t r, c;
484 1.1 oster int rc, i;
485 1.1 oster
486 1.1 oster raidPtr->maxQueueDepth = cfgPtr->maxOutstandingDiskReqs;
487 1.1 oster
488 1.1 oster for(p=NULL,i=0;i<NUM_DISK_QUEUE_TYPES;i++) {
489 1.1 oster if (!strcmp(diskqueuesw[i].queueType, cfgPtr->diskQueueType)) {
490 1.1 oster p = &diskqueuesw[i];
491 1.1 oster break;
492 1.1 oster }
493 1.1 oster }
494 1.1 oster if (p == NULL) {
495 1.1 oster RF_ERRORMSG2("Unknown queue type \"%s\". Using %s\n",cfgPtr->diskQueueType, diskqueuesw[0].queueType);
496 1.1 oster p = &diskqueuesw[0];
497 1.1 oster }
498 1.1 oster
499 1.1 oster RF_CallocAndAdd(diskQueues, raidPtr->numRow, sizeof(RF_DiskQueue_t *), (RF_DiskQueue_t **), raidPtr->cleanupList);
500 1.1 oster if (diskQueues == NULL) {
501 1.1 oster return(ENOMEM);
502 1.1 oster }
503 1.1 oster raidPtr->Queues = diskQueues;
504 1.1 oster for (r=0; r<raidPtr->numRow; r++) {
505 1.1 oster RF_CallocAndAdd(diskQueues[r], raidPtr->numCol + ((r==0) ? raidPtr->numSpare : 0), sizeof(RF_DiskQueue_t), (RF_DiskQueue_t *), raidPtr->cleanupList);
506 1.1 oster if (diskQueues[r] == NULL)
507 1.1 oster return(ENOMEM);
508 1.1 oster for (c=0; c<raidPtr->numCol; c++) {
509 1.1 oster rc = config_disk_queue(raidPtr, &diskQueues[r][c], r, c, p,
510 1.1 oster raidPtr->sectorsPerDisk, raidPtr->Disks[r][c].dev,
511 1.1 oster cfgPtr->maxOutstandingDiskReqs, listp, raidPtr->cleanupList);
512 1.1 oster if (rc)
513 1.1 oster return(rc);
514 1.1 oster }
515 1.1 oster }
516 1.1 oster
517 1.1 oster spareQueues = &raidPtr->Queues[0][raidPtr->numCol];
518 1.1 oster for (r=0; r<raidPtr->numSpare; r++) {
519 1.1 oster rc = config_disk_queue(raidPtr, &spareQueues[r],
520 1.1 oster 0, raidPtr->numCol+r, p,
521 1.1 oster raidPtr->sectorsPerDisk,
522 1.1 oster raidPtr->Disks[0][raidPtr->numCol+r].dev,
523 1.1 oster cfgPtr->maxOutstandingDiskReqs, listp,
524 1.1 oster raidPtr->cleanupList);
525 1.1 oster if (rc)
526 1.1 oster return(rc);
527 1.1 oster }
528 1.1 oster return(0);
529 1.1 oster }
530 1.1 oster
531 1.1 oster /* Enqueue a disk I/O
532 1.1 oster *
533 1.1 oster * Unfortunately, we have to do things differently in the different
534 1.1 oster * environments (simulator, user-level, kernel).
535 1.1 oster * At user level, all I/O is blocking, so we have 1 or more threads/disk
536 1.1 oster * and the thread that enqueues is different from the thread that dequeues.
537 1.1 oster * In the kernel, I/O is non-blocking and so we'd like to have multiple
538 1.1 oster * I/Os outstanding on the physical disks when possible.
539 1.1 oster *
540 1.1 oster * when any request arrives at a queue, we have two choices:
541 1.1 oster * dispatch it to the lower levels
542 1.1 oster * queue it up
543 1.1 oster *
544 1.1 oster * kernel rules for when to do what:
545 1.1 oster * locking request: queue empty => dispatch and lock queue,
546 1.1 oster * else queue it
547 1.1 oster * unlocking req : always dispatch it
548 1.1 oster * normal req : queue empty => dispatch it & set priority
549 1.1 oster * queue not full & priority is ok => dispatch it
550 1.1 oster * else queue it
551 1.1 oster *
552 1.1 oster * user-level rules:
553 1.1 oster * always enqueue. In the special case of an unlocking op, enqueue
554 1.1 oster * in a special way that will cause the unlocking op to be the next
555 1.1 oster * thing dequeued.
556 1.1 oster *
557 1.1 oster * simulator rules:
558 1.1 oster * Do the same as at user level, with the sleeps and wakeups suppressed.
559 1.1 oster */
560 1.1 oster void rf_DiskIOEnqueue(queue, req, pri)
561 1.1 oster RF_DiskQueue_t *queue;
562 1.1 oster RF_DiskQueueData_t *req;
563 1.1 oster int pri;
564 1.1 oster {
565 1.1 oster int tid;
566 1.1 oster
567 1.1 oster RF_ETIMER_START(req->qtime);
568 1.1 oster rf_get_threadid(tid);
569 1.1 oster RF_ASSERT(req->type == RF_IO_TYPE_NOP || req->numSector);
570 1.1 oster req->priority = pri;
571 1.1 oster
572 1.1 oster if (rf_queueDebug && (req->numSector == 0)) {
573 1.1 oster printf("Warning: Enqueueing zero-sector access\n");
574 1.1 oster }
575 1.1 oster
576 1.1 oster #ifdef KERNEL
577 1.1 oster /*
578 1.1 oster * kernel
579 1.1 oster */
580 1.1 oster RF_LOCK_QUEUE_MUTEX( queue, "DiskIOEnqueue" );
581 1.1 oster /* locking request */
582 1.1 oster if (RF_LOCKING_REQ(req)) {
583 1.1 oster if (RF_QUEUE_EMPTY(queue)) {
584 1.1 oster Dprintf3("Dispatching pri %d locking op to r %d c %d (queue empty)\n",pri,queue->row, queue->col);
585 1.1 oster RF_LOCK_QUEUE(queue);
586 1.1 oster rf_DispatchKernelIO(queue, req);
587 1.1 oster } else {
588 1.1 oster queue->queueLength++; /* increment count of number of requests waiting in this queue */
589 1.1 oster Dprintf3("Enqueueing pri %d locking op to r %d c %d (queue not empty)\n",pri,queue->row, queue->col);
590 1.1 oster req->queue = (void *)queue;
591 1.1 oster (queue->qPtr->Enqueue)(queue->qHdr, req, pri);
592 1.1 oster }
593 1.1 oster }
594 1.1 oster /* unlocking request */
595 1.1 oster else if (RF_UNLOCKING_REQ(req)) { /* we'll do the actual unlock when this I/O completes */
596 1.1 oster Dprintf3("Dispatching pri %d unlocking op to r %d c %d\n",pri,queue->row, queue->col);
597 1.1 oster RF_ASSERT(RF_QUEUE_LOCKED(queue));
598 1.1 oster rf_DispatchKernelIO(queue, req);
599 1.1 oster }
600 1.1 oster /* normal request */
601 1.1 oster else if (RF_OK_TO_DISPATCH(queue, req)) {
602 1.1 oster Dprintf3("Dispatching pri %d regular op to r %d c %d (ok to dispatch)\n",pri,queue->row, queue->col);
603 1.1 oster rf_DispatchKernelIO(queue, req);
604 1.1 oster } else {
605 1.1 oster queue->queueLength++; /* increment count of number of requests waiting in this queue */
606 1.1 oster Dprintf3("Enqueueing pri %d regular op to r %d c %d (not ok to dispatch)\n",pri,queue->row, queue->col);
607 1.1 oster req->queue = (void *)queue;
608 1.1 oster (queue->qPtr->Enqueue)(queue->qHdr, req, pri);
609 1.1 oster }
610 1.1 oster RF_UNLOCK_QUEUE_MUTEX( queue, "DiskIOEnqueue" );
611 1.1 oster
612 1.1 oster #else /* KERNEL */
613 1.1 oster /*
614 1.1 oster * user-level
615 1.1 oster */
616 1.1 oster RF_LOCK_QUEUE_MUTEX( queue, "DiskIOEnqueue" );
617 1.1 oster queue->queueLength++; /* increment count of number of requests waiting in this queue */
618 1.1 oster /* unlocking request */
619 1.1 oster if (RF_UNLOCKING_REQ(req)) {
620 1.1 oster Dprintf4("[%d] enqueueing pri %d unlocking op & signalling r %d c %d\n", tid, pri, queue->row, queue->col);
621 1.1 oster RF_ASSERT(RF_QUEUE_LOCKED(queue) && queue->unlockingOp == NULL);
622 1.1 oster queue->unlockingOp = req;
623 1.1 oster }
624 1.1 oster /* locking and normal requests */
625 1.1 oster else {
626 1.1 oster req->queue = (void *)queue;
627 1.1 oster Dprintf5("[%d] enqueueing pri %d %s op & signalling r %d c %d\n", tid, pri,
628 1.1 oster (RF_LOCKING_REQ(req)) ? "locking" : "regular",queue->row,queue->col);
629 1.1 oster (queue->qPtr->Enqueue)(queue->qHdr, req, pri);
630 1.1 oster }
631 1.1 oster SIGNAL_DISK_QUEUE( queue, "DiskIOEnqueue");
632 1.1 oster RF_UNLOCK_QUEUE_MUTEX( queue, "DiskIOEnqueue" );
633 1.1 oster #endif /* KERNEL */
634 1.1 oster }
635 1.1 oster
636 1.1 oster #if !defined(KERNEL) && !defined(SIMULATE)
637 1.1 oster /* user-level only: tell all threads to wake up & recheck the queue */
638 1.1 oster void rf_BroadcastOnQueue(queue)
639 1.1 oster RF_DiskQueue_t *queue;
640 1.1 oster {
641 1.1 oster int i;
642 1.1 oster
643 1.1 oster if (queue->maxOutstanding > 1) for (i=0; i<queue->maxOutstanding; i++) {
644 1.1 oster SIGNAL_DISK_QUEUE(queue, "BroadcastOnQueue" );
645 1.1 oster }
646 1.1 oster }
647 1.1 oster #endif /* !KERNEL && !SIMULATE */
648 1.1 oster
649 1.1 oster #ifndef KERNEL /* not used in kernel */
650 1.1 oster
651 1.1 oster RF_DiskQueueData_t *rf_DiskIODequeue(queue)
652 1.1 oster RF_DiskQueue_t *queue;
653 1.1 oster {
654 1.1 oster RF_DiskQueueData_t *p, *headItem;
655 1.1 oster int tid;
656 1.1 oster
657 1.1 oster rf_get_threadid(tid);
658 1.1 oster RF_LOCK_QUEUE_MUTEX( queue, "DiskIODequeue" );
659 1.1 oster for (p=NULL; !p; ) {
660 1.1 oster if (queue->unlockingOp) {
661 1.1 oster /* unlocking request */
662 1.1 oster RF_ASSERT(RF_QUEUE_LOCKED(queue));
663 1.1 oster p = queue->unlockingOp;
664 1.1 oster queue->unlockingOp = NULL;
665 1.1 oster Dprintf4("[%d] dequeueing pri %d unlocking op r %d c %d\n", tid, p->priority, queue->row,queue->col);
666 1.1 oster }
667 1.1 oster else {
668 1.1 oster headItem = (queue->qPtr->Peek)(queue->qHdr);
669 1.1 oster if (headItem) {
670 1.1 oster if (RF_LOCKING_REQ(headItem)) {
671 1.1 oster /* locking request */
672 1.1 oster if (!RF_QUEUE_LOCKED(queue)) {
673 1.1 oster /* queue isn't locked, so dequeue the request & lock the queue */
674 1.1 oster p = (queue->qPtr->Dequeue)( queue->qHdr );
675 1.1 oster if (p)
676 1.1 oster Dprintf4("[%d] dequeueing pri %d locking op r %d c %d\n", tid, p->priority, queue->row, queue->col);
677 1.1 oster else
678 1.1 oster Dprintf3("[%d] no dequeue -- raw queue empty r %d c %d\n", tid, queue->row, queue->col);
679 1.1 oster }
680 1.1 oster else {
681 1.1 oster /* queue already locked, no dequeue occurs */
682 1.1 oster Dprintf3("[%d] no dequeue -- queue is locked r %d c %d\n", tid, queue->row, queue->col);
683 1.1 oster p = NULL;
684 1.1 oster }
685 1.1 oster }
686 1.1 oster else {
687 1.1 oster /* normal request, always dequeue and assume caller already has lock (if needed) */
688 1.1 oster p = (queue->qPtr->Dequeue)( queue->qHdr );
689 1.1 oster if (p)
690 1.1 oster Dprintf4("[%d] dequeueing pri %d regular op r %d c %d\n", tid, p->priority, queue->row, queue->col);
691 1.1 oster else
692 1.1 oster Dprintf3("[%d] no dequeue -- raw queue empty r %d c %d\n", tid, queue->row, queue->col);
693 1.1 oster }
694 1.1 oster }
695 1.1 oster else {
696 1.1 oster Dprintf3("[%d] no dequeue -- raw queue empty r %d c %d\n", tid, queue->row, queue->col);
697 1.1 oster }
698 1.1 oster }
699 1.1 oster
700 1.1 oster if (queue->raidPtr->terminate_disk_queues) {
701 1.1 oster p = NULL;
702 1.1 oster break;
703 1.1 oster }
704 1.1 oster #ifdef SIMULATE
705 1.1 oster break; /* in simulator, return NULL on empty queue instead of blocking */
706 1.1 oster #else /* SIMULATE */
707 1.1 oster if (!p) {
708 1.1 oster Dprintf3("[%d] nothing to dequeue: waiting r %d c %d\n", tid, queue->row, queue->col);
709 1.1 oster WAIT_DISK_QUEUE( queue, "DiskIODequeue" );
710 1.1 oster }
711 1.1 oster #endif /* SIMULATE */
712 1.1 oster }
713 1.1 oster
714 1.1 oster if (p) {
715 1.1 oster queue->queueLength--; /* decrement count of number of requests waiting in this queue */
716 1.1 oster RF_ASSERT(queue->queueLength >= 0);
717 1.1 oster queue->numOutstanding++;
718 1.1 oster queue->last_deq_sector = p->sectorOffset;
719 1.1 oster /* record the amount of time this request spent in the disk queue */
720 1.1 oster RF_ETIMER_STOP(p->qtime);
721 1.1 oster RF_ETIMER_EVAL(p->qtime);
722 1.1 oster if (p->tracerec)
723 1.1 oster p->tracerec->diskqueue_us += RF_ETIMER_VAL_US(p->qtime);
724 1.1 oster }
725 1.1 oster
726 1.1 oster if (p && RF_LOCKING_REQ(p)) {
727 1.1 oster RF_ASSERT(!RF_QUEUE_LOCKED(queue));
728 1.1 oster Dprintf3("[%d] locking queue r %d c %d\n",tid,queue->row,queue->col);
729 1.1 oster RF_LOCK_QUEUE(queue);
730 1.1 oster }
731 1.1 oster RF_UNLOCK_QUEUE_MUTEX( queue, "DiskIODequeue" );
732 1.1 oster
733 1.1 oster return(p);
734 1.1 oster }
735 1.1 oster
736 1.1 oster #else /* !KERNEL */
737 1.1 oster
738 1.1 oster /* get the next set of I/Os started, kernel version only */
739 1.1 oster void rf_DiskIOComplete(queue, req, status)
740 1.1 oster RF_DiskQueue_t *queue;
741 1.1 oster RF_DiskQueueData_t *req;
742 1.1 oster int status;
743 1.1 oster {
744 1.1 oster int done=0;
745 1.1 oster
746 1.1 oster RF_LOCK_QUEUE_MUTEX( queue, "DiskIOComplete" );
747 1.1 oster
748 1.1 oster /* unlock the queue:
749 1.1 oster (1) after an unlocking req completes
750 1.1 oster (2) after a locking req fails
751 1.1 oster */
752 1.1 oster if (RF_UNLOCKING_REQ(req) || (RF_LOCKING_REQ(req) && status)) {
753 1.1 oster Dprintf2("DiskIOComplete: unlocking queue at r %d c %d\n", queue->row, queue->col);
754 1.1 oster RF_ASSERT(RF_QUEUE_LOCKED(queue) && (queue->unlockingOp == NULL));
755 1.1 oster RF_UNLOCK_QUEUE(queue);
756 1.1 oster }
757 1.1 oster
758 1.1 oster queue->numOutstanding--;
759 1.1 oster RF_ASSERT(queue->numOutstanding >= 0);
760 1.1 oster
761 1.1 oster /* dispatch requests to the disk until we find one that we can't. */
762 1.1 oster /* no reason to continue once we've filled up the queue */
763 1.1 oster /* no reason to even start if the queue is locked */
764 1.1 oster
765 1.1 oster while (!done && !RF_QUEUE_FULL(queue) && !RF_QUEUE_LOCKED(queue)) {
766 1.1 oster if (queue->nextLockingOp) {
767 1.1 oster req = queue->nextLockingOp; queue->nextLockingOp = NULL;
768 1.1 oster Dprintf3("DiskIOComplete: a pri %d locking req was pending at r %d c %d\n",req->priority,queue->row, queue->col);
769 1.1 oster } else {
770 1.1 oster req = (queue->qPtr->Dequeue)( queue->qHdr );
771 1.2 oster if (req != NULL) {
772 1.2 oster Dprintf3("DiskIOComplete: extracting pri %d req from queue at r %d c %d\n",req->priority,queue->row, queue->col);
773 1.2 oster } else {
774 1.2 oster Dprintf1("DiskIOComplete: no more requests to extract.\n","");
775 1.2 oster }
776 1.1 oster }
777 1.1 oster if (req) {
778 1.1 oster queue->queueLength--; /* decrement count of number of requests waiting in this queue */
779 1.1 oster RF_ASSERT(queue->queueLength >= 0);
780 1.1 oster }
781 1.1 oster if (!req) done=1;
782 1.1 oster else if (RF_LOCKING_REQ(req)) {
783 1.1 oster if (RF_QUEUE_EMPTY(queue)) { /* dispatch it */
784 1.1 oster Dprintf3("DiskIOComplete: dispatching pri %d locking req to r %d c %d (queue empty)\n",req->priority,queue->row, queue->col);
785 1.1 oster RF_LOCK_QUEUE(queue);
786 1.1 oster rf_DispatchKernelIO(queue, req);
787 1.1 oster done = 1;
788 1.1 oster } else { /* put it aside to wait for the queue to drain */
789 1.1 oster Dprintf3("DiskIOComplete: postponing pri %d locking req to r %d c %d\n",req->priority,queue->row, queue->col);
790 1.1 oster RF_ASSERT(queue->nextLockingOp == NULL);
791 1.1 oster queue->nextLockingOp = req;
792 1.1 oster done = 1;
793 1.1 oster }
794 1.1 oster } else if (RF_UNLOCKING_REQ(req)) { /* should not happen: unlocking ops should not get queued */
795 1.1 oster RF_ASSERT(RF_QUEUE_LOCKED(queue)); /* support it anyway for the future */
796 1.1 oster Dprintf3("DiskIOComplete: dispatching pri %d unl req to r %d c %d (SHOULD NOT SEE THIS)\n",req->priority,queue->row, queue->col);
797 1.1 oster rf_DispatchKernelIO(queue, req);
798 1.1 oster done = 1;
799 1.1 oster } else if (RF_OK_TO_DISPATCH(queue, req)) {
800 1.1 oster Dprintf3("DiskIOComplete: dispatching pri %d regular req to r %d c %d (ok to dispatch)\n",req->priority,queue->row, queue->col);
801 1.1 oster rf_DispatchKernelIO(queue, req);
802 1.1 oster } else { /* we can't dispatch it, so just re-enqueue it. */
803 1.1 oster /* potential trouble here if disk queues batch reqs */
804 1.1 oster Dprintf3("DiskIOComplete: re-enqueueing pri %d regular req to r %d c %d\n",req->priority,queue->row, queue->col);
805 1.1 oster queue->queueLength++;
806 1.1 oster (queue->qPtr->Enqueue)(queue->qHdr, req, req->priority);
807 1.1 oster done = 1;
808 1.1 oster }
809 1.1 oster }
810 1.1 oster
811 1.1 oster RF_UNLOCK_QUEUE_MUTEX( queue, "DiskIOComplete" );
812 1.1 oster }
813 1.1 oster #endif /* !KERNEL */
814 1.1 oster
815 1.1 oster /* promotes accesses tagged with the given parityStripeID from low priority
816 1.1 oster * to normal priority. This promotion is optional, meaning that a queue
817 1.1 oster * need not implement it. If there is no promotion routine associated with
818 1.1 oster * a queue, this routine does nothing and returns -1.
819 1.1 oster */
820 1.1 oster int rf_DiskIOPromote(queue, parityStripeID, which_ru)
821 1.1 oster RF_DiskQueue_t *queue;
822 1.1 oster RF_StripeNum_t parityStripeID;
823 1.1 oster RF_ReconUnitNum_t which_ru;
824 1.1 oster {
825 1.1 oster int retval;
826 1.1 oster
827 1.1 oster if (!queue->qPtr->Promote)
828 1.1 oster return(-1);
829 1.1 oster RF_LOCK_QUEUE_MUTEX( queue, "DiskIOPromote" );
830 1.1 oster retval = (queue->qPtr->Promote)( queue->qHdr, parityStripeID, which_ru );
831 1.1 oster RF_UNLOCK_QUEUE_MUTEX( queue, "DiskIOPromote" );
832 1.1 oster return(retval);
833 1.1 oster }
834 1.1 oster
835 1.1 oster RF_DiskQueueData_t *rf_CreateDiskQueueData(
836 1.1 oster RF_IoType_t typ,
837 1.1 oster RF_SectorNum_t ssect,
838 1.1 oster RF_SectorCount_t nsect,
839 1.1 oster caddr_t buf,
840 1.1 oster RF_StripeNum_t parityStripeID,
841 1.1 oster RF_ReconUnitNum_t which_ru,
842 1.1 oster int (*wakeF)(void *,int),
843 1.1 oster void *arg,
844 1.1 oster RF_DiskQueueData_t *next,
845 1.1 oster RF_AccTraceEntry_t *tracerec,
846 1.1 oster void *raidPtr,
847 1.1 oster RF_DiskQueueDataFlags_t flags,
848 1.1 oster void *kb_proc)
849 1.1 oster {
850 1.1 oster RF_DiskQueueData_t *p;
851 1.1 oster
852 1.1 oster RF_FREELIST_GET_INIT(rf_dqd_freelist,p,next,(RF_DiskQueueData_t *),init_dqd);
853 1.1 oster
854 1.1 oster p->sectorOffset = ssect + rf_protectedSectors;
855 1.1 oster p->numSector = nsect;
856 1.1 oster p->type = typ;
857 1.1 oster p->buf = buf;
858 1.1 oster p->parityStripeID= parityStripeID;
859 1.1 oster p->which_ru = which_ru;
860 1.1 oster p->CompleteFunc = wakeF;
861 1.1 oster p->argument = arg;
862 1.1 oster p->next = next;
863 1.1 oster p->tracerec = tracerec;
864 1.1 oster p->priority = RF_IO_NORMAL_PRIORITY;
865 1.1 oster p->AuxFunc = NULL;
866 1.1 oster p->buf2 = NULL;
867 1.1 oster #ifdef SIMULATE
868 1.1 oster p->owner = rf_GetCurrentOwner();
869 1.1 oster #endif /* SIMULATE */
870 1.1 oster p->raidPtr = raidPtr;
871 1.1 oster p->flags = flags;
872 1.1 oster #ifdef KERNEL
873 1.1 oster p->b_proc = kb_proc;
874 1.1 oster #endif /* KERNEL */
875 1.1 oster return(p);
876 1.1 oster }
877 1.1 oster
878 1.1 oster RF_DiskQueueData_t *rf_CreateDiskQueueDataFull(
879 1.1 oster RF_IoType_t typ,
880 1.1 oster RF_SectorNum_t ssect,
881 1.1 oster RF_SectorCount_t nsect,
882 1.1 oster caddr_t buf,
883 1.1 oster RF_StripeNum_t parityStripeID,
884 1.1 oster RF_ReconUnitNum_t which_ru,
885 1.1 oster int (*wakeF)(void *,int),
886 1.1 oster void *arg,
887 1.1 oster RF_DiskQueueData_t *next,
888 1.1 oster RF_AccTraceEntry_t *tracerec,
889 1.1 oster int priority,
890 1.1 oster int (*AuxFunc)(void *,...),
891 1.1 oster caddr_t buf2,
892 1.1 oster void *raidPtr,
893 1.1 oster RF_DiskQueueDataFlags_t flags,
894 1.1 oster void *kb_proc)
895 1.1 oster {
896 1.1 oster RF_DiskQueueData_t *p;
897 1.1 oster
898 1.1 oster RF_FREELIST_GET_INIT(rf_dqd_freelist,p,next,(RF_DiskQueueData_t *),init_dqd);
899 1.1 oster
900 1.1 oster p->sectorOffset = ssect + rf_protectedSectors;
901 1.1 oster p->numSector = nsect;
902 1.1 oster p->type = typ;
903 1.1 oster p->buf = buf;
904 1.1 oster p->parityStripeID= parityStripeID;
905 1.1 oster p->which_ru = which_ru;
906 1.1 oster p->CompleteFunc = wakeF;
907 1.1 oster p->argument = arg;
908 1.1 oster p->next = next;
909 1.1 oster p->tracerec = tracerec;
910 1.1 oster p->priority = priority;
911 1.1 oster p->AuxFunc = AuxFunc;
912 1.1 oster p->buf2 = buf2;
913 1.1 oster #ifdef SIMULATE
914 1.1 oster p->owner = rf_GetCurrentOwner();
915 1.1 oster #endif /* SIMULATE */
916 1.1 oster p->raidPtr = raidPtr;
917 1.1 oster p->flags = flags;
918 1.1 oster #ifdef KERNEL
919 1.1 oster p->b_proc = kb_proc;
920 1.1 oster #endif /* KERNEL */
921 1.1 oster return(p);
922 1.1 oster }
923 1.1 oster
924 1.1 oster void rf_FreeDiskQueueData(p)
925 1.1 oster RF_DiskQueueData_t *p;
926 1.1 oster {
927 1.1 oster RF_FREELIST_FREE_CLEAN(rf_dqd_freelist,p,next,clean_dqd);
928 1.1 oster }
929