Rx: Permit MakeDebugCall() be be compiled when RXDEBUG is undefined
[openafs.git] / src / rx / rx.c
index 5fe0286..0f015c8 100644 (file)
@@ -78,7 +78,7 @@ extern afs_int32 afs_termState;
 #include "sys/lockl.h"
 #include "sys/lock_def.h"
 #endif /* AFS_AIX41_ENV */
-# include "rxgen_consts.h"
+# include "afs/rxgen_consts.h"
 #else /* KERNEL */
 # include <sys/types.h>
 # include <string.h>
@@ -1581,7 +1581,7 @@ rxi_ServerProc(int threadID, struct rx_call *newcall, osi_socket * socketp)
        if (tservice->beforeProc)
            (*tservice->beforeProc) (call);
 
-       code = call->conn->service->executeRequestProc(call);
+       code = tservice->executeRequestProc(call);
 
        if (tservice->afterProc)
            (*tservice->afterProc) (call, code);
@@ -1679,8 +1679,7 @@ rx_GetCall(int tno, struct rx_service *cur_service, osi_socket * socketp)
        MUTEX_EXIT(&freeSQEList_lock);
     } else {                   /* otherwise allocate a new one and return that */
        MUTEX_EXIT(&freeSQEList_lock);
-       sq = (struct rx_serverQueueEntry *)
-           rxi_Alloc(sizeof(struct rx_serverQueueEntry));
+       sq = rxi_Alloc(sizeof(struct rx_serverQueueEntry));
        MUTEX_INIT(&sq->lock, "server Queue lock", MUTEX_DEFAULT, 0);
        CV_INIT(&sq->cv, "server Queue lock", CV_DEFAULT, 0);
     }
@@ -1852,8 +1851,7 @@ rx_GetCall(int tno, struct rx_service *cur_service, osi_socket * socketp)
        MUTEX_EXIT(&freeSQEList_lock);
     } else {                   /* otherwise allocate a new one and return that */
        MUTEX_EXIT(&freeSQEList_lock);
-       sq = (struct rx_serverQueueEntry *)
-           rxi_Alloc(sizeof(struct rx_serverQueueEntry));
+       sq = rxi_Alloc(sizeof(struct rx_serverQueueEntry));
        MUTEX_INIT(&sq->lock, "server Queue lock", MUTEX_DEFAULT, 0);
        CV_INIT(&sq->cv, "server Queue lock", CV_DEFAULT, 0);
     }
@@ -2123,7 +2121,9 @@ rx_EndCall(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) {
+#ifdef RX_TRACK_PACKETS
         call->currentPacket->flags &= ~RX_PKTFLAG_CP;
+#endif
        rxi_FreePacket(call->currentPacket);
        call->currentPacket = (struct rx_packet *)0;
     }
@@ -2316,7 +2316,7 @@ rxi_NewCall(struct rx_connection *conn, int channel)
        rxi_ResetCall(call, 1);
     } else {
 
-       call = (struct rx_call *)rxi_Alloc(sizeof(struct rx_call));
+       call = rxi_Alloc(sizeof(struct rx_call));
 #ifdef RXDEBUG_PACKET
         call->allNextp = rx_allCallsp;
         rx_allCallsp = call;
@@ -2429,7 +2429,7 @@ rxi_FreeCall(struct rx_call *call)
 }
 
 afs_int32 rxi_Alloccnt = 0, rxi_Allocsize = 0;
-char *
+void *
 rxi_Alloc(size_t size)
 {
     char *p;
@@ -3472,7 +3472,9 @@ rxi_ReceiveDataPacket(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 */
+#ifdef RX_TRACK_PACKETS
            np->flags |= RX_PKTFLAG_RQ;
+#endif
            queue_Prepend(&call->rq, np);
 #ifdef RXDEBUG_PACKET
             call->rqc++;
@@ -3607,7 +3609,9 @@ rxi_ReceiveDataPacket(struct rx_call *call,
             * packet before which to insert the new packet, or at the
             * queue head if the queue is empty or the packet should be
             * appended. */
+#ifdef RX_TRACK_PACKETS
             np->flags |= RX_PKTFLAG_RQ;
+#endif
 #ifdef RXDEBUG_PACKET
             call->rqc++;
 #endif /* RXDEBUG_PACKET */
@@ -3819,12 +3823,12 @@ rxi_ReceiveAckPacket(struct rx_call *call, struct rx_packet *np,
     afs_uint32 skew = 0;
     int nbytes;
     int missing;
-    int backedOff = 0;
     int acked;
     int nNacked = 0;
     int newAckCount = 0;
     int maxDgramPackets = 0;   /* Set if peer supports AFS 3.5 jumbo datagrams */
     int pktsize = 0;            /* Set if we need to update the peer mtu */
+    int conn_data_locked = 0;
 
     if (rx_stats_active)
         rx_MutexIncrement(rx_stats.ackPacketsRead, rx_stats_mutex);
@@ -3854,42 +3858,28 @@ rxi_ReceiveAckPacket(struct rx_call *call, struct rx_packet *np,
 
     if (conn->lastPacketSizeSeq) {
        MUTEX_ENTER(&conn->conn_data_lock);
+        conn_data_locked = 1;
        if ((first > conn->lastPacketSizeSeq) && (conn->lastPacketSize)) {
            pktsize = conn->lastPacketSize;
            conn->lastPacketSize = conn->lastPacketSizeSeq = 0;
        }
-       MUTEX_EXIT(&conn->conn_data_lock);
     }
     if ((ap->reason == RX_ACK_PING_RESPONSE) && (conn->lastPingSizeSer)) {
-       MUTEX_ENTER(&conn->conn_data_lock);
+        if (!conn_data_locked) {
+            MUTEX_ENTER(&conn->conn_data_lock);
+            conn_data_locked = 1;
+        }
        if ((conn->lastPingSizeSer == serial) && (conn->lastPingSize)) {
            /* process mtu ping ack */
            pktsize = conn->lastPingSize;
            conn->lastPingSizeSer = conn->lastPingSize = 0;
        }
-       MUTEX_EXIT(&conn->conn_data_lock);
     }
 
-    if (pktsize) {
-       MUTEX_ENTER(&peer->peer_lock);
-       /*
-        * Start somewhere. Can't assume we can send what we can receive,
-        * but we are clearly receiving.
-        */
-       if (!peer->maxPacketSize)
-           peer->maxPacketSize = RX_MIN_PACKET_SIZE+RX_IPUDP_SIZE;
-
-       if (pktsize > peer->maxPacketSize) {
-           peer->maxPacketSize = pktsize;
-           if ((pktsize-RX_IPUDP_SIZE > peer->ifMTU)) {
-               peer->ifMTU=pktsize-RX_IPUDP_SIZE;
-               peer->natMTU = rxi_AdjustIfMTU(peer->ifMTU);
-               rxi_ScheduleGrowMTUEvent(call, 1);
-           }
-       }
-       MUTEX_EXIT(&peer->peer_lock);
+    if (conn_data_locked) {
+       MUTEX_EXIT(&conn->conn_data_lock);
+        conn_data_locked = 0;
     }
-
 #ifdef RXDEBUG
 #ifdef AFS_NT40_ENV
     if (rxdebug_active) {
@@ -3930,11 +3920,29 @@ rxi_ReceiveAckPacket(struct rx_call *call, struct rx_packet *np,
 #endif /* AFS_NT40_ENV */
 #endif
 
+    MUTEX_ENTER(&peer->peer_lock);
+    if (pktsize) {
+       /*
+        * Start somewhere. Can't assume we can send what we can receive,
+        * but we are clearly receiving.
+        */
+       if (!peer->maxPacketSize)
+           peer->maxPacketSize = RX_MIN_PACKET_SIZE+RX_IPUDP_SIZE;
+
+       if (pktsize > peer->maxPacketSize) {
+           peer->maxPacketSize = pktsize;
+           if ((pktsize-RX_IPUDP_SIZE > peer->ifMTU)) {
+               peer->ifMTU=pktsize-RX_IPUDP_SIZE;
+               peer->natMTU = rxi_AdjustIfMTU(peer->ifMTU);
+               rxi_ScheduleGrowMTUEvent(call, 1);
+           }
+       }
+    }
+
     /* Update the outgoing packet skew value to the latest value of
      * the peer's incoming packet skew value.  The ack packet, of
      * course, could arrive out of order, but that won't affect things
      * much */
-    MUTEX_ENTER(&peer->peer_lock);
     peer->outPacketSkew = skew;
 
     /* Check for packets that no longer need to be transmitted, and
@@ -3971,7 +3979,9 @@ rxi_ReceiveAckPacket(struct rx_call *call, struct rx_packet *np,
 #endif /* AFS_GLOBAL_RXLOCK_KERNEL */
        {
            queue_Remove(tp);
+#ifdef RX_TRACK_PACKETS
            tp->flags &= ~RX_PKTFLAG_TQ;
+#endif
 #ifdef RXDEBUG_PACKET
             call->tqc--;
 #endif /* RXDEBUG_PACKET */
@@ -4045,14 +4055,14 @@ rxi_ReceiveAckPacket(struct rx_call *call, struct rx_packet *np,
          * timeout value for future packets until a successful response
          * is received for an initial transmission.
          */
-        if (missing && !backedOff) {
+        if (missing && !peer->backedOff) {
             struct clock c = peer->timeout;
             struct clock max_to = {3, 0};
 
             clock_Add(&peer->timeout, &c);
             if (clock_Gt(&peer->timeout, &max_to))
                 peer->timeout = max_to;
-            backedOff = 1;
+            peer->backedOff = 1;
         }
 
        /* If packet isn't yet acked, and it has been transmitted at least
@@ -4890,8 +4900,10 @@ rxi_ResetCall(struct rx_call *call, int newcall)
     /* why init the queue if you just emptied it? queue_Init(&call->rq); */
 
     if (call->currentPacket) {
+#ifdef RX_TRACK_PACKETS
         call->currentPacket->flags &= ~RX_PKTFLAG_CP;
         call->currentPacket->flags |= RX_PKTFLAG_IOVQ;
+#endif
         queue_Prepend(&call->iovq, call->currentPacket);
 #ifdef RXDEBUG_PACKET
         call->iovqc++;
@@ -5267,10 +5279,15 @@ rxi_SendList(struct rx_call *call, struct rx_packet **list, int len,
     peer->nSent += len;
     if (resending)
        peer->reSends += len;
-    if (rx_stats_active)
-        rx_MutexAdd(rx_stats.dataPacketsSent, len, rx_stats_mutex);
     MUTEX_EXIT(&peer->peer_lock);
 
+    if (rx_stats_active) {
+        if (resending)
+            rx_MutexAdd(rx_stats.dataPacketsReSent, len, rx_stats_mutex);
+        else
+            rx_MutexAdd(rx_stats.dataPacketsSent, len, rx_stats_mutex);
+    }
+
     if (list[len - 1]->header.flags & RX_LAST_PACKET) {
        lastPacket = 1;
     }
@@ -5303,8 +5320,6 @@ rxi_SendList(struct rx_call *call, struct rx_packet **list, int len,
         * packet until the congestion window reaches the ack rate. */
        if (list[i]->header.serial) {
            requestAck = 1;
-            if (rx_stats_active)
-                rx_MutexIncrement(rx_stats.dataPacketsReSent, rx_stats_mutex);
        } else {
            /* improved RTO calculation- not Karn */
            list[i]->firstSent = *now;
@@ -5553,8 +5568,9 @@ rxi_Start(struct rxevent *event,
         * recent additions.
         * Do a dance to avoid blocking after setting now. */
        MUTEX_ENTER(&peer->peer_lock);
-       retryTime = peer->timeout;
+        retryTime = peer->timeout;
        MUTEX_EXIT(&peer->peer_lock);
+
        clock_GetTime(&now);
        clock_Add(&retryTime, &now);
        usenow = now;
@@ -5608,6 +5624,7 @@ rxi_Start(struct rxevent *event,
                             *(call->callNumber)));
                        break;
                    }
+#ifdef RX_TRACK_PACKETS
                    if ((p->flags & RX_PKTFLAG_FREE)
                        || (!queue_IsEnd(&call->tq, nxp)
                            && (nxp->flags & RX_PKTFLAG_FREE))
@@ -5615,6 +5632,7 @@ rxi_Start(struct rxevent *event,
                        || (nxp == (struct rx_packet *)&rx_freePacketQueue)) {
                        osi_Panic("rxi_Start: xmit queue clobbered");
                    }
+#endif
                    if (p->flags & RX_PKTFLAG_ACKED) {
                        /* Since we may block, don't trust this */
                        usenow.sec = usenow.usec = 0;
@@ -5721,7 +5739,9 @@ rxi_Start(struct rxevent *event,
                        if (p->header.seq < call->tfirst
                            && (p->flags & RX_PKTFLAG_ACKED)) {
                            queue_Remove(p);
+#ifdef RX_TRACK_PACKETS
                            p->flags &= ~RX_PKTFLAG_TQ;
+#endif
 #ifdef RXDEBUG_PACKET
                             call->tqc--;
 #endif
@@ -6467,6 +6487,9 @@ rxi_ComputeRoundTripTime(struct rx_packet *p,
     clock_Zero(&(peer->timeout));
     clock_Addmsec(&(peer->timeout), rtt_timeout);
 
+    /* Reset the backedOff flag since we just computed a new timeout value */
+    peer->backedOff = 0;
+
     dpf(("rxi_ComputeRoundTripTime(call=%d packet=%"AFS_PTR_FMT" rtt=%d ms, srtt=%d ms, rtt_dev=%d ms, timeout=%d.%06d sec)\n",
           p->header.callNumber, p, MSEC(rttp), peer->rtt >> 3, peer->rtt_dev >> 2, (peer->timeout.sec), (peer->timeout.usec)));
 }
@@ -6746,7 +6769,7 @@ rxi_ComputeRate(struct rx_peer *peer, struct rx_call *call,
        } else {
            return;
        }
-       xferSize = rx_AckDataSize(rx_Window) + RX_HEADER_SIZE;
+       xferSize = rx_AckDataSize(rx_maxSendWindow) + RX_HEADER_SIZE;
        break;
 
     default:
@@ -6801,9 +6824,9 @@ rxi_ComputeRate(struct rx_peer *peer, struct rx_call *call,
      * one packet exchange */
     if (clock_Gt(&newTO, &peer->timeout)) {
 
-       dpf(("CONG peer %lx/%u: timeout %d.%06d ==> %ld.%06d (rtt %u, ps %u)",
+       dpf(("CONG peer %lx/%u: timeout %d.%06d ==> %ld.%06d (rtt %u)",
               ntohl(peer->host), ntohs(peer->port), peer->timeout.sec, peer->timeout.usec,
-              newTO.sec, newTO.usec, peer->smRtt, peer->packetSize));
+              newTO.sec, newTO.usec, peer->smRtt));
 
        peer->timeout = newTO;
     }
@@ -6813,18 +6836,18 @@ rxi_ComputeRate(struct rx_peer *peer, struct rx_call *call,
     /* Now, convert to the number of full packets that could fit in a
      * reasonable fraction of that interval */
     minTime /= (peer->smRtt << 1);
+    minTime = MAX(minTime, rx_minPeerTimeout);
     xferSize = minTime;                /* (make a copy) */
 
     /* Now clamp the size to reasonable bounds. */
     if (minTime <= 1)
        minTime = 1;
-    else if (minTime > rx_Window)
-       minTime = rx_Window;
+    else if (minTime > rx_maxSendWindow)
+       minTime = rx_maxSendWindow;
 /*    if (minTime != peer->maxWindow) {
-      dpf(("CONG peer %lx/%u: windowsize %lu ==> %lu (to %lu.%06lu, rtt %u, ps %u)",
+      dpf(("CONG peer %lx/%u: windowsize %lu ==> %lu (to %lu.%06lu, rtt %u)",
             ntohl(peer->host), ntohs(peer->port), peer->maxWindow, minTime,
-            peer->timeout.sec, peer->timeout.usec, peer->smRtt,
-            peer->packetSize));
+            peer->timeout.sec, peer->timeout.usec, peer->smRtt));
       peer->maxWindow = minTime;
        elide... call->twind = minTime;
     }
@@ -6833,13 +6856,13 @@ rxi_ComputeRate(struct rx_peer *peer, struct rx_call *call,
     /* Cut back on the peer timeout if it had earlier grown unreasonably.
      * Discern this by calculating the timeout necessary for rx_Window
      * packets. */
-    if ((xferSize > rx_Window) && (peer->timeout.sec >= 3)) {
+    if ((xferSize > rx_maxSendWindow) && (peer->timeout.sec >= 3)) {
        /* calculate estimate for transmission interval in milliseconds */
-       minTime = rx_Window * peer->smRtt;
+       minTime = rx_maxSendWindow * peer->smRtt;
        if (minTime < 1000) {
-           dpf(("CONG peer %lx/%u: cut TO %d.%06d by 0.5 (rtt %u, ps %u)",
+           dpf(("CONG peer %lx/%u: cut TO %d.%06d by 0.5 (rtt %u)",
                 ntohl(peer->host), ntohs(peer->port), peer->timeout.sec,
-                peer->timeout.usec, peer->smRtt, peer->packetSize));
+                peer->timeout.usec, peer->smRtt));
 
            newTO.sec = 0;      /* cut back on timeout by half a second */
            newTO.usec = 500000;
@@ -6952,7 +6975,6 @@ void
 rx_PrintTheseStats(FILE * file, struct rx_statistics *s, int size,
                   afs_int32 freePackets, char version)
 {
-#ifdef RXDEBUG
     int i;
 
     if (size != sizeof(struct rx_statistics)) {
@@ -7027,9 +7049,6 @@ rx_PrintTheseStats(FILE * file, struct rx_statistics *s, int size,
 #if    !defined(AFS_PTHREAD_ENV) && !defined(AFS_USE_GETTIMEOFDAY)
     fprintf(file, "   %d clock updates\n", clock_nUpdates);
 #endif
-#else
-    fprintf(file, "ERROR: compiled without RXDEBUG\n");
-#endif
 }
 
 /* for backward compatibility */
@@ -7046,7 +7065,7 @@ void
 rx_PrintPeerStats(FILE * file, struct rx_peer *peer)
 {
     fprintf(file, "Peer %x.%d.  " "Burst size %d, " "burst wait %d.%06d.\n",
-           ntohl(peer->host), (int)peer->port, (int)peer->burstSize,
+           ntohl(peer->host), (int)ntohs(peer->port), (int)peer->burstSize,
            (int)peer->burstWait.sec, (int)peer->burstWait.usec);
 
     fprintf(file,
@@ -7074,7 +7093,7 @@ rx_PrintPeerStats(FILE * file, struct rx_peer *peer)
 #define UNLOCK_RX_DEBUG
 #endif /* AFS_PTHREAD_ENV */
 
-#ifdef RXDEBUG
+#if defined(RXDEBUG) || defined(MAKEDEBUGCALL)
 static int
 MakeDebugCall(osi_socket socket, afs_uint32 remoteAddr, afs_uint16 remotePort,
              u_char type, void *inputData, size_t inputLength,
@@ -7190,9 +7209,7 @@ rx_GetServerDebug(osi_socket socket, afs_uint32 remoteAddr,
                  afs_uint16 remotePort, struct rx_debugStats * stat,
                  afs_uint32 * supportedValues)
 {
-#ifndef RXDEBUG
-     afs_int32 rc = -1;
-#else
+#if defined(RXDEBUG) || defined(MAKEDEBUGCALL)
     afs_int32 rc = 0;
     struct rx_debugIn in;
 
@@ -7245,6 +7262,8 @@ rx_GetServerDebug(osi_socket socket, afs_uint32 remoteAddr,
         stat->nWaited = ntohl(stat->nWaited);
         stat->nPackets = ntohl(stat->nPackets);
     }
+#else
+    afs_int32 rc = -1;
 #endif
     return rc;
 }
@@ -7254,9 +7273,7 @@ rx_GetServerStats(osi_socket socket, afs_uint32 remoteAddr,
                  afs_uint16 remotePort, struct rx_statistics * stat,
                  afs_uint32 * supportedValues)
 {
-#ifndef RXDEBUG
-     afs_int32 rc = -1;
-#else
+#if defined(RXDEBUG) || defined(MAKEDEBUGCALL)
     afs_int32 rc = 0;
     struct rx_debugIn in;
     afs_int32 *lp = (afs_int32 *) stat;
@@ -7285,6 +7302,8 @@ rx_GetServerStats(osi_socket socket, afs_uint32 remoteAddr,
            *lp = ntohl(*lp);
        }
     }
+#else
+    afs_int32 rc = -1;
 #endif
     return rc;
 }
@@ -7294,7 +7313,7 @@ rx_GetServerVersion(osi_socket socket, afs_uint32 remoteAddr,
                    afs_uint16 remotePort, size_t version_length,
                    char *version)
 {
-#ifdef RXDEBUG
+#if defined(RXDEBUG) || defined(MAKEDEBUGCALL)
     char a[1] = { 0 };
     return MakeDebugCall(socket, remoteAddr, remotePort,
                         RX_PACKET_TYPE_VERSION, a, 1, version,
@@ -7311,9 +7330,7 @@ rx_GetServerConnections(osi_socket socket, afs_uint32 remoteAddr,
                        struct rx_debugConn * conn,
                        afs_uint32 * supportedValues)
 {
-#ifndef RXDEBUG
-    afs_int32 rc = -1;
-#else
+#if defined(RXDEBUG) || defined(MAKEDEBUGCALL)
     afs_int32 rc = 0;
     struct rx_debugIn in;
     int i;
@@ -7387,6 +7404,8 @@ rx_GetServerConnections(osi_socket socket, afs_uint32 remoteAddr,
        conn->epoch = ntohl(conn->epoch);
        conn->natMTU = ntohl(conn->natMTU);
     }
+#else
+    afs_int32 rc = -1;
 #endif
     return rc;
 }
@@ -7397,9 +7416,7 @@ rx_GetServerPeers(osi_socket socket, afs_uint32 remoteAddr,
                  afs_uint32 debugSupportedValues, struct rx_debugPeer * peer,
                  afs_uint32 * supportedValues)
 {
-#ifndef RXDEBUG
-    afs_int32 rc = -1;
-#else
+#if defined(RXDEBUG) || defined(MAKEDEBUGCALL)
     afs_int32 rc = 0;
     struct rx_debugIn in;
 
@@ -7452,6 +7469,8 @@ rx_GetServerPeers(osi_socket socket, afs_uint32 remoteAddr,
        peer->bytesReceived.high = ntohl(peer->bytesReceived.high);
        peer->bytesReceived.low = ntohl(peer->bytesReceived.low);
     }
+#else
+    afs_int32 rc = -1;
 #endif
     return rc;
 }
@@ -7873,7 +7892,7 @@ rxi_AddRpcStat(struct rx_queue *stats, afs_uint32 rxInterface,
            sizeof(rx_interface_stat_t) +
            totalFunc * sizeof(rx_function_entry_v1_t);
 
-       rpc_stat = (rx_interface_stat_p) rxi_Alloc(space);
+       rpc_stat = rxi_Alloc(space);
        if (rpc_stat == NULL) {
            rc = 1;
            goto fail;
@@ -8137,7 +8156,7 @@ rx_RetrieveProcessRPCStats(afs_uint32 callerVersion, afs_uint32 * myVersion,
 
     if (space > (size_t) 0) {
        *allocSize = space;
-       ptr = *stats = (afs_uint32 *) rxi_Alloc(space);
+       ptr = *stats = rxi_Alloc(space);
 
        if (ptr != NULL) {
            rx_interface_stat_p rpc_stat, nrpc_stat;
@@ -8236,7 +8255,7 @@ rx_RetrievePeerRPCStats(afs_uint32 callerVersion, afs_uint32 * myVersion,
 
     if (space > (size_t) 0) {
        *allocSize = space;
-       ptr = *stats = (afs_uint32 *) rxi_Alloc(space);
+       ptr = *stats = rxi_Alloc(space);
 
        if (ptr != NULL) {
            rx_interface_stat_p rpc_stat, nrpc_stat;