rx-flag-all-packets-20080925
[openafs.git] / src / rx / rx.c
index 489c4ea..e887680 100644 (file)
@@ -85,6 +85,7 @@ extern afs_int32 afs_termState;
 #else /* KERNEL */
 # include <sys/types.h>
 # include <string.h>
+# include <stdarg.h>
 # include <errno.h>
 #ifdef AFS_NT40_ENV
 # include <stdlib.h>
@@ -108,8 +109,17 @@ extern afs_int32 afs_termState;
 # include <afs/rxgen_consts.h>
 #endif /* KERNEL */
 
-int (*registerProgram) () = 0;
-int (*swapNameProgram) () = 0;
+#ifndef KERNEL
+#ifdef AFS_PTHREAD_ENV
+#ifndef AFS_NT40_ENV
+int (*registerProgram) (pid_t, char *) = 0;
+int (*swapNameProgram) (pid_t, const char *, char *) = 0;
+#endif
+#else
+int (*registerProgram) (PROCESS, char *) = 0;
+int (*swapNameProgram) (PROCESS, const char *, char *) = 0;
+#endif
+#endif
 
 /* Local static routines */
 static void rxi_DestroyConnectionNoLock(register struct rx_connection *conn);
@@ -286,7 +296,8 @@ assert(pthread_once(&rx_once_init, rxi_InitPthread)==0)
 
 #if defined(RX_ENABLE_LOCKS) && defined(KERNEL)
 static afs_kmutex_t rx_rpc_stats;
-void rxi_StartUnlocked();
+void rxi_StartUnlocked(struct rxevent *event, void *call,
+                       void *arg1, int istack);
 #endif
 
 /* We keep a "last conn pointer" in rxi_FindConnection. The odds are 
@@ -465,7 +476,7 @@ rx_InitHost(u_int host, u_int port)
     rxi_nCalls = 0;
     rx_connDeadTime = 12;
     rx_tranquil = 0;           /* reset flag */
-    memset((char *)&rx_stats, 0, sizeof(struct rx_stats));
+    memset((char *)&rx_stats, 0, sizeof(struct rx_statistics));
     htable = (char *)
        osi_Alloc(rx_hashTableSize * sizeof(struct rx_connection *));
     PIN(htable, rx_hashTableSize * sizeof(struct rx_connection *));    /* XXXXX */
@@ -506,7 +517,11 @@ rx_InitHost(u_int host, u_int port)
        rx_port = 0;
 #else
        struct sockaddr_in addr;
-       int addrlen = sizeof(addr);
+#ifdef AFS_NT40_ENV
+        int addrlen = sizeof(addr);
+#else
+       socklen_t addrlen = sizeof(addr);
+#endif
        if (getsockname((int)rx_socket, (struct sockaddr *)&addr, &addrlen)) {
            rx_Finalize();
            return -1;
@@ -721,7 +736,7 @@ rx_StartServer(int donateMe)
     }
 
     /* Turn on reaping of idle server connections */
-    rxi_ReapConnections();
+    rxi_ReapConnections(NULL, NULL, NULL);
 
     USERPRI;
 
@@ -1105,6 +1120,7 @@ rx_GetConnection(register struct rx_connection *conn)
     USERPRI;
 }
 
+#ifdef  AFS_GLOBAL_RXLOCK_KERNEL
 /* Wait for the transmit queue to no longer be busy. 
  * requires the call->lock to be held */
 static void rxi_WaitforTQBusy(struct rx_call *call) {
@@ -1123,6 +1139,8 @@ static void rxi_WaitforTQBusy(struct rx_call *call) {
        }
     }
 }
+#endif
+
 /* Start a new rx remote procedure call, on the specified connection.
  * If wait is set to 1, wait for a free call channel; otherwise return
  * 0.  Maxtime gives the maximum number of seconds this call may take,
@@ -1263,7 +1281,7 @@ rx_NewCall(register struct rx_connection *conn)
     MUTEX_ENTER(&call->lock);
     rxi_WaitforTQBusy(call);
     if (call->flags & RX_CALL_TQ_CLEARME) {
-       rxi_ClearTransmitQueue(call, 0);
+       rxi_ClearTransmitQueue(call, 1);
        queue_Init(&call->tq);
     }
     MUTEX_EXIT(&call->lock);
@@ -2047,7 +2065,8 @@ rx_EndCall(register struct rx_call *call, afs_int32 rc)
      * kernel version, and may interrupt the macros rx_Read or
      * rx_Write, which run at normal priority for efficiency. */
     if (call->currentPacket) {
-       queue_Prepend(&call->iovq, call->currentPacket);
+        call->currentPacket->flags &= ~RX_PKTFLAG_CP;
+       rxi_FreePacket(call->currentPacket);
        call->currentPacket = (struct rx_packet *)0;
     }
        
@@ -2215,7 +2234,7 @@ rxi_NewCall(register struct rx_connection *conn, register int channel)
 #ifdef AFS_GLOBAL_RXLOCK_KERNEL
        /* Now, if TQ wasn't cleared earlier, do it now. */
        if (call->flags & RX_CALL_TQ_CLEARME) {
-           rxi_ClearTransmitQueue(call, 0);
+           rxi_ClearTransmitQueue(call, 1);
            queue_Init(&call->tq);
        }
 #endif /* AFS_GLOBAL_RXLOCK_KERNEL */
@@ -2375,7 +2394,7 @@ rxi_SetPeerMtu(register afs_uint32 host, register afs_uint32 port, int mtu)
            }
        }
     } else {
-       struct rx_peer *peer, *next;
+       struct rx_peer *peer;
        hashIndex = PEER_HASH(host, port);
        for (peer = rx_peerHashTable[hashIndex]; peer; peer = peer->next) {
            if ((peer->host == host) && (peer->port == port)) {
@@ -2548,8 +2567,8 @@ rxi_FindConnection(osi_socket socket, register afs_int32 host,
  * containing the network address.  Both can be modified.  The return value, if
  * non-zero, indicates that the packet should be dropped.  */
 
-int (*rx_justReceived) () = 0;
-int (*rx_almostSent) () = 0;
+int (*rx_justReceived) (struct rx_packet *, struct sockaddr_in *) = 0;
+int (*rx_almostSent) (struct rx_packet *, struct sockaddr_in *) = 0;
 
 /* A packet has been received off the interface.  Np is the packet, socket is
  * the socket number it was received from (useful in determining which service
@@ -3099,9 +3118,10 @@ TooLow(struct rx_packet *ap, struct rx_call *acall)
 #endif /* KERNEL */
 
 static void
-rxi_CheckReachEvent(struct rxevent *event, struct rx_connection *conn,
-                   struct rx_call *acall)
+rxi_CheckReachEvent(struct rxevent *event, void *arg1, void *arg2)
 {
+    struct rx_connection *conn = arg1;
+    struct rx_call *acall = arg2;
     struct rx_call *call = acall;
     struct clock when, now;
     int i, waiting;
@@ -3316,6 +3336,7 @@ rxi_ReceiveDataPacket(register struct rx_call *call,
            /* It's the next packet. Stick it on the receive queue
             * for this call. Set newPackets to make sure we wake
             * the reader once all packets have been processed */
+           np->flags |= RX_PKTFLAG_RQ;
            queue_Prepend(&call->rq, np);
            call->nSoftAcks++;
            np = NULL;          /* We can't use this anymore */
@@ -3762,6 +3783,7 @@ rxi_ReceiveAckPacket(register struct rx_call *call, struct rx_packet *np,
 #endif /* AFS_GLOBAL_RXLOCK_KERNEL */
        {
            queue_Remove(tp);
+           tp->flags &= ~RX_PKTFLAG_TQ;
            rxi_FreePacket(tp); /* rxi_FreePacket mustn't wake up anyone, preemptively. */
        }
     }
@@ -4301,9 +4323,9 @@ rxi_AckAll(struct rxevent *event, register struct rx_call *call, char *dummy)
 }
 
 void
-rxi_SendDelayedAck(struct rxevent *event, register struct rx_call *call,
-                  char *dummy)
+rxi_SendDelayedAck(struct rxevent *event, void *arg1, void *unused)
 {
+    struct rx_call *call = arg1;
 #ifdef RX_ENABLE_LOCKS
     if (event) {
        MUTEX_ENTER(&call->lock);
@@ -4540,7 +4562,7 @@ rxi_CallError(register struct rx_call *call, afs_int32 error)
     if (call->error)
        error = call->error;
 
-#ifdef RX_GLOBAL_RXLOCK_KERNEL
+#ifdef AFS_GLOBAL_RXLOCK_KERNEL
     if (!((call->flags & RX_CALL_TQ_BUSY) || (call->tqWaiters > 0))) {
        rxi_ResetCall(call, 0);
     }
@@ -4617,7 +4639,6 @@ rxi_ResetCall(register struct rx_call *call, register int newcall)
     MUTEX_EXIT(&peer->peer_lock);
 
     flags = call->flags;
-    rxi_ClearReceiveQueue(call);
 #ifdef AFS_GLOBAL_RXLOCK_KERNEL
     if (flags & RX_CALL_TQ_BUSY) {
        call->flags = RX_CALL_TQ_CLEARME | RX_CALL_TQ_BUSY;
@@ -4625,8 +4646,8 @@ rxi_ResetCall(register struct rx_call *call, register int newcall)
     } else
 #endif /* AFS_GLOBAL_RXLOCK_KERNEL */
     {
-       rxi_ClearTransmitQueue(call, 0);
-       queue_Init(&call->tq);
+       rxi_ClearTransmitQueue(call, 1);
+       /* why init the queue if you just emptied it? queue_Init(&call->tq); */
        if (call->tqWaiters || (flags & RX_CALL_TQ_WAIT)) {
            dpf(("rcall %x has %d waiters and flags %d\n", call, call->tqWaiters, call->flags));
        }
@@ -4640,7 +4661,19 @@ rxi_ResetCall(register struct rx_call *call, register int newcall)
            call->tqWaiters--;
        }
     }
-    queue_Init(&call->rq);
+
+    rxi_ClearReceiveQueue(call);
+    /* why init the queue if you just emptied it? queue_Init(&call->rq); */
+    
+    if (call->currentPacket) {
+        call->currentPacket->flags &= ~RX_PKTFLAG_CP;
+       rxi_FreePacket(call->currentPacket);
+       call->currentPacket = (struct rx_packet *)0;
+    }
+    call->curlen = call->nLeft = call->nFree = 0;
+
+    rxi_FreePackets(0, &call->iovq);
+
     call->error = 0;
     call->twind = call->conn->twind[call->channel];
     call->rwind = call->conn->rwind[call->channel];
@@ -5156,9 +5189,11 @@ rxi_SendXmitList(struct rx_call *call, struct rx_packet **list, int len,
 #ifdef RX_ENABLE_LOCKS
 /* Call rxi_Start, below, but with the call lock held. */
 void
-rxi_StartUnlocked(struct rxevent *event, register struct rx_call *call,
-                 void *arg1, int istack)
+rxi_StartUnlocked(struct rxevent *event, 
+                 void *arg0, void *arg1, int istack)
 {
+    struct rx_call *call = arg0;
+    
     MUTEX_ENTER(&call->lock);
     rxi_Start(event, call, arg1, istack);
     MUTEX_EXIT(&call->lock);
@@ -5171,9 +5206,11 @@ rxi_StartUnlocked(struct rxevent *event, register struct rx_call *call,
  * better optimized for new packets, the usual case, now that we've
  * got rid of queues of send packets. XXXXXXXXXXX */
 void
-rxi_Start(struct rxevent *event, register struct rx_call *call,
-         void *arg1, int istack)
+rxi_Start(struct rxevent *event, 
+          void *arg0, void *arg1, int istack)
 {
+    struct rx_call *call = arg0;
+    
     struct rx_packet *p;
     register struct rx_packet *nxp;    /* Next pointer for queue_Scan */
     struct rx_peer *peer = call->conn->peer;
@@ -5405,6 +5442,7 @@ rxi_Start(struct rxevent *event, register struct rx_call *call,
                        if (p->header.seq < call->tfirst
                            && (p->flags & RX_PKTFLAG_ACKED)) {
                            queue_Remove(p);
+                           p->flags &= ~RX_PKTFLAG_TQ;
                            rxi_FreePacket(p);
                        } else
                            missing = 1;
@@ -5546,7 +5584,7 @@ rxi_CheckCall(register struct rx_call *call)
     afs_uint32 now;
     afs_uint32 deadTime;
 
-#ifdef RX_GLOBAL_RXLOCK_KERNEL
+#ifdef AFS_GLOBAL_RXLOCK_KERNEL
     if (call->flags & RX_CALL_TQ_BUSY) {
        /* Call is active and will be reset by rxi_Start if it's
         * in an error state.
@@ -5648,9 +5686,9 @@ rxi_CheckCall(register struct rx_call *call)
  * keep-alive packet (if we're actually trying to keep the call alive)
  */
 void
-rxi_KeepAliveEvent(struct rxevent *event, register struct rx_call *call,
-                  char *dummy)
+rxi_KeepAliveEvent(struct rxevent *event, void *arg1, void *dummy)
 {
+    struct rx_call *call = arg1;
     struct rx_connection *conn;
     afs_uint32 now;
 
@@ -5719,8 +5757,10 @@ rxi_KeepAliveOn(register struct rx_call *call)
  * that have been delayed to throttle looping clients. */
 void
 rxi_SendDelayedConnAbort(struct rxevent *event,
-                        register struct rx_connection *conn, char *dummy)
+                        void *arg1, void *unused)
 {
+    struct rx_connection *conn = arg1;
+    
     afs_int32 error;
     struct rx_packet *packet;
 
@@ -5742,9 +5782,11 @@ rxi_SendDelayedConnAbort(struct rxevent *event,
 /* This routine is called to send call abort messages
  * that have been delayed to throttle looping clients. */
 void
-rxi_SendDelayedCallAbort(struct rxevent *event, register struct rx_call *call,
-                        char *dummy)
+rxi_SendDelayedCallAbort(struct rxevent *event, 
+                        void *arg1, void *dummy)
 {
+    struct rx_call *call = arg1;
+    
     afs_int32 error;
     struct rx_packet *packet;
 
@@ -5768,9 +5810,11 @@ rxi_SendDelayedCallAbort(struct rxevent *event, register struct rx_call *call,
  * issues a challenge to the client, which is obtained from the
  * security object associated with the connection */
 void
-rxi_ChallengeEvent(struct rxevent *event, register struct rx_connection *conn,
-                  void *arg1, int tries)
+rxi_ChallengeEvent(struct rxevent *event, 
+                  void *arg0, void *arg1, int tries)
 {
+    struct rx_connection *conn = arg0;
+    
     conn->challengeEvent = NULL;
     if (RXS_CheckAuthentication(conn->securityObject, conn) != 0) {
        register struct rx_packet *packet;
@@ -5931,7 +5975,7 @@ rxi_ComputeRoundTripTime(register struct rx_packet *p,
 /* Find all server connections that have not been active for a long time, and
  * toss them */
 void
-rxi_ReapConnections(void)
+rxi_ReapConnections(struct rxevent *unused, void *unused1, void *unused2)
 {
     struct clock now, when;
     clock_GetTime(&now);
@@ -6292,9 +6336,7 @@ rx_DebugOnOff(int on)
 
 /* Don't call this debugging routine directly; use dpf */
 void
-rxi_DebugPrint(char *format, int a1, int a2, int a3, int a4, int a5, int a6,
-              int a7, int a8, int a9, int a10, int a11, int a12, int a13,
-              int a14, int a15)
+rxi_DebugPrint(char *format, ...)
 {
 #ifdef AFS_NT40_ENV
     char msg[512];
@@ -6304,9 +6346,7 @@ rxi_DebugPrint(char *format, int a1, int a2, int a3, int a4, int a5, int a6,
     len = _snprintf(tformat, sizeof(tformat), "tid[%d] %s", GetCurrentThreadId(), format);
 
     if (len > 0) {
-       len = _snprintf(msg, sizeof(msg)-2, 
-                       tformat, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 
-                       a11, a12, a13, a14, a15);
+       len = _vsnprintf(msg, sizeof(msg)-2, tformat, ap);
        if (len > 0) {
            if (msg[len-1] != '\n') {
                msg[len] = '\n';
@@ -6315,14 +6355,19 @@ rxi_DebugPrint(char *format, int a1, int a2, int a3, int a4, int a5, int a6,
            OutputDebugString(msg);
        }
     }
+    va_end(ap);
 #else
     struct clock now;
+    va_list ap;
+    
+    va_start(ap, format);
+
     clock_GetTime(&now);
     fprintf(rx_Log, " %u.%.3u:", (unsigned int)now.sec,
            (unsigned int)now.usec / 1000);
-    fprintf(rx_Log, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
-           a13, a14, a15);
+    vfprintf(rx_Log, format, ap);
     putc('\n', rx_Log);
+    va_end(ap);
 #endif
 }
 
@@ -6333,15 +6378,15 @@ rxi_DebugPrint(char *format, int a1, int a2, int a3, int a4, int a5, int a6,
  * checking.
  */
 void
-rx_PrintTheseStats(FILE * file, struct rx_stats *s, int size,
+rx_PrintTheseStats(FILE * file, struct rx_statistics *s, int size,
                   afs_int32 freePackets, char version)
 {
     int i;
 
-    if (size != sizeof(struct rx_stats)) {
+    if (size != sizeof(struct rx_statistics)) {
        fprintf(file,
-               "Unexpected size of stats structure: was %d, expected %d\n",
-               size, sizeof(struct rx_stats));
+               "Unexpected size of stats structure: was %d, expected %lud\n",
+               size, sizeof(struct rx_statistics));
     }
 
     fprintf(file, "rx stats: free packets %d, allocs %d, ", (int)freePackets,
@@ -6466,7 +6511,11 @@ MakeDebugCall(osi_socket socket, afs_uint32 remoteAddr, afs_uint16 remotePort,
     register afs_int32 code;
     struct timeval tv_now, tv_wake, tv_delta;
     struct sockaddr_in taddr, faddr;
+#ifdef AFS_NT40_ENV
     int faddrLen;
+#else
+    socklen_t faddrLen;
+#endif
     fd_set imask;
     register char *tp;
 
@@ -6615,7 +6664,7 @@ rx_GetServerDebug(osi_socket socket, afs_uint32 remoteAddr,
 
 afs_int32
 rx_GetServerStats(osi_socket socket, afs_uint32 remoteAddr,
-                 afs_uint16 remotePort, struct rx_stats * stat,
+                 afs_uint16 remotePort, struct rx_statistics * stat,
                  afs_uint32 * supportedValues)
 {
     struct rx_debugIn in;