2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2006 Sine Nomine Associates
12 #ifndef _AFS_VICED_HOST_H
13 #define _AFS_VICED_HOST_H
15 #include "fs_stats.h" /*File Server stats package */
17 #ifdef AFS_PTHREAD_ENV
19 * There are three locks in the host package.
20 * the global hash lock protects hash chains.
21 * the global list lock protects the list of hosts.
22 * a mutex in each host structure protects the structure.
23 * precedence is host_listlock_mutex, host->mutex, host_glock_mutex.
25 #include <rx/rx_globals.h>
28 extern pthread_mutex_t host_glock_mutex;
30 assert(pthread_mutex_lock(&host_glock_mutex) == 0)
32 assert(pthread_mutex_unlock(&host_glock_mutex) == 0)
33 #else /* AFS_PTHREAD_ENV */
36 #endif /* AFS_PTHREAD_ENV */
38 #define h_MAXHOSTTABLEENTRIES 1000
39 #define h_HASHENTRIES 256 /* Power of 2 */
40 #define h_MAXHOSTTABLES 200
41 #define h_HTSPERBLOCK 512 /* Power of 2 */
42 #define h_HTSHIFT 9 /* log base 2 of HTSPERBLOCK */
44 #define h_threadsPerSlot 32 /* bits per afs_int32 */
45 #define h_threadsShift 5 /* for multiply/divide */
46 #define h_threadsMask 31 /* for remainder */
48 /* size of the hold array for each host */
49 #define h_maxSlots (((MAX_FILESERVER_THREAD+h_threadsPerSlot-1)>>h_threadsShift)+1)
52 char valid; /* zero if UUID is unknown */
57 afs_uint32 addr; /* in network byte order */
58 afs_uint16 port; /* in network byte order */
63 int numberOfInterfaces;
64 struct AddrPort interface[1];/* there are actually more than one here */
65 /* in network byte order */
69 struct host *next, *prev; /* linked list of all hosts */
70 struct rx_connection *callback_rxcon; /* rx callback connection */
71 afs_int32 holds[h_maxSlots];
72 /* holds on this host; 1 bit per lwp.
73 * A hold prevents this structure and
74 * inferior structures from disappearing */
75 afs_uint32 host; /* IP address of host interface that is
76 * currently being used, in network
78 afs_uint16 port; /* port address of host */
79 char Console; /* XXXX This host is a console */
80 unsigned short hostFlags; /* bit map */
82 char InSameNetwork; /*Is host's addr in the same network as
83 * the File Server's? */
84 char dummy[3]; /* for padding */
85 #endif /* FS_STATS_DETAILED */
86 char hcpsfailed; /* Retry the cps call next time */
87 prlist hcps; /* cps for hostip acls */
88 afs_uint32 LastCall; /* time of last call from host */
89 afs_uint32 ActiveCall; /* time of any call but gettime,
90 getstats and getcaps */
91 struct client *FirstClient; /* first connection from host */
92 afs_uint32 cpsCall; /* time of last cps call from this host */
93 struct Interface *interface; /* all alternate addr for client */
94 afs_uint32 cblist; /* index of a cb in the per-host circular CB list */
96 * These don't get zeroed, keep them at the end. If index doesn't
97 * follow an unsigned short then we need to pad to ensure that
98 * the index fields isn't zeroed. XXX
100 afs_uint32 index; /* Host table index, for vicecb.c */
101 struct Lock lock; /* Write lock for synchronization of
103 #ifdef AFS_PTHREAD_ENV
104 pthread_cond_t cond; /* used to wait on hcpsValid */
105 #endif /* AFS_PTHREAD_ENV */
108 /* * Don't zero the index, lock or condition varialbles */
109 #define HOST_TO_ZERO(H) (int)(((char *)(&((H)->index))-(char *)(H)))
112 struct host *hostPtr;
113 struct h_hashChain *next;
119 struct client *next; /* next client entry for host */
120 struct host *host; /* ptr to parent host entry */
121 afs_int32 sid; /* Connection number from this host */
122 struct rx_connection *tcon; /* most recent server connection
123 * associated with this client */
124 prlist CPS; /* cps for authentication */
125 int ViceId; /* Vice ID of user */
126 afs_int32 expTime; /* RX-only: expiration time */
127 afs_uint32 LastCall; /* time of last call */
128 afs_uint32 VenusEpoch; /* Venus start time--used to identify
129 * venus. Actually, now an extension of the
130 * sid, which is why it moved.
132 afs_int32 refCount; /* reference count */
133 char deleted; /* True if this client should be deleted
134 * when there are no more users of the
136 char authClass; /* auth type, RX-only */
137 char prfail; /* True if prserver couldn't be contacted */
138 #if FS_STATS_DETAILED
139 char InSameNetwork; /* Is client's IP address in the same
140 * network as ours? */
141 #else /* FS_STATS_DETAILED */
142 char dummy; /* For padding */
143 #endif /* FS_STATS_DETAILED */
144 struct Lock lock; /* lock to ensure CPS valid if entry
145 * on host's clients list. */
148 /* Don't zero the lock */
149 #define CLIENT_TO_ZERO(C) ((int)(((char *)(&((C)->lock))-(char *)(C))))
153 * key for the client structure stored in connection specific data
155 extern int rxcon_client_key;
157 /* Some additional functions to get at client information. Client must have
158 an active connection for this to work. If a lwp is working on a request
159 for the client, then the client must have a connection */
160 /* N.B. h_UserName returns pointer to static data; also relatively expensive */
161 extern char *h_UserName(struct client *client);
163 /* all threads whose thread-id is greater than the size of the hold array,
164 ** then use the most significant bit in the 'hold' field in the host structure
166 #ifdef AFS_PTHREAD_ENV
167 #define h_lwpIndex() ( ((long)(pthread_getspecific(rx_thread_id_key)) > \
168 ((h_maxSlots << h_threadsShift)-1)) ? \
169 (h_maxSlots << h_threadsShift) -1 : \
170 (long)(pthread_getspecific(rx_thread_id_key)) )
171 #else /* AFS_PTHREAD_ENV */
172 #define h_lwpIndex() ( (LWP_Index() > ((h_maxSlots << h_threadsShift)-1)) ? \
173 (h_maxSlots << h_threadsShift) -1 : \
175 #endif /* AFS_PTHREAD_ENV */
176 #define h_holdIndex()( h_lwpIndex() & h_threadsMask)
177 #define h_holdSlot() ( h_lwpIndex() >> h_threadsShift) /*index in 'holds' */
178 #define h_holdbit() ( 1<<h_holdIndex() )
180 #define h_Hold_r(host) ((host)->holds[h_holdSlot()] |= h_holdbit())
181 extern int h_Release(register struct host *host);
182 extern int h_Release_r(register struct host *host);
184 #define h_Held_r(host) ((h_holdbit() & (host)->holds[h_holdSlot()]) != 0)
185 extern int h_OtherHolds_r(register struct host *host);
186 #define h_Lock(host) ObtainWriteLock(&(host)->lock)
187 extern int h_Lock_r(register struct host *host);
188 #define h_Unlock(host) ReleaseWriteLock(&(host)->lock)
189 #define h_Unlock_r(host) ReleaseWriteLock(&(host)->lock)
191 #define AddCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 1/*CB_NORMAL*/, 0)
192 #define AddVolCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 3/*CB_VOLUME*/, 0)
193 #define AddBulkCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 4/*CB_BULK*/, 0)
195 /* operations on the global linked list of hosts */
196 #define h_InsertList_r(h) (h)->next = hostList; \
198 hostList ? (hostList->prev = (h)):0; \
201 #define h_DeleteList_r(h) assert(hostCount>0); \
203 (h)->next ? ((h)->next->prev = (h)->prev):0;\
204 (h)->prev ? ((h)->prev->next = (h)->next):0;\
205 ( h == hostList )? (hostList = h->next):0;
207 extern int DeleteAllCallBacks_r(struct host *host, int deletefe);
208 extern int DeleteCallBack(struct host *host, AFSFid * fid);
209 extern int MultiProbeAlternateAddress_r(struct host *host);
210 extern int BreakDelayedCallBacks_r(struct host *host);
211 extern int AddCallBack1(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
213 extern int BreakCallBack(struct host *xhost, AFSFid * fid, int flag);
214 extern int DeleteFileCallBacks(AFSFid * fid);
215 extern int CleanupTimedOutCallBacks(void);
216 extern int CleanupTimedOutCallBacks_r(void);
217 extern int MultiBreakCallBackAlternateAddress(struct host *host, struct AFSCBFids *afidp);
218 extern int MultiBreakCallBackAlternateAddress_r(struct host *host,
219 struct AFSCBFids *afidp);
220 extern int DumpCallBackState(void);
221 extern int PrintCallBackStats(void);
222 extern int ShutDown(void);
223 extern void ShutDownAndCore(int dopanic);
225 extern struct host *h_Alloc(register struct rx_connection *r_con);
226 extern struct host *h_Alloc_r(register struct rx_connection *r_con);
227 extern struct host *h_Lookup_r(afs_uint32 hostaddr, afs_uint16 hport,
229 extern void hashInsert_r(afs_uint32 addr, afs_uint16 port,
231 extern struct host *h_LookupUuid_r(afsUUID * uuidp);
232 extern int h_FreeConnection(struct rx_connection *tcon);
233 extern void h_Enumerate(int (*proc) (), char *param);
234 extern void h_Enumerate_r(int (*proc) (), struct host *enumstart, char *param);
235 extern struct host *h_GetHost_r(struct rx_connection *tcon);
236 extern struct client *h_FindClient_r(struct rx_connection *tcon);
237 extern int h_ReleaseClient_r(struct client *client);
238 extern struct client *h_ID2Client(afs_int32 vid);
239 extern int GetClient(struct rx_connection *tcon, struct client **cp);
240 extern int PutClient(struct client **cp);
241 extern void h_PrintStats();
242 extern void h_PrintClients();
243 extern void h_GetWorkStats();
244 extern void h_flushhostcps(register afs_uint32 hostaddr,
245 register afs_uint16 hport);
246 extern void h_GetHostNetStats(afs_int32 * a_numHostsP, afs_int32 * a_sameNetOrSubnetP,
247 afs_int32 * a_diffSubnetP, afs_int32 * a_diffNetworkP);
248 extern int h_NBLock_r(register struct host *host);
249 extern void h_DumpHosts();
250 extern void h_InitHostPackage();
251 extern void h_CheckHosts();
252 struct Interface *MultiVerifyInterface_r();
253 extern int initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf);
255 #ifdef AFS_DEMAND_ATTACH_FS
258 * state serialization
260 extern int h_SaveState(void);
261 extern int h_RestoreState(void);
264 #define H_ENUMERATE_BAIL(held) ((held)|0x80000000)
265 #define H_ENUMERATE_ISSET_BAIL(held) ((held)&0x80000000)
266 #define H_ENUMERATE_ISSET_HELD(held) ((held)&0x7FFFFFFF)
268 struct host *(hosttableptrs[h_MAXHOSTTABLES]); /* Used by h_itoh */
269 #define h_htoi(host) ((host)->index) /* index isn't zeroed, no need to lock */
270 #define h_itoh(hostindex) (hosttableptrs[(hostindex)>>h_HTSHIFT]+((hostindex)&(h_HTSPERBLOCK-1)))
272 #define rxr_GetEpoch(aconn) (((struct rx_connection *)(aconn))->epoch)
274 #define rxr_CidOf(aconn) (((struct rx_connection *)(aconn))->cid)
276 #define rxr_PortOf(aconn) \
277 rx_PortOf(rx_PeerOf(((struct rx_connection *)(aconn))))
279 #define rxr_HostOf(aconn) \
280 rx_HostOf(rx_PeerOf((struct rx_connection *)(aconn)))
282 #define HCPS_INPROGRESS 0x01 /*set when CPS is being updated */
283 #define HCPS_WAITING 0x02 /*waiting for CPS to get updated */
284 #define ALTADDR 0x04 /*InitCallBack is being done */
285 #define VENUSDOWN 0x08 /* venus CallBack failed */
286 #define HOSTDELETED 0x10 /* host delated */
287 #define CLIENTDELETED 0x20 /* client deleted */
288 #define RESETDONE 0x40 /* callback reset done */
289 #define HFE_LATER 0x80 /* host has FE_LATER callbacks */
290 #define HERRORTRANS 0x100 /* do error translation */
292 #endif /* _AFS_VICED_HOST_H */