viced: Improve client error log messages
[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 /*
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.
23  */
24 #include <rx/rx_globals.h>
25 #include <pthread.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;
30
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 */
36
37 struct Identity {
38     char valid;                 /* zero if UUID is unknown */
39     afsUUID uuid;
40 };
41
42 struct AddrPort  {
43     afs_uint32 addr;            /* in network byte order */
44     afs_uint16 port;            /* in network byte order */
45     afs_int16  valid;
46 };
47
48 struct Interface {
49     afsUUID uuid;
50     int numberOfInterfaces;
51     struct AddrPort interface[1];/* there are actually more than one here */
52     /* in network byte order */
53 };
54
55 struct host {
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
61                                  * byte order */
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 */
77     /*
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
81      */
82     afs_uint32 index;           /* Host table index, for vicecb.c */
83     struct Lock lock;           /* Write lock for synchronization of
84                                  * VenusDown flag */
85     pthread_cond_t cond;        /* used to wait on hcpsValid */
86 };
87
88 /* * Don't zero the index, lock or condition varialbles */
89 #define HOST_TO_ZERO(H) (int)(((char *)(&((H)->index))-(char *)(H)))
90
91 struct h_AddrHashChain {
92     struct host *hostPtr;
93     struct h_AddrHashChain *next;
94     afs_uint32 addr;
95     afs_uint16 port;
96 };
97
98 struct h_UuidHashChain {
99     struct host *hostPtr;
100     struct h_UuidHashChain *next;
101 };
102
103 struct client {
104     struct client *next;        /* next client entry for host */
105     struct host *host;          /* ptr to parent host entry */
106     afs_int32 sid;              /* Connection number from this host */
107     prlist CPS;                 /* cps for authentication */
108     int ViceId;                 /* Vice ID of user */
109     afs_int32 expTime;          /* RX-only: expiration time */
110     afs_uint32 LastCall;        /* time of last call */
111     afs_uint32 VenusEpoch;      /* Venus start time--used to identify
112                                  * venus.  Actually, now an extension of the
113                                  * sid, which is why it moved.
114                                  */
115     afs_int32 refCount;         /* reference count */
116     char deleted;               /* True if this client should be deleted
117                                  * when there are no more users of the
118                                  * structure */
119     char authClass;             /* auth type, RX-only */
120     char prfail;                /* True if prserver couldn't be contacted */
121     char InSameNetwork;         /* Is client's IP address in the same
122                                  * network as ours? */
123     struct Lock lock;           /* lock to ensure CPS valid if entry
124                                  * on host's clients list. */
125 };
126
127 /* Don't zero the lock */
128 #define CLIENT_TO_ZERO(C)       ((int)(((char *)(&((C)->lock))-(char *)(C))))
129
130
131 /*
132  * key for the client structure stored in connection specific data
133  */
134 extern int rxcon_client_key;
135
136 /* Some additional functions to get at client information.  Client must have
137    an active connection for this to work.  If a lwp is working on a request
138    for the client, then the client must have a connection */
139 /* N.B. h_UserName returns pointer to static data; also relatively expensive */
140 extern char *h_UserName(struct client *client);
141 #define h_Lock(host)    ObtainWriteLock(&(host)->lock)
142 extern int h_Lock_r(struct host *host);
143 #define h_Unlock(host)  ReleaseWriteLock(&(host)->lock)
144 #define h_Unlock_r(host)  ReleaseWriteLock(&(host)->lock)
145
146 #define AddCallBack(host, fid)  AddCallBack1((host), (fid), (afs_uint32 *)0, 1/*CB_NORMAL*/, 0)
147 #define AddVolCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 3/*CB_VOLUME*/, 0)
148 #define AddBulkCallBack(host, fid) AddCallBack1((host), (fid), (afs_uint32 *)0, 4/*CB_BULK*/, 0)
149
150 /* A simple refCount replaces per-thread hold mechanism.  The former
151  * hold semantics are not different from refcounting, except with respect
152  * to cross-thread assertions.  In this change, refcount is protected by
153  * H_LOCK, just like former hold bitmap.  A future change will replace locks
154  * th lock-free operations.  */
155
156 #define h_Hold_r(x) \
157 do { \
158         ++((x)->refCount); \
159 } while(0)
160
161 #define h_Decrement_r(x) \
162 do { \
163         --((x)->refCount); \
164 } while (0)
165
166 #define h_Release_r(x) \
167 do { \
168         h_Decrement_r(x); \
169         if (((x)->refCount < 1) && \
170                 (((x)->hostFlags & HOSTDELETED) || \
171                  ((x)->hostFlags & CLIENTDELETED))) h_TossStuff_r((x));  \
172 } while(0)
173
174 /* operations on the global linked list of hosts */
175 #define h_InsertList_r(h)       (h)->next =  hostList;                  \
176                                 (h)->prev = 0;                          \
177                                 hostList ? (hostList->prev = (h)):0;    \
178                                 hostList = (h);                         \
179                                 hostCount++;
180 #define h_DeleteList_r(h)       opr_Assert(hostCount>0);                    \
181                                 hostCount--;                                \
182                                 (h)->next ? ((h)->next->prev = (h)->prev):0;\
183                                 (h)->prev ? ((h)->prev->next = (h)->next):0;\
184                                 ( h == hostList )? (hostList = h->next):0;
185
186 extern int DeleteAllCallBacks_r(struct host *host, int deletefe);
187 extern int DeleteCallBack(struct host *host, AFSFid * fid);
188 extern int MultiProbeAlternateAddress_r(struct host *host);
189 extern int BreakDelayedCallBacks_r(struct host *host);
190 extern int AddCallBack1(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
191              int locked);
192 extern int BreakCallBack(struct host *xhost, AFSFid * fid, int flag);
193 extern int DeleteFileCallBacks(AFSFid * fid);
194 extern int CleanupTimedOutCallBacks(void);
195 extern int CleanupTimedOutCallBacks_r(void);
196 extern int MultiBreakCallBackAlternateAddress(struct host *host, struct AFSCBFids *afidp);
197 extern int MultiBreakCallBackAlternateAddress_r(struct host *host,
198                                      struct AFSCBFids *afidp);
199 extern int DumpCallBackState(void);
200 extern int PrintCallBackStats(void);
201 extern void *ShutDown(void *);
202 extern void ShutDownAndCore(int dopanic);
203
204 extern int h_Lookup_r(afs_uint32 hostaddr, afs_uint16 hport,
205                       struct host **hostp);
206 extern struct host *h_LookupUuid_r(afsUUID * uuidp);
207 extern void h_Enumerate(int (*proc) (struct host *, void *), void *param);
208 extern void h_Enumerate_r(int (*proc) (struct host *, void *), struct host *enumstart, void *param);
209 extern struct host *h_GetHost_r(struct rx_connection *tcon);
210 extern struct client *h_FindClient_r(struct rx_connection *tcon, afs_int32 *viceid);
211 extern int h_ReleaseClient_r(struct client *client);
212 extern void h_TossStuff_r(struct host *host);
213 extern void h_EnumerateClients(VolumeId vid,
214                                int (*proc)(struct client *client, void *rock),
215                                void *arock);
216 extern int GetClient(struct rx_connection *tcon, struct client **cp);
217 extern int PutClient(struct client **cp);
218 extern void h_PrintStats(void);
219 extern void h_PrintClients(void);
220 extern void h_GetWorkStats(int *, int *, int *, afs_int32);
221 extern void h_GetWorkStats64(afs_uint64 *, afs_uint64 *, afs_uint64 *, afs_int32);
222 extern void h_flushhostcps(afs_uint32 hostaddr,
223                            afs_uint16 hport);
224 extern void h_GetHostNetStats(afs_int32 * a_numHostsP, afs_int32 * a_sameNetOrSubnetP,
225                   afs_int32 * a_diffSubnetP, afs_int32 * a_diffNetworkP);
226 extern int h_NBLock_r(struct host *host);
227 extern void h_DumpHosts(void);
228 extern void h_InitHostPackage(void);
229 extern void h_CheckHosts(void );
230 extern void h_AddHostToAddrHashTable_r(afs_uint32 addr, afs_uint16 port, struct host * host);
231 extern void h_AddHostToUuidHashTable_r(afsUUID * uuid, struct host * host);
232 extern int h_DeleteHostFromAddrHashTable_r(afs_uint32 addr, afs_uint16 port, struct host *host);
233 extern int h_DeleteHostFromUuidHashTable_r(struct host *host);
234 extern int addInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port);
235 extern int removeInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port);
236 extern afs_int32 hpr_Initialize(struct ubik_client **);
237 extern int hpr_End(struct ubik_client *);
238 extern int hpr_IdToName(idlist *ids, namelist *names);
239 extern int hpr_NameToId(namelist *names, idlist *ids);
240
241 #ifdef AFS_DEMAND_ATTACH_FS
242 /*
243  * demand attach fs
244  * state serialization
245  */
246 extern int h_SaveState(void);
247 extern int h_RestoreState(void);
248 #endif
249
250 #define H_ENUMERATE_BAIL(flags)        ((flags)|0x80000000)
251 #define H_ENUMERATE_ISSET_BAIL(flags)  ((flags)&0x80000000)
252
253 struct host *(hosttableptrs[h_MAXHOSTTABLES]);  /* Used by h_itoh */
254 #define h_htoi(host) ((host)->index)    /* index isn't zeroed, no need to lock */
255 #define h_itoh(hostindex) (hosttableptrs[(hostindex)>>h_HTSHIFT]+((hostindex)&(h_HTSPERBLOCK-1)))
256
257 #define rxr_GetEpoch(aconn) (((struct rx_connection *)(aconn))->epoch)
258
259 #define rxr_CidOf(aconn) (((struct rx_connection *)(aconn))->cid)
260
261 #define rxr_PortOf(aconn) \
262     rx_PortOf(rx_PeerOf(((struct rx_connection *)(aconn))))
263
264 #define rxr_HostOf(aconn) \
265     rx_HostOf(rx_PeerOf((struct rx_connection *)(aconn)))
266
267 #define HCPS_INPROGRESS                 0x01    /*set when CPS is being updated */
268 #define HCPS_WAITING                    0x02    /*waiting for CPS to get updated */
269 #define ALTADDR                         0x04    /*InitCallBack is being done */
270 #define VENUSDOWN                       0x08    /* venus CallBack failed */
271 #define HOSTDELETED                     0x10    /* host delated */
272 #define CLIENTDELETED                   0x20    /* client deleted */
273 #define RESETDONE                       0x40    /* callback reset done */
274 #define HFE_LATER                       0x80    /* host has FE_LATER callbacks */
275 #define HERRORTRANS                    0x100    /* do error translation */
276 #define HWHO_INPROGRESS                0x200    /* set when WhoAreYou running */
277 #define HCBREAK                        0x400    /* flag for a multi CB break */
278 #endif /* _AFS_VICED_HOST_H */