HP-UX/AIX sendfile patches.

William Jojo jojowil at hvcc.edu
Mon Dec 20 20:57:54 GMT 2004



I have a fix for the sendfile.c code for HP-UX - length not properly
specified prior to call.

I've also added code to support the AIX send_file() function and
configure.in code to check for AIX specific send_file API and sets
AIX_SENDFILE_API if successful.


Could you consider this patch for 3.0.11?


I also sent a web/cgi.c patch for "struct var" last week with respect to
compile problems on AIX 5.3.

My performance was amazing the goodtime.avi file passed from share to
local win-XP-sp1 noticably faster than without sendfile. I had oplocks and
level II oplocks, write cache size set to 2MB and had to forcible set max
xmit to 65535, which apparently default to 16K even though the docs say
64K.

Writes back to the server seemed faster with max xmit larger and with the
2MB write cache size.


Also a few of the return value tests look suspicious about sendfile
returning 0 and sys_sendfile returns -1. It's possible that, if I'm
reading one man page correctly, that a 0 means a possible EWOULDBLOCK and
another offers an EAGAIN on -1 instead of EINTR. I'd be very interested in
researching these further, but I have no access to updated man pages for
FreeBSD, HP-UX or Solaris (googled docs are rather aged).


Bill
-------------- next part --------------
*** configure.orig.in	Mon Dec 20 11:00:03 2004
--- configure.aix.in	Mon Dec 20 10:38:36 2004
***************
*** 4242,4247 ****
--- 4242,4277 ----
  	fi
  	;;
  
+ 	*aix*)
+ 		AC_CACHE_CHECK([for AIX send_file support],samba_cv_HAVE_SENDFILE,[
+ 		AC_TRY_LINK([\
+ #include <sys/socket.h>],
+ [\
+ 	int fromfd, tofd;
+ 	size_t total=0;
+ 	struct sf_parms hdtrl;
+ 	ssize_t nwritten;
+ 	off64_t offset;
+ 
+ 	hdtrl.header_data = 0;
+ 	hdtrl.header_length = 0;
+ 	hdtrl.file_descriptor = fromfd;
+ 	hdtrl.file_offset = 0;
+ 	hdtrl.file_bytes = 0;
+ 	hdtrl.trailer_data = 0;
+ 	hdtrl.trailer_length = 0;
+ 
+ 	nwritten = send_file(&tofd, &hdtrl, 0);
+ ],
+ samba_cv_HAVE_SENDFILE=yes,samba_cv_HAVE_SENDFILE=no)])
+ 	if test x"$samba_cv_HAVE_SENDFILE" = x"yes"; then
+     		AC_DEFINE(HAVE_SENDFILE,1,[Whether sendfile() is available])
+ 		AC_DEFINE(AIX_SENDFILE_API,1,[Whether the AIX send_file() API is available])
+ 		AC_DEFINE(WITH_SENDFILE,1,[Whether to include sendfile() support])
+ 	else
+ 		AC_MSG_RESULT(no);
+ 	fi
+ 	;;
  	*)
  	;;
          esac
-------------- next part --------------
*** sendfile.orig.c	Mon Dec 20 10:39:09 2004
--- sendfile.aix.c	Mon Dec 20 15:38:19 2004
***************
*** 371,376 ****
--- 371,434 ----
  	return count + hdr_len;
  }
  
+ #elif defined(AIX_SENDFILE_API)
+ 
+ /* BEGIN AIX SEND_FILE */
+ 
+ #include <sys/socket.h>
+ 
+ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)
+ {
+ 
+ 	size_t total=0;
+ 	struct sf_parms hdtrl;
+ 
+ 	/* Set up the header/trailer struct params. */
+ 	if (header) {
+ 		hdtrl.header_data = header->data;
+ 		hdtrl.header_length = header->length;
+ 	} else {
+ 		hdtrl.header_data = NULL;
+ 		hdtrl.header_length = 0;
+ 	}
+ 	hdtrl.trailer_data = NULL;
+ 	hdtrl.trailer_length = 0;
+ 
+ 	hdtrl.file_descriptor = fromfd;
+ 	hdtrl.file_offset = offset;
+ 	hdtrl.file_bytes = count;
+ 
+ 	while ( hdtrl.file_bytes + hdtrl.header_length ) {
+ 		ssize_t ret;
+ 
+ 
+ 		/*
+ 		Return Value
+ 
+ 		There are three possible return values from send_file:
+ 
+ 		Value Description
+ 
+ 		-1 an error has occurred, errno contains the error code.
+ 
+ 		0 the command has completed successfully.
+ 
+ 		1 the command was completed partially, some data has been
+ 		transmitted but the command has to return for some reason,
+ 		for example, the command was interrupted by signals.
+ 		*/
+ 		do {
+ 			ret = send_file(&tofd, &hdtrl, 0);
+ 		} while ( (ret == 1) || (ret == -1 && errno == EINTR) );
+ 		if ( ret == -1 )
+ 			return -1;
+ 	}
+ 
+ 	return count + header->length;
+ 
+ }
+ /* END AIX SEND_FILE */
+ 
  #else /* No sendfile implementation. Return error. */
  
  ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)
-------------- next part --------------
*** sendfile.orig.c	Thu Dec 16 12:57:28 2004
--- sendfile.hpux.c	Thu Dec 16 15:47:15 2004
***************
*** 250,256 ****
  		hdtrl[0].iov_len = hdr_len = 0;
  	}
  	hdtrl[1].iov_base = NULL;
! 	hdtrl[1].iov_base = 0;
  
  	total = count;
  	while (total + hdtrl[0].iov_len) {
--- 250,256 ----
  		hdtrl[0].iov_len = hdr_len = 0;
  	}
  	hdtrl[1].iov_base = NULL;
! 	hdtrl[1].iov_len = 0;
  
  	total = count;
  	while (total + hdtrl[0].iov_len) {


More information about the samba-technical mailing list