Annotation of src/sys/dev/raidframe/rf_diskqueue.c, revision 1.11

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

CVSweb <webmaster@jp.NetBSD.org>