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 extern pthread_key_t viced_uclient_key;
34 #else /* AFS_PTHREAD_ENV */
37 #endif /* AFS_PTHREAD_ENV */
39 #define h_MAXHOSTTABLEENTRIES 1000
40 #define h_HASHENTRIES 256 /* Power of 2 */
41 #define h_MAXHOSTTABLES 200
42 #define h_HTSPERBLOCK 512 /* Power of 2 */
43 #define h_HTSHIFT 9 /* log base 2 of HTSPERBLOCK */
46 char valid; /* zero if UUID is unknown */
51 afs_uint32 addr; /* in network byte order */
52 afs_uint16 port; /* in network byte order */
58 int numberOfInterfaces;
59 struct AddrPort interface[1];/* there are actually more than one here */
60 /* in network byte order */
64 struct host *next, *prev; /* linked list of all hosts */
65 struct rx_connection *callback_rxcon; /* rx callback connection */
66 afs_uint32 refCount; /* reference count */
67 afs_uint32 host; /* IP address of host interface that is
68 * currently being used, in network
70 afs_uint16 port; /* port address of host */
71 char Console; /* XXXX This host is a console */
72 unsigned short hostFlags; /* bit map */
74 char InSameNetwork; /*Is host's addr in the same network as
75 * the File Server's? */
76 char dummy[3]; /* for padding */
77 #endif /* FS_STATS_DETAILED */
78 char hcpsfailed; /* Retry the cps call next time */
79 prlist hcps; /* cps for hostip acls */
80 afs_uint32 LastCall; /* time of last call from host */
81 afs_uint32 ActiveCall; /* time of any call but gettime,
82 getstats and getcaps */
83 struct client *FirstClient; /* first connection from host */
84 afs_uint32 cpsCall; /* time of last cps call from this host */
85 struct Interface *interface; /* all alternate addr for client */
86 afs_uint32 cblist; /* index of a cb in the per-host circular CB list */
88 * These don't get zeroed, keep them at the end. If index doesn't
89 * follow an unsigned short then we need to pad to ensure that
90 * the index fields isn't zeroed. XXX
92 afs_uint32 index; /* Host table index, for vicecb.c */
93 struct Lock lock; /* Write lock for synchronization of
95 #ifdef AFS_PTHREAD_ENV
96 pthread_cond_t cond; /* used to wait on hcpsValid */
97 #endif /* AFS_PTHREAD_ENV */
100 /* * Don't zero the index, lock or condition varialbles */
101 #define HOST_TO_ZERO(H) (int)(((char *)(&((H)->index))-(char *)(H)))
103 struct h_AddrHashChain {
104 struct host *hostPtr;
105 struct h_AddrHashChain *next;
110 struct h_UuidHashChain {
111 struct host *hostPtr;
112 struct h_UuidHashChain *next;
116 struct client *next; /* next client entry for host */
117 struct host *host; /* ptr to parent host entry */
118 afs_int32 sid; /* Connection number from this host */
119 prlist CPS; /* cps for authentication */
120 int ViceId; /* Vice ID of user */
121 afs_int32 expTime; /* RX-only: expiration time */
122 afs_uint32 LastCall; /* time of last call */
123 afs_uint32 VenusEpoch; /* Venus start time--used to identify
124 * venus. Actually, now an extension of the
125 * sid, which is why it moved.
127 afs_int32 refCount; /* reference count */
128 char deleted; /* True if this client should be deleted
129 * when there are no more users of the
131 char authClass; /* auth type, RX-only */
132 char prfail; /* True if prserver couldn't be contacted */
133 #if FS_STATS_DETAILED
134 char InSameNetwork; /* Is client's IP address in the same
135 * network as ours? */
136 #else /* FS_STATS_DETAILED */
137 char dummy; /* For padding */
138 #endif /* FS_STATS_DETAILED */
139 struct Lock lock; /* lock to ensure CPS valid if entry
140 * on host's clients list. */
143 /* Don't zero the lock */
144 #define CLIENT_TO_ZERO(C) ((int)(((char *)(&((C)->lock))-(char *)(C))))
148 * key for the client structure stored in connection specific data
150 extern int rxcon_client_key;
152 /* Some additional functions to get at client information. Client must have
153 an active connection for this to work. If a lwp is working on a request
154 for the client, then the client must have a connection */
155 /* N.B. h_UserName returns pointer to static data; also relatively expensive */
156 extern char *h_UserName(struct client *client);
157 #define h_Lock(host) ObtainWriteLock(&(host)->lock)
158 extern int h_Lock_r(register struct host *host);
159 #define h_Unlock(host) ReleaseWriteLock(&(host)->lock)
160 #define h_Unlock_r(host) ReleaseWriteLock(&(host)->lock)
162 #define AddCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 1/*CB_NORMAL*/, 0)
163 #define AddVolCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 3/*CB_VOLUME*/, 0)
164 #define AddBulkCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 4/*CB_BULK*/, 0)
166 /* A simple refCount replaces per-thread hold mechanism. The former
167 * hold semantics are not different from refcounting, except with respect
168 * to cross-thread assertions. In this change, refcount is protected by
169 * H_LOCK, just like former hold bitmap. A future change will replace locks
170 * th lock-free operations. */
172 #define h_Hold_r(x) \
177 #define h_Release_r(x) \
180 if (((x)->refCount < 1) && \
181 (((x)->hostFlags & HOSTDELETED) || \
182 ((x)->hostFlags & CLIENTDELETED))) h_TossStuff_r((x)); \
185 /* operations on the global linked list of hosts */
186 #define h_InsertList_r(h) (h)->next = hostList; \
188 hostList ? (hostList->prev = (h)):0; \
191 #define h_DeleteList_r(h) assert(hostCount>0); \
193 (h)->next ? ((h)->next->prev = (h)->prev):0;\
194 (h)->prev ? ((h)->prev->next = (h)->next):0;\
195 ( h == hostList )? (hostList = h->next):0;
197 extern int DeleteAllCallBacks_r(struct host *host, int deletefe);
198 extern int DeleteCallBack(struct host *host, AFSFid * fid);
199 extern int MultiProbeAlternateAddress_r(struct host *host);
200 extern int BreakDelayedCallBacks_r(struct host *host);
201 extern int AddCallBack1(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
203 extern int BreakCallBack(struct host *xhost, AFSFid * fid, int flag);
204 extern int DeleteFileCallBacks(AFSFid * fid);
205 extern int CleanupTimedOutCallBacks(void);
206 extern int CleanupTimedOutCallBacks_r(void);
207 extern int MultiBreakCallBackAlternateAddress(struct host *host, struct AFSCBFids *afidp);
208 extern int MultiBreakCallBackAlternateAddress_r(struct host *host,
209 struct AFSCBFids *afidp);
210 extern int DumpCallBackState(void);
211 extern int PrintCallBackStats(void);
212 extern void *ShutDown(void *);
213 extern void ShutDownAndCore(int dopanic);
215 extern struct host *h_Alloc(register struct rx_connection *r_con);
216 extern struct host *h_Alloc_r(register struct rx_connection *r_con);
217 extern int h_Lookup_r(afs_uint32 hostaddr, afs_uint16 hport,
218 struct host **hostp);
219 extern struct host *h_LookupUuid_r(afsUUID * uuidp);
220 extern void h_Enumerate(int (*proc) (struct host *, int, void *), void *param);
221 extern void h_Enumerate_r(int (*proc) (struct host *, int, void *), struct host *enumstart, void *param);
222 extern struct host *h_GetHost_r(struct rx_connection *tcon);
223 extern struct client *h_FindClient_r(struct rx_connection *tcon);
224 extern int h_ReleaseClient_r(struct client *client);
225 extern void h_TossStuff_r(register struct host *host);
226 extern struct client *h_ID2Client(afs_int32 vid);
227 extern int GetClient(struct rx_connection *tcon, struct client **cp);
228 extern int PutClient(struct client **cp);
229 extern void h_PrintStats(void);
230 extern void h_PrintClients(void);
231 extern void h_GetWorkStats(int *, int *, int *, afs_int32);
232 extern void h_flushhostcps(register afs_uint32 hostaddr,
233 register afs_uint16 hport);
234 extern void h_GetHostNetStats(afs_int32 * a_numHostsP, afs_int32 * a_sameNetOrSubnetP,
235 afs_int32 * a_diffSubnetP, afs_int32 * a_diffNetworkP);
236 extern int h_NBLock_r(register struct host *host);
237 extern void h_DumpHosts(void);
238 extern void h_InitHostPackage(void);
239 extern void h_CheckHosts(void );
240 extern int initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf);
241 extern void h_AddHostToAddrHashTable_r(afs_uint32 addr, afs_uint16 port, struct host * host);
242 extern void h_AddHostToUuidHashTable_r(afsUUID * uuid, struct host * host);
243 extern int h_DeleteHostFromAddrHashTable_r(afs_uint32 addr, afs_uint16 port, struct host *host);
244 extern int h_DeleteHostFromUuidHashTable_r(struct host *host);
245 extern int initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf);
246 extern int addInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port);
247 extern int removeInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port);
248 extern afs_int32 hpr_Initialize(struct ubik_client **);
249 extern int hpr_End(struct ubik_client *);
252 #ifdef AFS_DEMAND_ATTACH_FS
255 * state serialization
257 extern int h_SaveState(void);
258 extern int h_RestoreState(void);
261 #define H_ENUMERATE_BAIL(flags) ((flags)|0x80000000)
262 #define H_ENUMERATE_ISSET_BAIL(flags) ((flags)&0x80000000)
263 #define H_ENUMERATE_ISSET_HELD(flags) ((flags)&0x7FFFFFFF)
265 struct host *(hosttableptrs[h_MAXHOSTTABLES]); /* Used by h_itoh */
266 #define h_htoi(host) ((host)->index) /* index isn't zeroed, no need to lock */
267 #define h_itoh(hostindex) (hosttableptrs[(hostindex)>>h_HTSHIFT]+((hostindex)&(h_HTSPERBLOCK-1)))
269 #define rxr_GetEpoch(aconn) (((struct rx_connection *)(aconn))->epoch)
271 #define rxr_CidOf(aconn) (((struct rx_connection *)(aconn))->cid)
273 #define rxr_PortOf(aconn) \
274 rx_PortOf(rx_PeerOf(((struct rx_connection *)(aconn))))
276 #define rxr_HostOf(aconn) \
277 rx_HostOf(rx_PeerOf((struct rx_connection *)(aconn)))
279 #define HCPS_INPROGRESS 0x01 /*set when CPS is being updated */
280 #define HCPS_WAITING 0x02 /*waiting for CPS to get updated */
281 #define ALTADDR 0x04 /*InitCallBack is being done */
282 #define VENUSDOWN 0x08 /* venus CallBack failed */
283 #define HOSTDELETED 0x10 /* host delated */
284 #define CLIENTDELETED 0x20 /* client deleted */
285 #define RESETDONE 0x40 /* callback reset done */
286 #define HFE_LATER 0x80 /* host has FE_LATER callbacks */
287 #define HERRORTRANS 0x100 /* do error translation */
288 #define HWHO_INPROGRESS 0x200 /* set when WhoAreYou running */
289 #endif /* _AFS_VICED_HOST_H */