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