2 /* Copyright (C) 1990 Transarc Corporation - All rights reserved */
4 * (C) COPYRIGHT IBM CORPORATION 1987
5 * LICENSED MATERIALS - PROPERTY OF IBM
9 #include "fs_stats.h" /*File Server stats package*/
11 #ifdef AFS_PTHREAD_ENV
13 * There are three locks in the host package.
14 * the global hash lock protects hash chains.
15 * the global list lock protects the list of hosts.
16 * a mutex in each host structure protects the structure.
17 * precedence is host_listlock_mutex, host->mutex, host_glock_mutex.
19 #include <rx/rx_globals.h>
22 extern pthread_mutex_t host_glock_mutex;
24 assert(pthread_mutex_lock(&host_glock_mutex) == 0);
26 assert(pthread_mutex_unlock(&host_glock_mutex) == 0);
27 #else /* AFS_PTHREAD_ENV */
30 #endif /* AFS_PTHREAD_ENV */
32 #define h_MAXHOSTTABLEENTRIES 1000
33 #define h_HASHENTRIES 256 /* Power of 2 */
34 #define h_MAXHOSTTABLES 200
35 #define h_HTSPERBLOCK 512 /* Power of 2 */
36 #define h_HTSHIFT 9 /* log base 2 of HTSPERBLOCK */
38 #define h_threadsPerSlot 32 /* bits per afs_int32 */
39 #define h_threadsShift 5 /* for multiply/divide */
40 #define h_threadsMask 31 /* for remainder */
42 /* size of the hold array for each host */
43 #define h_maxSlots ((MAX_FILESERVER_THREAD+h_threadsPerSlot-1)>>h_threadsShift)
47 char valid; /* zero if UUID is unknown */
53 int numberOfInterfaces;
55 afs_int32 addr[1]; /* there are actually more than one here */
56 /* in network byte order */
59 struct host *next, *prev; /* linked list of all hosts */
60 struct rx_connection *callback_rxcon; /* rx callback connection */
61 afs_int32 holds[h_maxSlots];
62 /* holds on this host; 1 bit per lwp.
63 A hold prevents this structure and
64 inferior structures from disappearing */
65 unsigned int host; /* IP address of host interface that is
66 currently being used, in network
68 unsigned short port; /* port address of host */
69 char Console; /* XXXX This host is a console */
70 char hostFlags; /* bit map */
72 char InSameNetwork; /*Is host's addr in the same network as
74 char dummy[3]; /* for padding */
75 #endif /* FS_STATS_DETAILED */
76 char hcpsfailed; /* Retry the cps call next time */
77 prlist hcps; /* cps for hostip acls */
78 afs_uint32 LastCall; /* time of last call from host */
79 afs_uint32 ActiveCall; /* time of any call but gettime */
80 struct client *FirstClient; /* first connection from host */
81 afs_uint32 cpsCall; /* time of last cps call from this host */
82 struct Interface* interface; /* all alternate addr for client */
83 unsigned short cblist; /* Call back list for this host */
85 * These don't get zeroed, keep them at the end. If index doesn't
86 * follow an unsigned short then we need to pad to ensure that
87 * the index fields isn't zeroed.
89 unsigned short index; /* Host table index, for vicecb.c */
90 struct Lock lock; /* Write lock for synchronization of
92 #ifdef AFS_PTHREAD_ENV
93 pthread_cond_t cond; /* used to wait on hpcsValid */
94 #endif /* AFS_PTHREAD_ENV */
97 /* * Don't zero the index, lock or condition varialbles */
98 #define HOST_TO_ZERO(H) (int)(((char *)(&((H)->index))-(char *)(H)))
102 struct host* hostPtr;
103 struct h_hashChain* next;
108 struct client *next; /* next client entry for host */
109 struct host *host; /* ptr to parent host entry */
110 afs_int32 sid; /* Connection number from this host */
111 struct rx_connection *tcon; /* most recent server connection
112 * associated with this client */
113 prlist CPS; /* cps for authentication */
114 int ViceId; /* Vice ID of user */
115 afs_int32 expTime; /* RX-only: expiration time */
116 afs_uint32 LastCall; /* time of last call */
117 afs_uint32 VenusEpoch; /* Venus start time--used to identify
118 * venus. Actually, now an extension of the
119 * sid, which is why it moved.
121 afs_int32 refCount; /* reference count */
122 char deleted; /* True if this client should be deleted
123 when there are no more users of the
125 char authClass; /* auth type, RX-only */
126 char prfail; /* True if prserver couldn't be contacted */
127 #if FS_STATS_DETAILED
128 char InSameNetwork; /* Is client's IP address in the same
130 #else /* FS_STATS_DETAILED */
131 char dummy; /* For padding */
132 #endif /* FS_STATS_DETAILED */
133 struct Lock lock; /* lock to ensure CPS valid if entry
134 * on host's clients list. */
137 /* Don't zero the lock */
138 #define CLIENT_TO_ZERO(C) ((int)(((char *)(&((C)->lock))-(char *)(C))))
141 * key for the client structure stored in connection specific data
143 extern int rxcon_client_key;
145 /* Some additional functions to get at client information. Client must have
146 an active connection for this to work. If a lwp is working on a request
147 for the client, then the client must have a connection */
148 /* N.B. h_UserName returns pointer to static data; also relatively expensive */
149 extern char *h_UserName();
151 /* all threads whose thread-id is greater than the size of the hold array,
152 ** then use the most significant bit in the 'hold' field in the host structure
154 #ifdef AFS_PTHREAD_ENV
155 #define h_lwpIndex() ( ((long)(pthread_getspecific(rx_thread_id_key)) > \
156 ((h_maxSlots << h_threadsShift)-1)) ? \
157 (h_maxSlots << h_threadsShift) -1 : \
158 (long)(pthread_getspecific(rx_thread_id_key)) )
159 #else /* AFS_PTHREAD_ENV */
160 #define h_lwpIndex() ( (LWP_Index() > ((h_maxSlots << h_threadsShift)-1)) ? \
161 (h_maxSlots << h_threadsShift) -1 : \
163 #endif /* AFS_PTHREAD_ENV */
164 #define h_holdIndex()( h_lwpIndex() & h_threadsMask)
165 #define h_holdSlot() ( h_lwpIndex() >> h_threadsShift) /*index in 'holds'*/
166 #define h_holdbit() ( 1<<h_holdIndex() )
168 #define h_Hold_r(host) ((host)->holds[h_holdSlot()] |= h_holdbit())
170 extern int h_Release();
171 extern int h_Release_r();
173 #define h_Held_r(host) ((h_holdbit() & (host)->holds[h_holdSlot()]) != 0)
175 extern int h_OtherHolds();
176 extern int h_OtherHolds_r();
177 #define h_Lock(host) ObtainWriteLock(&(host)->lock)
178 extern int h_Lock_r();
179 #define h_Unlock(host) ReleaseWriteLock(&(host)->lock)
180 #define h_Unlock_r(host) ReleaseWriteLock(&(host)->lock)
182 #define AddCallBack(host, fid) AddCallBack1((host), (fid), (u_short *)0, 1/*CB_NORMAL*/, 0)
183 #define AddVolCallBack(host, fid) AddCallBack1((host), (fid), (u_short *)0, 3/*CB_VOLUME*/, 0)
184 #define AddBulkCallBack(host, fid) AddCallBack1((host), (fid), (u_short *)0, 4/*CB_BULK*/, 0)
186 /* operations on the global linked list of hosts */
187 #define h_InsertList_r(h) (h)->next = hostList; \
189 hostList ? (hostList->prev = (h)):0; \
192 #define h_DeleteList_r(h) assert(hostCount>0); \
194 (h)->next ? ((h)->next->prev = (h)->prev):0;\
195 (h)->prev ? ((h)->prev->next = (h)->next):0;\
196 ( h == hostList )? (hostList = h->next):0;
198 extern struct host *h_Alloc();
199 extern struct host *h_Alloc_r();
200 extern struct host *h_Lookup();
201 extern struct host *h_Lookup_r();
202 extern struct host *h_LookupUuid_r();
203 extern int h_FreeConnection();
204 extern int h_Enumerate();
205 extern struct host *h_GetHost();
206 extern struct host *h_GetHost_r();
207 extern struct client *h_FindClient_r();
208 extern int h_ReleaseClient_r();
209 extern struct client *h_ID2Client();
210 extern int GetClient();
211 extern h_PrintStats();
212 extern h_PrintStats_r();
213 extern h_PrintClients();
214 extern h_PrintClients_r();
215 extern h_GetWorkStats();
216 extern h_GetWorkStats_r();
217 extern void h_flushhostcps();
218 struct Interface *MultiVerifyInterface_r();
220 struct host *(hosttableptrs[h_MAXHOSTTABLES]); /* Used by h_itoh */
221 #define h_htoi(host) ((host)->index) /* index isn't zeroed, no need to lock */
222 #define h_itoh(hostindex) (hosttableptrs[(hostindex)>>h_HTSHIFT]+((hostindex)&(h_HTSPERBLOCK-1)))
224 #define HPCS_INPROGRESS 0x01 /*set when CPS is being updated */
225 #define HPCS_WAITING 0x02 /*waiting for CPS to get updated*/
226 #define ALTADDR 0x04 /*InitCallBack is being done */
227 #define VENUSDOWN 0x08 /* venus CallBack failed */
228 #define HOSTDELETED 0x10 /* host delated */
229 #define CLIENTDELETED 0x20 /* client deleted */
230 #define RESETDONE 0x40 /* callback reset done */