mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 18:14:12 +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);
|
buffer + ceil_powerof2(meta_bytes, env->me_os_psize);
|
||||||
for (size_t offset = meta_bytes; rc == MDBX_SUCCESS && offset < used_size;) {
|
for (size_t offset = meta_bytes; rc == MDBX_SUCCESS && offset < used_size;) {
|
||||||
#if MDBX_USE_SENDFILE
|
#if MDBX_USE_SENDFILE
|
||||||
if (dest_is_pipe) {
|
static bool sendfile_unavailable;
|
||||||
|
if (dest_is_pipe && likely(!sendfile_unavailable)) {
|
||||||
off_t in_offset = offset;
|
off_t in_offset = offset;
|
||||||
const intptr_t written =
|
const ssize_t written =
|
||||||
sendfile(fd, env->me_lazy_fd, &in_offset, used_size - offset);
|
sendfile(fd, env->me_lazy_fd, &in_offset, used_size - offset);
|
||||||
if (unlikely(written <= 0)) {
|
if (likely(written > 0)) {
|
||||||
rc = written ? errno : MDBX_ENODATA;
|
offset = in_offset;
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
offset = in_offset;
|
rc = MDBX_ENODATA;
|
||||||
continue;
|
if (written == 0 || ignore_enosys(rc = errno) != MDBX_RESULT_TRUE)
|
||||||
|
break;
|
||||||
|
sendfile_unavailable = true;
|
||||||
}
|
}
|
||||||
#endif /* MDBX_USE_SENDFILE */
|
#endif /* MDBX_USE_SENDFILE */
|
||||||
|
|
||||||
#if MDBX_USE_COPYFILERANGE
|
#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;
|
off_t in_offset = offset, out_offset = offset;
|
||||||
ssize_t bytes_copied = copy_file_range(
|
ssize_t bytes_copied = copy_file_range(
|
||||||
env->me_lazy_fd, &in_offset, fd, &out_offset, used_size - offset, 0);
|
env->me_lazy_fd, &in_offset, fd, &out_offset, used_size - offset, 0);
|
||||||
if (unlikely(bytes_copied <= 0)) {
|
if (likely(bytes_copied > 0)) {
|
||||||
rc = bytes_copied ? errno : MDBX_ENODATA;
|
offset = in_offset;
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
offset = in_offset;
|
rc = MDBX_ENODATA;
|
||||||
continue;
|
if (bytes_copied == 0 || ignore_enosys(rc = errno) != MDBX_RESULT_TRUE)
|
||||||
|
break;
|
||||||
|
copyfilerange_unavailable = true;
|
||||||
}
|
}
|
||||||
#endif /* MDBX_USE_COPYFILERANGE */
|
#endif /* MDBX_USE_COPYFILERANGE */
|
||||||
|
|
||||||
|
@ -164,9 +164,9 @@
|
|||||||
|
|
||||||
/** Advanced: Using sendfile() syscall (autodetection by default). */
|
/** Advanced: Using sendfile() syscall (autodetection by default). */
|
||||||
#ifndef MDBX_USE_SENDFILE
|
#ifndef MDBX_USE_SENDFILE
|
||||||
#if (defined(__linux__) || defined(__gnu_linux__)) && \
|
#if ((defined(__linux__) || defined(__gnu_linux__)) && \
|
||||||
(!defined(__ANDROID_API__) || __ANDROID_API__ >= 21) && \
|
__GLIBC_PREREQ(2, 3)) || \
|
||||||
!defined(MDBX_SAFE4QEMU)
|
(defined(__ANDROID_API__) && __ANDROID_API__ >= 21)
|
||||||
#define MDBX_USE_SENDFILE 1
|
#define MDBX_USE_SENDFILE 1
|
||||||
#else
|
#else
|
||||||
#define MDBX_USE_SENDFILE 0
|
#define MDBX_USE_SENDFILE 0
|
||||||
@ -175,7 +175,7 @@
|
|||||||
|
|
||||||
/** Advanced: Using copy_file_range() syscall (autodetection by default). */
|
/** Advanced: Using copy_file_range() syscall (autodetection by default). */
|
||||||
#ifndef MDBX_USE_COPYFILERANGE
|
#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
|
#define MDBX_USE_COPYFILERANGE 1
|
||||||
#else
|
#else
|
||||||
#define MDBX_USE_COPYFILERANGE 0
|
#define MDBX_USE_COPYFILERANGE 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user