From nobody  Fri Jan 24 17:57:03 1997
Received: (from nobody@localhost)
          by freefall.freebsd.org (8.8.5/8.8.5) id RAA09644;
          Fri, 24 Jan 1997 17:57:03 -0800 (PST)
Message-Id: <199701250157.RAA09644@freefall.freebsd.org>
Date: Fri, 24 Jan 1997 17:57:03 -0800 (PST)
From: dunc@netcom.com
To: freebsd-gnats-submit@freebsd.org
Subject: mmap on nfs mounted file hangs system
X-Send-Pr-Version: www-1.0

>Number:         2573
>Category:       kern
>Synopsis:       mmap on nfs mounted file hangs system
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 24 18:00:01 PST 1997
>Closed-Date:    Mon May 19 07:37:13 PDT 1997
>Last-Modified:  Mon May 19 07:37:44 PDT 1997
>Originator:     Kevet Duncombe
>Release:        FreeBSD 2.1.5-RELEASE
>Organization:
Filoli Information Systems
>Environment:
FreeBSD falcon.filoli.com 2.1.5-RELEASE FreeBSD 2.1.5-RELEASE #2: Mon Jan 13 17:05:44 PST 1997     
>Description:
I create a file, mmap it, then use that as the buffer for a read;
when the read is done, I msync, munmap, and have my bytes copied
to disk.  If I create the file on a local disk, it runs fine and
a cat of the file shows all the expected data.  When I create it
in my nfs mounted home directory, though, the system locks up.

Since I don't have X installed I mostly work via rsh from a Next
box nearby.  All those rsh sessions freeze; so does the top left
running on the console.  Attempts to rsh or telnet to it connect
but immediately hang.  Ping works, and Alt-F? switches among the
virtual consoles, but those are the only signs of life as far as
I can see.  Reset is the only escape I've found.

I stripped the code to a short example.   For what it's worth, I
also tried it on a Sun and had no problem, so I'm pretty sure it
is the FreeBSD end and not the server end that's acting up.
>How-To-Repeat:
1) compile the following program
2) run it to create file "deleteme"
3) cat deleteme

#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>

#ifdef __FreeBSD__
#include <err.h>
#else
void
err(int ret,char *msg)
{
        fprintf(stderr,"%s: %s\n",msg,strerror(errno));
        exit(ret);
}
#endif

void
main()
{
        char *filebuf;
        char zero = 0;
        int filelen = 603;      /* not magic as far as I know */
        int src = open("/dev/zero",O_RDONLY);
        int dst = open("deleteme",O_CREAT|O_TRUNC|O_RDWR,0644);
        if (src == -1)
                err(1,"can't open input file");
        if (dst == -1)
                err(1,"can't open output file");

        if (lseek(dst,filelen-1,SEEK_SET) == -1)
                err(1,"can't seek output file to filelen");
        if (write(dst,&zero,1) != 1)
                err(1,"can't extend output file to filelen");

        filebuf = mmap(0,filelen,PROT_READ|PROT_WRITE,MAP_SHARED,dst,0);
        if ((long)filebuf == -1)
                err(1,"can't mmap file");
                /*
        if (close(dst) == -1)
                err(1,"can't close output file");
                */

        if (read(src,filebuf,filelen) != filelen)
                err(1,"error reading file from jukeomatic");
        if (msync((caddr_t)filebuf,filelen,0) == -1)
                err(1,"can't msync mmap'd output file");
        if (munmap((caddr_t)filebuf,filelen) == -1)
                err(1,"can't munmap mmap'd output file");
}

>Fix:

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: mpp 
State-Changed-When: Tue Mar 25 17:35:49 PST 1997 
State-Changed-Why:  
This is still a problem under 3.0-current.  I screwed 
up thud with the example program in the PR :-(... 
darn...I wasn't reading the PR close enough - I thought it just 
hung the one process, not the entire machine...:-(. 
State-Changed-From-To: analyzed->closed 
State-Changed-By: dfr 
State-Changed-When: Mon May 19 07:37:13 PDT 1997 
State-Changed-Why:  
Fixed in current 20 May 1997. 
>Unformatted:
