Skip to content

Commit f105da1

Browse files
committed
afs: Don't truncate iter during data fetch
Don't truncate the iterator to correspond to the actual data size when fetching the data from the server - rather, pass the length we want to read to rxrpc. This will allow the clear-after-read code in future to simply clear the remaining iterator capacity rather than having to reinitialise the iterator. Signed-off-by: David Howells <dhowells@redhat.com> Tested-By: Marc Dionne <marc.dionne@auristor.com> cc: linux-afs@lists.infradead.org cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org Link: https://lore.kernel.org/r/158861249201.340223.13035445866976590375.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/159465825061.1377938.14403904452300909320.stgit@warthog.procyon.org.uk/ Link: https://lore.kernel.org/r/160588531418.3465195.10712005940763063144.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/161118148567.1232039.13380313332292947956.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/161161044610.2537118.17908520793806837792.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/161340407907.1303470.6501394859511712746.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/161539551721.286939.14655713136572200716.stgit@warthog.procyon.org.uk/ # v4 Link: https://lore.kernel.org/r/161653807790.2770958.14034599989374173734.stgit@warthog.procyon.org.uk/ # v5 Link: https://lore.kernel.org/r/161789090823.6155.15673999934535049102.stgit@warthog.procyon.org.uk/ # v6
1 parent c69bf47 commit f105da1

6 files changed

Lines changed: 29 additions & 13 deletions

File tree

fs/afs/fsclient.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call)
305305
unsigned int size;
306306
int ret;
307307

308-
_enter("{%u,%zu/%llu}",
309-
call->unmarshall, iov_iter_count(call->iter), req->actual_len);
308+
_enter("{%u,%zu,%zu/%llu}",
309+
call->unmarshall, call->iov_len, iov_iter_count(call->iter),
310+
req->actual_len);
310311

311312
switch (call->unmarshall) {
312313
case 0:
@@ -343,6 +344,7 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call)
343344
size = PAGE_SIZE - req->offset;
344345
else
345346
size = req->remain;
347+
call->iov_len = size;
346348
call->bvec[0].bv_len = size;
347349
call->bvec[0].bv_offset = req->offset;
348350
call->bvec[0].bv_page = req->pages[req->index];

fs/afs/internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ struct afs_call {
104104
struct afs_server *server; /* The fileserver record if fs op (pins ref) */
105105
struct afs_vlserver *vlserver; /* The vlserver record if vl op */
106106
void *request; /* request data (first part) */
107+
size_t iov_len; /* Size of *iter to be used */
107108
struct iov_iter def_iter; /* Default buffer/data iterator */
108109
struct iov_iter *iter; /* Iterator currently in use */
109110
union { /* Convenience for ->def_iter */
@@ -1271,28 +1272,33 @@ static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *c
12711272

12721273
static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
12731274
{
1275+
call->iov_len = size;
12741276
call->kvec[0].iov_base = buf;
12751277
call->kvec[0].iov_len = size;
12761278
iov_iter_kvec(&call->def_iter, READ, call->kvec, 1, size);
12771279
}
12781280

12791281
static inline void afs_extract_to_tmp(struct afs_call *call)
12801282
{
1283+
call->iov_len = sizeof(call->tmp);
12811284
afs_extract_begin(call, &call->tmp, sizeof(call->tmp));
12821285
}
12831286

12841287
static inline void afs_extract_to_tmp64(struct afs_call *call)
12851288
{
1289+
call->iov_len = sizeof(call->tmp64);
12861290
afs_extract_begin(call, &call->tmp64, sizeof(call->tmp64));
12871291
}
12881292

12891293
static inline void afs_extract_discard(struct afs_call *call, size_t size)
12901294
{
1295+
call->iov_len = size;
12911296
iov_iter_discard(&call->def_iter, READ, size);
12921297
}
12931298

12941299
static inline void afs_extract_to_buf(struct afs_call *call, size_t size)
12951300
{
1301+
call->iov_len = size;
12961302
afs_extract_begin(call, call->buffer, size);
12971303
}
12981304

fs/afs/rxrpc.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
363363
struct rxrpc_call *rxcall;
364364
struct msghdr msg;
365365
struct kvec iov[1];
366+
size_t len;
366367
s64 tx_total_len;
367368
int ret;
368369

@@ -466,9 +467,10 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
466467
rxrpc_kernel_abort_call(call->net->socket, rxcall,
467468
RX_USER_ABORT, ret, "KSD");
468469
} else {
470+
len = 0;
469471
iov_iter_kvec(&msg.msg_iter, READ, NULL, 0, 0);
470472
rxrpc_kernel_recv_data(call->net->socket, rxcall,
471-
&msg.msg_iter, false,
473+
&msg.msg_iter, &len, false,
472474
&call->abort_code, &call->service_id);
473475
ac->abort_code = call->abort_code;
474476
ac->responded = true;
@@ -504,6 +506,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
504506
static void afs_deliver_to_call(struct afs_call *call)
505507
{
506508
enum afs_call_state state;
509+
size_t len;
507510
u32 abort_code, remote_abort = 0;
508511
int ret;
509512

@@ -516,10 +519,11 @@ static void afs_deliver_to_call(struct afs_call *call)
516519
state == AFS_CALL_SV_AWAIT_ACK
517520
) {
518521
if (state == AFS_CALL_SV_AWAIT_ACK) {
522+
len = 0;
519523
iov_iter_kvec(&call->def_iter, READ, NULL, 0, 0);
520524
ret = rxrpc_kernel_recv_data(call->net->socket,
521525
call->rxcall, &call->def_iter,
522-
false, &remote_abort,
526+
&len, false, &remote_abort,
523527
&call->service_id);
524528
trace_afs_receive_data(call, &call->def_iter, false, ret);
525529

@@ -929,10 +933,11 @@ int afs_extract_data(struct afs_call *call, bool want_more)
929933
u32 remote_abort = 0;
930934
int ret;
931935

932-
_enter("{%s,%zu},%d", call->type->name, iov_iter_count(iter), want_more);
936+
_enter("{%s,%zu,%zu},%d",
937+
call->type->name, call->iov_len, iov_iter_count(iter), want_more);
933938

934939
ret = rxrpc_kernel_recv_data(net->socket, call->rxcall, iter,
935-
want_more, &remote_abort,
940+
&call->iov_len, want_more, &remote_abort,
936941
&call->service_id);
937942
if (ret == 0 || ret == -EAGAIN)
938943
return ret;

fs/afs/yfsclient.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,9 @@ static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
363363
unsigned int size;
364364
int ret;
365365

366-
_enter("{%u,%zu/%llu}",
367-
call->unmarshall, iov_iter_count(call->iter), req->actual_len);
366+
_enter("{%u,%zu, %zu/%llu}",
367+
call->unmarshall, call->iov_len, iov_iter_count(call->iter),
368+
req->actual_len);
368369

369370
switch (call->unmarshall) {
370371
case 0:
@@ -396,6 +397,7 @@ static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
396397
size = PAGE_SIZE - req->offset;
397398
else
398399
size = req->remain;
400+
call->iov_len = size;
399401
call->bvec[0].bv_len = size;
400402
call->bvec[0].bv_offset = req->offset;
401403
call->bvec[0].bv_page = req->pages[req->index];

include/net/af_rxrpc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *,
5353
struct msghdr *, size_t,
5454
rxrpc_notify_end_tx_t);
5555
int rxrpc_kernel_recv_data(struct socket *, struct rxrpc_call *,
56-
struct iov_iter *, bool, u32 *, u16 *);
56+
struct iov_iter *, size_t *, bool, u32 *, u16 *);
5757
bool rxrpc_kernel_abort_call(struct socket *, struct rxrpc_call *,
5858
u32, int, const char *);
5959
void rxrpc_kernel_end_call(struct socket *, struct rxrpc_call *);

net/rxrpc/recvmsg.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
669669
* @sock: The socket that the call exists on
670670
* @call: The call to send data through
671671
* @iter: The buffer to receive into
672+
* @_len: The amount of data we want to receive (decreased on return)
672673
* @want_more: True if more data is expected to be read
673674
* @_abort: Where the abort code is stored if -ECONNABORTED is returned
674675
* @_service: Where to store the actual service ID (may be upgraded)
@@ -684,15 +685,15 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
684685
* *_abort should also be initialised to 0.
685686
*/
686687
int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,
687-
struct iov_iter *iter,
688+
struct iov_iter *iter, size_t *_len,
688689
bool want_more, u32 *_abort, u16 *_service)
689690
{
690691
size_t offset = 0;
691692
int ret;
692693

693694
_enter("{%d,%s},%zu,%d",
694695
call->debug_id, rxrpc_call_states[call->state],
695-
iov_iter_count(iter), want_more);
696+
*_len, want_more);
696697

697698
ASSERTCMP(call->state, !=, RXRPC_CALL_SERVER_SECURING);
698699

@@ -703,8 +704,8 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,
703704
case RXRPC_CALL_SERVER_RECV_REQUEST:
704705
case RXRPC_CALL_SERVER_ACK_REQUEST:
705706
ret = rxrpc_recvmsg_data(sock, call, NULL, iter,
706-
iov_iter_count(iter), 0,
707-
&offset);
707+
*_len, 0, &offset);
708+
*_len -= offset;
708709
if (ret < 0)
709710
goto out;
710711

0 commit comments

Comments
 (0)