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

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

CVSweb <webmaster@jp.NetBSD.org>