static unsigned int rxi_rpc_process_stat_cnt;
-/*
- * rxi_busyChannelError is a boolean. It indicates whether or not RX_CALL_BUSY
- * errors should be reported to the application when a call channel appears busy
- * (inferred from the receipt of RX_PACKET_TYPE_BUSY packets on the channel),
- * and there are other call channels in the connection that are not busy.
- * If 0, we do not return errors upon receiving busy packets; we just keep
- * trying on the same call channel until we hit a timeout.
- */
-static afs_int32 rxi_busyChannelError = 0;
-
rx_atomic_t rx_nWaiting = RX_ATOMIC_INIT(0);
rx_atomic_t rx_nWaited = RX_ATOMIC_INIT(0);
MUTEX_INIT(&rx_rpc_stats, "rx_rpc_stats", MUTEX_DEFAULT, 0);
MUTEX_INIT(&rx_freePktQ_lock, "rx_freePktQ_lock", MUTEX_DEFAULT, 0);
+ MUTEX_INIT(&rx_mallocedPktQ_lock, "rx_mallocedPktQ_lock", MUTEX_DEFAULT,
+ 0);
+
#ifdef RX_ENABLE_LOCKS
#ifdef RX_LOCKS_DB
rxdb_init();
* by the kernel. Whether this will ever overlap anything in
* /etc/services is anybody's guess... Returns 0 on success, -1 on
* error. */
-#ifndef AFS_NT40_ENV
+#if !(defined(AFS_NT40_ENV) || defined(RXK_UPCALL_ENV))
static
#endif
rx_atomic_t rxinit_status = RX_ATOMIC_INIT(1);
MUTEX_INIT(&rx_connHashTable_lock, "rx_connHashTable_lock", MUTEX_DEFAULT,
0);
MUTEX_INIT(&rx_serverPool_lock, "rx_serverPool_lock", MUTEX_DEFAULT, 0);
+ MUTEX_INIT(&rx_mallocedPktQ_lock, "rx_mallocedPktQ_lock", MUTEX_DEFAULT,
+ 0);
+
#if defined(AFS_HPUX110_ENV)
if (!uniprocessor)
rx_sleepLock = alloc_spinlock(LAST_HELD_ORDER - 10, "rx_sleepLock");
opr_queue_Init(&rx_freePacketQueue);
rxi_NeedMorePackets = FALSE;
rx_nPackets = 0; /* rx_nPackets is managed by rxi_MorePackets* */
+ opr_queue_Init(&rx_mallocedPacketQueue);
/* enforce a minimum number of allocated packets */
if (rx_extraPackets < rxi_nSendFrags * rx_maxSendWindow)
{
struct clock now, retryTime;
+ MUTEX_ASSERT(&call->lock);
clock_GetTime(&now);
retryTime = now;
static_inline void
rxi_rto_cancel(struct rx_call *call)
{
- if (call->resendEvent != NULL) {
- rxevent_Cancel(&call->resendEvent);
+ MUTEX_ASSERT(&call->lock);
+ if (rxevent_Cancel(&call->resendEvent))
CALL_RELE(call, RX_CALL_REFCOUNT_RESEND);
- }
}
/*!
}
/**
- * Enables or disables the busy call channel error (RX_CALL_BUSY).
- *
- * @param[in] onoff Non-zero to enable busy call channel errors.
- *
- * @pre Neither rx_Init nor rx_InitHost have been called yet
- */
-void
-rx_SetBusyChannelError(afs_int32 onoff)
-{
- osi_Assert(rx_atomic_test_bit(&rxinit_status, 0));
- rxi_busyChannelError = onoff ? 1 : 0;
-}
-
-/**
* Set a delayed ack event on the specified call for the given time
*
* @param[in] call - the call on which to set the event
{
struct clock now, when;
+ MUTEX_ASSERT(&call->lock);
clock_GetTime(&now);
when = now;
clock_Add(&when, offset);
- if (call->delayedAckEvent && clock_Gt(&call->delayedAckTime, &when)) {
- /* The event we're cancelling already has a reference, so we don't
- * need a new one */
- rxevent_Cancel(&call->delayedAckEvent);
+ if (clock_Gt(&call->delayedAckTime, &when) &&
+ rxevent_Cancel(&call->delayedAckEvent)) {
+ /* We successfully cancelled an event too far in the future to install
+ * our new one; we can reuse the reference on the call. */
call->delayedAckEvent = rxevent_Post(&when, &now, rxi_SendDelayedAck,
call, NULL, 0);
call->delayedAckTime = when;
- } else if (!call->delayedAckEvent) {
+ } else if (call->delayedAckEvent == NULL) {
CALL_HOLD(call, RX_CALL_REFCOUNT_DELAY);
call->delayedAckEvent = rxevent_Post(&when, &now,
rxi_SendDelayedAck,
void
rxi_CancelDelayedAckEvent(struct rx_call *call)
{
- if (call->delayedAckEvent) {
- rxevent_Cancel(&call->delayedAckEvent);
+ MUTEX_ASSERT(&call->lock);
+ /* Only drop the ref if we cancelled it before it could run. */
+ if (rxevent_Cancel(&call->delayedAckEvent))
CALL_RELE(call, RX_CALL_REFCOUNT_DELAY);
- }
}
/* called with unincremented nRequestsRunning to see if it is OK to start
{
struct rx_connection **conn_ptr;
int havecalls = 0;
- struct rx_packet *packet;
int i;
SPLVAR;
if (conn->refCount > 0)
conn->refCount--;
else {
+#ifdef RX_REFCOUNT_CHECK
+ osi_Assert(conn->refCount == 0);
+#endif
if (rx_stats_active) {
MUTEX_ENTER(&rx_stats_mutex);
rxi_lowConnRefCount++;
if ((conn->type == RX_CLIENT_CONNECTION)
&& (conn->flags & (RX_CONN_MAKECALL_WAITING|RX_CONN_MAKECALL_ACTIVE))) {
conn->flags |= RX_CONN_DESTROY_ME;
+ MUTEX_EXIT(&rx_refcnt_mutex);
MUTEX_EXIT(&conn->conn_data_lock);
USERPRI;
return;
return;
}
- if (conn->natKeepAliveEvent) {
- rxi_NatKeepAliveOff(conn);
- }
-
- if (conn->delayedAbortEvent) {
- rxevent_Cancel(&conn->delayedAbortEvent);
- packet = rxi_AllocPacket(RX_PACKET_CLASS_SPECIAL);
- if (packet) {
- MUTEX_ENTER(&conn->conn_data_lock);
- rxi_SendConnectionAbort(conn, packet, 0, 1);
- MUTEX_EXIT(&conn->conn_data_lock);
- rxi_FreePacket(packet);
- }
- }
-
/* Remove from connection hash table before proceeding */
conn_ptr =
&rx_connHashTable[CONN_HASH
rxLastConn = 0;
/* Make sure the connection is completely reset before deleting it. */
- /* get rid of pending events that could zap us later */
- rxevent_Cancel(&conn->challengeEvent);
- rxevent_Cancel(&conn->checkReachEvent);
- rxevent_Cancel(&conn->natKeepAliveEvent);
+ /*
+ * Pending events hold a refcount, so we can't get here if they are
+ * non-NULL. */
+ osi_Assert(conn->challengeEvent == NULL);
+ osi_Assert(conn->delayedAbortEvent == NULL);
+ osi_Assert(conn->natKeepAliveEvent == NULL);
+ osi_Assert(conn->checkReachEvent == NULL);
/* Add the connection to the list of destroyed connections that
* need to be cleaned up. This is necessary to avoid deadlocks
}
if (i < RX_MAXCALLS) {
conn->lastBusy[i] = 0;
- call->flags &= ~RX_CALL_PEER_BUSY;
break;
}
if (!wait)
MUTEX_ENTER(&call->lock);
}
if (call->app.mode == RX_MODE_SENDING) {
- MUTEX_EXIT(&call->lock);
- rxi_FlushWrite(call);
- MUTEX_ENTER(&call->lock);
+ rxi_FlushWriteLocked(call);
}
rxi_calltrace(RX_CALL_END, call);
/* Call goes to hold state until reply packets are acknowledged */
MUTEX_ENTER(&conn->conn_call_lock);
MUTEX_ENTER(&call->lock);
- if (!(call->flags & RX_CALL_PEER_BUSY)) {
+ if (!call->error) {
+ /* While there are some circumstances where a call with an error is
+ * obviously not on a "busy" channel, be conservative (clearing
+ * lastBusy is just best-effort to possibly speed up rx_NewCall).
+ * The call channel is definitely not busy if we just successfully
+ * completed a call on it. */
conn->lastBusy[call->channel] = 0;
+
+ } else if (call->error == RX_CALL_TIMEOUT) {
+ /* The call is still probably running on the server side, so try to
+ * avoid this call channel in the future. */
+ conn->lastBusy[call->channel] = clock_Sec();
}
MUTEX_ENTER(&conn->conn_data_lock);
return conn;
}
-/**
- * Timeout a call on a busy call channel if appropriate.
- *
- * @param[in] call The busy call.
- *
- * @pre 'call' is marked as busy (namely,
- * call->conn->lastBusy[call->channel] != 0)
- *
- * @pre call->lock is held
- * @pre rxi_busyChannelError is nonzero
- *
- * @note call->lock is dropped and reacquired
- */
-static void
-rxi_CheckBusy(struct rx_call *call)
-{
- struct rx_connection *conn = call->conn;
- int channel = call->channel;
- int freechannel = 0;
- int i;
-
- MUTEX_EXIT(&call->lock);
-
- MUTEX_ENTER(&conn->conn_call_lock);
-
- /* Are there any other call slots on this conn that we should try? Look for
- * slots that are empty and are either non-busy, or were marked as busy
- * longer than conn->secondsUntilDead seconds before this call started. */
-
- for (i = 0; i < RX_MAXCALLS && !freechannel; i++) {
- if (i == channel) {
- /* only look at channels that aren't us */
- continue;
- }
-
- if (conn->lastBusy[i]) {
- /* if this channel looked busy too recently, don't look at it */
- if (conn->lastBusy[i] >= call->startTime.sec) {
- continue;
- }
- if (call->startTime.sec - conn->lastBusy[i] < conn->secondsUntilDead) {
- continue;
- }
- }
-
- if (conn->call[i]) {
- struct rx_call *tcall = conn->call[i];
- MUTEX_ENTER(&tcall->lock);
- if (tcall->state == RX_STATE_DALLY) {
- freechannel = 1;
- }
- MUTEX_EXIT(&tcall->lock);
- } else {
- freechannel = 1;
- }
- }
-
- MUTEX_ENTER(&call->lock);
-
- /* Since the call->lock has been released it is possible that the call may
- * no longer be busy (the call channel cannot have been reallocated as we
- * haven't dropped the conn_call_lock) Therefore, we must confirm
- * that the call state has not changed when deciding whether or not to
- * force this application thread to retry by forcing a Timeout error. */
-
- if (freechannel && (call->flags & RX_CALL_PEER_BUSY)) {
- /* Since 'freechannel' is set, there exists another channel in this
- * rx_conn that the application thread might be able to use. We know
- * that we have the correct call since callNumber is unchanged, and we
- * know that the call is still busy. So, set the call error state to
- * rxi_busyChannelError so the application can retry the request,
- * presumably on a less-busy call channel. */
-
- rxi_CallError(call, RX_CALL_BUSY);
- }
- MUTEX_EXIT(&conn->conn_call_lock);
-}
-
/*!
* Abort the call if the server is over the busy threshold. This
* can be used without requiring a call structure be initialised,
channel = np->header.cid & RX_CHANNELMASK;
MUTEX_ENTER(&conn->conn_call_lock);
call = conn->call[channel];
+ if (np->header.type == RX_PACKET_TYPE_BUSY) {
+ conn->lastBusy[channel] = clock_Sec();
+ }
if (!call || conn->callNumber[channel] != np->header.callNumber) {
MUTEX_EXIT(&conn->conn_call_lock);
if (rx_stats_active)
putConnection(conn);
return np; /* xmitting; drop packet */
}
- case RX_PACKET_TYPE_BUSY: {
- struct clock busyTime;
- clock_NewTime();
- clock_GetTime(&busyTime);
-
- MUTEX_EXIT(&call->lock);
-
- MUTEX_ENTER(&conn->conn_call_lock);
- MUTEX_ENTER(&call->lock);
- conn->lastBusy[call->channel] = busyTime.sec;
- call->flags |= RX_CALL_PEER_BUSY;
- MUTEX_EXIT(&call->lock);
- MUTEX_EXIT(&conn->conn_call_lock);
-
- putConnection(conn);
- return np;
- }
+ case RX_PACKET_TYPE_BUSY:
+ /* Mostly ignore BUSY packets. We will update lastReceiveTime below,
+ * so we don't think the endpoint is completely dead, but otherwise
+ * just act as if we never saw anything. If all we get are BUSY packets
+ * back, then we will eventually error out with RX_CALL_TIMEOUT if the
+ * connection is configured with idle/hard timeouts. */
+ break;
case RX_PACKET_TYPE_ACKALL:
/* All packets acknowledged, so we can drop all packets previously
* the packet will be delivered to the user before any get time is required
* (if not, then the time won't actually be re-evaluated here). */
call->lastReceiveTime = clock_Sec();
- /* we've received a legit packet, so the channel is not busy */
- call->flags &= ~RX_CALL_PEER_BUSY;
MUTEX_EXIT(&call->lock);
putConnection(conn);
return np;
}
}
+/*
+ * Event handler function for connection-specific events for checking
+ * reachability. Also called directly from main code with |event| == NULL
+ * in order to trigger the initial reachability check.
+ *
+ * When |event| == NULL, must be called with the connection data lock held,
+ * but returns with the lock unlocked.
+ */
static void
rxi_CheckReachEvent(struct rxevent *event, void *arg1, void *arg2, int dummy)
{
struct clock when, now;
int i, waiting;
- MUTEX_ENTER(&conn->conn_data_lock);
+ if (event != NULL)
+ MUTEX_ENTER(&conn->conn_data_lock);
+ else
+ MUTEX_ASSERT(&conn->conn_data_lock);
- if (event)
+ if (event != NULL && event == conn->checkReachEvent)
rxevent_Put(&conn->checkReachEvent);
-
waiting = conn->flags & RX_CONN_ATTACHWAIT;
- if (event) {
- putConnection(conn);
- }
MUTEX_EXIT(&conn->conn_data_lock);
if (waiting) {
when.sec += RX_CHECKREACH_TIMEOUT;
MUTEX_ENTER(&conn->conn_data_lock);
if (!conn->checkReachEvent) {
- MUTEX_ENTER(&rx_refcnt_mutex);
- conn->refCount++;
- MUTEX_EXIT(&rx_refcnt_mutex);
+ rx_GetConnection(conn);
conn->checkReachEvent = rxevent_Post(&when, &now,
rxi_CheckReachEvent, conn,
NULL, 0);
MUTEX_EXIT(&conn->conn_data_lock);
}
}
+ /* If fired as an event handler, drop our refcount on the connection. */
+ if (event != NULL)
+ putConnection(conn);
}
static int
return 1;
}
conn->flags |= RX_CONN_ATTACHWAIT;
- MUTEX_EXIT(&conn->conn_data_lock);
- if (!conn->checkReachEvent)
+ if (conn->checkReachEvent == NULL) {
+ /* rxi_CheckReachEvent(NULL, ...) will drop the lock. */
rxi_CheckReachEvent(NULL, conn, call, 0);
+ } else {
+ MUTEX_EXIT(&conn->conn_data_lock);
+ }
return 1;
}
* queue - they're not addressed by the contents of this ACK packet.
*/
- /* If the window has been extended by this acknowledge packet,
- * then wakeup a sender waiting in alloc for window space, or try
- * sending packets now, if he's been sitting on packets due to
- * lack of window space */
- if (call->tnext < (call->tfirst + call->twind)) {
-#ifdef RX_ENABLE_LOCKS
- CV_SIGNAL(&call->cv_twind);
-#else
- if (call->flags & RX_CALL_WAIT_WINDOW_ALLOC) {
- call->flags &= ~RX_CALL_WAIT_WINDOW_ALLOC;
- osi_rxWakeup(&call->twind);
- }
-#endif
- if (call->flags & RX_CALL_WAIT_WINDOW_SEND) {
- call->flags &= ~RX_CALL_WAIT_WINDOW_SEND;
- }
- }
-
/* if the ack packet has a receivelen field hanging off it,
* update our state */
if (np->length >= rx_AckDataSize(ap->nAcks) + 2 * sizeof(afs_int32)) {
call->MTU = OLD_MAX_PACKET_SIZE;
}
+ /* If the window has been extended by this acknowledge packet,
+ * then wakeup a sender waiting in alloc for window space, or try
+ * sending packets now, if he's been sitting on packets due to
+ * lack of window space */
+ if (call->tnext < (call->tfirst + call->twind)) {
+#ifdef RX_ENABLE_LOCKS
+ CV_SIGNAL(&call->cv_twind);
+#else
+ if (call->flags & RX_CALL_WAIT_WINDOW_ALLOC) {
+ call->flags &= ~RX_CALL_WAIT_WINDOW_ALLOC;
+ osi_rxWakeup(&call->twind);
+ }
+#endif
+ if (call->flags & RX_CALL_WAIT_WINDOW_SEND) {
+ call->flags &= ~RX_CALL_WAIT_WINDOW_SEND;
+ }
+ }
+
if (nNacked) {
/*
* Calculate how many datagrams were successfully received after
rxi_SendConnectionAbortLater(struct rx_connection *conn, int msec)
{
struct clock when, now;
+
+ MUTEX_ASSERT(&conn->conn_data_lock);
if (!conn->error) {
return;
}
clock_GetTime(&now);
when = now;
clock_Addmsec(&when, msec);
+ rx_GetConnection(conn);
conn->delayedAbortEvent =
rxevent_Post(&when, &now, rxi_SendDelayedConnAbort, conn, NULL, 0);
}
call->flags |= RX_CALL_ACKALL_SENT;
}
+/*
+ * Event handler for per-call delayed acks.
+ * Also called synchronously, with |event| == NULL, to send a "delayed" ack
+ * immediately.
+ */
static void
rxi_SendDelayedAck(struct rxevent *event, void *arg1, void *unused1,
int unused2)
MUTEX_ENTER(&call->lock);
if (event == call->delayedAckEvent)
rxevent_Put(&call->delayedAckEvent);
- CALL_RELE(call, RX_CALL_REFCOUNT_DELAY);
}
(void)rxi_SendAck(call, 0, 0, RX_ACK_DELAY, 0);
if (event)
rxevent_Put(&call->delayedAckEvent);
(void)rxi_SendAck(call, 0, 0, RX_ACK_DELAY, 0);
#endif /* RX_ENABLE_LOCKS */
+ /* Release the call reference for the event that fired. */
+ if (event)
+ CALL_RELE(call, RX_CALL_REFCOUNT_DELAY);
}
#ifdef RX_ENABLE_LOCKS
rxi_SendCallAbort(struct rx_call *call, struct rx_packet *packet,
int istack, int force)
{
- afs_int32 error, cerror;
+ afs_int32 error;
struct clock when, now;
if (!call->error)
return packet;
- switch (call->error) {
- case RX_CALL_BUSY:
- cerror = RX_CALL_TIMEOUT;
- break;
- default:
- cerror = call->error;
- }
-
/* Clients should never delay abort messages */
if (rx_IsClientConn(call->conn))
force = 1;
- if (call->abortCode != cerror) {
- call->abortCode = cerror;
+ if (call->abortCode != call->error) {
+ call->abortCode = call->error;
call->abortCount = 0;
}
if (force || rxi_callAbortThreshhold == 0
|| call->abortCount < rxi_callAbortThreshhold) {
rxi_CancelDelayedAbortEvent(call);
- error = htonl(cerror);
+ error = htonl(call->error);
call->abortCount++;
packet =
rxi_SendSpecial(call, call->conn, packet, RX_PACKET_TYPE_ABORT,
static void
rxi_CancelDelayedAbortEvent(struct rx_call *call)
{
- if (call->delayedAbortEvent) {
- rxevent_Cancel(&call->delayedAbortEvent);
+ MUTEX_ASSERT(&call->lock);
+ if (rxevent_Cancel(&call->delayedAbortEvent))
CALL_RELE(call, RX_CALL_REFCOUNT_ABORT);
- }
}
/* Send an abort packet for the specified connection. Packet is an
if (force || rxi_connAbortThreshhold == 0
|| conn->abortCount < rxi_connAbortThreshhold) {
- rxevent_Cancel(&conn->delayedAbortEvent);
+ if (rxevent_Cancel(&conn->delayedAbortEvent))
+ putConnection(conn);
error = htonl(conn->error);
conn->abortCount++;
MUTEX_EXIT(&conn->conn_data_lock);
dpf(("rxi_ConnectionError conn %"AFS_PTR_FMT" error %d\n", conn, error));
MUTEX_ENTER(&conn->conn_data_lock);
- rxevent_Cancel(&conn->challengeEvent);
- rxevent_Cancel(&conn->natKeepAliveEvent);
- if (conn->checkReachEvent) {
- rxevent_Cancel(&conn->checkReachEvent);
+ if (rxevent_Cancel(&conn->challengeEvent))
+ putConnection(conn);
+ if (rxevent_Cancel(&conn->natKeepAliveEvent))
+ putConnection(conn);
+ if (rxevent_Cancel(&conn->checkReachEvent)) {
conn->flags &= ~(RX_CONN_ATTACHWAIT|RX_CONN_NAT_PING);
putConnection(conn);
}
}
call->flags = 0;
- if (!newcall && (flags & RX_CALL_PEER_BUSY)) {
- /* The call channel is still busy; resetting the call doesn't change
- * that. However, if 'newcall' is set, we are processing a call
- * structure that has either been recycled from the free list, or has
- * been newly allocated. So, RX_CALL_PEER_BUSY is not relevant if
- * 'newcall' is set, since it describes a completely different call
- * channel which we do not care about. */
- call->flags |= RX_CALL_PEER_BUSY;
- }
-
rxi_ClearReceiveQueue(call);
/* why init the queue if you just emptied it? queue_Init(&call->rq); */
int reason; Reason an acknowledge was prompted
*/
+#define RX_ZEROS 1024
+static char rx_zeros[RX_ZEROS];
+
struct rx_packet *
rxi_SendAck(struct rx_call *call,
struct rx_packet *optionalPacket, int serial, int reason,
ap->nAcks = offset;
p->length = rx_AckDataSize(offset) + 4 * sizeof(afs_int32);
+ /* Must zero the 3 octets that rx_AckDataSize skips at the end of the
+ * ACK list.
+ */
+ rx_packetwrite(p, rx_AckDataSize(offset) - 3, 3, rx_zeros);
+
/* these are new for AFS 3.3 */
templ = rxi_AdjustMaxMTU(call->conn->peer->ifMTU, rx_maxReceiveSize);
templ = htonl(templ);
rx_packetwrite(p, rx_AckDataSize(offset) + 3 * sizeof(afs_int32),
sizeof(afs_int32), &templ);
+ p->length = rx_AckDataSize(offset) + 4 * sizeof(afs_int32);
+
p->header.serviceId = call->conn->serviceId;
p->header.cid = (call->conn->cid | call->channel);
p->header.callNumber = *call->callNumber;
p->header.epoch = call->conn->epoch;
p->header.type = RX_PACKET_TYPE_ACK;
p->header.flags = RX_SLOW_START_OK;
- if (reason == RX_ACK_PING) {
+ if (reason == RX_ACK_PING)
p->header.flags |= RX_REQUEST_ACK;
- if (padbytes) {
- p->length = padbytes +
- rx_AckDataSize(call->rwind) + 4 * sizeof(afs_int32);
- while (padbytes--)
- /* not fast but we can potentially use this if truncated
- * fragments are delivered to figure out the mtu.
- */
- rx_packetwrite(p, rx_AckDataSize(offset) + 4 *
- sizeof(afs_int32), sizeof(afs_int32),
- &padbytes);
+ while (padbytes > 0) {
+ if (padbytes > RX_ZEROS) {
+ rx_packetwrite(p, p->length, RX_ZEROS, rx_zeros);
+ p->length += RX_ZEROS;
+ padbytes -= RX_ZEROS;
+ } else {
+ rx_packetwrite(p, p->length, padbytes, rx_zeros);
+ p->length += padbytes;
+ padbytes = 0;
}
}
+
if (call->conn->type == RX_CLIENT_CONNECTION)
p->header.flags |= RX_CLIENT_INITIATED;
/* Make sure that the event pointer is removed from the call
* structure, since there is no longer a per-call retransmission
* event pending. */
- if (event == call->resendEvent) {
- CALL_RELE(call, RX_CALL_REFCOUNT_RESEND);
+ if (event == call->resendEvent)
rxevent_Put(&call->resendEvent);
- }
rxi_CheckPeerDead(call);
- if (rxi_busyChannelError && (call->flags & RX_CALL_PEER_BUSY)) {
- rxi_CheckBusy(call);
- }
-
if (opr_queue_IsEmpty(&call->tq)) {
/* Nothing to do. This means that we've been raced, and that an
* ACK has come in between when we were triggered, and when we
rxi_Start(call, istack);
out:
+ CALL_RELE(call, RX_CALL_REFCOUNT_RESEND);
MUTEX_EXIT(&call->lock);
}
rxi_SetPeerMtu(conn->peer, 0, 0, newmtu);
/* clean up */
- conn->lastPacketSize = 0;
+ conn->lastPacketSize = conn->lastPacketSizeSeq = 0;
/* needed so ResetCall doesn't clobber us. */
call->MTU = conn->peer->ifMTU;
struct sockaddr_in taddr;
char *tp;
char a[1] = { 0 };
+ int resched = 0;
struct iovec tmpiov[2];
osi_socket socket =
(conn->type ==
osi_NetSend(socket, &taddr, tmpiov, 1, 1 + sizeof(struct rx_header), 1);
MUTEX_ENTER(&conn->conn_data_lock);
+ /* We ran, so the handle is no longer needed to try to cancel ourselves. */
+ if (event == conn->natKeepAliveEvent)
+ rxevent_Put(&conn->natKeepAliveEvent);
MUTEX_ENTER(&rx_refcnt_mutex);
/* Only reschedule ourselves if the connection would not be destroyed */
- if (conn->refCount <= 1) {
- rxevent_Put(&conn->natKeepAliveEvent);
- MUTEX_EXIT(&rx_refcnt_mutex);
- MUTEX_EXIT(&conn->conn_data_lock);
- rx_DestroyConnection(conn); /* drop the reference for this */
- } else {
- conn->refCount--; /* drop the reference for this */
- MUTEX_EXIT(&rx_refcnt_mutex);
- rxevent_Put(&conn->natKeepAliveEvent);
- rxi_ScheduleNatKeepAliveEvent(conn);
- MUTEX_EXIT(&conn->conn_data_lock);
+ if (conn->refCount > 1)
+ resched = 1;
+ if (conn->refCount <= 0) {
+#ifdef RX_REFCOUNT_CHECK
+ osi_Assert(conn->refCount == 0);
+#endif
+ if (rx_stats_active) {
+ MUTEX_ENTER(&rx_stats_mutex);
+ rxi_lowConnRefCount++;
+ MUTEX_EXIT(&rx_stats_mutex);
+ }
}
+ MUTEX_EXIT(&rx_refcnt_mutex);
+ if (resched)
+ rxi_ScheduleNatKeepAliveEvent(conn);
+ MUTEX_EXIT(&conn->conn_data_lock);
+ putConnection(conn);
}
static void
rxi_ScheduleNatKeepAliveEvent(struct rx_connection *conn)
{
+ MUTEX_ASSERT(&conn->conn_data_lock);
if (!conn->natKeepAliveEvent && conn->secondsUntilNatPing) {
struct clock when, now;
clock_GetTime(&now);
when = now;
when.sec += conn->secondsUntilNatPing;
- MUTEX_ENTER(&rx_refcnt_mutex);
- conn->refCount++; /* hold a reference for this */
- MUTEX_EXIT(&rx_refcnt_mutex);
+ rx_GetConnection(conn);
conn->natKeepAliveEvent =
rxevent_Post(&when, &now, rxi_NatKeepAliveEvent, conn, NULL, 0);
}
struct rx_connection *conn;
afs_uint32 now;
- CALL_RELE(call, RX_CALL_REFCOUNT_ALIVE);
MUTEX_ENTER(&call->lock);
if (event == call->keepAliveEvent)
/* Don't try to keep alive dallying calls */
if (call->state == RX_STATE_DALLY) {
MUTEX_EXIT(&call->lock);
+ CALL_RELE(call, RX_CALL_REFCOUNT_ALIVE);
return;
}
}
rxi_ScheduleKeepAliveEvent(call);
MUTEX_EXIT(&call->lock);
+ CALL_RELE(call, RX_CALL_REFCOUNT_ALIVE);
}
/* Does what's on the nameplate. */
struct rx_call *call = arg1;
struct rx_connection *conn;
- CALL_RELE(call, RX_CALL_REFCOUNT_MTU);
MUTEX_ENTER(&call->lock);
if (event == call->growMTUEvent)
rxevent_Put(&call->growMTUEvent);
- if (rxi_CheckCall(call, 0)) {
- MUTEX_EXIT(&call->lock);
- return;
- }
+ if (rxi_CheckCall(call, 0))
+ goto out;
/* Don't bother with dallying calls */
- if (call->state == RX_STATE_DALLY) {
- MUTEX_EXIT(&call->lock);
- return;
- }
+ if (call->state == RX_STATE_DALLY)
+ goto out;
conn = call->conn;
conn->idleDeadTime)
(void)rxi_SendAck(call, NULL, 0, RX_ACK_MTU, 0);
rxi_ScheduleGrowMTUEvent(call, 0);
+out:
MUTEX_EXIT(&call->lock);
+ CALL_RELE(call, RX_CALL_REFCOUNT_MTU);
}
static void
rxi_ScheduleKeepAliveEvent(struct rx_call *call)
{
+ MUTEX_ASSERT(&call->lock);
if (!call->keepAliveEvent) {
struct clock when, now;
clock_GetTime(&now);
static void
rxi_CancelKeepAliveEvent(struct rx_call *call) {
- if (call->keepAliveEvent) {
- rxevent_Cancel(&call->keepAliveEvent);
+ MUTEX_ASSERT(&call->lock);
+ if (rxevent_Cancel(&call->keepAliveEvent))
CALL_RELE(call, RX_CALL_REFCOUNT_ALIVE);
- }
}
static void
rxi_ScheduleGrowMTUEvent(struct rx_call *call, int secs)
{
+ MUTEX_ASSERT(&call->lock);
if (!call->growMTUEvent) {
struct clock when, now;
static void
rxi_CancelGrowMTUEvent(struct rx_call *call)
{
- if (call->growMTUEvent) {
- rxevent_Cancel(&call->growMTUEvent);
+ MUTEX_ASSERT(&call->lock);
+ if (rxevent_Cancel(&call->growMTUEvent))
CALL_RELE(call, RX_CALL_REFCOUNT_MTU);
- }
}
/*
struct rx_packet *packet;
MUTEX_ENTER(&conn->conn_data_lock);
- rxevent_Put(&conn->delayedAbortEvent);
+ if (event == conn->delayedAbortEvent)
+ rxevent_Put(&conn->delayedAbortEvent);
error = htonl(conn->error);
conn->abortCount++;
MUTEX_EXIT(&conn->conn_data_lock);
sizeof(error), 0);
rxi_FreePacket(packet);
}
+ putConnection(conn);
}
/* This routine is called to send call abort messages
struct rx_packet *packet;
MUTEX_ENTER(&call->lock);
- rxevent_Put(&call->delayedAbortEvent);
+ if (event == call->delayedAbortEvent)
+ rxevent_Put(&call->delayedAbortEvent);
error = htonl(call->error);
call->abortCount++;
packet = rxi_AllocPacket(RX_PACKET_CLASS_SPECIAL);
CALL_RELE(call, RX_CALL_REFCOUNT_ABORT);
}
-/* This routine is called periodically (every RX_AUTH_REQUEST_TIMEOUT
+/*
+ * This routine is called periodically (every RX_AUTH_REQUEST_TIMEOUT
* seconds) to ask the client to authenticate itself. The routine
* issues a challenge to the client, which is obtained from the
- * security object associated with the connection */
+ * security object associated with the connection
+ *
+ * This routine is both an event handler and a function called directly;
+ * when called directly the passed |event| is NULL and the
+ * conn->conn->data>lock must must not be held.
+ */
static void
rxi_ChallengeEvent(struct rxevent *event,
void *arg0, void *arg1, int tries)
{
struct rx_connection *conn = arg0;
- if (event)
+ MUTEX_ENTER(&conn->conn_data_lock);
+ if (event != NULL && event == conn->challengeEvent)
rxevent_Put(&conn->challengeEvent);
+ MUTEX_EXIT(&conn->conn_data_lock);
/* If there are no active calls it is not worth re-issuing the
* challenge. If the client issues another call on this connection
* the challenge can be requested at that time.
*/
- if (!rxi_HasActiveCalls(conn))
+ if (!rxi_HasActiveCalls(conn)) {
+ putConnection(conn);
return;
+ }
if (RXS_CheckAuthentication(conn->securityObject, conn) != 0) {
struct rx_packet *packet;
}
}
MUTEX_EXIT(&conn->conn_call_lock);
+ putConnection(conn);
return;
}
clock_GetTime(&now);
when = now;
when.sec += RX_CHALLENGE_TIMEOUT;
- conn->challengeEvent =
- rxevent_Post(&when, &now, rxi_ChallengeEvent, conn, 0,
- (tries - 1));
+ MUTEX_ENTER(&conn->conn_data_lock);
+ /* Only reschedule ourselves if not already pending. */
+ if (conn->challengeEvent == NULL) {
+ rx_GetConnection(conn);
+ conn->challengeEvent =
+ rxevent_Post(&when, &now, rxi_ChallengeEvent, conn, 0,
+ (tries - 1));
+ }
+ MUTEX_EXIT(&conn->conn_data_lock);
}
+ putConnection(conn);
}
/* Call this routine to start requesting the client to authenticate
* itself. This will continue until authentication is established,
* the call times out, or an invalid response is returned. The
* security object associated with the connection is asked to create
- * the challenge at this time. N.B. rxi_ChallengeOff is a macro,
- * defined earlier. */
+ * the challenge at this time. */
static void
rxi_ChallengeOn(struct rx_connection *conn)
{
- if (!conn->challengeEvent) {
+ int start = 0;
+ MUTEX_ENTER(&conn->conn_data_lock);
+ if (!conn->challengeEvent)
+ start = 1;
+ MUTEX_EXIT(&conn->conn_data_lock);
+ if (start) {
RXS_CreateChallenge(conn->securityObject, conn);
rxi_ChallengeEvent(NULL, conn, 0, RX_CHALLENGE_MAXTRIES);
};
rx_hashTableSize * sizeof(struct rx_connection *));
UNPIN(rx_peerHashTable, rx_hashTableSize * sizeof(struct rx_peer *));
- rxi_FreeAllPackets();
-
MUTEX_ENTER(&rx_quota_mutex);
rxi_dataQuota = RX_MAX_QUOTA;
rxi_availProcs = rxi_totalMin = rxi_minDeficit = 0;