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