SUNRPC: Fix a race in xs_tcp_state_change()
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Tue, 6 Nov 2007 15:18:36 +0000 (10:18 -0500)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Wed, 30 Jan 2008 07:05:24 +0000 (02:05 -0500)
When scheduling the autoclose RPC call, we want to ensure that we don't
race against the test_bit() call in xprt_clear_locked().

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
include/linux/sunrpc/xprt.h
net/sunrpc/xprt.c
net/sunrpc/xprtsock.c

index 30b17b3bc1a9b9eea991874d83a9a8f24799e4b8..6f524a9e7fd01d26f4c2b6ae0acc1282e0b3f780 100644 (file)
@@ -246,6 +246,7 @@ struct rpc_rqst *   xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid);
 void                   xprt_complete_rqst(struct rpc_task *task, int copied);
 void                   xprt_release_rqst_cong(struct rpc_task *task);
 void                   xprt_disconnect(struct rpc_xprt *xprt);
+void                   xprt_force_disconnect(struct rpc_xprt *xprt);
 
 /*
  * Reserved bit positions in xprt->state
index fb92f51405c5d5a2a9016eb980c4536fc455121b..a3af02168af1d1b66e7f28d972b6901c3084637d 100644 (file)
@@ -570,6 +570,7 @@ static void xprt_autoclose(struct work_struct *work)
 
        xprt_disconnect(xprt);
        xprt->ops->close(xprt);
+       clear_bit(XPRT_CLOSE_WAIT, &xprt->state);
        xprt_release_write(xprt, NULL);
 }
 
@@ -588,6 +589,25 @@ void xprt_disconnect(struct rpc_xprt *xprt)
 }
 EXPORT_SYMBOL_GPL(xprt_disconnect);
 
+/**
+ * xprt_force_disconnect - force a transport to disconnect
+ * @xprt: transport to disconnect
+ *
+ */
+void xprt_force_disconnect(struct rpc_xprt *xprt)
+{
+       /* Don't race with the test_bit() in xprt_clear_locked() */
+       spin_lock_bh(&xprt->transport_lock);
+       set_bit(XPRT_CLOSE_WAIT, &xprt->state);
+       /* Try to schedule an autoclose RPC call */
+       if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
+               queue_work(rpciod_workqueue, &xprt->task_cleanup);
+       else if (xprt->snd_task != NULL)
+               rpc_wake_up_task(xprt->snd_task);
+       spin_unlock_bh(&xprt->transport_lock);
+}
+EXPORT_SYMBOL_GPL(xprt_force_disconnect);
+
 static void
 xprt_init_autodisconnect(unsigned long data)
 {
index 6fa52f44de0fd1b43f8630ae7d50ef0805be06a1..abb40c14073818b991ecb41235602cb40f4dc3f3 100644 (file)
@@ -1122,10 +1122,7 @@ static void xs_tcp_state_change(struct sock *sk)
        case TCP_SYN_RECV:
                break;
        case TCP_CLOSE_WAIT:
-               /* Try to schedule an autoclose RPC calls */
-               set_bit(XPRT_CLOSE_WAIT, &xprt->state);
-               if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
-                       queue_work(rpciod_workqueue, &xprt->task_cleanup);
+               xprt_force_disconnect(xprt);
        default:
                xprt_disconnect(xprt);
        }