Commit 0be53f27 authored by Trond Myklebust's avatar Trond Myklebust Committed by Linus Torvalds

[PATCH] clean up RPC write_space() code

Make the RPC write_space() algoritm use the standard socket flags
SOCK_ASYNC_NOSPACE and SOCK_NOSPACE instead of its own custom flag.
parent 0e0dad87
...@@ -178,12 +178,7 @@ void xprt_release(struct rpc_task *); ...@@ -178,12 +178,7 @@ void xprt_release(struct rpc_task *);
void xprt_reconnect(struct rpc_task *); void xprt_reconnect(struct rpc_task *);
int xprt_clear_backlog(struct rpc_xprt *); int xprt_clear_backlog(struct rpc_xprt *);
#define XPRT_WSPACE 0 #define XPRT_CONNECT 0
#define XPRT_CONNECT 1
#define xprt_wspace(xp) (test_bit(XPRT_WSPACE, &(xp)->sockstate))
#define xprt_test_and_set_wspace(xp) (test_and_set_bit(XPRT_WSPACE, &(xp)->sockstate))
#define xprt_clear_wspace(xp) (clear_bit(XPRT_WSPACE, &(xp)->sockstate))
#define xprt_connected(xp) (!(xp)->stream || test_bit(XPRT_CONNECT, &(xp)->sockstate)) #define xprt_connected(xp) (!(xp)->stream || test_bit(XPRT_CONNECT, &(xp)->sockstate))
#define xprt_set_connected(xp) (set_bit(XPRT_CONNECT, &(xp)->sockstate)) #define xprt_set_connected(xp) (set_bit(XPRT_CONNECT, &(xp)->sockstate))
......
...@@ -233,6 +233,7 @@ xprt_sendmsg(struct rpc_xprt *xprt, struct rpc_rqst *req) ...@@ -233,6 +233,7 @@ xprt_sendmsg(struct rpc_xprt *xprt, struct rpc_rqst *req)
msg.msg_controllen = 0; msg.msg_controllen = 0;
oldfs = get_fs(); set_fs(get_ds()); oldfs = get_fs(); set_fs(get_ds());
clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags);
result = sock_sendmsg(sock, &msg, slen); result = sock_sendmsg(sock, &msg, slen);
set_fs(oldfs); set_fs(oldfs);
...@@ -248,10 +249,7 @@ xprt_sendmsg(struct rpc_xprt *xprt, struct rpc_rqst *req) ...@@ -248,10 +249,7 @@ xprt_sendmsg(struct rpc_xprt *xprt, struct rpc_rqst *req)
/* When the server has died, an ICMP port unreachable message /* When the server has died, an ICMP port unreachable message
* prompts ECONNREFUSED. * prompts ECONNREFUSED.
*/ */
break;
case -EAGAIN: case -EAGAIN:
if (test_bit(SOCK_NOSPACE, &sock->flags))
result = -ENOMEM;
break; break;
case -ENOTCONN: case -ENOTCONN:
case -EPIPE: case -EPIPE:
...@@ -965,19 +963,15 @@ xprt_write_space(struct sock *sk) ...@@ -965,19 +963,15 @@ xprt_write_space(struct sock *sk)
if (!sock_writeable(sk)) if (!sock_writeable(sk))
return; return;
if (!xprt_test_and_set_wspace(xprt)) { if (!test_and_clear_bit(SOCK_NOSPACE, &sock->flags))
return;
spin_lock_bh(&xprt->sock_lock); spin_lock_bh(&xprt->sock_lock);
if (xprt->snd_task && xprt->snd_task->tk_rpcwait == &xprt->pending) if (xprt->snd_task && xprt->snd_task->tk_rpcwait == &xprt->pending)
rpc_wake_up_task(xprt->snd_task); rpc_wake_up_task(xprt->snd_task);
spin_unlock_bh(&xprt->sock_lock); spin_unlock_bh(&xprt->sock_lock);
} if (sk->sleep && waitqueue_active(sk->sleep))
if (test_bit(SOCK_NOSPACE, &sock->flags)) {
if (sk->sleep && waitqueue_active(sk->sleep)) {
clear_bit(SOCK_NOSPACE, &sock->flags);
wake_up_interruptible(sk->sleep); wake_up_interruptible(sk->sleep);
}
}
} }
/* /*
...@@ -1083,7 +1077,6 @@ do_xprt_transmit(struct rpc_task *task) ...@@ -1083,7 +1077,6 @@ do_xprt_transmit(struct rpc_task *task)
* called xprt_sendmsg(). * called xprt_sendmsg().
*/ */
while (1) { while (1) {
xprt_clear_wspace(xprt);
req->rq_xtime = jiffies; req->rq_xtime = jiffies;
status = xprt_sendmsg(xprt, req); status = xprt_sendmsg(xprt, req);
...@@ -1098,7 +1091,7 @@ do_xprt_transmit(struct rpc_task *task) ...@@ -1098,7 +1091,7 @@ do_xprt_transmit(struct rpc_task *task)
} else { } else {
if (status >= req->rq_slen) if (status >= req->rq_slen)
goto out_receive; goto out_receive;
status = -ENOMEM; status = -EAGAIN;
break; break;
} }
...@@ -1121,16 +1114,17 @@ do_xprt_transmit(struct rpc_task *task) ...@@ -1121,16 +1114,17 @@ do_xprt_transmit(struct rpc_task *task)
task->tk_status = status; task->tk_status = status;
switch (status) { switch (status) {
case -ENOMEM: case -EAGAIN:
/* Protect against (udp|tcp)_write_space */ if (test_bit(SOCK_ASYNC_NOSPACE, &xprt->sock->flags)) {
/* Protect against races with xprt_write_space */
spin_lock_bh(&xprt->sock_lock); spin_lock_bh(&xprt->sock_lock);
if (!xprt_wspace(xprt)) { if (test_bit(SOCK_NOSPACE, &xprt->sock->flags)) {
task->tk_timeout = req->rq_timeout.to_current; task->tk_timeout = req->rq_timeout.to_current;
rpc_sleep_on(&xprt->pending, task, NULL, NULL); rpc_sleep_on(&xprt->pending, task, NULL, NULL);
} }
spin_unlock_bh(&xprt->sock_lock); spin_unlock_bh(&xprt->sock_lock);
return; return;
case -EAGAIN: }
/* Keep holding the socket if it is blocked */ /* Keep holding the socket if it is blocked */
rpc_delay(task, HZ>>4); rpc_delay(task, HZ>>4);
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment