SUNRPC: resend a request whose reply asked for a retry
Subsystems (3)
PATCH 1/1 SUNRPC: resend a request whose reply asked for a retry
[BUG]
xfstests generic/761 fails over NFSv4 with sec=krb5i. write() on an O_DIRECT file returns EACCES.
The test changes the write buffer from a second thread while the write is in flight. With krb5i the client computes the RPCSEC_GSS integrity checksum over the live pages, so some WRITEs reach the server with a checksum that does not match the data.
The client is expected to send the request again. It does not.
[CAUSE]
When rpc_decode_header() gets a reply it treats as possibly garbled, it decrements tk_garb_retry and returns -EAGAIN. call_decode() then calls xprt_conditional_disconnect() when the client has cl_discrtry set, and moves the task to call_encode().
call_encode() encodes only when rpc_task_need_encode() says so. For a task that was already sent with RPC_TASK_NO_RETRANS_TIMEOUT set, as every NFSv4 task is, that requires xprt_request_need_retransmit(), i.e. a connection that has already dropped.
The disconnect is only queued on xprtiod, so call_encode() can run before it. The task then skips the encode and the transmit, goes on to call_decode() with rq_reply_bytes_recvd still set, and decodes the same rejected reply again. Two more passes use up tk_garb_retry and the RPC fails without the request being sent a second time.
Until commit cc204d01262a ("SUNRPC: Dequeue the request from the receive queue while we're re-encoding"), the -EAGAIN case of call_decode() cleared rq_reply_bytes_recvd itself. That commit moved the clearing into rpc_xdr_encode(), which this path does not reach because rpc_task_need_encode() returns false. Since then the rejected reply is neither cleared nor replaced.
[FIX]
I have considered the following ideas to solve the problem:
- Copy the payload before computing the krb5i checksum The checksum then always matches what is sent, so the server does not reject the WRITE. generic/761 passed 5 of 5 runs with such a copy. But it costs a copy of every krb5i payload.
- Clear rq_reply_bytes_recvd in call_decode() again and wait for the disconnect
The request would also have to be put back on the receive queue so that the task sleeps. And without cl_discrtry there is no disconnect to wake it.
Not tested.
- Treat a received reply as a reason to retransmit This is the solution utilized by this patch.
rpc_task_need_encode() now also returns true when xprt_request_data_received() says a reply has been received. call_encode() runs with a received reply when rpc_decode_header() rejected that reply. rpc_xdr_encode() clears rq_reply_bytes_recvd, so this only changes the paths that come back to call_encode() after a reply was received. xprt_request_data_received() loses its static qualifier so that clnt.c can call it.
The request is encoded again at once, which for krb5i computes a new checksum. It is still sent only after the reconnect: the pending close holds the transport send lock, and xprt_request_transmit() refuses to send while XPRT_CLOSE_WAIT is set.
---
include/linux/sunrpc/xprt.h +1 -0
@@ -397,6 +397,7 @@ int xprt_request_enqueue_receive(strucvoid xprt_request_wait_receive (struct rpc_task *task);void xprt_request_dequeue_xprt (struct rpc_task *task);bool xprt_request_need_retransmit (struct rpc_task *task); +bool xprt_request_data_received (struct rpc_task *task);void xprt_transmit (struct rpc_task *task);void xprt_end_transmit (struct rpc_task *task);int xprt_adjust_timeout (struct rpc_rqst *req);
net/sunrpc/clnt.c +2 -0
@@ -2020,6 +2020,8 @@ rpc_task_need_encode(struct rpc_task *tareturn test_bit (RPC_TASK_NEED_XMIT , &task->tk_runstate) ==0 && (!(task->tk_flags &RPC_TASK_SENT ) || !(task->tk_flags &RPC_TASK_NO_RETRANS_TIMEOUT ) || +/* the reply was rejected, resend */ +xprt_request_data_received (task) ||xprt_request_need_retransmit (task)); }
net/sunrpc/xprt.c +1 -1
@@ -1129,7 +1129,7 @@ static void xprt_wait_on_pinned_rqst(strwait_var_event (&req->rq_pin, !xprt_is_pinned_rqst (req)); } -static bool +bool xprt_request_data_received (struct rpc_task *task) { return !test_bit(RPC_TASK_NEED_RECV, &task->tk_runstate) &&