rx: Remove surplus call to FindPeer
[openafs.git] / src / rx / rx_packet.c
index 0f0513d..94e7482 100644 (file)
@@ -66,6 +66,7 @@
 #include "rx_internal.h"
 #include "rx_stats.h"
 
+#include "rx_peer.h"
 #include "rx_conn.h"
 #include "rx_call.h"
 
@@ -85,13 +86,21 @@ static int AllocPacketBufs(int class, int num_pkts, struct rx_queue *q);
 static void rxi_SendDebugPacket(struct rx_packet *apacket, osi_socket asocket,
                                afs_uint32 ahost, short aport,
                                afs_int32 istack);
+static struct rx_packet *rxi_AllocPacketNoLock(int class);
+
+#ifndef KERNEL
+static void rxi_MorePacketsNoLock(int apackets);
+#endif
 
 #ifdef RX_ENABLE_TSFPQ
-static int
-rxi_FreeDataBufsTSFPQ(struct rx_packet *p, afs_uint32 first, int flush_global);
+static int rxi_FreeDataBufsTSFPQ(struct rx_packet *p, afs_uint32 first,
+                                int flush_global);
+static void rxi_AdjustLocalPacketsTSFPQ(int num_keep_local,
+                                       int allow_overcommit);
 #else
-static int rxi_FreeDataBufsToQueue(struct rx_packet *p,
-                                  afs_uint32 first,
+static void rxi_FreePacketNoLock(struct rx_packet *p);
+static int rxi_FreeDataBufsNoLock(struct rx_packet *p, afs_uint32 first);
+static int rxi_FreeDataBufsToQueue(struct rx_packet *p, afs_uint32 first,
                                   struct rx_queue * q);
 #endif
 
@@ -665,7 +674,7 @@ rxi_MorePacketsTSFPQ(int apackets, int flush_global, int num_keep_local)
 
 #ifndef KERNEL
 /* Add more packet buffers */
-void
+static void
 rxi_MorePacketsNoLock(int apackets)
 {
 #ifdef RX_ENABLE_TSFPQ
@@ -731,7 +740,7 @@ rxi_FreeAllPackets(void)
 }
 
 #ifdef RX_ENABLE_TSFPQ
-void
+static void
 rxi_AdjustLocalPacketsTSFPQ(int num_keep_local, int allow_overcommit)
 {
     struct rx_ts_info_t * rx_ts_info;
@@ -793,21 +802,8 @@ rx_CheckPackets(void)
    */
 
 /* Actually free the packet p. */
-#ifdef RX_ENABLE_TSFPQ
-void
-rxi_FreePacketNoLock(struct rx_packet *p)
-{
-    struct rx_ts_info_t * rx_ts_info;
-    dpf(("Free %"AFS_PTR_FMT"\n", p));
-
-    RX_TS_INFO_GET(rx_ts_info);
-    RX_TS_FPQ_CHECKIN(rx_ts_info,p);
-    if (rx_ts_info->_FPQ.len > rx_TSFPQLocalMax) {
-        RX_TS_FPQ_LTOG(rx_ts_info);
-    }
-}
-#else /* RX_ENABLE_TSFPQ */
-void
+#ifndef RX_ENABLE_TSFPQ
+static void
 rxi_FreePacketNoLock(struct rx_packet *p)
 {
     dpf(("Free %"AFS_PTR_FMT"\n", p));
@@ -819,7 +815,7 @@ rxi_FreePacketNoLock(struct rx_packet *p)
 #endif /* RX_ENABLE_TSFPQ */
 
 #ifdef RX_ENABLE_TSFPQ
-void
+static void
 rxi_FreePacketTSFPQ(struct rx_packet *p, int flush_global)
 {
     struct rx_ts_info_t * rx_ts_info;
@@ -874,7 +870,6 @@ rxi_FreeDataBufsToQueue(struct rx_packet *p, afs_uint32 first, struct rx_queue *
 
     return count;
 }
-#endif
 
 /*
  * free packet continuation buffers into the global free packet pool
@@ -885,7 +880,7 @@ rxi_FreeDataBufsToQueue(struct rx_packet *p, afs_uint32 first, struct rx_queue *
  * returns:
  *   zero always
  */
-int
+static int
 rxi_FreeDataBufsNoLock(struct rx_packet *p, afs_uint32 first)
 {
     struct iovec *iov;
@@ -902,7 +897,8 @@ rxi_FreeDataBufsNoLock(struct rx_packet *p, afs_uint32 first)
     return 0;
 }
 
-#ifdef RX_ENABLE_TSFPQ
+#else
+
 /*
  * free packet continuation buffers into the thread-local free pool
  *
@@ -1096,7 +1092,7 @@ rxi_FreePacket(struct rx_packet *p)
  * The header is absolutely necessary, besides, this is the way the
  * length field is usually used */
 #ifdef RX_ENABLE_TSFPQ
-struct rx_packet *
+static struct rx_packet *
 rxi_AllocPacketNoLock(int class)
 {
     struct rx_packet *p;
@@ -1159,7 +1155,7 @@ rxi_AllocPacketNoLock(int class)
     return p;
 }
 #else /* RX_ENABLE_TSFPQ */
-struct rx_packet *
+static struct rx_packet *
 rxi_AllocPacketNoLock(int class)
 {
     struct rx_packet *p;
@@ -1219,7 +1215,7 @@ rxi_AllocPacketNoLock(int class)
 #endif /* RX_ENABLE_TSFPQ */
 
 #ifdef RX_ENABLE_TSFPQ
-struct rx_packet *
+static struct rx_packet *
 rxi_AllocPacketTSFPQ(int class, int pull_global)
 {
     struct rx_packet *p;
@@ -1407,7 +1403,7 @@ rxi_ReadPacket(osi_socket socket, struct rx_packet *p, afs_uint32 * host,
               u_short * port)
 {
     struct sockaddr_in from;
-    unsigned int nbytes;
+    int nbytes;
     afs_int32 rlen;
     afs_uint32 tlen, savelen;
     struct msghdr msg;
@@ -1446,7 +1442,7 @@ rxi_ReadPacket(osi_socket socket, struct rx_packet *p, afs_uint32 * host,
     p->wirevec[p->niovecs - 1].iov_len = savelen;
 
     p->length = (u_short)(nbytes - RX_HEADER_SIZE);
-    if ((nbytes > tlen) || (p->length & 0x8000)) {     /* Bogus packet */
+    if (nbytes < 0 || (nbytes > tlen) || (p->length & 0x8000)) { /* Bogus packet */
        if (nbytes < 0 && errno == EWOULDBLOCK) {
             if (rx_stats_active)
                 rx_atomic_inc(&rx_stats.noPacketOnRead);
@@ -1484,32 +1480,10 @@ rxi_ReadPacket(osi_socket socket, struct rx_packet *p, afs_uint32 * host,
 
        *host = from.sin_addr.s_addr;
        *port = from.sin_port;
-       if (p->header.type > 0 && p->header.type < RX_N_PACKET_TYPES) {
-            if (rx_stats_active) {
-                struct rx_peer *peer;
-                rx_atomic_inc(&rx_stats.packetsRead[p->header.type - 1]);
-                /*
-                 * Try to look up this peer structure.  If it doesn't exist,
-                 * don't create a new one -
-                 * we don't keep count of the bytes sent/received if a peer
-                 * structure doesn't already exist.
-                 *
-                 * The peer/connection cleanup code assumes that there is 1 peer
-                 * per connection.  If we actually created a peer structure here
-                 * and this packet was an rxdebug packet, the peer structure would
-                 * never be cleaned up.
-                 */
-                peer = rxi_FindPeer(*host, *port, 0, 0);
-                /* Since this may not be associated with a connection,
-                 * it may have no refCount, meaning we could race with
-                 * ReapConnections
-                 */
-                if (peer && (peer->refCount > 0)) {
-                    MUTEX_ENTER(&peer->peer_lock);
-                    hadd32(peer->bytesReceived, p->length);
-                    MUTEX_EXIT(&peer->peer_lock);
-                }
-            }
+       if (rx_stats_active
+           && p->header.type > 0 && p->header.type < RX_N_PACKET_TYPES) {
+
+               rx_atomic_inc(&rx_stats.packetsRead[p->header.type - 1]);
        }
 
 #ifdef RX_TRIMDATABUFS
@@ -1979,16 +1953,14 @@ rxi_ReceiveDebugPacket(struct rx_packet *ap, osi_socket asocket,
                        tpeer.ifMTU = htons(tp->ifMTU);
                        tpeer.idleWhen = htonl(tp->idleWhen);
                        tpeer.refCount = htons(tp->refCount);
-                       tpeer.burstSize = tp->burstSize;
-                       tpeer.burst = tp->burst;
-                       tpeer.burstWait.sec = htonl(tp->burstWait.sec);
-                       tpeer.burstWait.usec = htonl(tp->burstWait.usec);
+                       tpeer.burstSize = 0;
+                       tpeer.burst = 0;
+                       tpeer.burstWait.sec = 0;
+                       tpeer.burstWait.usec = 0;
                        tpeer.rtt = htonl(tp->rtt);
                        tpeer.rtt_dev = htonl(tp->rtt_dev);
                        tpeer.nSent = htonl(tp->nSent);
                        tpeer.reSends = htonl(tp->reSends);
-                       tpeer.inPacketSkew = htonl(tp->inPacketSkew);
-                       tpeer.outPacketSkew = htonl(tp->outPacketSkew);
                        tpeer.natMTU = htons(tp->natMTU);
                        tpeer.maxMTU = htons(tp->maxMTU);
                        tpeer.maxDgramPackets = htons(tp->maxDgramPackets);
@@ -2138,7 +2110,7 @@ rxi_SendDebugPacket(struct rx_packet *apacket, osi_socket asocket,
        afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
                   "before osi_NetSend()");
        AFS_GUNLOCK();
-    } else
+    }
 #else
     if (waslocked)
        AFS_GUNLOCK();
@@ -2155,7 +2127,7 @@ rxi_SendDebugPacket(struct rx_packet *apacket, osi_socket asocket,
                   "after osi_NetSend()");
        if (!waslocked)
            AFS_GUNLOCK();
-    } else
+    }
 #else
     if (waslocked)
        AFS_GLOCK();
@@ -2265,7 +2237,7 @@ rxi_SendPacket(struct rx_call *call, struct rx_connection *conn,
            afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
                       "before osi_NetSend()");
            AFS_GUNLOCK();
-       } else
+       }
 #else
        if (waslocked)
            AFS_GUNLOCK();
@@ -2305,7 +2277,7 @@ rxi_SendPacket(struct rx_call *call, struct rx_connection *conn,
                       "after osi_NetSend()");
            if (!waslocked)
                AFS_GUNLOCK();
-       } else
+       }
 #else
        if (waslocked)
            AFS_GLOCK();