Use clock_gettime(CLOCK_MONOTONIC_COARSE) if/when available
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>libnfs-4.0.0-vitalif
parent
14adfbfc4b
commit
2db0878396
14
configure.ac
14
configure.ac
|
@ -192,6 +192,20 @@ AC_CHECK_MEMBER([struct sockaddr_storage.ss_family],
|
|||
#include <sys/socket.h>
|
||||
])
|
||||
|
||||
# check for clock_gettime(CLOCK_MONOTONIC_COARSE)
|
||||
AC_MSG_CHECKING(if clock_gettime(CLOCK_MONOTONIC_COARSE) is available)
|
||||
AC_TRY_COMPILE([#include <time.h>], [
|
||||
int i = clock_gettime(CLOCK_MONOTONIC_COARSE, NULL);
|
||||
], ac_cv_have_clock_gettime=yes, ac_cv_have_clock_gettime=no)
|
||||
if test "$ac_cv_have_clock_gettime" = yes ; then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Whether we have clock_gettime])
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
AC_MSG_NOTICE(clock_gettime(CLOCK_MONOTONIC_COARSE) support is missing.)
|
||||
AC_MSG_NOTICE(Compiling without clock_gettime support..)
|
||||
fi
|
||||
|
||||
# check for tevent + talloc
|
||||
AC_CACHE_CHECK([for talloc and tevent support],libnfs_cv_HAVE_TALLOC_TEVENT,[
|
||||
AC_TRY_COMPILE([
|
||||
|
|
|
@ -233,6 +233,7 @@ int rpc_get_timeout(struct rpc_context *rpc);
|
|||
int rpc_add_fragment(struct rpc_context *rpc, char *data, uint32_t size);
|
||||
void rpc_free_all_fragments(struct rpc_context *rpc);
|
||||
int rpc_is_udp_socket(struct rpc_context *rpc);
|
||||
int rpc_current_time(void);
|
||||
|
||||
const struct nfs_fh3 *nfs_get_rootfh(struct nfs_context *nfs);
|
||||
|
||||
|
|
14
lib/init.c
14
lib/init.c
|
@ -50,6 +50,18 @@
|
|||
#include "libnfs-raw.h"
|
||||
#include "libnfs-private.h"
|
||||
|
||||
int rpc_current_time(void)
|
||||
{
|
||||
#ifdef HAVE_CLOCK_GETTIME
|
||||
struct timespec tp;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC_COARSE, &tp);
|
||||
return tp.tv_sec;
|
||||
#else
|
||||
return time(NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct rpc_context *rpc_init_context(void)
|
||||
{
|
||||
struct rpc_context *rpc;
|
||||
|
@ -69,7 +81,7 @@ struct rpc_context *rpc_init_context(void)
|
|||
free(rpc);
|
||||
return NULL;
|
||||
}
|
||||
rpc->xid = salt + time(NULL) + (getpid() << 16);
|
||||
rpc->xid = salt + rpc_current_time() + (getpid() << 16);
|
||||
salt += 0x01000000;
|
||||
rpc->fd = -1;
|
||||
rpc->tcp_syncnt = RPC_PARAM_UNDEFINED;
|
||||
|
|
|
@ -556,7 +556,7 @@ struct AUTH *libnfs_authunix_create(const char *host, uint32_t uid, uint32_t gid
|
|||
memset(auth->ah_cred.oa_base, 0x00, size);
|
||||
buf = (uint32_t *)(void *)auth->ah_cred.oa_base;
|
||||
idx = 0;
|
||||
buf[idx++] = htonl(time(NULL));
|
||||
buf[idx++] = htonl(rpc_current_time());
|
||||
buf[idx++] = htonl(strlen(host));
|
||||
memcpy(&buf[2], host, strlen(host));
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@ void nfs_pagecache_invalidate(struct nfs_context *nfs, struct nfsfh *nfsfh) {
|
|||
}
|
||||
|
||||
static void nfs_pagecache_put(struct nfs_pagecache *pagecache, uint64_t offset, const char *buf, size_t len) {
|
||||
time_t ts = pagecache->ttl ? time(NULL) : 1;
|
||||
time_t ts = pagecache->ttl ? rpc_current_time() : 1;
|
||||
if (!pagecache->num_entries) return;
|
||||
while (len > 0) {
|
||||
uint64_t page_offset = offset & ~(NFS_BLKSIZE - 1);
|
||||
|
@ -256,7 +256,10 @@ char *nfs_pagecache_get(struct nfs_pagecache *pagecache, uint64_t offset) {
|
|||
if (!e->ts) {
|
||||
return NULL;
|
||||
}
|
||||
if (pagecache->ttl && time(NULL) - e->ts > pagecache->ttl) return NULL;
|
||||
if (pagecache->ttl && rpc_current_time() - e->ts > pagecache->ttl) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return e->buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ int rpc_queue_pdu(struct rpc_context *rpc, struct rpc_pdu *pdu)
|
|||
assert(rpc->magic == RPC_CONTEXT_MAGIC);
|
||||
|
||||
if (rpc->timeout > 0) {
|
||||
pdu->timeout = time(NULL) + rpc->timeout / 1000;
|
||||
pdu->timeout = rpc_current_time() + rpc->timeout / 1000;
|
||||
} else {
|
||||
pdu->timeout = 0;
|
||||
}
|
||||
|
|
|
@ -349,7 +349,7 @@ rpc_timeout_scan(struct rpc_context *rpc)
|
|||
{
|
||||
struct rpc_pdu *pdu;
|
||||
struct rpc_pdu *next_pdu;
|
||||
time_t t = time(NULL);
|
||||
time_t t = rpc_current_time();
|
||||
unsigned int i;
|
||||
|
||||
for (pdu = rpc->outqueue.head; pdu; pdu = next_pdu) {
|
||||
|
@ -589,7 +589,7 @@ static int rpc_connect_sockaddr_async(struct rpc_context *rpc)
|
|||
int startOfs, port, rc;
|
||||
|
||||
if (portOfs == 0) {
|
||||
portOfs = time(NULL) % 400;
|
||||
portOfs = rpc_current_time() % 400;
|
||||
}
|
||||
startOfs = portOfs;
|
||||
do {
|
||||
|
|
Loading…
Reference in New Issue