Skip to content

Commit

Permalink
Update KRB5P so we can use it with iovectors
Browse files Browse the repository at this point in the history
Though at the cost that it will not be zero-copy.
This brings the special handling in the pread callback to be identical
between v3 and v4.

Signed-off-by: sahlberg <sahlberg@nfs-client-1.nfs>
  • Loading branch information
sahlberg committed Aug 13, 2024
1 parent d61cfdd commit a806cf3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
27 changes: 24 additions & 3 deletions lib/nfs_v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -4498,6 +4498,9 @@ nfs3_pread_cb(struct rpc_context *rpc, int status, void *command_data,
}
#ifdef HAVE_LIBKRB5
if (rpc->sec == RPC_SEC_KRB5P) {
struct iovec *iov;
int idx, num, copied;

if (!zdr_uint32_t(&rpc->pdu->zdr, &rpc->pdu->read_count)) {
data->cb(-1, nfs, NULL, data->private_data);
free_nfs_cb_data(data);
Expand All @@ -4509,7 +4512,27 @@ nfs3_pread_cb(struct rpc_context *rpc, int status, void *command_data,
if (count > libnfs_zdr_getsize(&rpc->pdu->zdr) - libnfs_zdr_getpos(&rpc->pdu->zdr)) {
count = libnfs_zdr_getsize(&rpc->pdu->zdr) - libnfs_zdr_getpos(&rpc->pdu->zdr);
}
memcpy(data->buffer, libnfs_zdr_getptr(&rpc->pdu->zdr) + libnfs_zdr_getpos(&rpc->pdu->zdr), count);
iov = rpc->pdu->in.iov;
idx = rpc->pdu->in.iovcnt;
copied = 0;
while(count) {
num = count;
if (num > iov->iov_len) {
num = iov->iov_len;
}
printf("memcpy\n");

memcpy(iov->iov_base, libnfs_zdr_getptr(&rpc->pdu->zdr) + libnfs_zdr_getpos(&rpc->pdu->zdr), num);
libnfs_zdr_setpos(&rpc->pdu->zdr, libnfs_zdr_getpos(&rpc->pdu->zdr) + num);
count -= num;
copied += num;
iov++;
idx--;
if (idx == 0) {
break;
}
}
count = copied;
}
#endif /* HAVE_LIBKRB5 */

Expand Down Expand Up @@ -4544,8 +4567,6 @@ nfs3_pread_async_internal(struct nfs_context *nfs, struct nfsfh *nfsfh,
data->org_offset = offset;
data->org_count = count;
data->update_pos = update_pos;
data->buffer = buf;
data->not_my_buffer = 1;

assert(data->num_calls == 0);

Expand Down
25 changes: 22 additions & 3 deletions lib/nfs_v4.c
Original file line number Diff line number Diff line change
Expand Up @@ -2799,6 +2799,9 @@ nfs4_pread_cb(struct rpc_context *rpc, int status, void *command_data,

#ifdef HAVE_LIBKRB5
if (rpc->sec == RPC_SEC_KRB5P) {
struct iovec *iov;
int idx, num, copied;

if (!zdr_uint32_t(&rpc->pdu->zdr, &rpc->pdu->read_count)) {
data->cb(-1, nfs, NULL, data->private_data);
free_nfs4_cb_data(data);
Expand All @@ -2810,7 +2813,25 @@ nfs4_pread_cb(struct rpc_context *rpc, int status, void *command_data,
if (count > libnfs_zdr_getsize(&rpc->pdu->zdr) - libnfs_zdr_getpos(&rpc->pdu->zdr)) {
count = libnfs_zdr_getsize(&rpc->pdu->zdr) - libnfs_zdr_getpos(&rpc->pdu->zdr);
}
memcpy(data->filler.blob1.val, libnfs_zdr_getptr(&rpc->pdu->zdr) + libnfs_zdr_getpos(&rpc->pdu->zdr), count);
iov = rpc->pdu->in.iov;
idx = rpc->pdu->in.iovcnt;
copied = 0;
while(count) {
num = count;
if (num > iov->iov_len) {
num = iov->iov_len;
}
memcpy(iov->iov_base, libnfs_zdr_getptr(&rpc->pdu->zdr) + libnfs_zdr_getpos(&rpc->pdu->zdr), num);
libnfs_zdr_setpos(&rpc->pdu->zdr, libnfs_zdr_getpos(&rpc->pdu->zdr) + num);
count -= num;
copied += num;
iov++;
idx--;
if (idx == 0) {
break;
}
}
count = copied;
}
#endif /* HAVE_LIBKRB5 */

Expand Down Expand Up @@ -2842,8 +2863,6 @@ nfs4_pread_async_internal(struct nfs_context *nfs, struct nfsfh *nfsfh,

data->filler.blob0.val = nfsfh;
data->filler.blob0.free = NULL;
data->filler.blob1.val = buf;
data->filler.blob1.free = NULL;
data->rw_data.offset = offset;
data->rw_data.update_pos = update_pos;

Expand Down
4 changes: 0 additions & 4 deletions nfs/nfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,6 @@ rpc_nfs3_readv_task(struct rpc_context *rpc, rpc_cb cb,
struct rpc_pdu *pdu;
int i;

/*
* TODO: We never use iov for KRB5P so we should prepare this function
* to accept iov == NULL
*/
if (iovcnt == 0 || iov == NULL) {
rpc_set_error(rpc, "Invalid arguments: iov and iovcnt must be specified");
return NULL;
Expand Down
4 changes: 0 additions & 4 deletions nfs4/nfs4.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@ struct rpc_pdu *rpc_nfs4_readv_task(struct rpc_context *rpc, rpc_cb cb,
struct rpc_pdu *pdu;
int i;

/*
* TODO: We never use iov for KRB5P so we should prepare this function
* to accept iov == NULL
*/
if (iovcnt == 0 || iov == NULL) {
rpc_set_error(rpc, "Invalid arguments: iov and iovcnt must be specified");
return NULL;
Expand Down

0 comments on commit a806cf3

Please sign in to comment.