From owner-freebsd-current Sun Dec 30 11:48:33 2001 Delivered-To: freebsd-current@freebsd.org Received: from mutley.ebuilt.net (nat.ebuilt.com [209.216.46.200]) by hub.freebsd.org (Postfix) with ESMTP id 977AF37B419 for ; Sun, 30 Dec 2001 11:48:30 -0800 (PST) Received: (from root@localhost) by mutley.ebuilt.net (8.11.1/8.11.1) id fBUJmL725516 for ; Sun, 30 Dec 2001 11:48:21 -0800 Received: from cerberus.ebuilt.net (cerberus.ebuilt.net [192.168.168.110]) by mutley.ebuilt.net (8.11.1/8.11.1) with ESMTP id fBUJmLC25435; Sun, 30 Dec 2001 11:48:21 -0800 Received: (from jerenkrantz@localhost) by cerberus.ebuilt.net (8.9.3+Sun/8.9.1) id LAA05437; Sun, 30 Dec 2001 11:48:20 -0800 (PST) Date: Sun, 30 Dec 2001 11:48:20 -0800 From: Justin Erenkrantz To: Sheldon Hearn Cc: Michal Mertl , current@freebsd.org Subject: [PATCH] Re: ntfs and sendfile problem (corrupted data) Message-ID: <20011230194820.GB3904@ebuilt.com> References: <91552.1009724501@axl.seasidesoftware.co.za> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <91552.1009724501@axl.seasidesoftware.co.za> User-Agent: Mutt/1.3.23.2i X-AntiVirus: scanned for viruses by AMaViS 0.2.1-pre3 (http://amavis.org/) Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Sun, Dec 30, 2001 at 05:01:41PM +0200, Sheldon Hearn wrote: > On Sun, 30 Dec 2001 15:47:45 +0100, Michal Mertl wrote: > > > I did use the "goto oldway;" and the problem went away. I tried to look at > > /sys/kern/uipc_syscalls.c sendfile implementation but it is too complex > > for me :-(. > > I've added your feedback to the audit trail of PR bin/31692, thanks. > > > I tried ktrace on ftpd but only saw the call to sendfile(2). If you > > give me some guidance I can try to look into problem deeper. I don't > > have any experience in kernel debugging but would like to learn it. > > No idea. I was just trying to narrow this down so we know who to nag. > > This smells like one of those things someone like dillon or bmilekic > could fix. Gents, any takers? I don't know if this is correct, but I find the usage of cnt for the loop to be very suspicious. Could you try this patch (against -CURRENT, but should apply to -STABLE)? Consider that sendfile may be executed many times and cnt will only be the value of how much was written that last iteration. Therefore, you need to check whether the *entire* file has been written. And, I would wonder with a network-based FS, it would potentially take multiple sendfile(2) calls - therefore the check against cnt is invalid. And, of course, ftpd.c isn't built against libc_r. Otherwise, I'd say to upgrade your kernel. Alfred got the libc_r sendfile working again a few weeks ago. -- justin --- libexec/ftpd/ftpd.c.old Mon Nov 19 13:52:03 2001 +++ libexec/ftpd/ftpd.c Sun Dec 30 11:33:26 2001 @@ -1811,7 +1811,7 @@ len = filesize; err = cnt = offset = 0; - while (err != -1 && cnt < filesize) { + while (err != -1 && len > 0) { err = sendfile(filefd, netfd, offset, len, (struct sf_hdtr *) NULL, &cnt, 0); byte_count += cnt; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message