viced: remove FS_STATS_DETAILED
[openafs.git] / src / viced / host.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  *
9  * Portions Copyright (c) 2006 Sine Nomine Associates
10  */
11
12 #ifndef _AFS_VICED_HOST_H
13 #define _AFS_VICED_HOST_H
14
15 #include "fs_stats.h"           /*File Server stats package */
16
17 #ifdef AFS_PTHREAD_ENV
18 /*
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.
24  */
25 #include <rx/rx_globals.h>
26 #include <pthread.h>
27 extern pthread_mutex_t host_glock_mutex;
28 #define H_LOCK MUTEX_ENTER(&host_glock_mutex);
29 #define H_UNLOCK MUTEX_EXIT(&host_glock_mutex);
30 extern pthread_key_t viced_uclient_key;
31 #else /* AFS_PTHREAD_ENV */
32 #define H_LOCK
33 #define H_UNLOCK
34 #endif /* AFS_PTHREAD_ENV */
35
36 #define h_MAXHOSTTABLEENTRIES 1000
37 #define h_HASHENTRIES 256       /* Power of 2 */
38 #define h_MAXHOSTTABLES 200
39 #define h_HTSPERBLOCK 512       /* Power of 2 */
40 #define h_HTSHIFT 9             /* log base 2 of HTSPERBLOCK */
41
42 struct Identity {
43     char valid;                 /* zero if UUID is unknown */
44     afsUUID uuid;
45 };
46
47 struct AddrPort  {
48     afs_uint32 addr;            /* in network byte order */
49     afs_uint16 port;            /* in network byte order */
50     afs_int16  valid;
51 };
52
53 struct Interface {
54     afsUUID uuid;
55     int numberOfInterfaces;
56     struct AddrPort interface[1];/* there are actually more than one here */
57     /* in network byte order */
58 };
59
60 struct host {
61     struct host *next, *prev;   /* linked list of all hosts */
62     struct rx_connection *callback_rxcon;       /* rx callback connection */
63     afs_uint32 refCount; /* reference count */
64     afs_uint32 host;            /* IP address of host interface that is
65                                  * currently being used, in network
66                                  * byte order */
67     afs_uint16 port;            /* port address of host */
68     char Console;               /* XXXX This host is a console */
69     unsigned short hostFlags;           /*  bit map */
70     char InSameNetwork;         /*Is host's addr in the same network as
71                                  * the File Server's? */
72     char dummy[3];              /* for padding */
73     char hcpsfailed;            /* Retry the cps call next time */
74     prlist hcps;                /* cps for hostip acls */
75     afs_uint32 LastCall;        /* time of last call from host */
76     afs_uint32 ActiveCall;      /* time of any call but gettime,
77                                    getstats and getcaps */
78     struct client *FirstClient; /* first connection from host */
79     afs_uint32 cpsCall;         /* time of last cps call from this host */
80     struct Interface *interface;        /* all alternate addr for client */
81     afs_uint32 cblist;          /* index of a cb in the per-host circular CB list */
82     /*
83      * These don't get zeroed, keep them at the end. If index doesn't
84      * follow an unsigned short then we need to pad to ensure that
85      * the index fields isn't zeroed. XXX
86      */
87     afs_uint32 index;           /* Host table index, for vicecb.c */
88     struct Lock lock;           /* Write lock for synchronization of
89                                  * VenusDown flag */
90 #ifdef AFS_PTHREAD_ENV
91     pthread_cond_t cond;        /* used to wait on hcpsValid */
92 #endif                          /* AFS_PTHREAD_ENV */
93 };
94
95 /* * Don't zero the index, lock or condition varialbles */
96 #define HOST_TO_ZERO(H) (int)(((char *)(&((H)->index))-(char *)(H)))
97
98 struct h_AddrHashChain {
99     struct host *hostPtr;
100     struct h_AddrHashChain *next;
101     afs_uint32 addr;
102     afs_uint16 port;
103 };
104
105 struct h_UuidHashChain {
106     struct host *hostPtr;
107     struct h_UuidHashChain *next;
108 };
109
110 struct client {
111     struct client *next;        /* next client entry for host */
112     struct host *host;          /* ptr to parent host entry */
113     afs_int32 sid;              /* Connection number from this host */
114     prlist CPS;                 /* cps for authentication */
115     int ViceId;                 /* Vice ID of user */
116     afs_int32 expTime;          /* RX-only: expiration time */
117     afs_uint32 LastCall;        /* time of last call */
118     afs_uint32 VenusEpoch;      /* Venus start time--used to identify
119                                  * venus.  Actually, now an extension of the
120                                  * sid, which is why it moved.
121                                  */
122     afs_int32 refCount;         /* reference count */
123     char deleted;               /* True if this client should be deleted
124                                  * when there are no more users of the
125                                  * structure */
126     char authClass;             /* auth type, RX-only */
127     char prfail;                /* True if prserver couldn't be contacted */
128     char InSameNetwork;         /* Is client's IP address in the same
129                                  * network as ours? */
130     struct Lock lock;           /* lock to ensure CPS valid if entry
131                                  * on host's clients list. */
132 };
133
134 /* Don't zero the lock */
135 #define CLIENT_TO_ZERO(C)       ((int)(((char *)(&((C)->lock))-(char *)(C))))
136
137
138 /*
139  * key for the client structure stored in connection specific data
140  */
141 extern int rxcon_client_key;
142
143 /* Some additional functions to get at client information.  Client must have
144    an active connection for this to work.  If a lwp is working on a request
145    for the client, then the client must have a connection */
146 /* N.B. h_UserName returns pointer to static data; also relatively expensive */
147 extern char *h_UserName(struct client *client);
148 #define h_Lock(host)    ObtainWriteLock(&(host)->lock)
149 extern int h_Lock_r(struct host *host);
150 #define h_Unlock(host)  ReleaseWriteLock(&(host)->lock)
151 #define h_Unlock_r(host)  ReleaseWriteLock(&(host)->lock)
152
153 #define AddCallBack(host, fid)  AddCallBack1((host), (fid), (afs_uint32 *)0, 1/*CB_NORMAL*/, 0)
154 #define AddVolCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 3/*CB_VOLUME*/, 0)
155 #define AddBulkCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 4/*CB_BULK*/, 0)
156
157 /* A simple refCount replaces per-thread hold mechanism.  The former
158  * hold semantics are not different from refcounting, except with respect
159  * to cross-thread assertions.  In this change, refcount is protected by
160  * H_LOCK, just like former hold bitmap.  A future change will replace locks
161  * th lock-free operations.  */
162
163 #define h_Hold_r(x) \
164 do { \
165         ++((x)->refCount); \
166 } while(0)
167
168 #define h_Decrement_r(x) \
169 do { \
170         --((x)->refCount); \
171 } while (0)
172
173 #define h_Release_r(x) \
174 do { \
175         h_Decrement_r(x); \
176         if (((x)->refCount < 1) && \
177                 (((x)->hostFlags & HOSTDELETED) || \
178                  ((x)->hostFlags & CLIENTDELETED))) h_TossStuff_r((x));  \
179 } while(0)
180
181 /* operations on the global linked list of hosts */
182 #define h_InsertList_r(h)       (h)->next =  hostList;                  \
183                                 (h)->prev = 0;                          \
184                                 hostList ? (hostList->prev = (h)):0;    \
185                                 hostList = (h);                         \
186                                 hostCount++;
187 #define h_DeleteList_r(h)       osi_Assert(hostCount>0);                    \
188                                 hostCount--;                                \
189                                 (h)->next ? ((h)->next->prev = (h)->prev):0;\
190                                 (h)->prev ? ((h)->prev->next = (h)->next):0;\
191                                 ( h == hostList )? (hostList = h->next):0;
192
193 extern int DeleteAllCallBacks_r(struct host *host, int deletefe);
194 extern int DeleteCallBack(struct host *host, AFSFid * fid);
195 extern int MultiProbeAlternateAddress_r(struct host *host);
196 extern int BreakDelayedCallBacks_r(struct host *host);
197 extern int AddCallBack1(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
198              int locked);
199 extern int BreakCallBack(struct host *xhost, AFSFid * fid, int flag);
200 extern int DeleteFileCallBacks(AFSFid * fid);
201 extern int CleanupTimedOutCallBacks(void);
202 extern int CleanupTimedOutCallBacks_r(void);
203 extern int MultiBreakCallBackAlternateAddress(struct host *host, struct AFSCBFids *afidp);
204 extern int MultiBreakCallBackAlternateAddress_r(struct host *host,
205                                      struct AFSCBFids *afidp);
206 extern int DumpCallBackState(void);
207 extern int PrintCallBackStats(void);
208 extern void *ShutDown(void *);
209 extern void ShutDownAndCore(int dopanic);
210
211 extern int h_Lookup_r(afs_uint32 hostaddr, afs_uint16 hport,
212                       struct host **hostp);
213 extern struct host *h_LookupUuid_r(afsUUID * uuidp);
214 extern void h_Enumerate(int (*proc) (struct host *, void *), void *param);
215 extern void h_Enumerate_r(int (*proc) (struct host *, void *), struct host *enumstart, void *param);
216 extern struct host *h_GetHost_r(struct rx_connection *tcon);
217 extern struct client *h_FindClient_r(struct rx_connection *tcon);
218 extern int h_ReleaseClient_r(struct client *client);
219 extern void h_TossStuff_r(struct host *host);
220 extern struct client *h_ID2Client(afs_int32 vid);
221 extern int GetClient(struct rx_connection *tcon, struct client **cp);
222 extern int PutClient(struct client **cp);
223 extern void h_PrintStats(void);
224 extern void h_PrintClients(void);
225 extern void h_GetWorkStats(int *, int *, int *, afs_int32);
226 extern void h_GetWorkStats64(afs_uint64 *, afs_uint64 *, afs_uint64 *, afs_int32);
227 extern void h_flushhostcps(afs_uint32 hostaddr,
228                            afs_uint16 hport);
229 extern void h_GetHostNetStats(afs_int32 * a_numHostsP, afs_int32 * a_sameNetOrSubnetP,
230                   afs_int32 * a_diffSubnetP, afs_int32 * a_diffNetworkP);
231 extern int h_NBLock_r(struct host *host);
232 extern void h_DumpHosts(void);
233 extern void h_InitHostPackage(void);
234 extern void h_CheckHosts(void );
235 extern int initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf);
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 initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf);
241 extern int addInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port);
242 extern int removeInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port);
243 extern afs_int32 hpr_Initialize(struct ubik_client **);
244 extern int hpr_End(struct ubik_client *);
245 extern int hpr_IdToName(idlist *ids, namelist *names);
246 extern int hpr_NameToId(namelist *names, idlist *ids);
247
248 #ifdef AFS_DEMAND_ATTACH_FS
249 /*
250  * demand attach fs
251  * state serialization
252  */
253 extern int h_SaveState(void);
254 extern int h_RestoreState(void);
255 #endif
256
257 #define H_ENUMERATE_BAIL(flags)        ((flags)|0x80000000)
258 #define H_ENUMERATE_ISSET_BAIL(flags)  ((flags)&0x80000000)
259
260 struct host *(hosttableptrs[h_MAXHOSTTABLES]);  /* Used by h_itoh */
261 #define h_htoi(host) ((host)->index)    /* index isn't zeroed, no need to lock */
262 #define h_itoh(hostindex) (hosttableptrs[(hostindex)>>h_HTSHIFT]+((hostindex)&(h_HTSPERBLOCK-1)))
263
264 #define rxr_GetEpoch(aconn) (((struct rx_connection *)(aconn))->epoch)
265
266 #define rxr_CidOf(aconn) (((struct rx_connection *)(aconn))->cid)
267
268 #define rxr_PortOf(aconn) \
269     rx_PortOf(rx_PeerOf(((struct rx_connection *)(aconn))))
270
271 #define rxr_HostOf(aconn) \
272     rx_HostOf(rx_PeerOf((struct rx_connection *)(aconn)))
273
274 #define HCPS_INPROGRESS                 0x01    /*set when CPS is being updated */
275 #define HCPS_WAITING                    0x02    /*waiting for CPS to get updated */
276 #define ALTADDR                         0x04    /*InitCallBack is being done */
277 #define VENUSDOWN                       0x08    /* venus CallBack failed */
278 #define HOSTDELETED                     0x10    /* host delated */
279 #define CLIENTDELETED                   0x20    /* client deleted */
280 #define RESETDONE                       0x40    /* callback reset done */
281 #define HFE_LATER                       0x80    /* host has FE_LATER callbacks */
282 #define HERRORTRANS                    0x100    /* do error translation */
283 #define HWHO_INPROGRESS                0x200    /* set when WhoAreYou running */
284 #define HCBREAK                        0x400    /* flag for a multi CB break */
285 #endif /* _AFS_VICED_HOST_H */