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