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 */
18 * There are three locks in the host package.
19 * the global hash lock protects hash chains.
20 * the global list lock protects the list of hosts.
21 * a mutex in each host structure protects the structure.
22 * precedence is host_listlock_mutex, host->mutex, host_glock_mutex.
24 #include <rx/rx_globals.h>
26 extern pthread_mutex_t host_glock_mutex;
27 #define H_LOCK opr_mutex_enter(&host_glock_mutex)
28 #define H_UNLOCK opr_mutex_exit(&host_glock_mutex)
29 extern pthread_key_t viced_uclient_key;
31 #define h_MAXHOSTTABLEENTRIES 1000
32 #define h_HASHENTRIES 256 /* Power of 2 */
33 #define h_MAXHOSTTABLES 200
34 #define h_HTSPERBLOCK 512 /* Power of 2 */
35 #define h_HTSHIFT 9 /* log base 2 of HTSPERBLOCK */
38 char valid; /* zero if UUID is unknown */
43 afs_uint32 addr; /* in network byte order */
44 afs_uint16 port; /* in network byte order */
50 int numberOfInterfaces;
51 struct AddrPort interface[1];/* there are actually more than one here */
52 /* in network byte order */
56 struct host *next, *prev; /* linked list of all hosts */
57 struct rx_connection *callback_rxcon; /* rx callback connection */
58 afs_uint32 refCount; /* reference count */
59 afs_uint32 host; /* IP address of host interface that is
60 * currently being used, in network
62 afs_uint16 port; /* port address of host */
63 char Console; /* XXXX This host is a console */
64 unsigned short hostFlags; /* bit map */
65 char InSameNetwork; /*Is host's addr in the same network as
66 * the File Server's? */
67 char dummy[3]; /* for padding */
68 char hcpsfailed; /* Retry the cps call next time */
69 prlist hcps; /* cps for hostip acls */
70 afs_uint32 LastCall; /* time of last call from host */
71 afs_uint32 ActiveCall; /* time of any call but gettime,
72 getstats and getcaps */
73 struct client *FirstClient; /* first connection from host */
74 afs_uint32 cpsCall; /* time of last cps call from this host */
75 struct Interface *interface; /* all alternate addr for client */
76 afs_uint32 cblist; /* index of a cb in the per-host circular CB list */
78 * These don't get zeroed, keep them at the end. If index doesn't
79 * follow an unsigned short then we need to pad to ensure that
80 * the index fields isn't zeroed. XXX
82 afs_uint32 index; /* Host table index, for vicecb.c */
83 unsigned int n_tmays; /* how many successful TellMeAboutYourself calls
84 * have we made against this host? */
85 /* cache of the result of the last successful TMAY call to this host */
86 struct interfaceAddr tmay_interf;
87 Capabilities tmay_caps;
89 struct Lock lock; /* Write lock for synchronization of
91 pthread_cond_t cond; /* used to wait on hcpsValid */
94 /* * Don't zero the index, lock or condition varialbles */
95 #define HOST_TO_ZERO(H) (int)(((char *)(&((H)->index))-(char *)(H)))
97 struct h_AddrHashChain {
99 struct h_AddrHashChain *next;
104 struct h_UuidHashChain {
105 struct host *hostPtr;
106 struct h_UuidHashChain *next;
110 struct client *next; /* next client entry for host */
111 struct host *host; /* ptr to parent host entry */
112 afs_int32 sid; /* Connection number from this host */
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 char InSameNetwork; /* Is client's IP address in the same
128 * network as ours? */
129 struct Lock lock; /* lock to ensure CPS valid if entry
130 * on host's clients list. */
133 /* Don't zero the lock */
134 #define CLIENT_TO_ZERO(C) ((int)(((char *)(&((C)->lock))-(char *)(C))))
138 * key for the client structure stored in connection specific data
140 extern int rxcon_client_key;
142 /* Some additional functions to get at client information. Client must have
143 an active connection for this to work. If a lwp is working on a request
144 for the client, then the client must have a connection */
145 /* N.B. h_UserName returns pointer to static data; also relatively expensive */
146 extern char *h_UserName(struct client *client);
147 #define h_Lock(host) ObtainWriteLock(&(host)->lock)
148 extern int h_Lock_r(struct host *host);
149 #define h_Unlock(host) ReleaseWriteLock(&(host)->lock)
150 #define h_Unlock_r(host) ReleaseWriteLock(&(host)->lock)
152 #define AddCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 1/*CB_NORMAL*/, 0)
153 #define AddVolCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 3/*CB_VOLUME*/, 0)
154 #define AddBulkCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 4/*CB_BULK*/, 0)
156 /* A simple refCount replaces per-thread hold mechanism. The former
157 * hold semantics are not different from refcounting, except with respect
158 * to cross-thread assertions. In this change, refcount is protected by
159 * H_LOCK, just like former hold bitmap. A future change will replace locks
160 * th lock-free operations. */
162 #define h_Hold_r(x) \
167 #define h_Decrement_r(x) \
172 #define h_Release_r(x) \
175 if (((x)->refCount < 1) && \
176 (((x)->hostFlags & HOSTDELETED) || \
177 ((x)->hostFlags & CLIENTDELETED))) h_TossStuff_r((x)); \
180 /* operations on the global linked list of hosts */
181 #define h_InsertList_r(h) (h)->next = hostList; \
183 hostList ? (hostList->prev = (h)):0; \
186 #define h_DeleteList_r(h) opr_Assert(hostCount>0); \
188 (h)->next ? ((h)->next->prev = (h)->prev):0;\
189 (h)->prev ? ((h)->prev->next = (h)->next):0;\
190 ( h == hostList )? (hostList = h->next):0;
192 extern int DeleteAllCallBacks_r(struct host *host, int deletefe);
193 extern int DeleteCallBack(struct host *host, AFSFid * fid);
194 extern int MultiProbeAlternateAddress_r(struct host *host);
195 extern int BreakDelayedCallBacks_r(struct host *host);
196 extern int AddCallBack1(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
198 extern int BreakCallBack(struct host *xhost, AFSFid * fid, int flag);
199 extern int DeleteFileCallBacks(AFSFid * fid);
200 extern int CleanupTimedOutCallBacks(void);
201 extern int CleanupTimedOutCallBacks_r(void);
202 extern int MultiBreakCallBackAlternateAddress(struct host *host, struct AFSCBFids *afidp);
203 extern int MultiBreakCallBackAlternateAddress_r(struct host *host,
204 struct AFSCBFids *afidp);
205 extern int DumpCallBackState(void);
206 extern int PrintCallBackStats(void);
207 extern void *ShutDown(void *);
208 extern void ShutDownAndCore(int dopanic);
210 extern int h_Lookup_r(afs_uint32 hostaddr, afs_uint16 hport,
211 struct host **hostp);
212 extern struct host *h_LookupUuid_r(afsUUID * uuidp);
213 extern void h_Enumerate(int (*proc) (struct host *, void *), void *param);
214 extern void h_Enumerate_r(int (*proc) (struct host *, void *), struct host *enumstart, void *param);
215 extern struct host *h_GetHost_r(struct rx_connection *tcon);
216 extern struct client *h_FindClient_r(struct rx_connection *tcon, afs_int32 *viceid);
217 extern int h_ReleaseClient_r(struct client *client);
218 extern void h_TossStuff_r(struct host *host);
219 extern void h_EnumerateClients(VolumeId vid,
220 int (*proc)(struct client *client, void *rock),
222 extern int GetClient(struct rx_connection *tcon, struct client **cp);
223 extern int PutClient(struct client **cp);
224 extern void h_PrintStats(void);
225 extern void h_PrintClients(void);
226 extern void h_GetWorkStats(int *, int *, int *, afs_int32);
227 extern void h_GetWorkStats64(afs_uint64 *, afs_uint64 *, afs_uint64 *, afs_int32);
228 extern void h_flushhostcps(afs_uint32 hostaddr,
230 extern void h_GetHostNetStats(afs_int32 * a_numHostsP, afs_int32 * a_sameNetOrSubnetP,
231 afs_int32 * a_diffSubnetP, afs_int32 * a_diffNetworkP);
232 extern int h_NBLock_r(struct host *host);
233 extern void h_DumpHosts(void);
234 extern void h_InitHostPackage(int hquota);
235 extern void h_CheckHosts(void );
236 extern void h_AddHostToAddrHashTable_r(afs_uint32 addr, afs_uint16 port, struct host * host);
237 extern void h_AddHostToUuidHashTable_r(afsUUID * uuid, struct host * host);
238 extern int h_DeleteHostFromAddrHashTable_r(afs_uint32 addr, afs_uint16 port, struct host *host);
239 extern int h_DeleteHostFromUuidHashTable_r(struct host *host);
240 extern int addInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port);
241 extern int removeInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port);
242 extern afs_int32 hpr_Initialize(struct ubik_client **);
243 extern int hpr_End(struct ubik_client *);
244 extern int hpr_IdToName(idlist *ids, namelist *names);
245 extern int hpr_NameToId(namelist *names, idlist *ids);
247 #ifdef AFS_DEMAND_ATTACH_FS
250 * state serialization
252 extern int h_SaveState(void);
253 extern int h_RestoreState(void);
256 #define H_ENUMERATE_BAIL(flags) ((flags)|0x80000000)
257 #define H_ENUMERATE_ISSET_BAIL(flags) ((flags)&0x80000000)
259 struct host *(hosttableptrs[h_MAXHOSTTABLES]); /* Used by h_itoh */
260 #define h_htoi(host) ((host)->index) /* index isn't zeroed, no need to lock */
261 #define h_itoh(hostindex) (hosttableptrs[(hostindex)>>h_HTSHIFT]+((hostindex)&(h_HTSPERBLOCK-1)))
263 #define rxr_GetEpoch(aconn) (((struct rx_connection *)(aconn))->epoch)
265 #define rxr_CidOf(aconn) (((struct rx_connection *)(aconn))->cid)
267 #define rxr_PortOf(aconn) \
268 rx_PortOf(rx_PeerOf(((struct rx_connection *)(aconn))))
270 #define rxr_HostOf(aconn) \
271 rx_HostOf(rx_PeerOf((struct rx_connection *)(aconn)))
273 #define HCPS_INPROGRESS 0x01 /*set when CPS is being updated */
274 #define HCPS_WAITING 0x02 /*waiting for CPS to get updated */
275 #define ALTADDR 0x04 /*InitCallBack is being done */
276 #define VENUSDOWN 0x08 /* venus CallBack failed */
277 #define HOSTDELETED 0x10 /* host delated */
278 #define CLIENTDELETED 0x20 /* client deleted */
279 #define RESETDONE 0x40 /* callback reset done */
280 #define HFE_LATER 0x80 /* host has FE_LATER callbacks */
281 #define HERRORTRANS 0x100 /* do error translation */
282 #define HWHO_INPROGRESS 0x200 /* set when WhoAreYou running */
283 #define HCBREAK 0x400 /* flag for a multi CB break */
284 #endif /* _AFS_VICED_HOST_H */