summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorVijay Bellur <vbellur@redhat.com>2019-06-20 15:50:01 -0700
committerXavi Hernandez <xhernandez@redhat.com>2019-07-11 10:37:52 +0000
commit3c1efa0c92445638bbfa57c2e868c79f7d987fc3 (patch)
tree3cc28f420d5aebe771de4985fc669dd99e8a42fa /libglusterfs
parentb82743a5822626e83b233956803421fda9b1c3f9 (diff)
Replace usleep() with nanosleep()
As usleep has been obsoleted, changed all invocations of usleep to nanosleep. From man 3 usleep: "4.3BSD, POSIX.1-2001. POSIX.1-2001 declares this function obsolete; use nanosleep(2) instead. POSIX.1-2008 removes the specification of usleep()." Added a helper function gf_nanosleep() to have a single place for handling edge cases that might arise from the conversion of usleep to nanosleep and allow the sleep to resume with right remaining value upon being interrupted. Fixes: bz#1721686 Change-Id: Ia39ab82c9e0f4669d2c00d4cdf25e38d94ef9f62 Signed-off-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/common-utils.c18
-rw-r--r--libglusterfs/src/glusterfs/common-utils.h6
-rw-r--r--libglusterfs/src/libglusterfs.sym1
-rw-r--r--libglusterfs/src/throttle-tbf.c2
4 files changed, 26 insertions, 1 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 8e2ffa3accd..132e63e520a 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -5421,3 +5421,21 @@ gf_d_type_from_ia_type(ia_type_t type)
return DT_UNKNOWN;
}
}
+
+int
+gf_nanosleep(uint64_t nsec)
+{
+ struct timespec req;
+ struct timespec rem;
+ int ret = -1;
+
+ req.tv_sec = nsec / GF_SEC_IN_NS;
+ req.tv_nsec = nsec % GF_SEC_IN_NS;
+
+ do {
+ ret = nanosleep(&req, &rem);
+ req = rem;
+ } while (ret == -1 && errno == EINTR);
+
+ return ret;
+}
diff --git a/libglusterfs/src/glusterfs/common-utils.h b/libglusterfs/src/glusterfs/common-utils.h
index 41328496e6d..b184031e565 100644
--- a/libglusterfs/src/glusterfs/common-utils.h
+++ b/libglusterfs/src/glusterfs/common-utils.h
@@ -115,6 +115,9 @@ trap(void);
#define GF_HOUR_IN_SECONDS (60 * 60)
#define GF_DAY_IN_SECONDS (24 * 60 * 60)
#define GF_WEEK_IN_SECONDS (7 * 24 * 60 * 60)
+#define GF_SEC_IN_NS 1000000000
+#define GF_MS_IN_NS 1000000
+#define GF_US_IN_NS 1000
/* Default timeout for both barrier and changelog translator */
#define BARRIER_TIMEOUT "120"
@@ -1165,4 +1168,7 @@ find_xlator_option_in_cmd_args_t(const char *option_name, cmd_args_t *args);
int
gf_d_type_from_ia_type(ia_type_t type);
+int
+gf_nanosleep(uint64_t nsec);
+
#endif /* _COMMON_UTILS_H */
diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym
index 188cda27bc5..0e24630c6d5 100644
--- a/libglusterfs/src/libglusterfs.sym
+++ b/libglusterfs/src/libglusterfs.sym
@@ -1166,3 +1166,4 @@ glusterfs_mux_volfile_reconfigure
glusterfs_process_svc_detach
mgmt_is_multiplexed_daemon
xlator_is_cleanup_starting
+gf_nanosleep
diff --git a/libglusterfs/src/throttle-tbf.c b/libglusterfs/src/throttle-tbf.c
index 81efebd7efe..e11ca4f9d35 100644
--- a/libglusterfs/src/throttle-tbf.c
+++ b/libglusterfs/src/throttle-tbf.c
@@ -99,7 +99,7 @@ tbf_tokengenerator(void *arg)
token_gen_interval = bucket->token_gen_interval;
while (1) {
- usleep(token_gen_interval);
+ gf_nanosleep(token_gen_interval * GF_US_IN_NS);
LOCK(&bucket->lock);
{