rf_diskqueue.c revision 1.12 1 1.12 oster /* $NetBSD: rf_diskqueue.c,v 1.12 2000/03/04 03:27:13 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.6 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.6 oster * new I/Os to the scsi driver at the time of enqueue, and also at the time
58 1.6 oster * of completion. At user level, I/O is blocking, and so only the disk threads
59 1.6 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 #include "rf_types.h"
65 1.1 oster #include "rf_threadstuff.h"
66 1.1 oster #include "rf_raid.h"
67 1.1 oster #include "rf_diskqueue.h"
68 1.1 oster #include "rf_alloclist.h"
69 1.1 oster #include "rf_acctrace.h"
70 1.1 oster #include "rf_etimer.h"
71 1.1 oster #include "rf_configure.h"
72 1.1 oster #include "rf_general.h"
73 1.1 oster #include "rf_freelist.h"
74 1.1 oster #include "rf_debugprint.h"
75 1.1 oster #include "rf_shutdown.h"
76 1.1 oster #include "rf_cvscan.h"
77 1.1 oster #include "rf_sstf.h"
78 1.1 oster #include "rf_fifo.h"
79 1.11 oster #include "rf_kintf.h"
80 1.1 oster
81 1.1 oster static int init_dqd(RF_DiskQueueData_t *);
82 1.1 oster static void clean_dqd(RF_DiskQueueData_t *);
83 1.1 oster static void rf_ShutdownDiskQueueSystem(void *);
84 1.1 oster
85 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)
86 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)
87 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)
88 1.1 oster
89 1.1 oster /*****************************************************************************************
90 1.1 oster *
91 1.1 oster * the disk queue switch defines all the functions used in the different queueing
92 1.1 oster * disciplines
93 1.1 oster * queue ID, init routine, enqueue routine, dequeue routine
94 1.1 oster *
95 1.1 oster ****************************************************************************************/
96 1.1 oster
97 1.1 oster static RF_DiskQueueSW_t diskqueuesw[] = {
98 1.6 oster {"fifo", /* FIFO */
99 1.6 oster rf_FifoCreate,
100 1.6 oster rf_FifoEnqueue,
101 1.6 oster rf_FifoDequeue,
102 1.6 oster rf_FifoPeek,
103 1.1 oster rf_FifoPromote},
104 1.1 oster
105 1.6 oster {"cvscan", /* cvscan */
106 1.6 oster rf_CvscanCreate,
107 1.6 oster rf_CvscanEnqueue,
108 1.6 oster rf_CvscanDequeue,
109 1.6 oster rf_CvscanPeek,
110 1.6 oster rf_CvscanPromote},
111 1.6 oster
112 1.6 oster {"sstf", /* shortest seek time first */
113 1.6 oster rf_SstfCreate,
114 1.6 oster rf_SstfEnqueue,
115 1.6 oster rf_SstfDequeue,
116 1.6 oster rf_SstfPeek,
117 1.1 oster rf_SstfPromote},
118 1.1 oster
119 1.6 oster {"scan", /* SCAN (two-way elevator) */
120 1.6 oster rf_ScanCreate,
121 1.6 oster rf_SstfEnqueue,
122 1.6 oster rf_ScanDequeue,
123 1.6 oster rf_ScanPeek,
124 1.1 oster rf_SstfPromote},
125 1.1 oster
126 1.6 oster {"cscan", /* CSCAN (one-way elevator) */
127 1.6 oster rf_CscanCreate,
128 1.6 oster rf_SstfEnqueue,
129 1.6 oster rf_CscanDequeue,
130 1.6 oster rf_CscanPeek,
131 1.1 oster rf_SstfPromote},
132 1.1 oster
133 1.1 oster };
134 1.1 oster #define NUM_DISK_QUEUE_TYPES (sizeof(diskqueuesw)/sizeof(RF_DiskQueueSW_t))
135 1.1 oster
136 1.1 oster static RF_FreeList_t *rf_dqd_freelist;
137 1.1 oster
138 1.1 oster #define RF_MAX_FREE_DQD 256
139 1.1 oster #define RF_DQD_INC 16
140 1.1 oster #define RF_DQD_INITIAL 64
141 1.1 oster
142 1.1 oster #include <sys/buf.h>
143 1.1 oster
144 1.6 oster static int
145 1.6 oster init_dqd(dqd)
146 1.6 oster RF_DiskQueueData_t *dqd;
147 1.6 oster {
148 1.6 oster /* XXX not sure if the following malloc is appropriate... probably not
149 1.6 oster * quite... */
150 1.9 oster dqd->bp = (struct buf *) malloc(sizeof(struct buf),
151 1.9 oster M_RAIDFRAME, M_NOWAIT);
152 1.1 oster if (dqd->bp == NULL) {
153 1.6 oster return (ENOMEM);
154 1.1 oster }
155 1.6 oster memset(dqd->bp, 0, sizeof(struct buf)); /* if you don't do it, nobody
156 1.6 oster * else will.. */
157 1.6 oster return (0);
158 1.1 oster }
159 1.1 oster
160 1.6 oster static void
161 1.6 oster clean_dqd(dqd)
162 1.6 oster RF_DiskQueueData_t *dqd;
163 1.1 oster {
164 1.6 oster free(dqd->bp, M_RAIDFRAME);
165 1.6 oster }
166 1.6 oster /* configures a single disk queue */
167 1.9 oster
168 1.7 oster int
169 1.9 oster rf_ConfigureDiskQueue(
170 1.9 oster RF_Raid_t * raidPtr,
171 1.9 oster RF_DiskQueue_t * diskqueue,
172 1.9 oster RF_RowCol_t r, /* row & col -- debug only. BZZT not any
173 1.6 oster * more... */
174 1.9 oster RF_RowCol_t c,
175 1.9 oster RF_DiskQueueSW_t * p,
176 1.9 oster RF_SectorCount_t sectPerDisk,
177 1.9 oster dev_t dev,
178 1.9 oster int maxOutstanding,
179 1.9 oster RF_ShutdownList_t ** listp,
180 1.9 oster RF_AllocListElem_t * clList)
181 1.6 oster {
182 1.6 oster int rc;
183 1.6 oster
184 1.6 oster diskqueue->row = r;
185 1.6 oster diskqueue->col = c;
186 1.6 oster diskqueue->qPtr = p;
187 1.6 oster diskqueue->qHdr = (p->Create) (sectPerDisk, clList, listp);
188 1.6 oster diskqueue->dev = dev;
189 1.6 oster diskqueue->numOutstanding = 0;
190 1.6 oster diskqueue->queueLength = 0;
191 1.6 oster diskqueue->maxOutstanding = maxOutstanding;
192 1.6 oster diskqueue->curPriority = RF_IO_NORMAL_PRIORITY;
193 1.6 oster diskqueue->nextLockingOp = NULL;
194 1.6 oster diskqueue->unlockingOp = NULL;
195 1.6 oster diskqueue->numWaiting = 0;
196 1.6 oster diskqueue->flags = 0;
197 1.6 oster diskqueue->raidPtr = raidPtr;
198 1.6 oster diskqueue->rf_cinfo = &raidPtr->raid_cinfo[r][c];
199 1.6 oster rc = rf_create_managed_mutex(listp, &diskqueue->mutex);
200 1.6 oster if (rc) {
201 1.6 oster RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__,
202 1.6 oster __LINE__, rc);
203 1.6 oster return (rc);
204 1.6 oster }
205 1.6 oster rc = rf_create_managed_cond(listp, &diskqueue->cond);
206 1.6 oster if (rc) {
207 1.6 oster RF_ERRORMSG3("Unable to init cond file %s line %d rc=%d\n", __FILE__,
208 1.6 oster __LINE__, rc);
209 1.6 oster return (rc);
210 1.6 oster }
211 1.6 oster return (0);
212 1.1 oster }
213 1.1 oster
214 1.6 oster static void
215 1.6 oster rf_ShutdownDiskQueueSystem(ignored)
216 1.6 oster void *ignored;
217 1.6 oster {
218 1.6 oster RF_FREELIST_DESTROY_CLEAN(rf_dqd_freelist, next, (RF_DiskQueueData_t *), clean_dqd);
219 1.1 oster }
220 1.1 oster
221 1.6 oster int
222 1.6 oster rf_ConfigureDiskQueueSystem(listp)
223 1.6 oster RF_ShutdownList_t **listp;
224 1.6 oster {
225 1.6 oster int rc;
226 1.6 oster
227 1.6 oster RF_FREELIST_CREATE(rf_dqd_freelist, RF_MAX_FREE_DQD,
228 1.6 oster RF_DQD_INC, sizeof(RF_DiskQueueData_t));
229 1.6 oster if (rf_dqd_freelist == NULL)
230 1.6 oster return (ENOMEM);
231 1.6 oster rc = rf_ShutdownCreate(listp, rf_ShutdownDiskQueueSystem, NULL);
232 1.6 oster if (rc) {
233 1.6 oster RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n",
234 1.6 oster __FILE__, __LINE__, rc);
235 1.6 oster rf_ShutdownDiskQueueSystem(NULL);
236 1.6 oster return (rc);
237 1.6 oster }
238 1.6 oster RF_FREELIST_PRIME_INIT(rf_dqd_freelist, RF_DQD_INITIAL, next,
239 1.6 oster (RF_DiskQueueData_t *), init_dqd);
240 1.6 oster return (0);
241 1.6 oster }
242 1.6 oster
243 1.6 oster int
244 1.6 oster rf_ConfigureDiskQueues(
245 1.6 oster RF_ShutdownList_t ** listp,
246 1.6 oster RF_Raid_t * raidPtr,
247 1.6 oster RF_Config_t * cfgPtr)
248 1.6 oster {
249 1.6 oster RF_DiskQueue_t **diskQueues, *spareQueues;
250 1.6 oster RF_DiskQueueSW_t *p;
251 1.6 oster RF_RowCol_t r, c;
252 1.6 oster int rc, i;
253 1.6 oster
254 1.6 oster raidPtr->maxQueueDepth = cfgPtr->maxOutstandingDiskReqs;
255 1.6 oster
256 1.6 oster for (p = NULL, i = 0; i < NUM_DISK_QUEUE_TYPES; i++) {
257 1.6 oster if (!strcmp(diskqueuesw[i].queueType, cfgPtr->diskQueueType)) {
258 1.6 oster p = &diskqueuesw[i];
259 1.6 oster break;
260 1.6 oster }
261 1.6 oster }
262 1.6 oster if (p == NULL) {
263 1.6 oster RF_ERRORMSG2("Unknown queue type \"%s\". Using %s\n", cfgPtr->diskQueueType, diskqueuesw[0].queueType);
264 1.6 oster p = &diskqueuesw[0];
265 1.6 oster }
266 1.10 oster raidPtr->qType = p;
267 1.6 oster RF_CallocAndAdd(diskQueues, raidPtr->numRow, sizeof(RF_DiskQueue_t *), (RF_DiskQueue_t **), raidPtr->cleanupList);
268 1.6 oster if (diskQueues == NULL) {
269 1.6 oster return (ENOMEM);
270 1.6 oster }
271 1.6 oster raidPtr->Queues = diskQueues;
272 1.6 oster for (r = 0; r < raidPtr->numRow; r++) {
273 1.7 oster RF_CallocAndAdd(diskQueues[r], raidPtr->numCol +
274 1.7 oster ((r == 0) ? RF_MAXSPARE : 0),
275 1.7 oster sizeof(RF_DiskQueue_t), (RF_DiskQueue_t *),
276 1.7 oster raidPtr->cleanupList);
277 1.6 oster if (diskQueues[r] == NULL)
278 1.6 oster return (ENOMEM);
279 1.6 oster for (c = 0; c < raidPtr->numCol; c++) {
280 1.9 oster rc = rf_ConfigureDiskQueue(raidPtr, &diskQueues[r][c],
281 1.9 oster r, c, p,
282 1.9 oster raidPtr->sectorsPerDisk,
283 1.9 oster raidPtr->Disks[r][c].dev,
284 1.9 oster cfgPtr->maxOutstandingDiskReqs,
285 1.9 oster listp, raidPtr->cleanupList);
286 1.6 oster if (rc)
287 1.6 oster return (rc);
288 1.6 oster }
289 1.6 oster }
290 1.6 oster
291 1.6 oster spareQueues = &raidPtr->Queues[0][raidPtr->numCol];
292 1.6 oster for (r = 0; r < raidPtr->numSpare; r++) {
293 1.9 oster rc = rf_ConfigureDiskQueue(raidPtr, &spareQueues[r],
294 1.6 oster 0, raidPtr->numCol + r, p,
295 1.6 oster raidPtr->sectorsPerDisk,
296 1.6 oster raidPtr->Disks[0][raidPtr->numCol + r].dev,
297 1.6 oster cfgPtr->maxOutstandingDiskReqs, listp,
298 1.6 oster raidPtr->cleanupList);
299 1.6 oster if (rc)
300 1.6 oster return (rc);
301 1.6 oster }
302 1.6 oster return (0);
303 1.6 oster }
304 1.1 oster /* Enqueue a disk I/O
305 1.1 oster *
306 1.1 oster * Unfortunately, we have to do things differently in the different
307 1.1 oster * environments (simulator, user-level, kernel).
308 1.1 oster * At user level, all I/O is blocking, so we have 1 or more threads/disk
309 1.1 oster * and the thread that enqueues is different from the thread that dequeues.
310 1.1 oster * In the kernel, I/O is non-blocking and so we'd like to have multiple
311 1.1 oster * I/Os outstanding on the physical disks when possible.
312 1.1 oster *
313 1.1 oster * when any request arrives at a queue, we have two choices:
314 1.1 oster * dispatch it to the lower levels
315 1.1 oster * queue it up
316 1.1 oster *
317 1.1 oster * kernel rules for when to do what:
318 1.1 oster * locking request: queue empty => dispatch and lock queue,
319 1.1 oster * else queue it
320 1.1 oster * unlocking req : always dispatch it
321 1.1 oster * normal req : queue empty => dispatch it & set priority
322 1.1 oster * queue not full & priority is ok => dispatch it
323 1.1 oster * else queue it
324 1.1 oster *
325 1.1 oster * user-level rules:
326 1.1 oster * always enqueue. In the special case of an unlocking op, enqueue
327 1.1 oster * in a special way that will cause the unlocking op to be the next
328 1.1 oster * thing dequeued.
329 1.1 oster *
330 1.1 oster * simulator rules:
331 1.1 oster * Do the same as at user level, with the sleeps and wakeups suppressed.
332 1.1 oster */
333 1.6 oster void
334 1.6 oster rf_DiskIOEnqueue(queue, req, pri)
335 1.6 oster RF_DiskQueue_t *queue;
336 1.6 oster RF_DiskQueueData_t *req;
337 1.6 oster int pri;
338 1.6 oster {
339 1.6 oster RF_ETIMER_START(req->qtime);
340 1.6 oster RF_ASSERT(req->type == RF_IO_TYPE_NOP || req->numSector);
341 1.6 oster req->priority = pri;
342 1.6 oster
343 1.6 oster if (rf_queueDebug && (req->numSector == 0)) {
344 1.6 oster printf("Warning: Enqueueing zero-sector access\n");
345 1.6 oster }
346 1.6 oster /*
347 1.6 oster * kernel
348 1.6 oster */
349 1.6 oster RF_LOCK_QUEUE_MUTEX(queue, "DiskIOEnqueue");
350 1.6 oster /* locking request */
351 1.6 oster if (RF_LOCKING_REQ(req)) {
352 1.6 oster if (RF_QUEUE_EMPTY(queue)) {
353 1.6 oster Dprintf3("Dispatching pri %d locking op to r %d c %d (queue empty)\n", pri, queue->row, queue->col);
354 1.6 oster RF_LOCK_QUEUE(queue);
355 1.6 oster rf_DispatchKernelIO(queue, req);
356 1.6 oster } else {
357 1.6 oster queue->queueLength++; /* increment count of number
358 1.6 oster * of requests waiting in this
359 1.6 oster * queue */
360 1.6 oster Dprintf3("Enqueueing pri %d locking op to r %d c %d (queue not empty)\n", pri, queue->row, queue->col);
361 1.6 oster req->queue = (void *) queue;
362 1.6 oster (queue->qPtr->Enqueue) (queue->qHdr, req, pri);
363 1.6 oster }
364 1.6 oster }
365 1.6 oster /* unlocking request */
366 1.6 oster else
367 1.6 oster if (RF_UNLOCKING_REQ(req)) { /* we'll do the actual unlock
368 1.6 oster * when this I/O completes */
369 1.6 oster Dprintf3("Dispatching pri %d unlocking op to r %d c %d\n", pri, queue->row, queue->col);
370 1.6 oster RF_ASSERT(RF_QUEUE_LOCKED(queue));
371 1.6 oster rf_DispatchKernelIO(queue, req);
372 1.6 oster }
373 1.6 oster /* normal request */
374 1.6 oster else
375 1.6 oster if (RF_OK_TO_DISPATCH(queue, req)) {
376 1.6 oster Dprintf3("Dispatching pri %d regular op to r %d c %d (ok to dispatch)\n", pri, queue->row, queue->col);
377 1.6 oster rf_DispatchKernelIO(queue, req);
378 1.6 oster } else {
379 1.6 oster queue->queueLength++; /* increment count of
380 1.6 oster * number of requests
381 1.6 oster * waiting in this queue */
382 1.6 oster Dprintf3("Enqueueing pri %d regular op to r %d c %d (not ok to dispatch)\n", pri, queue->row, queue->col);
383 1.6 oster req->queue = (void *) queue;
384 1.6 oster (queue->qPtr->Enqueue) (queue->qHdr, req, pri);
385 1.6 oster }
386 1.6 oster RF_UNLOCK_QUEUE_MUTEX(queue, "DiskIOEnqueue");
387 1.1 oster }
388 1.6 oster
389 1.1 oster
390 1.1 oster /* get the next set of I/Os started, kernel version only */
391 1.6 oster void
392 1.6 oster rf_DiskIOComplete(queue, req, status)
393 1.6 oster RF_DiskQueue_t *queue;
394 1.6 oster RF_DiskQueueData_t *req;
395 1.6 oster int status;
396 1.6 oster {
397 1.6 oster int done = 0;
398 1.6 oster
399 1.6 oster RF_LOCK_QUEUE_MUTEX(queue, "DiskIOComplete");
400 1.6 oster
401 1.6 oster /* unlock the queue: (1) after an unlocking req completes (2) after a
402 1.6 oster * locking req fails */
403 1.6 oster if (RF_UNLOCKING_REQ(req) || (RF_LOCKING_REQ(req) && status)) {
404 1.6 oster Dprintf2("DiskIOComplete: unlocking queue at r %d c %d\n", queue->row, queue->col);
405 1.6 oster RF_ASSERT(RF_QUEUE_LOCKED(queue) && (queue->unlockingOp == NULL));
406 1.6 oster RF_UNLOCK_QUEUE(queue);
407 1.6 oster }
408 1.6 oster queue->numOutstanding--;
409 1.6 oster RF_ASSERT(queue->numOutstanding >= 0);
410 1.6 oster
411 1.6 oster /* dispatch requests to the disk until we find one that we can't. */
412 1.6 oster /* no reason to continue once we've filled up the queue */
413 1.6 oster /* no reason to even start if the queue is locked */
414 1.6 oster
415 1.6 oster while (!done && !RF_QUEUE_FULL(queue) && !RF_QUEUE_LOCKED(queue)) {
416 1.6 oster if (queue->nextLockingOp) {
417 1.6 oster req = queue->nextLockingOp;
418 1.6 oster queue->nextLockingOp = NULL;
419 1.6 oster Dprintf3("DiskIOComplete: a pri %d locking req was pending at r %d c %d\n", req->priority, queue->row, queue->col);
420 1.6 oster } else {
421 1.6 oster req = (queue->qPtr->Dequeue) (queue->qHdr);
422 1.6 oster if (req != NULL) {
423 1.6 oster Dprintf3("DiskIOComplete: extracting pri %d req from queue at r %d c %d\n", req->priority, queue->row, queue->col);
424 1.6 oster } else {
425 1.6 oster Dprintf1("DiskIOComplete: no more requests to extract.\n", "");
426 1.6 oster }
427 1.6 oster }
428 1.6 oster if (req) {
429 1.6 oster queue->queueLength--; /* decrement count of number
430 1.6 oster * of requests waiting in this
431 1.6 oster * queue */
432 1.6 oster RF_ASSERT(queue->queueLength >= 0);
433 1.6 oster }
434 1.6 oster if (!req)
435 1.6 oster done = 1;
436 1.6 oster else
437 1.6 oster if (RF_LOCKING_REQ(req)) {
438 1.6 oster if (RF_QUEUE_EMPTY(queue)) { /* dispatch it */
439 1.6 oster Dprintf3("DiskIOComplete: dispatching pri %d locking req to r %d c %d (queue empty)\n", req->priority, queue->row, queue->col);
440 1.6 oster RF_LOCK_QUEUE(queue);
441 1.6 oster rf_DispatchKernelIO(queue, req);
442 1.6 oster done = 1;
443 1.6 oster } else { /* put it aside to wait for
444 1.6 oster * the queue to drain */
445 1.6 oster Dprintf3("DiskIOComplete: postponing pri %d locking req to r %d c %d\n", req->priority, queue->row, queue->col);
446 1.6 oster RF_ASSERT(queue->nextLockingOp == NULL);
447 1.6 oster queue->nextLockingOp = req;
448 1.6 oster done = 1;
449 1.6 oster }
450 1.6 oster } else
451 1.6 oster if (RF_UNLOCKING_REQ(req)) { /* should not happen:
452 1.6 oster * unlocking ops should
453 1.6 oster * not get queued */
454 1.6 oster RF_ASSERT(RF_QUEUE_LOCKED(queue)); /* support it anyway for
455 1.6 oster * the future */
456 1.6 oster Dprintf3("DiskIOComplete: dispatching pri %d unl req to r %d c %d (SHOULD NOT SEE THIS)\n", req->priority, queue->row, queue->col);
457 1.6 oster rf_DispatchKernelIO(queue, req);
458 1.6 oster done = 1;
459 1.6 oster } else
460 1.6 oster if (RF_OK_TO_DISPATCH(queue, req)) {
461 1.6 oster Dprintf3("DiskIOComplete: dispatching pri %d regular req to r %d c %d (ok to dispatch)\n", req->priority, queue->row, queue->col);
462 1.6 oster rf_DispatchKernelIO(queue, req);
463 1.6 oster } else { /* we can't dispatch it,
464 1.6 oster * so just re-enqueue
465 1.6 oster * it. */
466 1.6 oster /* potential trouble here if
467 1.6 oster * disk queues batch reqs */
468 1.6 oster Dprintf3("DiskIOComplete: re-enqueueing pri %d regular req to r %d c %d\n", req->priority, queue->row, queue->col);
469 1.6 oster queue->queueLength++;
470 1.6 oster (queue->qPtr->Enqueue) (queue->qHdr, req, req->priority);
471 1.6 oster done = 1;
472 1.6 oster }
473 1.6 oster }
474 1.6 oster
475 1.6 oster RF_UNLOCK_QUEUE_MUTEX(queue, "DiskIOComplete");
476 1.1 oster }
477 1.1 oster /* promotes accesses tagged with the given parityStripeID from low priority
478 1.1 oster * to normal priority. This promotion is optional, meaning that a queue
479 1.1 oster * need not implement it. If there is no promotion routine associated with
480 1.1 oster * a queue, this routine does nothing and returns -1.
481 1.1 oster */
482 1.6 oster int
483 1.6 oster rf_DiskIOPromote(queue, parityStripeID, which_ru)
484 1.6 oster RF_DiskQueue_t *queue;
485 1.6 oster RF_StripeNum_t parityStripeID;
486 1.6 oster RF_ReconUnitNum_t which_ru;
487 1.6 oster {
488 1.6 oster int retval;
489 1.6 oster
490 1.6 oster if (!queue->qPtr->Promote)
491 1.6 oster return (-1);
492 1.6 oster RF_LOCK_QUEUE_MUTEX(queue, "DiskIOPromote");
493 1.6 oster retval = (queue->qPtr->Promote) (queue->qHdr, parityStripeID, which_ru);
494 1.6 oster RF_UNLOCK_QUEUE_MUTEX(queue, "DiskIOPromote");
495 1.6 oster return (retval);
496 1.6 oster }
497 1.6 oster
498 1.6 oster RF_DiskQueueData_t *
499 1.6 oster rf_CreateDiskQueueData(
500 1.6 oster RF_IoType_t typ,
501 1.6 oster RF_SectorNum_t ssect,
502 1.6 oster RF_SectorCount_t nsect,
503 1.6 oster caddr_t buf,
504 1.6 oster RF_StripeNum_t parityStripeID,
505 1.6 oster RF_ReconUnitNum_t which_ru,
506 1.6 oster int (*wakeF) (void *, int),
507 1.6 oster void *arg,
508 1.6 oster RF_DiskQueueData_t * next,
509 1.6 oster RF_AccTraceEntry_t * tracerec,
510 1.6 oster void *raidPtr,
511 1.6 oster RF_DiskQueueDataFlags_t flags,
512 1.6 oster void *kb_proc)
513 1.6 oster {
514 1.6 oster RF_DiskQueueData_t *p;
515 1.6 oster
516 1.6 oster RF_FREELIST_GET_INIT(rf_dqd_freelist, p, next, (RF_DiskQueueData_t *), init_dqd);
517 1.6 oster
518 1.6 oster p->sectorOffset = ssect + rf_protectedSectors;
519 1.6 oster p->numSector = nsect;
520 1.6 oster p->type = typ;
521 1.6 oster p->buf = buf;
522 1.6 oster p->parityStripeID = parityStripeID;
523 1.6 oster p->which_ru = which_ru;
524 1.6 oster p->CompleteFunc = wakeF;
525 1.6 oster p->argument = arg;
526 1.6 oster p->next = next;
527 1.6 oster p->tracerec = tracerec;
528 1.6 oster p->priority = RF_IO_NORMAL_PRIORITY;
529 1.6 oster p->AuxFunc = NULL;
530 1.6 oster p->buf2 = NULL;
531 1.6 oster p->raidPtr = raidPtr;
532 1.6 oster p->flags = flags;
533 1.6 oster p->b_proc = kb_proc;
534 1.6 oster return (p);
535 1.6 oster }
536 1.6 oster
537 1.6 oster RF_DiskQueueData_t *
538 1.6 oster rf_CreateDiskQueueDataFull(
539 1.6 oster RF_IoType_t typ,
540 1.6 oster RF_SectorNum_t ssect,
541 1.6 oster RF_SectorCount_t nsect,
542 1.6 oster caddr_t buf,
543 1.6 oster RF_StripeNum_t parityStripeID,
544 1.6 oster RF_ReconUnitNum_t which_ru,
545 1.6 oster int (*wakeF) (void *, int),
546 1.6 oster void *arg,
547 1.6 oster RF_DiskQueueData_t * next,
548 1.6 oster RF_AccTraceEntry_t * tracerec,
549 1.6 oster int priority,
550 1.6 oster int (*AuxFunc) (void *,...),
551 1.6 oster caddr_t buf2,
552 1.6 oster void *raidPtr,
553 1.6 oster RF_DiskQueueDataFlags_t flags,
554 1.6 oster void *kb_proc)
555 1.6 oster {
556 1.6 oster RF_DiskQueueData_t *p;
557 1.6 oster
558 1.6 oster RF_FREELIST_GET_INIT(rf_dqd_freelist, p, next, (RF_DiskQueueData_t *), init_dqd);
559 1.6 oster
560 1.6 oster p->sectorOffset = ssect + rf_protectedSectors;
561 1.6 oster p->numSector = nsect;
562 1.6 oster p->type = typ;
563 1.6 oster p->buf = buf;
564 1.6 oster p->parityStripeID = parityStripeID;
565 1.6 oster p->which_ru = which_ru;
566 1.6 oster p->CompleteFunc = wakeF;
567 1.6 oster p->argument = arg;
568 1.6 oster p->next = next;
569 1.6 oster p->tracerec = tracerec;
570 1.6 oster p->priority = priority;
571 1.6 oster p->AuxFunc = AuxFunc;
572 1.6 oster p->buf2 = buf2;
573 1.6 oster p->raidPtr = raidPtr;
574 1.6 oster p->flags = flags;
575 1.6 oster p->b_proc = kb_proc;
576 1.6 oster return (p);
577 1.6 oster }
578 1.6 oster
579 1.6 oster void
580 1.6 oster rf_FreeDiskQueueData(p)
581 1.6 oster RF_DiskQueueData_t *p;
582 1.1 oster {
583 1.6 oster RF_FREELIST_FREE_CLEAN(rf_dqd_freelist, p, next, clean_dqd);
584 1.1 oster }
585