From a7a8631bc3b8d5a6de58d501c9779ee0c620594f Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Mon, 21 Sep 2020 03:27:40 +0300 Subject: [PATCH] mdbx: allow sync_file_range() to fail for Valgrind/QEMU cases. Change-Id: I9aa77d1debfbd0cb18e940946533e4ed758d08e8 --- src/core.c | 18 ++++++++++++++---- src/options.h | 6 +++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core.c b/src/core.c index 0a89b724..d5e2f7ac 100644 --- a/src/core.c +++ b/src/core.c @@ -4950,14 +4950,24 @@ __cold static int mdbx_wipe_steady(MDBX_env *env, const txnid_t last_steady) { return err; } else { #if MDBX_USE_SYNCFILERANGE - if (sync_file_range(env->me_lazy_fd, 0, pgno2bytes(env, NUM_METAS), - SYNC_FILE_RANGE_WRITE | SYNC_FILE_RANGE_WAIT_AFTER)) + static bool syncfilerange_unavailable; + if (likely(!syncfilerange_unavailable)) { + if (likely(!sync_file_range( + env->me_lazy_fd, 0, pgno2bytes(env, NUM_METAS), + SYNC_FILE_RANGE_WRITE | SYNC_FILE_RANGE_WAIT_AFTER))) + goto done_filesync; err = errno; -#else + if (ignore_enosys(err) != MDBX_RESULT_TRUE) + return err; + syncfilerange_unavailable = true; + } +#endif /* MDBX_USE_SYNCFILERANGE */ err = mdbx_fsync(env->me_lazy_fd, MDBX_SYNC_DATA); -#endif if (unlikely(err != MDBX_SUCCESS)) return err; +#if MDBX_USE_SYNCFILERANGE + done_filesync: +#endif /* MDBX_USE_SYNCFILERANGE */ mdbx_flush_incoherent_mmap(env->me_map, pgno2bytes(env, NUM_METAS), env->me_os_psize); } diff --git a/src/options.h b/src/options.h index 75634013..8f0f213a 100644 --- a/src/options.h +++ b/src/options.h @@ -184,9 +184,9 @@ /** Advanced: Using sync_file_range() syscall (autodetection by default). */ #ifndef MDBX_USE_SYNCFILERANGE -#if (defined(__linux__) || defined(__gnu_linux__)) && \ - (!defined(__ANDROID_API__) || __ANDROID_API__ >= 26) && \ - defined(_GNU_SOURCE) && !defined(MDBX_SAFE4QEMU) +#if ((defined(__linux__) || defined(__gnu_linux__)) && __GLIBC_PREREQ(2, 6) && \ + defined(_GNU_SOURCE)) || \ + (defined(__ANDROID_API__) && __ANDROID_API__ >= 26) #define MDBX_USE_SYNCFILERANGE 1 #else #define MDBX_USE_SYNCFILERANGE 0