Home | History | Annotate | Line # | Download | only in raidframe
rf_stripelocks.h revision 1.8.56.1
      1  1.8.56.1  martin /*	$NetBSD: rf_stripelocks.h,v 1.8.56.1 2020/04/13 08:04:47 martin Exp $	*/
      2       1.1   oster /*
      3       1.1   oster  * Copyright (c) 1995 Carnegie-Mellon University.
      4       1.1   oster  * All rights reserved.
      5       1.1   oster  *
      6       1.1   oster  * Author: Mark Holland
      7       1.1   oster  *
      8       1.1   oster  * Permission to use, copy, modify and distribute this software and
      9       1.1   oster  * its documentation is hereby granted, provided that both the copyright
     10       1.1   oster  * notice and this permission notice appear in all copies of the
     11       1.1   oster  * software, derivative works or modified versions, and any portions
     12       1.1   oster  * thereof, and that both notices appear in supporting documentation.
     13       1.1   oster  *
     14       1.1   oster  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15       1.1   oster  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     16       1.1   oster  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17       1.1   oster  *
     18       1.1   oster  * Carnegie Mellon requests users of this software to return to
     19       1.1   oster  *
     20       1.1   oster  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21       1.1   oster  *  School of Computer Science
     22       1.1   oster  *  Carnegie Mellon University
     23       1.1   oster  *  Pittsburgh PA 15213-3890
     24       1.1   oster  *
     25       1.1   oster  * any improvements or extensions that they make and grant Carnegie the
     26       1.1   oster  * rights to redistribute these changes.
     27       1.1   oster  */
     28       1.1   oster 
     29       1.1   oster /*****************************************************************************
     30       1.1   oster  *
     31       1.3   oster  * stripelocks.h -- header file for locking stripes
     32       1.1   oster  *
     33       1.1   oster  * Note that these functions are called from the execution routines of certain
     34       1.1   oster  * DAG Nodes, and so they must be NON-BLOCKING to assure maximum parallelism
     35       1.1   oster  * in the DAG.  Accordingly, when a node wants to acquire a lock, it calls
     36       1.1   oster  * AcquireStripeLock, supplying a pointer to a callback function.  If the lock
     37       1.1   oster  * is free at the time of the call, 0 is returned, indicating that the lock
     38       1.1   oster  * has been acquired.  If the lock is not free, 1 is returned, and a copy of
     39       1.1   oster  * the function pointer and argument are held in the lock table.  When the
     40       1.1   oster  * lock becomes free, the callback function is invoked.
     41       1.1   oster  *
     42       1.1   oster  *****************************************************************************/
     43       1.1   oster 
     44       1.1   oster #ifndef _RF__RF_STRIPELOCKS_H_
     45       1.1   oster #define _RF__RF_STRIPELOCKS_H_
     46       1.1   oster 
     47       1.1   oster #include <sys/buf.h>
     48       1.4   oster #include <dev/raidframe/raidframevar.h>
     49       1.1   oster 
     50       1.1   oster #include "rf_threadstuff.h"
     51       1.1   oster #include "rf_general.h"
     52       1.1   oster 
     53       1.1   oster struct RF_LockReqDesc_s {
     54       1.3   oster 	RF_IoType_t type;	/* read or write */
     55       1.3   oster 	RF_int64 start, stop;	/* start and end of range to be locked */
     56       1.3   oster 	RF_int64 start2, stop2;	/* start and end of 2nd range to be locked */
     57  1.8.56.1  martin 	void    (*cbFunc) (void *);	/* callback function */
     58       1.3   oster 	void   *cbArg;		/* argument to callback function */
     59       1.3   oster 	RF_LockReqDesc_t *next;	/* next element in chain */
     60       1.3   oster 	RF_LockReqDesc_t *templink;	/* for making short-lived lists of
     61       1.3   oster 					 * request descriptors */
     62       1.1   oster };
     63       1.1   oster #define RF_ASSERT_VALID_LOCKREQ(_lr_) { \
     64       1.1   oster 	RF_ASSERT(RF_IO_IS_R_OR_W((_lr_)->type)); \
     65       1.1   oster }
     66       1.1   oster 
     67       1.1   oster struct RF_StripeLockDesc_s {
     68       1.3   oster 	RF_StripeNum_t stripeID;/* the stripe ID */
     69       1.3   oster 	RF_LockReqDesc_t *granted;	/* unordered list of granted requests */
     70       1.3   oster 	RF_LockReqDesc_t *waitersH;	/* FIFO queue of all waiting reqs,
     71       1.3   oster 					 * both read and write (Head and Tail) */
     72       1.3   oster 	RF_LockReqDesc_t *waitersT;
     73       1.3   oster 	int     nWriters;	/* number of writers either granted or waiting */
     74       1.3   oster 	RF_StripeLockDesc_t *next;	/* for hash table collision resolution */
     75       1.1   oster };
     76       1.1   oster 
     77       1.1   oster struct RF_LockTableEntry_s {
     78       1.8     mrg 	rf_declare_mutex2(mutex);	/* mutex on this hash chain */
     79       1.3   oster 	RF_StripeLockDesc_t *descList;	/* hash chain of lock descriptors */
     80       1.1   oster };
     81       1.1   oster /*
     82       1.1   oster  * Initializes a stripe lock descriptor.  _defSize is the number of sectors
     83       1.1   oster  * that we lock when there is no parity information in the ASM (e.g. RAID0).
     84       1.1   oster  */
     85       1.1   oster 
     86       1.1   oster #define RF_INIT_LOCK_REQ_DESC(_lrd, _typ, _cbf, _cba, _asm, _defSize)                                           \
     87       1.1   oster   {                                                                                                          \
     88       1.1   oster     (_lrd).type    = _typ;                                                                                   \
     89       1.1   oster     (_lrd).start2  = -1;                                                                                     \
     90       1.1   oster     (_lrd).stop2   = -1;                                                                                     \
     91       1.1   oster     if ((_asm)->parityInfo) {                                                                                \
     92       1.1   oster       (_lrd).start = (_asm)->parityInfo->startSector;                                                        \
     93       1.1   oster       (_lrd).stop  = (_asm)->parityInfo->startSector + (_asm)->parityInfo->numSector-1;                      \
     94       1.1   oster       if ((_asm)->parityInfo->next) {                                                                        \
     95       1.1   oster         (_lrd).start2  = (_asm)->parityInfo->next->startSector;                                              \
     96       1.1   oster         (_lrd).stop2   = (_asm)->parityInfo->next->startSector + (_asm)->parityInfo->next->numSector-1;      \
     97       1.1   oster       }                                                                                                      \
     98       1.1   oster     } else {                                                                                                 \
     99       1.1   oster       (_lrd).start = 0;                                                                                      \
    100       1.1   oster       (_lrd).stop  = (_defSize);                                                                             \
    101       1.1   oster     }													     \
    102       1.1   oster     (_lrd).templink= NULL;                                                                                   \
    103       1.1   oster     (_lrd).cbFunc  = (_cbf);                                                                                 \
    104       1.1   oster     (_lrd).cbArg   = (void *) (_cba);                                                                        \
    105       1.1   oster   }
    106       1.1   oster 
    107       1.6   oster int rf_ConfigureStripeLockFreeList(RF_ShutdownList_t **);
    108       1.6   oster int rf_ConfigureStripeLocks(RF_ShutdownList_t **, RF_Raid_t *, RF_Config_t *);
    109       1.6   oster int rf_AcquireStripeLock(RF_LockTableEntry_t *, RF_StripeNum_t, RF_LockReqDesc_t *);
    110       1.6   oster void rf_ReleaseStripeLock(RF_LockTableEntry_t *, RF_StripeNum_t, RF_LockReqDesc_t *);
    111       1.1   oster 
    112       1.3   oster #endif				/* !_RF__RF_STRIPELOCKS_H_ */
    113