Commit eb9950eb authored by David Howells's avatar David Howells Committed by David S. Miller

rxrpc: Push iov_iter up from rxrpc_kernel_recv_data() to caller

Push iov_iter up from rxrpc_kernel_recv_data() to its caller to allow
non-contiguous iovs to be passed down, thereby permitting file reading to
be simplified in the AFS filesystem in a future patch.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3424b700
...@@ -346,7 +346,6 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, ...@@ -346,7 +346,6 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,
struct rxrpc_call *rxcall; struct rxrpc_call *rxcall;
struct msghdr msg; struct msghdr msg;
struct kvec iov[1]; struct kvec iov[1];
size_t offset;
s64 tx_total_len; s64 tx_total_len;
int ret; int ret;
...@@ -433,10 +432,10 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, ...@@ -433,10 +432,10 @@ long afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call,
rxrpc_kernel_abort_call(call->net->socket, rxcall, rxrpc_kernel_abort_call(call->net->socket, rxcall,
RX_USER_ABORT, ret, "KSD"); RX_USER_ABORT, ret, "KSD");
} else { } else {
offset = 0; iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, NULL, 0, 0);
rxrpc_kernel_recv_data(call->net->socket, rxcall, NULL, rxrpc_kernel_recv_data(call->net->socket, rxcall,
0, &offset, false, &call->abort_code, &msg.msg_iter, false,
&call->service_id); &call->abort_code, &call->service_id);
ac->abort_code = call->abort_code; ac->abort_code = call->abort_code;
ac->responded = true; ac->responded = true;
} }
...@@ -467,13 +466,14 @@ static void afs_deliver_to_call(struct afs_call *call) ...@@ -467,13 +466,14 @@ static void afs_deliver_to_call(struct afs_call *call)
state == AFS_CALL_SV_AWAIT_ACK state == AFS_CALL_SV_AWAIT_ACK
) { ) {
if (state == AFS_CALL_SV_AWAIT_ACK) { if (state == AFS_CALL_SV_AWAIT_ACK) {
size_t offset = 0; struct iov_iter iter;
iov_iter_kvec(&iter, READ | ITER_KVEC, NULL, 0, 0);
ret = rxrpc_kernel_recv_data(call->net->socket, ret = rxrpc_kernel_recv_data(call->net->socket,
call->rxcall, call->rxcall, &iter, false,
NULL, 0, &offset, false,
&remote_abort, &remote_abort,
&call->service_id); &call->service_id);
trace_afs_recv_data(call, 0, offset, false, ret); trace_afs_recv_data(call, 0, 0, false, ret);
if (ret == -EINPROGRESS || ret == -EAGAIN) if (ret == -EINPROGRESS || ret == -EAGAIN)
return; return;
...@@ -894,6 +894,8 @@ int afs_extract_data(struct afs_call *call, void *buf, size_t count, ...@@ -894,6 +894,8 @@ int afs_extract_data(struct afs_call *call, void *buf, size_t count,
bool want_more) bool want_more)
{ {
struct afs_net *net = call->net; struct afs_net *net = call->net;
struct iov_iter iter;
struct kvec iov;
enum afs_call_state state; enum afs_call_state state;
u32 remote_abort = 0; u32 remote_abort = 0;
int ret; int ret;
...@@ -903,10 +905,14 @@ int afs_extract_data(struct afs_call *call, void *buf, size_t count, ...@@ -903,10 +905,14 @@ int afs_extract_data(struct afs_call *call, void *buf, size_t count,
ASSERTCMP(call->offset, <=, count); ASSERTCMP(call->offset, <=, count);
ret = rxrpc_kernel_recv_data(net->socket, call->rxcall, iov.iov_base = buf + call->offset;
buf, count, &call->offset, iov.iov_len = count - call->offset;
iov_iter_kvec(&iter, ITER_KVEC | READ, &iov, 1, count - call->offset);
ret = rxrpc_kernel_recv_data(net->socket, call->rxcall, &iter,
want_more, &remote_abort, want_more, &remote_abort,
&call->service_id); &call->service_id);
call->offset += (count - call->offset) - iov_iter_count(&iter);
trace_afs_recv_data(call, count, call->offset, want_more, ret); trace_afs_recv_data(call, count, call->offset, want_more, ret);
if (ret == 0 || ret == -EAGAIN) if (ret == 0 || ret == -EAGAIN)
return ret; return ret;
......
...@@ -61,7 +61,7 @@ int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *, ...@@ -61,7 +61,7 @@ int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *,
struct msghdr *, size_t, struct msghdr *, size_t,
rxrpc_notify_end_tx_t); rxrpc_notify_end_tx_t);
int rxrpc_kernel_recv_data(struct socket *, struct rxrpc_call *, int rxrpc_kernel_recv_data(struct socket *, struct rxrpc_call *,
void *, size_t, size_t *, bool, u32 *, u16 *); struct iov_iter *, bool, u32 *, u16 *);
bool rxrpc_kernel_abort_call(struct socket *, struct rxrpc_call *, bool rxrpc_kernel_abort_call(struct socket *, struct rxrpc_call *,
u32, int, const char *); u32, int, const char *);
void rxrpc_kernel_end_call(struct socket *, struct rxrpc_call *); void rxrpc_kernel_end_call(struct socket *, struct rxrpc_call *);
......
...@@ -611,9 +611,7 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, ...@@ -611,9 +611,7 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
* rxrpc_kernel_recv_data - Allow a kernel service to receive data/info * rxrpc_kernel_recv_data - Allow a kernel service to receive data/info
* @sock: The socket that the call exists on * @sock: The socket that the call exists on
* @call: The call to send data through * @call: The call to send data through
* @buf: The buffer to receive into * @iter: The buffer to receive into
* @size: The size of the buffer, including data already read
* @_offset: The running offset into the buffer.
* @want_more: True if more data is expected to be read * @want_more: True if more data is expected to be read
* @_abort: Where the abort code is stored if -ECONNABORTED is returned * @_abort: Where the abort code is stored if -ECONNABORTED is returned
* @_service: Where to store the actual service ID (may be upgraded) * @_service: Where to store the actual service ID (may be upgraded)
...@@ -626,39 +624,30 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, ...@@ -626,39 +624,30 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
* Note that we may return -EAGAIN to drain empty packets at the end of the * Note that we may return -EAGAIN to drain empty packets at the end of the
* data, even if we've already copied over the requested data. * data, even if we've already copied over the requested data.
* *
* This function adds the amount it transfers to *_offset, so this should be
* precleared as appropriate. Note that the amount remaining in the buffer is
* taken to be size - *_offset.
*
* *_abort should also be initialised to 0. * *_abort should also be initialised to 0.
*/ */
int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call, int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,
void *buf, size_t size, size_t *_offset, struct iov_iter *iter,
bool want_more, u32 *_abort, u16 *_service) bool want_more, u32 *_abort, u16 *_service)
{ {
struct iov_iter iter; size_t offset = 0;
struct kvec iov;
int ret; int ret;
_enter("{%d,%s},%zu/%zu,%d", _enter("{%d,%s},%zu,%d",
call->debug_id, rxrpc_call_states[call->state], call->debug_id, rxrpc_call_states[call->state],
*_offset, size, want_more); iov_iter_count(iter), want_more);
ASSERTCMP(*_offset, <=, size);
ASSERTCMP(call->state, !=, RXRPC_CALL_SERVER_ACCEPTING); ASSERTCMP(call->state, !=, RXRPC_CALL_SERVER_ACCEPTING);
iov.iov_base = buf + *_offset;
iov.iov_len = size - *_offset;
iov_iter_kvec(&iter, ITER_KVEC | READ, &iov, 1, size - *_offset);
mutex_lock(&call->user_mutex); mutex_lock(&call->user_mutex);
switch (READ_ONCE(call->state)) { switch (READ_ONCE(call->state)) {
case RXRPC_CALL_CLIENT_RECV_REPLY: case RXRPC_CALL_CLIENT_RECV_REPLY:
case RXRPC_CALL_SERVER_RECV_REQUEST: case RXRPC_CALL_SERVER_RECV_REQUEST:
case RXRPC_CALL_SERVER_ACK_REQUEST: case RXRPC_CALL_SERVER_ACK_REQUEST:
ret = rxrpc_recvmsg_data(sock, call, NULL, &iter, size, 0, ret = rxrpc_recvmsg_data(sock, call, NULL, iter,
_offset); iov_iter_count(iter), 0,
&offset);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -667,7 +656,7 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call, ...@@ -667,7 +656,7 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,
* full buffer or have been given -EAGAIN. * full buffer or have been given -EAGAIN.
*/ */
if (ret == 1) { if (ret == 1) {
if (*_offset < size) if (iov_iter_count(iter) > 0)
goto short_data; goto short_data;
if (!want_more) if (!want_more)
goto read_phase_complete; goto read_phase_complete;
...@@ -704,7 +693,7 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call, ...@@ -704,7 +693,7 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,
if (_service) if (_service)
*_service = call->service_id; *_service = call->service_id;
mutex_unlock(&call->user_mutex); mutex_unlock(&call->user_mutex);
_leave(" = %d [%zu,%d]", ret, *_offset, *_abort); _leave(" = %d [%zu,%d]", ret, iov_iter_count(iter), *_abort);
return ret; return ret;
short_data: short_data:
...@@ -720,7 +709,7 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call, ...@@ -720,7 +709,7 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,
ret = call->error; ret = call->error;
if (call->completion == RXRPC_CALL_SUCCEEDED) { if (call->completion == RXRPC_CALL_SUCCEEDED) {
ret = 1; ret = 1;
if (size > 0) if (iov_iter_count(iter) > 0)
ret = -ECONNRESET; ret = -ECONNRESET;
} }
goto out; goto out;
......
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