Skip to content

Commit

Permalink
Addressed review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagendra Tomar committed Aug 9, 2024
1 parent 05af756 commit 32c70a6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
3 changes: 1 addition & 2 deletions include/libnfs-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,7 @@ void rpc_enqueue(struct rpc_queue *q, struct rpc_pdu *pdu);
void rpc_return_to_queue(struct rpc_queue *q, struct rpc_pdu *pdu);
unsigned int rpc_hash_xid(struct rpc_context *rpc, uint32_t xid);
struct rpc_pdu *rpc_allocate_pdu(struct rpc_context *rpc, int program, int version, int procedure, rpc_cb cb, void *private_data, zdrproc_t zdr_decode_fn, int zdr_bufsize);
struct rpc_pdu *rpc_allocate_pdu2(struct rpc_context *rpc, int program, int version, int procedure, rpc_cb cb, void *private_data, zdrproc_t zdr_decode_fn, int zdr_bufsize, size_t alloc_hint);
struct rpc_pdu *rpc_allocate_pdu3(struct rpc_context *rpc, int program, int version, int procedure, rpc_cb cb, void *private_data, zdrproc_t zdr_decode_fn, int zdr_bufsize, size_t alloc_hint, int iovcnt_hint);
struct rpc_pdu *rpc_allocate_pdu2(struct rpc_context *rpc, int program, int version, int procedure, rpc_cb cb, void *private_data, zdrproc_t zdr_decode_fn, int zdr_bufsize, size_t alloc_hint, int iovcnt_hint);
void pdu_set_timeout(struct rpc_context *rpc, struct rpc_pdu *pdu, uint64_t now_msecs);

void rpc_free_pdu(struct rpc_context *rpc, struct rpc_pdu *pdu);
Expand Down
20 changes: 10 additions & 10 deletions lib/pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static struct rpc_pdu *rpc_allocate_reply_pdu(struct rpc_context *rpc,
return pdu;
}

struct rpc_pdu *rpc_allocate_pdu3(struct rpc_context *rpc, int program, int version, int procedure, rpc_cb cb, void *private_data, zdrproc_t zdr_decode_fn, int zdr_decode_bufsize, size_t alloc_hint, int iovcnt_hint)
struct rpc_pdu *rpc_allocate_pdu2(struct rpc_context *rpc, int program, int version, int procedure, rpc_cb cb, void *private_data, zdrproc_t zdr_decode_fn, int zdr_decode_bufsize, size_t alloc_hint, int iovcnt_hint)
{
struct rpc_pdu *pdu;
struct rpc_msg msg;
Expand Down Expand Up @@ -198,13 +198,17 @@ struct rpc_pdu *rpc_allocate_pdu3(struct rpc_context *rpc, int program, int vers
pdu->zdr_decode_fn = zdr_decode_fn;
pdu->zdr_decode_bufsize = zdr_decode_bufsize;

if (iovcnt_hint > RPC_FAST_VECTORS) {
if (iovcnt_hint > RPC_FAST_VECTORS) {
pdu->out.iov = (struct rpc_iovec *) calloc(iovcnt_hint, sizeof(struct rpc_iovec));
if (pdu->out.iov == NULL) {
rpc_set_error(rpc, "Out of memory: Failed to allocate out.iov");
goto failed2;
}
pdu->out.iov_capacity = iovcnt_hint;
} else {
} else {
pdu->out.iov = pdu->out.fast_iov;
pdu->out.iov_capacity = RPC_FAST_VECTORS;
}
}

/*
* Rest of the code depends on this, so assert it here.
Expand Down Expand Up @@ -354,18 +358,14 @@ struct rpc_pdu *rpc_allocate_pdu3(struct rpc_context *rpc, int program, int vers
rpc_set_error(rpc, "zdr_callmsg failed with %s",
rpc_get_error(rpc));
zdr_destroy(&pdu->zdr);
failed2:
free(pdu);
return NULL;
}

struct rpc_pdu *rpc_allocate_pdu(struct rpc_context *rpc, int program, int version, int procedure, rpc_cb cb, void *private_data, zdrproc_t zdr_decode_fn, int zdr_decode_bufsize)
{
return rpc_allocate_pdu2(rpc, program, version, procedure, cb, private_data, zdr_decode_fn, zdr_decode_bufsize, 0);
}

struct rpc_pdu *rpc_allocate_pdu2(struct rpc_context *rpc, int program, int version, int procedure, rpc_cb cb, void *private_data, zdrproc_t zdr_decode_fn, int zdr_decode_bufsize, size_t alloc_hint)
{
return rpc_allocate_pdu3(rpc, program, version, procedure, cb, private_data, zdr_decode_fn, zdr_decode_bufsize, alloc_hint, 0);
return rpc_allocate_pdu2(rpc, program, version, procedure, cb, private_data, zdr_decode_fn, zdr_decode_bufsize, 0, 0);
}

void rpc_free_pdu(struct rpc_context *rpc, struct rpc_pdu *pdu)
Expand Down
12 changes: 11 additions & 1 deletion lib/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,17 @@ rpc_write_to_socket(struct rpc_context *rpc)
assert(iov == fast_iov);
iov = (struct iovec *) calloc(RPC_MAX_VECTORS,
sizeof(struct iovec));
iovcnt = RPC_MAX_VECTORS;
/*
* If allocation fails, continue with smaller iov.
* It'll require more writev() calls to send out one
* pdu, but it'll work.
*/
if (iov != NULL) {
iovcnt = RPC_MAX_VECTORS;
} else {
iov = fast_iov;
iovcnt = RPC_FAST_VECTORS;
}
}

do {
Expand Down
4 changes: 2 additions & 2 deletions nfs/nfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ struct rpc_pdu *rpc_nfs3_writev_task(struct rpc_context *rpc, rpc_cb cb,
* - NFS header
* - Padding (optional)
*/
pdu = rpc_allocate_pdu3(rpc, NFS_PROGRAM, NFS_V3, NFS3_WRITE, cb, private_data, (zdrproc_t)zdr_WRITE3res, sizeof(WRITE3res), 0, iovcnt + 4);
pdu = rpc_allocate_pdu2(rpc, NFS_PROGRAM, NFS_V3, NFS3_WRITE, cb, private_data, (zdrproc_t)zdr_WRITE3res, sizeof(WRITE3res), 0, iovcnt + 4);
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS3/WRITE call");
return NULL;
Expand Down Expand Up @@ -1032,7 +1032,7 @@ struct rpc_pdu *rpc_nfs2_write_task(struct rpc_context *rpc, rpc_cb cb,
{
struct rpc_pdu *pdu;

pdu = rpc_allocate_pdu2(rpc, NFS_PROGRAM, NFS_V2, NFS2_WRITE, cb, private_data, (zdrproc_t)zdr_WRITE2res, sizeof(WRITE2res), args->totalcount);
pdu = rpc_allocate_pdu2(rpc, NFS_PROGRAM, NFS_V2, NFS2_WRITE, cb, private_data, (zdrproc_t)zdr_WRITE2res, sizeof(WRITE2res), args->totalcount, 0);
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for NFS2/WRITE call");
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions nfs4/nfs4.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ struct rpc_pdu *rpc_nfs4_compound_task2(struct rpc_context *rpc, rpc_cb cb,
pdu = rpc_allocate_pdu2(rpc, NFS4_PROGRAM, NFS_V4, NFSPROC4_COMPOUND,
cb, private_data, (zdrproc_t)zdr_COMPOUND4res,
sizeof(COMPOUND4res),
alloc_hint);
alloc_hint, 0);
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for "
"NFS4/COMPOUND call");
Expand Down Expand Up @@ -281,7 +281,7 @@ struct rpc_pdu *rpc_nfs4_readv_task(struct rpc_context *rpc, rpc_cb cb,

pdu = rpc_allocate_pdu2(rpc, NFS4_PROGRAM, NFS_V4, NFSPROC4_COMPOUND,
cb, private_data, (zdrproc_t)zdr_COMPOUND4res,
sizeof(COMPOUND4res), 0);
sizeof(COMPOUND4res), 0, 0);
if (pdu == NULL) {
rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for "
"NFS4/COMPOUND call");
Expand Down Expand Up @@ -354,7 +354,7 @@ struct rpc_pdu *rpc_nfs4_writev_task(struct rpc_context *rpc, rpc_cb cb,
return NULL;
}

pdu = rpc_allocate_pdu3(rpc, NFS4_PROGRAM, NFS_V4, NFSPROC4_COMPOUND,
pdu = rpc_allocate_pdu2(rpc, NFS4_PROGRAM, NFS_V4, NFSPROC4_COMPOUND,
cb, private_data, (zdrproc_t)zdr_COMPOUND4res,
sizeof(COMPOUND4res), 0, iovcnt);
if (pdu == NULL) {
Expand Down

0 comments on commit 32c70a6

Please sign in to comment.