Home | History | Annotate | Line # | Download | only in raidframe
rf_stripelocks.h revision 1.1
      1  1.1  oster /*	$NetBSD: rf_stripelocks.h,v 1.1 1998/11/13 04:20:34 oster Exp $	*/
      2  1.1  oster /*
      3  1.1  oster  * Copyright (c) 1995 Carnegie-Mellon University.
      4  1.1  oster  * All rights reserved.
      5  1.1  oster  *
      6  1.1  oster  * Author: Mark Holland
      7  1.1  oster  *
      8  1.1  oster  * Permission to use, copy, modify and distribute this software and
      9  1.1  oster  * its documentation is hereby granted, provided that both the copyright
     10  1.1  oster  * notice and this permission notice appear in all copies of the
     11  1.1  oster  * software, derivative works or modified versions, and any portions
     12  1.1  oster  * thereof, and that both notices appear in supporting documentation.
     13  1.1  oster  *
     14  1.1  oster  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  1.1  oster  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16  1.1  oster  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  1.1  oster  *
     18  1.1  oster  * Carnegie Mellon requests users of this software to return to
     19  1.1  oster  *
     20  1.1  oster  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  1.1  oster  *  School of Computer Science
     22  1.1  oster  *  Carnegie Mellon University
     23  1.1  oster  *  Pittsburgh PA 15213-3890
     24  1.1  oster  *
     25  1.1  oster  * any improvements or extensions that they make and grant Carnegie the
     26  1.1  oster  * rights to redistribute these changes.
     27  1.1  oster  */
     28  1.1  oster 
     29  1.1  oster /* :
     30  1.1  oster  * Log: rf_stripelocks.h,v
     31  1.1  oster  * Revision 1.22  1996/06/10 11:55:47  jimz
     32  1.1  oster  * Straightened out some per-array/not-per-array distinctions, fixed
     33  1.1  oster  * a couple bugs related to confusion. Added shutdown lists. Removed
     34  1.1  oster  * layout shutdown function (now subsumed by shutdown lists).
     35  1.1  oster  *
     36  1.1  oster  * Revision 1.21  1996/06/07  21:33:04  jimz
     37  1.1  oster  * begin using consistent types for sector numbers,
     38  1.1  oster  * stripe numbers, row+col numbers, recon unit numbers
     39  1.1  oster  *
     40  1.1  oster  * Revision 1.20  1996/06/05  18:06:02  jimz
     41  1.1  oster  * Major code cleanup. The Great Renaming is now done.
     42  1.1  oster  * Better modularity. Better typing. Fixed a bunch of
     43  1.1  oster  * synchronization bugs. Made a lot of global stuff
     44  1.1  oster  * per-desc or per-array. Removed dead code.
     45  1.1  oster  *
     46  1.1  oster  * Revision 1.19  1996/05/30  11:29:41  jimz
     47  1.1  oster  * Numerous bug fixes. Stripe lock release code disagreed with the taking code
     48  1.1  oster  * about when stripes should be locked (I made it consistent: no parity, no lock)
     49  1.1  oster  * There was a lot of extra serialization of I/Os which I've removed- a lot of
     50  1.1  oster  * it was to calculate values for the cache code, which is no longer with us.
     51  1.1  oster  * More types, function, macro cleanup. Added code to properly quiesce the array
     52  1.1  oster  * on shutdown. Made a lot of stuff array-specific which was (bogusly) general
     53  1.1  oster  * before. Fixed memory allocation, freeing bugs.
     54  1.1  oster  *
     55  1.1  oster  * Revision 1.18  1996/05/27  18:56:37  jimz
     56  1.1  oster  * more code cleanup
     57  1.1  oster  * better typing
     58  1.1  oster  * compiles in all 3 environments
     59  1.1  oster  *
     60  1.1  oster  * Revision 1.17  1996/05/24  22:17:04  jimz
     61  1.1  oster  * continue code + namespace cleanup
     62  1.1  oster  * typed a bunch of flags
     63  1.1  oster  *
     64  1.1  oster  * Revision 1.16  1996/05/23  21:46:35  jimz
     65  1.1  oster  * checkpoint in code cleanup (release prep)
     66  1.1  oster  * lots of types, function names have been fixed
     67  1.1  oster  *
     68  1.1  oster  * Revision 1.15  1996/05/23  00:33:23  jimz
     69  1.1  oster  * code cleanup: move all debug decls to rf_options.c, all extern
     70  1.1  oster  * debug decls to rf_options.h, all debug vars preceded by rf_
     71  1.1  oster  *
     72  1.1  oster  * Revision 1.14  1996/05/18  19:51:34  jimz
     73  1.1  oster  * major code cleanup- fix syntax, make some types consistent,
     74  1.1  oster  * add prototypes, clean out dead code, et cetera
     75  1.1  oster  *
     76  1.1  oster  * Revision 1.13  1996/05/06  22:08:46  wvcii
     77  1.1  oster  * added copyright info and change log
     78  1.1  oster  *
     79  1.1  oster  */
     80  1.1  oster 
     81  1.1  oster /*****************************************************************************
     82  1.1  oster  *
     83  1.1  oster  * stripelocks.h -- header file for locking stripes
     84  1.1  oster  *
     85  1.1  oster  * Note that these functions are called from the execution routines of certain
     86  1.1  oster  * DAG Nodes, and so they must be NON-BLOCKING to assure maximum parallelism
     87  1.1  oster  * in the DAG.  Accordingly, when a node wants to acquire a lock, it calls
     88  1.1  oster  * AcquireStripeLock, supplying a pointer to a callback function.  If the lock
     89  1.1  oster  * is free at the time of the call, 0 is returned, indicating that the lock
     90  1.1  oster  * has been acquired.  If the lock is not free, 1 is returned, and a copy of
     91  1.1  oster  * the function pointer and argument are held in the lock table.  When the
     92  1.1  oster  * lock becomes free, the callback function is invoked.
     93  1.1  oster  *
     94  1.1  oster  *****************************************************************************/
     95  1.1  oster 
     96  1.1  oster #ifndef _RF__RF_STRIPELOCKS_H_
     97  1.1  oster #define _RF__RF_STRIPELOCKS_H_
     98  1.1  oster 
     99  1.1  oster #include <sys/buf.h>
    100  1.1  oster 
    101  1.1  oster #include "rf_types.h"
    102  1.1  oster #include "rf_threadstuff.h"
    103  1.1  oster #include "rf_general.h"
    104  1.1  oster 
    105  1.1  oster struct RF_LockReqDesc_s {
    106  1.1  oster   RF_IoType_t type;            /* read or write */
    107  1.1  oster   RF_int64 start, stop;        /* start and end of range to be locked */
    108  1.1  oster   RF_int64 start2, stop2;      /* start and end of 2nd range to be locked */
    109  1.1  oster   void (*cbFunc)(struct buf *);/* callback function */
    110  1.1  oster   void *cbArg;                 /* argument to callback function */
    111  1.1  oster   RF_LockReqDesc_t *next;      /* next element in chain */
    112  1.1  oster   RF_LockReqDesc_t *templink;  /* for making short-lived lists of request descriptors */
    113  1.1  oster };
    114  1.1  oster 
    115  1.1  oster #define RF_ASSERT_VALID_LOCKREQ(_lr_) { \
    116  1.1  oster 	RF_ASSERT(RF_IO_IS_R_OR_W((_lr_)->type)); \
    117  1.1  oster }
    118  1.1  oster 
    119  1.1  oster struct RF_StripeLockDesc_s {
    120  1.1  oster   RF_StripeNum_t     stripeID; /* the stripe ID */
    121  1.1  oster   RF_LockReqDesc_t  *granted;  /* unordered list of granted requests */
    122  1.1  oster   RF_LockReqDesc_t  *waitersH; /* FIFO queue of all waiting reqs, both read and write (Head and Tail) */
    123  1.1  oster   RF_LockReqDesc_t  *waitersT;
    124  1.1  oster   int                nWriters; /* number of writers either granted or waiting */
    125  1.1  oster   RF_StripeLockDesc_t  *next;  /* for hash table collision resolution */
    126  1.1  oster };
    127  1.1  oster 
    128  1.1  oster struct RF_LockTableEntry_s {
    129  1.1  oster   RF_DECLARE_MUTEX(mutex)         /* mutex on this hash chain */
    130  1.1  oster   RF_StripeLockDesc_t  *descList; /* hash chain of lock descriptors */
    131  1.1  oster };
    132  1.1  oster 
    133  1.1  oster /*
    134  1.1  oster  * Initializes a stripe lock descriptor.  _defSize is the number of sectors
    135  1.1  oster  * that we lock when there is no parity information in the ASM (e.g. RAID0).
    136  1.1  oster  */
    137  1.1  oster 
    138  1.1  oster #define RF_INIT_LOCK_REQ_DESC(_lrd, _typ, _cbf, _cba, _asm, _defSize)                                           \
    139  1.1  oster   {                                                                                                          \
    140  1.1  oster     (_lrd).type    = _typ;                                                                                   \
    141  1.1  oster     (_lrd).start2  = -1;                                                                                     \
    142  1.1  oster     (_lrd).stop2   = -1;                                                                                     \
    143  1.1  oster     if ((_asm)->parityInfo) {                                                                                \
    144  1.1  oster       (_lrd).start = (_asm)->parityInfo->startSector;                                                        \
    145  1.1  oster       (_lrd).stop  = (_asm)->parityInfo->startSector + (_asm)->parityInfo->numSector-1;                      \
    146  1.1  oster       if ((_asm)->parityInfo->next) {                                                                        \
    147  1.1  oster         (_lrd).start2  = (_asm)->parityInfo->next->startSector;                                              \
    148  1.1  oster         (_lrd).stop2   = (_asm)->parityInfo->next->startSector + (_asm)->parityInfo->next->numSector-1;      \
    149  1.1  oster       }                                                                                                      \
    150  1.1  oster     } else {                                                                                                 \
    151  1.1  oster       (_lrd).start = 0;                                                                                      \
    152  1.1  oster       (_lrd).stop  = (_defSize);                                                                             \
    153  1.1  oster     }													     \
    154  1.1  oster     (_lrd).templink= NULL;                                                                                   \
    155  1.1  oster     (_lrd).cbFunc  = (_cbf);                                                                                 \
    156  1.1  oster     (_lrd).cbArg   = (void *) (_cba);                                                                        \
    157  1.1  oster   }
    158  1.1  oster 
    159  1.1  oster int rf_ConfigureStripeLockFreeList(RF_ShutdownList_t **listp);
    160  1.1  oster RF_LockTableEntry_t *rf_MakeLockTable(void);
    161  1.1  oster void rf_ShutdownStripeLocks(RF_LockTableEntry_t *lockTable);
    162  1.1  oster int rf_ConfigureStripeLocks(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr,
    163  1.1  oster 	RF_Config_t *cfgPtr);
    164  1.1  oster int rf_AcquireStripeLock(RF_LockTableEntry_t *lockTable,
    165  1.1  oster 	RF_StripeNum_t stripeID, RF_LockReqDesc_t *lockReqDesc);
    166  1.1  oster void rf_ReleaseStripeLock(RF_LockTableEntry_t *lockTable,
    167  1.1  oster 	RF_StripeNum_t stripeID, RF_LockReqDesc_t *lockReqDesc);
    168  1.1  oster 
    169  1.1  oster #endif /* !_RF__RF_STRIPELOCKS_H_ */
    170