Skip to content

Commit

Permalink
Merge pull request #413 from Peter-JanGootzen/rebased
Browse files Browse the repository at this point in the history
Added NFS 4.1 operations, fixed incomplete open_claim4 and added poll_timeout param
  • Loading branch information
sahlberg authored Dec 10, 2022
2 parents ba05c61 + a2b2fb0 commit 7e91d04
Show file tree
Hide file tree
Showing 9 changed files with 767 additions and 8 deletions.
3 changes: 3 additions & 0 deletions include/libnfs-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ struct rpc_context {
uint64_t last_timeout_scan;
int timeout;
char ifname[IFNAMSIZ];
int poll_timeout;

/* Is a server context ? */
int is_server_context;
Expand Down Expand Up @@ -271,6 +272,8 @@ void rpc_set_pagecache(struct rpc_context *rpc, uint32_t v);
void rpc_set_pagecache_ttl(struct rpc_context *rpc, uint32_t v);
void rpc_set_readahead(struct rpc_context *rpc, uint32_t v);
void rpc_set_debug(struct rpc_context *rpc, int level);
void rpc_set_poll_timeout(struct rpc_context *rpc, int poll_timeout);
int rpc_get_poll_timeout(struct rpc_context *rpc);
void rpc_set_timeout(struct rpc_context *rpc, int timeout);
int rpc_get_timeout(struct rpc_context *rpc);
int rpc_add_fragment(struct rpc_context *rpc, char *data, uint32_t size);
Expand Down
21 changes: 21 additions & 0 deletions include/nfsc/libnfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,27 @@ struct nfs_server_list {
struct nfs_server_list *nfs_find_local_servers(void);
void free_nfs_srvr_list(struct nfs_server_list *srv);

/*
* nfs_set_poll_timeout()
* This function sets the polling timeout used for nfs rpc calls.
*
* Function returns nothing.
*
* int milliseconds : timeout that is passed to poll(2)
* to be applied in milliseconds (-1 no timeout)
*/
EXTERN void nfs_set_poll_timeout(struct nfs_context *nfs, int milliseconds);

/*
* nfs_get_poll_timeout()
* This function gets the polling timeout used for nfs rpc calls.
*
* Function returns:
* int milliseconds : timeout that is passed to poll(2)
* to be applied in milliseconds (-1 no timeout)
*/
EXTERN int nfs_get_poll_timeout(struct nfs_context *nfs);

/*
* sync nfs_set_timeout()
* This function sets the timeout used for nfs rpc calls.
Expand Down
16 changes: 16 additions & 0 deletions lib/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ struct rpc_context *rpc_init_context(void)

/* Default is no timeout */
rpc->timeout = -1;
/* Default is to timeout after 100ms of poll(2) */
rpc->poll_timeout = 100;

return rpc;
}
Expand Down Expand Up @@ -472,6 +474,20 @@ void rpc_destroy_context(struct rpc_context *rpc)
free(rpc);
}

void rpc_set_poll_timeout(struct rpc_context *rpc, int poll_timeout)
{
assert(rpc->magic == RPC_CONTEXT_MAGIC);

rpc->poll_timeout = poll_timeout;
}

int rpc_get_poll_timeout(struct rpc_context *rpc)
{
assert(rpc->magic == RPC_CONTEXT_MAGIC);

return rpc->poll_timeout;
}

void rpc_set_timeout(struct rpc_context *rpc, int timeout)
{
assert(rpc->magic == RPC_CONTEXT_MAGIC);
Expand Down
4 changes: 2 additions & 2 deletions lib/libnfs-sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ wait_for_reply(struct rpc_context *rpc, struct sync_cb_data *cb_data)
pfd.events = rpc_which_events(rpc);
pfd.revents = 0;

ret = poll(&pfd, 1, 100);
ret = poll(&pfd, 1, rpc->poll_timeout);
if (ret < 0) {
rpc_set_error(rpc, "Poll failed");
revents = -1;
Expand Down Expand Up @@ -271,7 +271,7 @@ wait_for_nfs_reply(struct nfs_context *nfs, struct sync_cb_data *cb_data)
pfd.events = nfs_which_events(nfs);
pfd.revents = 0;

ret = poll(&pfd, 1, 100);
ret = poll(&pfd, 1, nfs->rpc->poll_timeout);
if (ret < 0) {
nfs_set_error(nfs, "Poll failed");
revents = -1;
Expand Down
20 changes: 19 additions & 1 deletion lib/libnfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2155,13 +2155,31 @@ nfs_umask(struct nfs_context *nfs, uint16_t mask) {
return tmp;
}

/*
* Sets polling timeout for nfs apis
*/
void
nfs_set_poll_timeout(struct nfs_context *nfs, int poll_timeout)
{
rpc_set_timeout(nfs->rpc,poll_timeout);
}

/*
* Gets polling timeout for nfs apis
*/
int
nfs_get_poll_timeout(struct nfs_context *nfs)
{
return rpc_get_poll_timeout(nfs->rpc);
}

/*
* Sets timeout for nfs apis
*/
void
nfs_set_timeout(struct nfs_context *nfs,int timeout)
{
rpc_set_timeout(nfs->rpc,timeout);
rpc_set_timeout(nfs->rpc,timeout);
}

/*
Expand Down
5 changes: 2 additions & 3 deletions lib/multithreading.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ static void *nfs_mt_service_thread(void *arg)
pfd.fd = nfs_get_fd(nfs);
pfd.events = nfs_which_events(nfs);
pfd.revents = 0;

// Wake up at least every 100ms to process timeouts.
ret = poll(&pfd, 1, 100);

ret = poll(&pfd, 1, nfs->rpc->poll_timeout);
if (ret < 0) {
nfs_set_error(nfs, "Poll failed");
revents = -1;
Expand Down
Loading

0 comments on commit 7e91d04

Please sign in to comment.