summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2018-07-18 15:49:29 -0700
committerKarolin Seeger <kseeger@samba.org>2018-07-28 10:57:39 +0200
commita431bdf08fdad479471bbb2ab0cf86c595260d23 (patch)
treeb116acdb53c0d1986add774e28b21200c2bfb87e /source3
parent7bf15686b60c35c853ae469906baa7d5ed51e4b7 (diff)
downloadsamba-a431bdf08fdad479471bbb2ab0cf86c595260d23.tar.gz
s3: smbd: Fix AIX sendfile() for SMB2. Ensure we don't spin on EAGAIN.
For SMB2 the socket is set non-blocking. Ensure sendfile() calls complete if they return EAGAIN by saving the socket state, setting it blocking, doing the sendfile until completion and then restoring the socket state. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13537 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Fri Jul 20 15:14:24 CEST 2018 on sn-devel-144 (cherry picked from commit 582ce5d6b599516d6d8d619529a2aa809139a175) Autobuild-User(v4-7-test): Karolin Seeger <kseeger@samba.org> Autobuild-Date(v4-7-test): Sat Jul 28 10:57:39 CEST 2018 on sn-devel-144
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/sendfile.c49
1 files changed, 44 insertions, 5 deletions
diff --git a/source3/lib/sendfile.c b/source3/lib/sendfile.c
index aa115948501..d3effaf30aa 100644
--- a/source3/lib/sendfile.c
+++ b/source3/lib/sendfile.c
@@ -510,6 +510,9 @@ ssize_t sys_sendfile(int tofd, int fromfd,
ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset, size_t count)
{
struct sf_parms hdtrl;
+ int old_flags = 0;
+ ssize_t ret = -1;
+ bool socket_flags_changed = false;
/* Set up the header/trailer struct params. */
if (header) {
@@ -527,8 +530,6 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset
hdtrl.file_bytes = count;
while ( hdtrl.file_bytes + hdtrl.header_length ) {
- ssize_t ret;
-
/*
Return Value
@@ -546,12 +547,50 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset
*/
do {
ret = send_file(&tofd, &hdtrl, 0);
- } while ((ret == 1) || (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)));
- if ( ret == -1 )
+ } while ((ret == 1) || (ret == -1 && errno == EINTR));
+ if ( ret == -1 ) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ /*
+ * Sendfile must complete before we can
+ * send any other outgoing data on the socket.
+ * Ensure socket is in blocking mode.
+ * For SMB2 by default the socket is in
+ * non-blocking mode.
+ */
+ old_flags = fcntl(tofd, F_GETFL, 0);
+ ret = set_blocking(tofd, true);
+ if (ret == -1) {
+ goto out;
+ }
+ socket_flags_changed = true;
+ continue;
+ }
+ goto out;
+ }
+ }
+
+ ret = count + header->length;
+
+ out:
+
+ if (socket_flags_changed) {
+ int saved_errno;
+ int err;
+
+ if (ret == -1) {
+ saved_errno = errno;
+ }
+ /* Restore the old state of the socket. */
+ err = fcntl(tofd, F_SETFL, old_flags);
+ if (err == -1) {
return -1;
+ }
+ if (ret == -1) {
+ errno = saved_errno;
+ }
}
- return count + header->length;
+ return ret;
}
/* END AIX SEND_FILE */