SUNRPC: Respond promptly to server TCP resets
If the server sends us an RST error while we're in the TCP_ESTABLISHED state, then that will not result in a state change, and so the RPC client ends up hanging forever (see http://bugzilla.kernel.org/show_bug.cgi?id=11154) We can intercept the reset by setting up an sk->sk_error_report callback, which will then allow us to initiate a proper shutdown and retry... We also make sure that if the send request receives an ECONNRESET, then we shutdown too... Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
parent
e946217e4f
commit
2a9e1cfa23
1 changed files with 48 additions and 10 deletions
|
@ -249,6 +249,7 @@ struct sock_xprt {
|
||||||
void (*old_data_ready)(struct sock *, int);
|
void (*old_data_ready)(struct sock *, int);
|
||||||
void (*old_state_change)(struct sock *);
|
void (*old_state_change)(struct sock *);
|
||||||
void (*old_write_space)(struct sock *);
|
void (*old_write_space)(struct sock *);
|
||||||
|
void (*old_error_report)(struct sock *);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -698,8 +699,9 @@ static int xs_tcp_send_request(struct rpc_task *task)
|
||||||
case -EAGAIN:
|
case -EAGAIN:
|
||||||
xs_nospace(task);
|
xs_nospace(task);
|
||||||
break;
|
break;
|
||||||
case -ECONNREFUSED:
|
|
||||||
case -ECONNRESET:
|
case -ECONNRESET:
|
||||||
|
xs_tcp_shutdown(xprt);
|
||||||
|
case -ECONNREFUSED:
|
||||||
case -ENOTCONN:
|
case -ENOTCONN:
|
||||||
case -EPIPE:
|
case -EPIPE:
|
||||||
status = -ENOTCONN;
|
status = -ENOTCONN;
|
||||||
|
@ -742,6 +744,22 @@ static void xs_tcp_release_xprt(struct rpc_xprt *xprt, struct rpc_task *task)
|
||||||
xprt_release_xprt(xprt, task);
|
xprt_release_xprt(xprt, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void xs_save_old_callbacks(struct sock_xprt *transport, struct sock *sk)
|
||||||
|
{
|
||||||
|
transport->old_data_ready = sk->sk_data_ready;
|
||||||
|
transport->old_state_change = sk->sk_state_change;
|
||||||
|
transport->old_write_space = sk->sk_write_space;
|
||||||
|
transport->old_error_report = sk->sk_error_report;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void xs_restore_old_callbacks(struct sock_xprt *transport, struct sock *sk)
|
||||||
|
{
|
||||||
|
sk->sk_data_ready = transport->old_data_ready;
|
||||||
|
sk->sk_state_change = transport->old_state_change;
|
||||||
|
sk->sk_write_space = transport->old_write_space;
|
||||||
|
sk->sk_error_report = transport->old_error_report;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xs_close - close a socket
|
* xs_close - close a socket
|
||||||
* @xprt: transport
|
* @xprt: transport
|
||||||
|
@ -765,9 +783,8 @@ static void xs_close(struct rpc_xprt *xprt)
|
||||||
transport->sock = NULL;
|
transport->sock = NULL;
|
||||||
|
|
||||||
sk->sk_user_data = NULL;
|
sk->sk_user_data = NULL;
|
||||||
sk->sk_data_ready = transport->old_data_ready;
|
|
||||||
sk->sk_state_change = transport->old_state_change;
|
xs_restore_old_callbacks(transport, sk);
|
||||||
sk->sk_write_space = transport->old_write_space;
|
|
||||||
write_unlock_bh(&sk->sk_callback_lock);
|
write_unlock_bh(&sk->sk_callback_lock);
|
||||||
|
|
||||||
sk->sk_no_check = 0;
|
sk->sk_no_check = 0;
|
||||||
|
@ -1179,6 +1196,28 @@ static void xs_tcp_state_change(struct sock *sk)
|
||||||
read_unlock(&sk->sk_callback_lock);
|
read_unlock(&sk->sk_callback_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xs_tcp_error_report - callback mainly for catching RST events
|
||||||
|
* @sk: socket
|
||||||
|
*/
|
||||||
|
static void xs_tcp_error_report(struct sock *sk)
|
||||||
|
{
|
||||||
|
struct rpc_xprt *xprt;
|
||||||
|
|
||||||
|
read_lock(&sk->sk_callback_lock);
|
||||||
|
if (sk->sk_err != ECONNRESET || sk->sk_state != TCP_ESTABLISHED)
|
||||||
|
goto out;
|
||||||
|
if (!(xprt = xprt_from_sock(sk)))
|
||||||
|
goto out;
|
||||||
|
dprintk("RPC: %s client %p...\n"
|
||||||
|
"RPC: error %d\n",
|
||||||
|
__func__, xprt, sk->sk_err);
|
||||||
|
|
||||||
|
xprt_force_disconnect(xprt);
|
||||||
|
out:
|
||||||
|
read_unlock(&sk->sk_callback_lock);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xs_udp_write_space - callback invoked when socket buffer space
|
* xs_udp_write_space - callback invoked when socket buffer space
|
||||||
* becomes available
|
* becomes available
|
||||||
|
@ -1454,10 +1493,9 @@ static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
|
||||||
|
|
||||||
write_lock_bh(&sk->sk_callback_lock);
|
write_lock_bh(&sk->sk_callback_lock);
|
||||||
|
|
||||||
|
xs_save_old_callbacks(transport, sk);
|
||||||
|
|
||||||
sk->sk_user_data = xprt;
|
sk->sk_user_data = xprt;
|
||||||
transport->old_data_ready = sk->sk_data_ready;
|
|
||||||
transport->old_state_change = sk->sk_state_change;
|
|
||||||
transport->old_write_space = sk->sk_write_space;
|
|
||||||
sk->sk_data_ready = xs_udp_data_ready;
|
sk->sk_data_ready = xs_udp_data_ready;
|
||||||
sk->sk_write_space = xs_udp_write_space;
|
sk->sk_write_space = xs_udp_write_space;
|
||||||
sk->sk_no_check = UDP_CSUM_NORCV;
|
sk->sk_no_check = UDP_CSUM_NORCV;
|
||||||
|
@ -1589,13 +1627,13 @@ static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
|
||||||
|
|
||||||
write_lock_bh(&sk->sk_callback_lock);
|
write_lock_bh(&sk->sk_callback_lock);
|
||||||
|
|
||||||
|
xs_save_old_callbacks(transport, sk);
|
||||||
|
|
||||||
sk->sk_user_data = xprt;
|
sk->sk_user_data = xprt;
|
||||||
transport->old_data_ready = sk->sk_data_ready;
|
|
||||||
transport->old_state_change = sk->sk_state_change;
|
|
||||||
transport->old_write_space = sk->sk_write_space;
|
|
||||||
sk->sk_data_ready = xs_tcp_data_ready;
|
sk->sk_data_ready = xs_tcp_data_ready;
|
||||||
sk->sk_state_change = xs_tcp_state_change;
|
sk->sk_state_change = xs_tcp_state_change;
|
||||||
sk->sk_write_space = xs_tcp_write_space;
|
sk->sk_write_space = xs_tcp_write_space;
|
||||||
|
sk->sk_error_report = xs_tcp_error_report;
|
||||||
sk->sk_allocation = GFP_ATOMIC;
|
sk->sk_allocation = GFP_ATOMIC;
|
||||||
|
|
||||||
/* socket options */
|
/* socket options */
|
||||||
|
|
Loading…
Reference in a new issue