From Jukka.Ukkonen@sysopen.fi  Mon Jan  3 09:05:27 2000
Return-Path: <Jukka.Ukkonen@sysopen.fi>
Received: from mutu.sysopen.fi (sysopen.fi [192.130.39.11])
	by hub.freebsd.org (Postfix) with ESMTP id E6DB214D68
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  3 Jan 2000 09:05:24 -0800 (PST)
	(envelope-from Jukka.Ukkonen@sysopen.fi)
Received: from japaninahven.sysopen.fi ([192.68.39.177] helo=sysopen.fi)
	by mutu.sysopen.fi with esmtp (Exim 3.02 #7)
	id 125Axn-00022A-00
	for FreeBSD-gnats-submit@freebsd.org; Mon, 03 Jan 2000 19:08:11 +0200
Message-Id: <3870E18E.4CF289E2@sysopen.fi>
Date: Mon, 03 Jan 2000 19:51:10 +0200
From: Jukka Ukkonen <Jukka.Ukkonen@sysopen.fi>
Reply-To: jau@iki.fi
To: FreeBSD Gnats <FreeBSD-gnats-submit@freebsd.org>
Subject: ftpd did not use sendfile(2) when sending regular files

>Number:         15861
>Category:       bin
>Synopsis:       ftpd did not use sendfile(2) when sending regular files
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dan
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan  3 09:10:00 PST 2000
>Closed-Date:    Tue Dec 19 19:46:58 PST 2000
>Last-Modified:  Tue Dec 19 19:47:44 PST 2000
>Originator:     Jukka A. Ukkonen
>Release:        FreeBSD 3.2-RELEASE i386
>Organization:
Private person
>Environment:

        FreeBSD 3.2-RELEASE i386 and the standard ftpd packaged with it.

>Description:

        The ftpd could have performed better by using the sendfile(2)
        call instead of mmap(), read(), write(), and munmap() combination
        while sending out a regular file.

>How-To-Repeat:

        Check the ftpd code for sending regular files to see what it does,
        and try it as it is and with sendfile() replacing the looping method
        using mmap(), read(), write(), and munmap() calls.

>Fix:
        
        A tentative quick hack patch below.
        Modify it, if you think changes are needed.
        Otherwise: share and enjoy. ;-)


--- ftpd.c.orig Sun May  2 12:35:30 1999
+++ ftpd.c      Wed Dec 29 14:41:26 1999
@@ -1466,6 +1466,7 @@
                filefd = fileno(instr);
 
                if (isreg && filesize < (off_t)16 * 1024 * 1024) {
+#if 0
                        buf = mmap(0, filesize, PROT_READ, MAP_SHARED, filefd,
                                   (off_t)0);
                        if (buf == MAP_FAILED) {
@@ -1484,8 +1485,31 @@
 
                        transflag = 0;
                        munmap(buf, (size_t)filesize);
+
                        if (cnt < 0)
                                goto data_err;
+#endif
+                       off_t   offset;
+                       int     fail;
+
+                       len = filesize;
+                       offset = 0;
+                       fail = 0;
+
+                       while (len &&
+                              ! (fail = sendfile (filefd, netfd, offset, len,
+                                                  NULL, &cnt, 0))) {
+                               len -= cnt;
+                               offset += cnt;
+                       }
+
+                       if (fail < 0) {
+                               if (errno == EINVAL)
+                                   goto oldway;
+
+                               goto data_err;
+                       }
+
                        reply(226, "Transfer complete.");
                        return;
                }

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->adrian 
Responsible-Changed-By: adrian 
Responsible-Changed-When: Mon Jul 24 01:48:19 PDT 2000 
Responsible-Changed-Why:  
I'll handle this one and probably make it a compile time option .. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=15861 
Responsible-Changed-From-To: adrian->dan 
Responsible-Changed-By: dan 
Responsible-Changed-When: Mon Sep 25 16:52:48 PDT 2000 
Responsible-Changed-Why:  
This patch is on my review plate 

http://www.freebsd.org/cgi/query-pr.cgi?pr=15861 
State-Changed-From-To: open->closed 
State-Changed-By: dan 
State-Changed-When: Tue Dec 19 19:46:58 PST 2000 
State-Changed-Why:  

This functionality exists now. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=15861 
>Unformatted:
