mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 01:04:13 +08:00
mdbx: allow sendfile() and copy_file_range() to fail for Valgrind/QEMU cases.
Change-Id: I37ee8d652d91a8d2106c782beceaacb13e9f667f
This commit is contained in:
parent
25e3968199
commit
a2e2e5c8a0
32
src/core.c
32
src/core.c
@ -16315,30 +16315,36 @@ static int __cold mdbx_env_copy_asis(MDBX_env *env, MDBX_txn *read_txn,
|
||||
buffer + ceil_powerof2(meta_bytes, env->me_os_psize);
|
||||
for (size_t offset = meta_bytes; rc == MDBX_SUCCESS && offset < used_size;) {
|
||||
#if MDBX_USE_SENDFILE
|
||||
if (dest_is_pipe) {
|
||||
static bool sendfile_unavailable;
|
||||
if (dest_is_pipe && likely(!sendfile_unavailable)) {
|
||||
off_t in_offset = offset;
|
||||
const intptr_t written =
|
||||
const ssize_t written =
|
||||
sendfile(fd, env->me_lazy_fd, &in_offset, used_size - offset);
|
||||
if (unlikely(written <= 0)) {
|
||||
rc = written ? errno : MDBX_ENODATA;
|
||||
break;
|
||||
if (likely(written > 0)) {
|
||||
offset = in_offset;
|
||||
continue;
|
||||
}
|
||||
offset = in_offset;
|
||||
continue;
|
||||
rc = MDBX_ENODATA;
|
||||
if (written == 0 || ignore_enosys(rc = errno) != MDBX_RESULT_TRUE)
|
||||
break;
|
||||
sendfile_unavailable = true;
|
||||
}
|
||||
#endif /* MDBX_USE_SENDFILE */
|
||||
|
||||
#if MDBX_USE_COPYFILERANGE
|
||||
if (!dest_is_pipe) {
|
||||
static bool copyfilerange_unavailable;
|
||||
if (!dest_is_pipe && likely(!copyfilerange_unavailable)) {
|
||||
off_t in_offset = offset, out_offset = offset;
|
||||
ssize_t bytes_copied = copy_file_range(
|
||||
env->me_lazy_fd, &in_offset, fd, &out_offset, used_size - offset, 0);
|
||||
if (unlikely(bytes_copied <= 0)) {
|
||||
rc = bytes_copied ? errno : MDBX_ENODATA;
|
||||
break;
|
||||
if (likely(bytes_copied > 0)) {
|
||||
offset = in_offset;
|
||||
continue;
|
||||
}
|
||||
offset = in_offset;
|
||||
continue;
|
||||
rc = MDBX_ENODATA;
|
||||
if (bytes_copied == 0 || ignore_enosys(rc = errno) != MDBX_RESULT_TRUE)
|
||||
break;
|
||||
copyfilerange_unavailable = true;
|
||||
}
|
||||
#endif /* MDBX_USE_COPYFILERANGE */
|
||||
|
||||
|
@ -164,9 +164,9 @@
|
||||
|
||||
/** Advanced: Using sendfile() syscall (autodetection by default). */
|
||||
#ifndef MDBX_USE_SENDFILE
|
||||
#if (defined(__linux__) || defined(__gnu_linux__)) && \
|
||||
(!defined(__ANDROID_API__) || __ANDROID_API__ >= 21) && \
|
||||
!defined(MDBX_SAFE4QEMU)
|
||||
#if ((defined(__linux__) || defined(__gnu_linux__)) && \
|
||||
__GLIBC_PREREQ(2, 3)) || \
|
||||
(defined(__ANDROID_API__) && __ANDROID_API__ >= 21)
|
||||
#define MDBX_USE_SENDFILE 1
|
||||
#else
|
||||
#define MDBX_USE_SENDFILE 0
|
||||
@ -175,7 +175,7 @@
|
||||
|
||||
/** Advanced: Using copy_file_range() syscall (autodetection by default). */
|
||||
#ifndef MDBX_USE_COPYFILERANGE
|
||||
#if __GLIBC_PREREQ(2, 27) && defined(_GNU_SOURCE) && !defined(MDBX_SAFE4QEMU)
|
||||
#if __GLIBC_PREREQ(2, 27) && defined(_GNU_SOURCE)
|
||||
#define MDBX_USE_COPYFILERANGE 1
|
||||
#else
|
||||
#define MDBX_USE_COPYFILERANGE 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user