ruby-changes:62904
From: Masaki <ko1@a...>
Date: Sat, 12 Sep 2020 16:08:56 +0900 (JST)
Subject: [ruby-changes:62904] 012785ef35 (master): Check copy_file_range(2) is actually supported.
https://git.ruby-lang.org/ruby.git/commit/?id=012785ef35 From 012785ef352d6eee983e087adad71692b3aeb354 Mon Sep 17 00:00:00 2001 From: Masaki Matsushita <glass.saga@g...> Date: Sat, 12 Sep 2020 13:36:53 +0900 Subject: Check copy_file_range(2) is actually supported. see also: https://gitlab.com/gitlab-org/gitlab/-/issues/218999#note_363225872 diff --git a/configure.ac b/configure.ac index cbfce07..6a58a80 100644 --- a/configure.ac +++ b/configure.ac @@ -2396,6 +2396,42 @@ AS_IF([test "$rb_cv_rshift_sign" = yes], [ https://github.com/ruby/ruby/blob/trunk/configure.ac#L2396 AC_DEFINE(RSHIFT(x,y), (((x)<0) ? ~((~(x))>>(int)(y)) : (x)>>(int)(y))) ]) +AS_IF([test "$ac_cv_func_copy_file_range" = no], [ + AC_CACHE_CHECK([for copy_file_range], + rb_cv_use_copy_file_range, + [AC_TRY_RUN([ +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/syscall.h> +#include <fcntl.h> +#include <unistd.h> + +#ifndef O_TMPFILE + #define O_TMPFILE __O_TMPFILE +#endif + +int +main() +{ +#ifdef __NR_copy_file_range + int ret, fd_in, fd_out; + fd_in = open("/tmp", O_TMPFILE|O_RDWR, S_IRUSR); + fd_out = open("/tmp", O_TMPFILE|O_WRONLY, S_IWUSR); + ret = syscall(__NR_copy_file_range, fd_in, NULL, fd_out, NULL, 0, 0); + if (ret == -1) { return 1; } + return 0; +#else + return 1; +#endif +} + ], + [rb_cv_use_copy_file_range=yes], + [rb_cv_use_copy_file_range=no])]) + AS_IF([test "$rb_cv_use_copy_file_range" = yes], [ + AC_DEFINE(USE_COPY_FILE_RANGE) + ]) +]) + AS_CASE(["$ac_cv_func_gettimeofday:$ac_cv_func_clock_gettime"], [*yes*], [], [ diff --git a/io.c b/io.c index 0d6e217..3cf0285 100644 --- a/io.c +++ b/io.c @@ -11074,10 +11074,6 @@ nogvl_copy_stream_wait_write(struct copy_stream_struct *stp) https://github.com/ruby/ruby/blob/trunk/io.c#L11074 return 0; } -#if defined HAVE_COPY_FILE_RANGE || (defined __linux__ && defined __NR_copy_file_range) -# define USE_COPY_FILE_RANGE -#endif - #ifdef USE_COPY_FILE_RANGE static ssize_t -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/