Skip to content

Commit

Permalink
afs: Set up the iov_iter before calling afs_extract_data()
Browse files Browse the repository at this point in the history
afs_extract_data sets up a temporary iov_iter and passes it to AF_RXRPC
each time it is called to describe the remaining buffer to be filled.

Instead:

 (1) Put an iterator in the afs_call struct.

 (2) Set the iterator for each marshalling stage to load data into the
     appropriate places.  A number of convenience functions are provided to
     this end (eg. afs_extract_to_buf()).

     This iterator is then passed to afs_extract_data().

 (3) Use the new ITER_DISCARD iterator to discard any excess data provided
     by FetchData.

Signed-off-by: David Howells <dhowells@redhat.com>
  • Loading branch information
David Howells committed Oct 23, 2018
1 parent 160cb95 commit 12bdcf3
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 309 deletions.
40 changes: 18 additions & 22 deletions fs/afs/cmservice.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ static int afs_deliver_cb_callback(struct afs_call *call)

switch (call->unmarshall) {
case 0:
call->offset = 0;
afs_extract_to_tmp(call);
call->unmarshall++;

/* extract the FID array and its count in two steps */
case 1:
_debug("extract FID count");
ret = afs_extract_data(call, &call->tmp, 4, true);
ret = afs_extract_data(call, true);
if (ret < 0)
return ret;

Expand All @@ -196,13 +196,12 @@ static int afs_deliver_cb_callback(struct afs_call *call)
GFP_KERNEL);
if (!call->buffer)
return -ENOMEM;
call->offset = 0;
afs_extract_to_buf(call, call->count * 3 * 4);
call->unmarshall++;

case 2:
_debug("extract FID array");
ret = afs_extract_data(call, call->buffer,
call->count * 3 * 4, true);
ret = afs_extract_data(call, true);
if (ret < 0)
return ret;

Expand All @@ -222,13 +221,13 @@ static int afs_deliver_cb_callback(struct afs_call *call)
cb->cb.type = AFSCM_CB_UNTYPED;
}

call->offset = 0;
afs_extract_to_tmp(call);
call->unmarshall++;

/* extract the callback array and its count in two steps */
case 3:
_debug("extract CB count");
ret = afs_extract_data(call, &call->tmp, 4, true);
ret = afs_extract_data(call, true);
if (ret < 0)
return ret;

Expand All @@ -237,13 +236,12 @@ static int afs_deliver_cb_callback(struct afs_call *call)
if (call->count2 != call->count && call->count2 != 0)
return afs_protocol_error(call, -EBADMSG,
afs_eproto_cb_count);
call->offset = 0;
afs_extract_to_buf(call, call->count2 * 3 * 4);
call->unmarshall++;

case 4:
_debug("extract CB array");
ret = afs_extract_data(call, call->buffer,
call->count2 * 3 * 4, false);
ret = afs_extract_data(call, false);
if (ret < 0)
return ret;

Expand All @@ -256,7 +254,6 @@ static int afs_deliver_cb_callback(struct afs_call *call)
cb->cb.type = ntohl(*bp++);
}

call->offset = 0;
call->unmarshall++;
case 5:
break;
Expand Down Expand Up @@ -303,7 +300,8 @@ static int afs_deliver_cb_init_call_back_state(struct afs_call *call)

rxrpc_kernel_get_peer(call->net->socket, call->rxcall, &srx);

ret = afs_extract_data(call, NULL, 0, false);
afs_extract_discard(call, 0);
ret = afs_extract_data(call, false);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -332,16 +330,15 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)

switch (call->unmarshall) {
case 0:
call->offset = 0;
call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
if (!call->buffer)
return -ENOMEM;
afs_extract_to_buf(call, 11 * sizeof(__be32));
call->unmarshall++;

case 1:
_debug("extract UUID");
ret = afs_extract_data(call, call->buffer,
11 * sizeof(__be32), false);
ret = afs_extract_data(call, false);
switch (ret) {
case 0: break;
case -EAGAIN: return 0;
Expand All @@ -364,7 +361,6 @@ static int afs_deliver_cb_init_call_back_state3(struct afs_call *call)
for (loop = 0; loop < 6; loop++)
r->node[loop] = ntohl(b[loop + 5]);

call->offset = 0;
call->unmarshall++;

case 2:
Expand Down Expand Up @@ -407,7 +403,8 @@ static int afs_deliver_cb_probe(struct afs_call *call)

_enter("");

ret = afs_extract_data(call, NULL, 0, false);
afs_extract_discard(call, 0);
ret = afs_extract_data(call, false);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -455,16 +452,15 @@ static int afs_deliver_cb_probe_uuid(struct afs_call *call)

switch (call->unmarshall) {
case 0:
call->offset = 0;
call->buffer = kmalloc_array(11, sizeof(__be32), GFP_KERNEL);
if (!call->buffer)
return -ENOMEM;
afs_extract_to_buf(call, 11 * sizeof(__be32));
call->unmarshall++;

case 1:
_debug("extract UUID");
ret = afs_extract_data(call, call->buffer,
11 * sizeof(__be32), false);
ret = afs_extract_data(call, false);
switch (ret) {
case 0: break;
case -EAGAIN: return 0;
Expand All @@ -487,7 +483,6 @@ static int afs_deliver_cb_probe_uuid(struct afs_call *call)
for (loop = 0; loop < 6; loop++)
r->node[loop] = ntohl(b[loop + 5]);

call->offset = 0;
call->unmarshall++;

case 2:
Expand Down Expand Up @@ -572,7 +567,8 @@ static int afs_deliver_cb_tell_me_about_yourself(struct afs_call *call)

_enter("");

ret = afs_extract_data(call, NULL, 0, false);
afs_extract_discard(call, 0);
ret = afs_extract_data(call, false);
if (ret < 0)
return ret;

Expand Down
Loading

0 comments on commit 12bdcf3

Please sign in to comment.