From owner-freebsd-bugs@FreeBSD.ORG Sat Mar 27 11:00:31 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B399416A4CF for ; Sat, 27 Mar 2004 11:00:31 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 96AEF43D2D for ; Sat, 27 Mar 2004 11:00:31 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i2RJ0Vbv045106 for ; Sat, 27 Mar 2004 11:00:31 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i2RJ0VsN045101; Sat, 27 Mar 2004 11:00:31 -0800 (PST) (envelope-from gnats) Resent-Date: Sat, 27 Mar 2004 11:00:31 -0800 (PST) Resent-Message-Id: <200403271900.i2RJ0VsN045101@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Patrick Mackinlay Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1E84316A4CE for ; Sat, 27 Mar 2004 10:51:18 -0800 (PST) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id 171E243D1D for ; Sat, 27 Mar 2004 10:51:18 -0800 (PST) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.10/8.12.10) with ESMTP id i2RIpH72066469 for ; Sat, 27 Mar 2004 10:51:17 -0800 (PST) (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.10/8.12.10/Submit) id i2RIpHK1066468; Sat, 27 Mar 2004 10:51:17 -0800 (PST) (envelope-from nobody) Message-Id: <200403271851.i2RIpHK1066468@www.freebsd.org> Date: Sat, 27 Mar 2004 10:51:17 -0800 (PST) From: Patrick Mackinlay To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: misc/64816: mmap and/or ftruncate does not work correctly on nfs mounted file systems X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Mar 2004 19:00:31 -0000 >Number: 64816 >Category: misc >Synopsis: mmap and/or ftruncate does not work correctly on nfs mounted file systems >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Mar 27 11:00:31 PST 2004 >Closed-Date: >Last-Modified: >Originator: Patrick Mackinlay >Release: 4.9 (5.2.1 also tried and found not to work) >Organization: SpaceSurfer Ltd. >Environment: FreeBSD ws3.spacesurfer.com 4.9-STABLE FreeBSD 4.9-STABLE #0: Sat Feb 14 18:01:36 GMT 2004 pim@ws3.uknet.spacesurfer.com:/usr/obj/usr/src/sys/WS3 i386 >Description: When using a file on an nfs mounted region, that has its last bytes memory mapped with mmap and then using ftruncate to increase the size of the file, the ftruncate call will result in whatever changes you have made via the mmaped area not being synced to disk (unless you use an msync or mmunmp before the ftruncate call). The c progam below demonstrates the problem. The files tested on where on a linux 2.4 nfs server and the test program worked fine on linux 2.4 nfs clients. #include #include #include #include #include #include #include #include void error(char *msg) { fprintf(stderr, "Error: %s\nSystem error %d: %s\n", msg, errno, strerror(errno)); exit(-1); } #define SZ 1024 // Less than page size int main(int argn, char *argv[]) { int fd; char buffer[SZ]; char *map; if (argn!=2) { fprintf(stderr, "Usage:\n %s [filename]\n", argv[0]); exit(-1); } memset(buffer, 0, SZ); fd=open(argv[1], O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); if (fd==-1) error("Could not create file"); if (write(fd, buffer, SZ)!=SZ) error("Could not write buffer"); map=mmap(NULL, SZ, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (map==MAP_FAILED) error("Map failed"); map[SZ-1]=1; if (ftruncate(fd, SZ+1)!=0) error("Could not truncate file"); if (map[SZ-1]==1) printf("Test passed\n"); else printf("Test failed\n"); exit(0); } >How-To-Repeat: >Fix: >Release-Note: >Audit-Trail: >Unformatted: