Skip to content

Commit ad3331a

Browse files
committed
SUNRPC: Fix up socket autodisconnect
Ensure that we don't forget to set up the disconnection timer for the case when a connect request is fulfilled after the RPC request that initiated it has timed out or been interrupted. Signed-off-by: Trond Myklebust <[email protected]>
1 parent 1f4c17a commit ad3331a

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

net/sunrpc/xprt.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,20 @@ void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie)
680680
spin_unlock_bh(&xprt->transport_lock);
681681
}
682682

683+
static bool
684+
xprt_has_timer(const struct rpc_xprt *xprt)
685+
{
686+
return xprt->idle_timeout != 0;
687+
}
688+
689+
static void
690+
xprt_schedule_autodisconnect(struct rpc_xprt *xprt)
691+
__must_hold(&xprt->transport_lock)
692+
{
693+
if (list_empty(&xprt->recv) && xprt_has_timer(xprt))
694+
mod_timer(&xprt->timer, xprt->last_used + xprt->idle_timeout);
695+
}
696+
683697
static void
684698
xprt_init_autodisconnect(unsigned long data)
685699
{
@@ -688,6 +702,8 @@ xprt_init_autodisconnect(unsigned long data)
688702
spin_lock(&xprt->transport_lock);
689703
if (!list_empty(&xprt->recv))
690704
goto out_abort;
705+
/* Reset xprt->last_used to avoid connect/autodisconnect cycling */
706+
xprt->last_used = jiffies;
691707
if (test_and_set_bit(XPRT_LOCKED, &xprt->state))
692708
goto out_abort;
693709
spin_unlock(&xprt->transport_lock);
@@ -725,6 +741,7 @@ void xprt_unlock_connect(struct rpc_xprt *xprt, void *cookie)
725741
goto out;
726742
xprt->snd_task =NULL;
727743
xprt->ops->release_xprt(xprt, NULL);
744+
xprt_schedule_autodisconnect(xprt);
728745
out:
729746
spin_unlock_bh(&xprt->transport_lock);
730747
wake_up_bit(&xprt->state, XPRT_LOCKED);
@@ -888,11 +905,6 @@ static void xprt_timer(struct rpc_task *task)
888905
spin_unlock_bh(&xprt->transport_lock);
889906
}
890907

891-
static inline int xprt_has_timer(struct rpc_xprt *xprt)
892-
{
893-
return xprt->idle_timeout != 0;
894-
}
895-
896908
/**
897909
* xprt_prepare_transmit - reserve the transport before sending a request
898910
* @task: RPC task about to send a request
@@ -1280,9 +1292,7 @@ void xprt_release(struct rpc_task *task)
12801292
if (!list_empty(&req->rq_list))
12811293
list_del(&req->rq_list);
12821294
xprt->last_used = jiffies;
1283-
if (list_empty(&xprt->recv) && xprt_has_timer(xprt))
1284-
mod_timer(&xprt->timer,
1285-
xprt->last_used + xprt->idle_timeout);
1295+
xprt_schedule_autodisconnect(xprt);
12861296
spin_unlock_bh(&xprt->transport_lock);
12871297
if (req->rq_buffer)
12881298
xprt->ops->buf_free(req->rq_buffer);

0 commit comments

Comments
 (0)