summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2020-08-10 11:45:58 +0300
committerAmar Tumballi <amar@kadalu.io>2020-08-17 11:27:09 +0000
commit9978ceb26327de9545c6e0a4f9230b401e629793 (patch)
tree19468386ccc3f04bfc7a059d6de5710cfd1e88fd /libglusterfs
parent005d2ac1d8cc57e0e36f7cf230ae09a4f860bd16 (diff)
downloadglusterfs-9978ceb26327de9545c6e0a4f9230b401e629793.tar.gz
glusterfs-9978ceb26327de9545c6e0a4f9230b401e629793.tar.xz
glusterfs-9978ceb26327de9545c6e0a4f9230b401e629793.zip
libglusterfs: add library wrapper for time()
Add thin convenient library wrapper gf_time(), adjust related users and comments as well. Change-Id: If8969af2f45ee69c30c3406bce5baa8305fb7f80 Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Updates: #1002
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/common-utils.c6
-rw-r--r--libglusterfs/src/events.c2
-rw-r--r--libglusterfs/src/gidcache.c5
-rw-r--r--libglusterfs/src/glusterfs/common-utils.h6
-rw-r--r--libglusterfs/src/statedump.c2
-rw-r--r--libglusterfs/src/syncop.c2
6 files changed, 15 insertions, 8 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index c37c45449f..bff4c3d633 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -646,7 +646,7 @@ gf_rev_dns_lookup_cached(const char *ip, struct dnscache *dnscache)
if (entrydata) {
dnsentry = (struct dnscache_entry *)entrydata->data;
/* First check the TTL & timestamp */
- if (time(NULL) - dnsentry->timestamp > dnscache->ttl) {
+ if (gf_time() - dnsentry->timestamp > dnscache->ttl) {
gf_dnscache_entry_deinit(dnsentry);
entrydata->data = NULL; /* Mark this as 'null' so
* dict_del () doesn't try free
@@ -683,7 +683,7 @@ out:
if (entry) {
entry->fqdn = fqdn;
entry->ip = gf_strdup(ip);
- entry->timestamp = time(NULL);
+ entry->timestamp = gf_time();
entrydata = bin_to_data(entry, sizeof(*entry));
dict_set(cache, (char *)ip, entrydata);
}
@@ -935,7 +935,7 @@ gf_print_trace(int32_t signum, glusterfs_ctx_t *ctx)
{
/* Dump the timestamp of the crash too, so the previous logs
can be related */
- gf_time_fmt(timestr, sizeof timestr, time(NULL), gf_timefmt_FT);
+ gf_time_fmt(timestr, sizeof timestr, gf_time(), gf_timefmt_FT);
gf_msg_plain_nomem(GF_LOG_ALERT, "time of crash: ");
gf_msg_plain_nomem(GF_LOG_ALERT, timestr);
}
diff --git a/libglusterfs/src/events.c b/libglusterfs/src/events.c
index 6d1e383647..908a318a8a 100644
--- a/libglusterfs/src/events.c
+++ b/libglusterfs/src/events.c
@@ -93,7 +93,7 @@ _gf_event(eventtypes_t event, const char *fmt, ...)
goto out;
}
- ret = gf_asprintf(&eventstr, "%u %d %s", (unsigned)time(NULL), event, msg);
+ ret = gf_asprintf(&eventstr, "%u %d %s", (unsigned)gf_time(), event, msg);
GF_FREE(msg);
if (ret <= 0) {
ret = EVENT_ERROR_MSG_FORMAT;
diff --git a/libglusterfs/src/gidcache.c b/libglusterfs/src/gidcache.c
index 40fcffbb35..64a93802f7 100644
--- a/libglusterfs/src/gidcache.c
+++ b/libglusterfs/src/gidcache.c
@@ -10,6 +10,7 @@
#include "glusterfs/gidcache.h"
#include "glusterfs/mem-pool.h"
+#include "glusterfs/common-utils.h"
/*
* We treat this as a very simple set-associative LRU cache, with entries aged
@@ -64,7 +65,7 @@ gid_cache_lookup(gid_cache_t *cache, uint64_t id, uint64_t uid, uint64_t gid)
time_t now;
const gid_list_t *agl;
- now = time(NULL);
+ now = gf_time();
LOCK(&cache->gc_lock);
bucket = id % cache->gc_nbuckets;
agl = BUCKET_START(cache->gc_cache, bucket);
@@ -132,7 +133,7 @@ gid_cache_add(gid_cache_t *cache, gid_list_t *gl)
if (!cache->gc_max_age)
return 0;
- now = time(NULL);
+ now = gf_time();
LOCK(&cache->gc_lock);
/*
diff --git a/libglusterfs/src/glusterfs/common-utils.h b/libglusterfs/src/glusterfs/common-utils.h
index f05bda1f53..d605beae46 100644
--- a/libglusterfs/src/glusterfs/common-utils.h
+++ b/libglusterfs/src/glusterfs/common-utils.h
@@ -1213,4 +1213,10 @@ gf_syncfs(int fd);
int
gf_nanosleep(uint64_t nsec);
+static inline time_t
+gf_time(void)
+{
+ return time(NULL);
+}
+
#endif /* _COMMON_UTILS_H */
diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c
index 655317f3ef..68e0110402 100644
--- a/libglusterfs/src/statedump.c
+++ b/libglusterfs/src/statedump.c
@@ -843,7 +843,7 @@ gf_proc_dump_info(int signum, glusterfs_ctx_t *ctx)
? dump_options.dump_path
: ((ctx->statedump_path != NULL) ? ctx->statedump_path
: DEFAULT_VAR_RUN_DIRECTORY)),
- brick_name, getpid(), (uint64_t)time(NULL));
+ brick_name, getpid(), (uint64_t)gf_time());
if ((ret < 0) || (ret >= sizeof(path))) {
goto out;
}
diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c
index 95bea67537..df20cec559 100644
--- a/libglusterfs/src/syncop.c
+++ b/libglusterfs/src/syncop.c
@@ -593,7 +593,7 @@ syncenv_task(struct syncproc *proc)
env->procs_idle++;
- sleep_till.tv_sec = time(NULL) + SYNCPROC_IDLE_TIME;
+ sleep_till.tv_sec = gf_time() + SYNCPROC_IDLE_TIME;
ret = pthread_cond_timedwait(&env->cond, &env->mutex, &sleep_till);
env->procs_idle--;