summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2020-06-22 16:43:26 +0300
committerDmitry Antipov <dmantipov@yandex.ru>2020-06-22 17:16:26 +0300
commit9f0beedd556daabd2ef48e05ead3fdab68598d2a (patch)
tree5757646631283da880ba49304c0bf6ea68821e35
parentc18782bc91bb028fe206996a7ef0075beabdf067 (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
-rw-r--r--configure.ac13
-rw-r--r--libglusterfs/src/common-utils.c20
-rw-r--r--libglusterfs/src/glusterfs/common-utils.h3
-rw-r--r--libglusterfs/src/libglusterfs.sym1
-rw-r--r--xlators/storage/posix/src/posix-helpers.c19
5 files changed, 39 insertions, 17 deletions
diff --git a/configure.ac b/configure.ac
index d24a7b5..c2dc202 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1037,6 +1037,19 @@ else
CFLAGS=${OLD_CFLAGS}
fi
+AC_CHECK_FUNC([syncfs], [have_syncfs=yes])
+if test "x${have_syncfs}" = "xyes"; then
+ AC_DEFINE(HAVE_SYNCFS, 1, [define if syncfs exists])
+else
+ OLD_CFLAGS=${CFLAGS}
+ CFLAGS="-D_GNU_SOURCE"
+ AC_CHECK_DECL([SYS_syncfs], , , [#include <sys/syscall.h>])
+ if test "x${ac_cv_have_decl_SYS_syncfs}" = "xyes"; then
+ AC_DEFINE(HAVE_SYNCFS_SYS, 1, [define if SYS_syncfs is available])
+ fi
+ CFLAGS=${OLD_CFLAGS}
+fi
+
BUILD_NANOSECOND_TIMESTAMPS=no
AC_CHECK_FUNC([utimensat], [have_utimensat=yes])
if test "x${have_utimensat}" = "xyes"; then
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 899d579..81c3995 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;
+}
diff --git a/libglusterfs/src/glusterfs/common-utils.h b/libglusterfs/src/glusterfs/common-utils.h
index 1954cca..8948fad 100644
--- a/libglusterfs/src/glusterfs/common-utils.h
+++ b/libglusterfs/src/glusterfs/common-utils.h
@@ -1205,6 +1205,9 @@ int
gf_d_type_from_ia_type(ia_type_t type);
int
+gf_syncfs(int fd);
+
+int
gf_nanosleep(uint64_t nsec);
#endif /* _COMMON_UTILS_H */
diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym
index c80b892..7040871 100644
--- a/libglusterfs/src/libglusterfs.sym
+++ b/libglusterfs/src/libglusterfs.sym
@@ -1180,4 +1180,5 @@ glusterfs_process_svc_detach
mgmt_is_multiplexed_daemon
xlator_is_cleanup_starting
gf_nanosleep
+gf_syncfs
graph_total_client_xlator
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index 73443a6..7f69afe 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -2395,23 +2395,8 @@ posix_fsyncer_syncfs(xlator_t *this, struct list_head *head)
stub = list_entry(head->prev, call_stub_t, list);
ret = posix_fd_ctx_get(stub->args.fd, this, &pfd, NULL);
- if (ret)
- return;
-
-#ifdef GF_LINUX_HOST_OS
- /* syncfs() is not "declared" in RHEL's glibc even though
- the kernel has support.
- */
-#include <sys/syscall.h>
-#include <unistd.h>
-#ifdef SYS_syncfs
- syscall(SYS_syncfs, pfd->fd);
-#else
- sync();
-#endif
-#else
- sync();
-#endif
+ if (!ret)
+ (void)gf_syncfs(pfd->fd);
}
void *