* [PATCH, libstdc++v3]: Fallback to read/write ops in case sendfile fails with ENOSYS or EINVAL.
@ 2016-08-11 19:27 Uros Bizjak
2016-08-15 9:44 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Uros Bizjak @ 2016-08-11 19:27 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, Jonathan Wakely
[-- Attachment #1: Type: text/plain, Size: 916 bytes --]
Hello!
Attached patch implements note from sendfile manpage:
<q>
Applications may wish to fall back to read(2)/write(2) in the case
where sendfile() fails with EINVAL or ENOSYS.
</q>
Also, the patch fixes a small inconsistency in how
_GLIBCXX_USE_FCHMODAT config flag is handled in do_copy_file function.
2016-08-11 Uros Bizjak <ubizjak@gmail.com>
* src/filesystem/ops.cc: Always include ostream and
ext/stdio_filebuf.h.
(do_copy_file): Check if _GLIBCXX_USE_FCHMODAT is defined.
[_GLIBCXX_USE_SENDFILE]: Fallback to read/write operations in case
sendfile fails with ENOSYS or EINVAL.
Patch was bootstrapped and regression tested on x86_64-linux-gnu
{,-m32} on CentOS 5.11 (where sendfile returns EINVAL for file->file
copy) and Fedora 24. In addition, the patch was bootstraped and
regression tested with _GLIBCXX_USE_SENDFILE manually disabled after
configure.
OK for mainline?
Uros.
[-- Attachment #2: l.diff.txt --]
[-- Type: text/plain, Size: 2383 bytes --]
Index: src/filesystem/ops.cc
===================================================================
--- src/filesystem/ops.cc (revision 239384)
+++ src/filesystem/ops.cc (working copy)
@@ -28,7 +28,9 @@
#include <experimental/filesystem>
#include <functional>
+#include <ostream>
#include <stack>
+#include <ext/stdio_filebuf.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
@@ -48,9 +50,6 @@
#endif
#ifdef _GLIBCXX_USE_SENDFILE
# include <sys/sendfile.h>
-#else
-# include <ext/stdio_filebuf.h>
-# include <ostream>
#endif
#if _GLIBCXX_HAVE_UTIME_H
# include <utime.h>
@@ -416,7 +415,7 @@ namespace
#ifdef _GLIBCXX_USE_FCHMOD
if (::fchmod(out.fd, from_st->st_mode))
-#elif _GLIBCXX_USE_FCHMODAT
+#elif defined _GLIBCXX_USE_FCHMODAT
if (::fchmodat(AT_FDCWD, to.c_str(), from_st->st_mode, 0))
#else
if (::chmod(to.c_str(), from_st->st_mode))
@@ -428,6 +427,31 @@ namespace
#ifdef _GLIBCXX_USE_SENDFILE
const auto n = ::sendfile(out.fd, in.fd, nullptr, from_st->st_size);
+ if (n < 0 && (errno == ENOSYS || errno == EINVAL))
+ {
+#endif
+ __gnu_cxx::stdio_filebuf<char> sbin(in.fd, std::ios::in);
+ __gnu_cxx::stdio_filebuf<char> sbout(out.fd, std::ios::out);
+ if (sbin.is_open())
+ in.fd = -1;
+ if (sbout.is_open())
+ out.fd = -1;
+ if (from_st->st_size && !(std::ostream(&sbout) << &sbin))
+ {
+ ec = std::make_error_code(std::errc::io_error);
+ return false;
+ }
+ if (!sbout.close() || !sbin.close())
+ {
+ ec.assign(errno, std::generic_category());
+ return false;
+ }
+
+ ec.clear();
+ return true;
+
+#ifdef _GLIBCXX_USE_SENDFILE
+ }
if (n != from_st->st_size)
{
ec.assign(errno, std::generic_category());
@@ -438,27 +462,10 @@ namespace
ec.assign(errno, std::generic_category());
return false;
}
-#else
- __gnu_cxx::stdio_filebuf<char> sbin(in.fd, std::ios::in);
- __gnu_cxx::stdio_filebuf<char> sbout(out.fd, std::ios::out);
- if (sbin.is_open())
- in.fd = -1;
- if (sbout.is_open())
- out.fd = -1;
- if (from_st->st_size && !(std::ostream(&sbout) << &sbin))
- {
- ec = std::make_error_code(std::errc::io_error);
- return false;
- }
- if (!sbout.close() || !sbin.close())
- {
- ec.assign(errno, std::generic_category());
- return false;
- }
-#endif
ec.clear();
return true;
+#endif
}
}
#endif
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH, libstdc++v3]: Fallback to read/write ops in case sendfile fails with ENOSYS or EINVAL.
2016-08-11 19:27 [PATCH, libstdc++v3]: Fallback to read/write ops in case sendfile fails with ENOSYS or EINVAL Uros Bizjak
@ 2016-08-15 9:44 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2016-08-15 9:44 UTC (permalink / raw)
To: Uros Bizjak; +Cc: gcc-patches, libstdc++
On 11/08/16 21:27 +0200, Uros Bizjak wrote:
>Hello!
>
>Attached patch implements note from sendfile manpage:
>
><q>
>Applications may wish to fall back to read(2)/write(2) in the case
>where sendfile() fails with EINVAL or ENOSYS.
></q>
>
>Also, the patch fixes a small inconsistency in how
>_GLIBCXX_USE_FCHMODAT config flag is handled in do_copy_file function.
>
>2016-08-11 Uros Bizjak <ubizjak@gmail.com>
>
> * src/filesystem/ops.cc: Always include ostream and
> ext/stdio_filebuf.h.
> (do_copy_file): Check if _GLIBCXX_USE_FCHMODAT is defined.
> [_GLIBCXX_USE_SENDFILE]: Fallback to read/write operations in case
> sendfile fails with ENOSYS or EINVAL.
>
>Patch was bootstrapped and regression tested on x86_64-linux-gnu
>{,-m32} on CentOS 5.11 (where sendfile returns EINVAL for file->file
>copy) and Fedora 24. In addition, the patch was bootstraped and
>regression tested with _GLIBCXX_USE_SENDFILE manually disabled after
>configure.
>
>OK for mainline?
Yes, thanks.
The src/filesystem/ops.cc code is identical on the gcc-5 and gcc-6
branches, so could you backport it there too please? (After the 6.3
release though).
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-15 9:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-11 19:27 [PATCH, libstdc++v3]: Fallback to read/write ops in case sendfile fails with ENOSYS or EINVAL Uros Bizjak
2016-08-15 9:44 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).