diff options
author | Dmitry Antipov <dmantipov@yandex.ru> | 2020-06-22 16:43:26 +0300 |
---|---|---|
committer | Dmitry Antipov <dmantipov@yandex.ru> | 2020-06-22 17:16:26 +0300 |
commit | 9f0beedd556daabd2ef48e05ead3fdab68598d2a (patch) | |
tree | 5757646631283da880ba49304c0bf6ea68821e35 /libglusterfs/src/common-utils.c | |
parent | c18782bc91bb028fe206996a7ef0075beabdf067 (diff) |
storage/posix, libglusterfs: library function to sync filesystem
Convert an ad-hoc hack to a regular library function gf_syncfs().
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Change-Id: I3ed93e9f28f22c273df1466ba4a458eacb8df395
Fixes: #1329
Diffstat (limited to 'libglusterfs/src/common-utils.c')
-rw-r--r-- | libglusterfs/src/common-utils.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 899d579e837..81c39959406 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -37,6 +37,9 @@ #ifndef GF_LINUX_HOST_OS #include <sys/resource.h> #endif +#ifdef HAVE_SYNCFS_SYS +#include <sys/syscall.h> +#endif #include "glusterfs/compat-errno.h" #include "glusterfs/common-utils.h" @@ -5412,3 +5415,20 @@ gf_nanosleep(uint64_t nsec) return ret; } + +int +gf_syncfs(int fd) +{ + int ret = 0; +#if defined(HAVE_SYNCFS) + /* Linux with glibc recent enough. */ + ret = syncfs(fd); +#elif defined(HAVE_SYNCFS_SYS) + /* Linux with no library function. */ + ret = syscall(SYS_syncfs, fd); +#else + /* Fallback to generic UNIX stuff. */ + sync(); +#endif + return ret; +} |