viced-avoid-tying-up-all-threads-20070730
[openafs.git] / src / viced / host.h
index a095d72..35e0f2d 100644 (file)
@@ -5,8 +5,13 @@
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
+ *
+ * Portions Copyright (c) 2006 Sine Nomine Associates
  */
 
+#ifndef _AFS_VICED_HOST_H
+#define _AFS_VICED_HOST_H
+
 #include "fs_stats.h"          /*File Server stats package */
 
 #ifdef AFS_PTHREAD_ENV
@@ -25,6 +30,7 @@ extern pthread_mutex_t host_glock_mutex;
     assert(pthread_mutex_lock(&host_glock_mutex) == 0)
 #define H_UNLOCK \
     assert(pthread_mutex_unlock(&host_glock_mutex) == 0)
+extern pthread_key_t viced_uclient_key;
 #else /* AFS_PTHREAD_ENV */
 #define H_LOCK
 #define H_UNLOCK
@@ -41,7 +47,7 @@ extern pthread_mutex_t host_glock_mutex;
 #define h_threadsMask          31      /* for remainder */
 
 /* size of the hold array for each host */
-#define h_maxSlots     ((MAX_FILESERVER_THREAD+h_threadsPerSlot-1)>>h_threadsShift)
+#define h_maxSlots     (((MAX_FILESERVER_THREAD+h_threadsPerSlot-1)>>h_threadsShift)+1)
 
 struct Identity {
     char valid;                        /* zero if UUID is unknown */
@@ -59,6 +65,7 @@ struct Interface {
     struct AddrPort interface[1];/* there are actually more than one here */
     /* in network byte order */
 };
+
 struct host {
     struct host *next, *prev;  /* linked list of all hosts */
     struct rx_connection *callback_rxcon;      /* rx callback connection */
@@ -66,10 +73,10 @@ struct host {
     /* holds on this host; 1 bit per lwp.
      * A hold prevents this structure and
      * inferior structures from disappearing */
-    unsigned int host;         /* IP address of host interface that is
+    afs_uint32 host;           /* IP address of host interface that is
                                 * currently being used, in network
                                 * byte order */
-    unsigned short port;       /* port address of host */
+    afs_uint16 port;           /* port address of host */
     char Console;              /* XXXX This host is a console */
     unsigned short hostFlags;          /*  bit map */
 #if FS_STATS_DETAILED
@@ -80,11 +87,12 @@ struct host {
     char hcpsfailed;           /* Retry the cps call next time */
     prlist hcps;               /* cps for hostip acls */
     afs_uint32 LastCall;       /* time of last call from host */
-    afs_uint32 ActiveCall;     /* time of any call but gettime */
+    afs_uint32 ActiveCall;     /* time of any call but gettime, 
+                                   getstats and getcaps */
     struct client *FirstClient;        /* first connection from host */
     afs_uint32 cpsCall;                /* time of last cps call from this host */
     struct Interface *interface;       /* all alternate addr for client */
-    afs_uint32 cblist;         /* Call back list for this host */
+    afs_uint32 cblist;         /* index of a cb in the per-host circular CB list */
     /*
      * These don't get zeroed, keep them at the end. If index doesn't
      * follow an unsigned short then we need to pad to ensure that
@@ -112,8 +120,6 @@ struct client {
     struct client *next;       /* next client entry for host */
     struct host *host;         /* ptr to parent host entry */
     afs_int32 sid;             /* Connection number from this host */
-    struct rx_connection *tcon;        /* most recent server connection
-                                * associated with this client */
     prlist CPS;                        /* cps for authentication */
     int ViceId;                        /* Vice ID of user */
     afs_int32 expTime;         /* RX-only: expiration time */
@@ -141,6 +147,7 @@ struct client {
 /* Don't zero the lock */
 #define CLIENT_TO_ZERO(C)      ((int)(((char *)(&((C)->lock))-(char *)(C))))
 
+
 /*
  * key for the client structure stored in connection specific data
  */
@@ -196,29 +203,80 @@ extern int h_Lock_r(register struct host *host);
                                (h)->prev ? ((h)->prev->next = (h)->next):0;\
                                ( h == hostList )? (hostList = h->next):0;
 
+extern int DeleteAllCallBacks_r(struct host *host, int deletefe);
+extern int DeleteCallBack(struct host *host, AFSFid * fid);
+extern int MultiProbeAlternateAddress_r(struct host *host);
+extern int BreakDelayedCallBacks_r(struct host *host);
+extern int AddCallBack1(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
+            int locked);
+extern int BreakCallBack(struct host *xhost, AFSFid * fid, int flag);
+extern int DeleteFileCallBacks(AFSFid * fid);
+extern int CleanupTimedOutCallBacks(void);
+extern int CleanupTimedOutCallBacks_r(void);
+extern int MultiBreakCallBackAlternateAddress(struct host *host, struct AFSCBFids *afidp);
+extern int MultiBreakCallBackAlternateAddress_r(struct host *host,
+                                    struct AFSCBFids *afidp);
+extern int DumpCallBackState(void);
+extern int PrintCallBackStats(void);
+extern int ShutDown(void);
+extern void ShutDownAndCore(int dopanic);
+
 extern struct host *h_Alloc(register struct rx_connection *r_con);
 extern struct host *h_Alloc_r(register struct rx_connection *r_con);
-extern struct host *h_Lookup_r(afs_uint32 hostaddr, afs_uint32 hport,
+extern struct host *h_Lookup_r(afs_uint32 hostaddr, afs_uint16 hport,
                               int *heldp);
+extern void   hashInsert_r(afs_uint32 addr, afs_uint16 port, 
+                          struct host* host);
 extern struct host *h_LookupUuid_r(afsUUID * uuidp);
-extern int h_FreeConnection(struct rx_connection *tcon);
 extern void h_Enumerate(int (*proc) (), char *param);
+extern void h_Enumerate_r(int (*proc) (), struct host *enumstart, char *param);
 extern struct host *h_GetHost_r(struct rx_connection *tcon);
 extern struct client *h_FindClient_r(struct rx_connection *tcon);
 extern int h_ReleaseClient_r(struct client *client);
 extern struct client *h_ID2Client(afs_int32 vid);
 extern int GetClient(struct rx_connection *tcon, struct client **cp);
+extern int PutClient(struct client **cp);
 extern void h_PrintStats();
 extern void h_PrintClients();
 extern void h_GetWorkStats();
 extern void h_flushhostcps(register afs_uint32 hostaddr,
-                          register afs_uint32 hport);
+                          register afs_uint16 hport);
+extern void h_GetHostNetStats(afs_int32 * a_numHostsP, afs_int32 * a_sameNetOrSubnetP,
+                 afs_int32 * a_diffSubnetP, afs_int32 * a_diffNetworkP);
+extern int h_NBLock_r(register struct host *host);
+extern void h_DumpHosts();
+extern void h_InitHostPackage();
+extern void h_CheckHosts();
 struct Interface *MultiVerifyInterface_r();
+extern int initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf);
+
+#ifdef AFS_DEMAND_ATTACH_FS
+/*
+ * demand attach fs
+ * state serialization
+ */
+extern int h_SaveState(void);
+extern int h_RestoreState(void);
+#endif
+
+#define H_ENUMERATE_BAIL(held)        ((held)|0x80000000)
+#define H_ENUMERATE_ISSET_BAIL(held)  ((held)&0x80000000)
+#define H_ENUMERATE_ISSET_HELD(held)  ((held)&0x7FFFFFFF)
 
 struct host *(hosttableptrs[h_MAXHOSTTABLES]); /* Used by h_itoh */
 #define h_htoi(host) ((host)->index)   /* index isn't zeroed, no need to lock */
 #define h_itoh(hostindex) (hosttableptrs[(hostindex)>>h_HTSHIFT]+((hostindex)&(h_HTSPERBLOCK-1)))
 
+#define rxr_GetEpoch(aconn) (((struct rx_connection *)(aconn))->epoch)
+
+#define rxr_CidOf(aconn) (((struct rx_connection *)(aconn))->cid)
+
+#define rxr_PortOf(aconn) \
+    rx_PortOf(rx_PeerOf(((struct rx_connection *)(aconn))))
+
+#define rxr_HostOf(aconn) \
+    rx_HostOf(rx_PeerOf((struct rx_connection *)(aconn)))
+
 #define HCPS_INPROGRESS                        0x01    /*set when CPS is being updated */
 #define HCPS_WAITING                   0x02    /*waiting for CPS to get updated */
 #define ALTADDR                                0x04    /*InitCallBack is being done */
@@ -228,3 +286,5 @@ struct host *(hosttableptrs[h_MAXHOSTTABLES]);      /* Used by h_itoh */
 #define RESETDONE                      0x40    /* callback reset done */
 #define HFE_LATER                       0x80   /* host has FE_LATER callbacks */
 #define HERRORTRANS                    0x100   /* do error translation */
+#define HWHO_INPROGRESS                0x200    /* set when WhoAreYou running */
+#endif /* _AFS_VICED_HOST_H */