Skip to content

Commit 7e91d04

Browse files
authored
Merge pull request #413 from Peter-JanGootzen/rebased
Added NFS 4.1 operations, fixed incomplete open_claim4 and added poll_timeout param
2 parents ba05c61 + a2b2fb0 commit 7e91d04

9 files changed

Lines changed: 767 additions & 8 deletions

File tree

include/libnfs-private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ struct rpc_context {
166166
uint64_t last_timeout_scan;
167167
int timeout;
168168
char ifname[IFNAMSIZ];
169+
int poll_timeout;
169170

170171
/* Is a server context ? */
171172
int is_server_context;
@@ -271,6 +272,8 @@ void rpc_set_pagecache(struct rpc_context *rpc, uint32_t v);
271272
void rpc_set_pagecache_ttl(struct rpc_context *rpc, uint32_t v);
272273
void rpc_set_readahead(struct rpc_context *rpc, uint32_t v);
273274
void rpc_set_debug(struct rpc_context *rpc, int level);
275+
void rpc_set_poll_timeout(struct rpc_context *rpc, int poll_timeout);
276+
int rpc_get_poll_timeout(struct rpc_context *rpc);
274277
void rpc_set_timeout(struct rpc_context *rpc, int timeout);
275278
int rpc_get_timeout(struct rpc_context *rpc);
276279
int rpc_add_fragment(struct rpc_context *rpc, char *data, uint32_t size);

include/nfsc/libnfs.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,27 @@ struct nfs_server_list {
19881988
struct nfs_server_list *nfs_find_local_servers(void);
19891989
void free_nfs_srvr_list(struct nfs_server_list *srv);
19901990

1991+
/*
1992+
* nfs_set_poll_timeout()
1993+
* This function sets the polling timeout used for nfs rpc calls.
1994+
*
1995+
* Function returns nothing.
1996+
*
1997+
* int milliseconds : timeout that is passed to poll(2)
1998+
* to be applied in milliseconds (-1 no timeout)
1999+
*/
2000+
EXTERN void nfs_set_poll_timeout(struct nfs_context *nfs, int milliseconds);
2001+
2002+
/*
2003+
* nfs_get_poll_timeout()
2004+
* This function gets the polling timeout used for nfs rpc calls.
2005+
*
2006+
* Function returns:
2007+
* int milliseconds : timeout that is passed to poll(2)
2008+
* to be applied in milliseconds (-1 no timeout)
2009+
*/
2010+
EXTERN int nfs_get_poll_timeout(struct nfs_context *nfs);
2011+
19912012
/*
19922013
* sync nfs_set_timeout()
19932014
* This function sets the timeout used for nfs rpc calls.

lib/init.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ struct rpc_context *rpc_init_context(void)
147147

148148
/* Default is no timeout */
149149
rpc->timeout = -1;
150+
/* Default is to timeout after 100ms of poll(2) */
151+
rpc->poll_timeout = 100;
150152

151153
return rpc;
152154
}
@@ -472,6 +474,20 @@ void rpc_destroy_context(struct rpc_context *rpc)
472474
free(rpc);
473475
}
474476

477+
void rpc_set_poll_timeout(struct rpc_context *rpc, int poll_timeout)
478+
{
479+
assert(rpc->magic == RPC_CONTEXT_MAGIC);
480+
481+
rpc->poll_timeout = poll_timeout;
482+
}
483+
484+
int rpc_get_poll_timeout(struct rpc_context *rpc)
485+
{
486+
assert(rpc->magic == RPC_CONTEXT_MAGIC);
487+
488+
return rpc->poll_timeout;
489+
}
490+
475491
void rpc_set_timeout(struct rpc_context *rpc, int timeout)
476492
{
477493
assert(rpc->magic == RPC_CONTEXT_MAGIC);

lib/libnfs-sync.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ wait_for_reply(struct rpc_context *rpc, struct sync_cb_data *cb_data)
225225
pfd.events = rpc_which_events(rpc);
226226
pfd.revents = 0;
227227

228-
ret = poll(&pfd, 1, 100);
228+
ret = poll(&pfd, 1, rpc->poll_timeout);
229229
if (ret < 0) {
230230
rpc_set_error(rpc, "Poll failed");
231231
revents = -1;
@@ -271,7 +271,7 @@ wait_for_nfs_reply(struct nfs_context *nfs, struct sync_cb_data *cb_data)
271271
pfd.events = nfs_which_events(nfs);
272272
pfd.revents = 0;
273273

274-
ret = poll(&pfd, 1, 100);
274+
ret = poll(&pfd, 1, nfs->rpc->poll_timeout);
275275
if (ret < 0) {
276276
nfs_set_error(nfs, "Poll failed");
277277
revents = -1;

lib/libnfs.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2155,13 +2155,31 @@ nfs_umask(struct nfs_context *nfs, uint16_t mask) {
21552155
return tmp;
21562156
}
21572157

2158+
/*
2159+
* Sets polling timeout for nfs apis
2160+
*/
2161+
void
2162+
nfs_set_poll_timeout(struct nfs_context *nfs, int poll_timeout)
2163+
{
2164+
rpc_set_timeout(nfs->rpc,poll_timeout);
2165+
}
2166+
2167+
/*
2168+
* Gets polling timeout for nfs apis
2169+
*/
2170+
int
2171+
nfs_get_poll_timeout(struct nfs_context *nfs)
2172+
{
2173+
return rpc_get_poll_timeout(nfs->rpc);
2174+
}
2175+
21582176
/*
21592177
* Sets timeout for nfs apis
21602178
*/
21612179
void
21622180
nfs_set_timeout(struct nfs_context *nfs,int timeout)
21632181
{
2164-
rpc_set_timeout(nfs->rpc,timeout);
2182+
rpc_set_timeout(nfs->rpc,timeout);
21652183
}
21662184

21672185
/*

lib/multithreading.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ static void *nfs_mt_service_thread(void *arg)
8484
pfd.fd = nfs_get_fd(nfs);
8585
pfd.events = nfs_which_events(nfs);
8686
pfd.revents = 0;
87-
88-
// Wake up at least every 100ms to process timeouts.
89-
ret = poll(&pfd, 1, 100);
87+
88+
ret = poll(&pfd, 1, nfs->rpc->poll_timeout);
9089
if (ret < 0) {
9190
nfs_set_error(nfs, "Poll failed");
9291
revents = -1;

0 commit comments

Comments
 (0)