rx: Don't double check conn->call
authorSimon Wilkinson <sxw@your-file-system.com>
Thu, 25 Oct 2012 10:27:33 +0000 (11:27 +0100)
committerDerrick Brashear <shadow@your-file-system.com>
Mon, 29 Oct 2012 16:12:04 +0000 (09:12 -0700)
We currently have

call = conn->call[channel]
if (call) {
   ...
} else {
    call = conn->call[channel]
    if (call) {
       ...
    }
}

As we don't drop (or acquire) any locks between the first and the
second check of call, there's no way that the result can be different
from the first time we checked. So just get rid of the uneccessary
code, and reindent the following block to match.

Change-Id: If21a1d0af461fe0c0651e713dfb99a7c5f01cba4
Reviewed-on: http://gerrit.openafs.org/8290
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>

src/rx/rx.c

index e984eac..269d215 100644 (file)
@@ -3411,44 +3411,40 @@ rxi_ReceivePacket(struct rx_packet *np, osi_socket socket,
         currentCallNumber = conn->callNumber[channel];
         MUTEX_EXIT(&conn->conn_call_lock);
     } else if (type == RX_SERVER_CONNECTION) {  /* No call allocated */
-        call = conn->call[channel];
-        if (call) {
-            MUTEX_ENTER(&call->lock);
-            currentCallNumber = conn->callNumber[channel];
-            MUTEX_EXIT(&conn->conn_call_lock);
-        } else {
-            call = rxi_NewCall(conn, channel);  /* returns locked call */
-            *call->callNumber = currentCallNumber = np->header.callNumber;
-            MUTEX_EXIT(&conn->conn_call_lock);
+       call = rxi_NewCall(conn, channel);  /* returns locked call */
+       *call->callNumber = currentCallNumber = np->header.callNumber;
+       MUTEX_EXIT(&conn->conn_call_lock);
 #ifdef RXDEBUG
-            if (np->header.callNumber == 0)
-                dpf(("RecPacket call 0 %d %s: %x.%u.%u.%u.%u.%u.%u flags %d, packet %"AFS_PTR_FMT" len %d\n",
-                     np->header.serial, rx_packetTypes[np->header.type - 1], ntohl(conn->peer->host), ntohs(conn->peer->port),
-                     np->header.serial, np->header.epoch, np->header.cid, np->header.callNumber, np->header.seq,
-                     np->header.flags, np, np->length));
+       if (np->header.callNumber == 0)
+           dpf(("RecPacket call 0 %d %s: %x.%u.%u.%u.%u.%u.%u flags %d, "
+                "packet %"AFS_PTR_FMT" len %d\n",
+                np->header.serial, rx_packetTypes[np->header.type - 1], 
+                ntohl(conn->peer->host), ntohs(conn->peer->port),
+                np->header.serial, np->header.epoch, np->header.cid, 
+                np->header.callNumber, np->header.seq,
+                np->header.flags, np, np->length));
 #endif
-            call->state = RX_STATE_PRECALL;
-            clock_GetTime(&call->queueTime);
-            call->app.bytesSent = 0;
-            call->app.bytesRcvd = 0;
-            /*
-             * If the number of queued calls exceeds the overload
-             * threshold then abort this call.
-             */
-            if ((rx_BusyThreshold > 0) &&
-                (rx_atomic_read(&rx_nWaiting) > rx_BusyThreshold)) {
-                struct rx_packet *tp;
+       call->state = RX_STATE_PRECALL;
+       clock_GetTime(&call->queueTime);
+       call->app.bytesSent = 0;
+       call->app.bytesRcvd = 0;
+       /*
+        * If the number of queued calls exceeds the overload
+        * threshold then abort this call.
+        */
+       if ((rx_BusyThreshold > 0) &&
+           (rx_atomic_read(&rx_nWaiting) > rx_BusyThreshold)) {
+           struct rx_packet *tp;
 
-                rxi_CallError(call, rx_BusyError);
-                tp = rxi_SendCallAbort(call, np, 1, 0);
-                MUTEX_EXIT(&call->lock);
-               putConnection(conn);
-                if (rx_stats_active)
-                    rx_atomic_inc(&rx_stats.nBusies);
-                return tp;
-            }
-            rxi_KeepAliveOn(call);
+           rxi_CallError(call, rx_BusyError);
+           tp = rxi_SendCallAbort(call, np, 1, 0);
+           MUTEX_EXIT(&call->lock);
+           putConnection(conn);
+           if (rx_stats_active)
+               rx_atomic_inc(&rx_stats.nBusies);
+           return tp;
         }
+       rxi_KeepAliveOn(call);
     } else {    /* RX_CLIENT_CONNECTION and No call allocated */
         /* This packet can't be for this call. If the new call address is
          * 0 then no call is running on this channel. If there is a call