NetBSD Problem Report #24516
Received: (qmail 27710 invoked by uid 605); 21 Feb 2004 23:33:25 -0000
Message-Id: <200402212332.i1LNWrhF026748@archangel.must-have-coffee.gen.nz>
Date: Sun, 22 Feb 2004 12:32:53 +1300 (NZDT)
From: Lloyd Parkes <lloyd@must-have-coffee.gen.nz>
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: lloyd@must-have-coffee.gen.nz
To: gnats-bugs@gnats.NetBSD.org
Subject: mmap not fully functional with smbfs
X-Send-Pr-Version: 3.95
>Number: 24516
>Category: kern
>Synopsis: open/mmap/close doesn't work like it should
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: jdolecek
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Feb 21 23:34:00 +0000 2004
>Closed-Date: Tue Mar 02 11:45:52 +0000 2004
>Last-Modified: Tue Mar 02 11:45:52 +0000 2004
>Originator: Lloyd Parkes
>Release: NetBSD 1.6ZH Jan 26 2004
>Organization:
Must Have Coffee
>Environment:
System: NetBSD archangel.must-have-coffee.gen.nz 1.6ZH NetBSD 1.6ZH (Archangel) #0: Thu Feb 19 20:33:16 NZDT 2004 lloyd@archangel.must-have-coffee.gen.nz:/vol/build/NetBSD/src-current/sys/arch/sparc64/compile/Archangel sparc64
Architecture: sparc64
Machine: sparc64
>Description:
I have a program that opens a file, mmaps it and the closes it. The
mmaped data is then used. This program works if the file is on a local
file system, but not if the file is on a remote XP box. If I don't
close the file, then it all works as expected (until I run out of file
descriptors). The program fails with SIGSEGV as soon as tries to
access the mamped memory after the file is closed.
>How-To-Repeat:
fd = open (filename, O_RDONLY);
fstat (fd, &sb);
memory = mmap (NULL, sb.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0);
close (fd);
>Fix:
Unknown.
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: jdolecek
State-Changed-When: Sun Feb 22 07:34:06 UTC 2004
State-Changed-Why:
This is exactly how it's supposed to work. You must not close()
the mmap()ped file - the memory is unmapped from the process
address space on the close().
State-Changed-From-To: closed->open
State-Changed-By: martin
State-Changed-When: Sun Feb 22 07:42:14 UTC 2004
State-Changed-Why:
See mmap(2) - search for close
From: Manuel Bouyer <bouyer@antioche.eu.org>
To: Lloyd Parkes <lloyd@must-have-coffee.gen.nz>
Cc: gnats-bugs@gnats.NetBSD.org, netbsd-bugs@netbsd.org
Subject: Re: kern/24516: mmap not fully functional with smbfs
Date: Sun, 22 Feb 2004 13:27:25 +0100
On Sun, Feb 22, 2004 at 12:32:53PM +1300, Lloyd Parkes wrote:
>
> >Description:
>
> I have a program that opens a file, mmaps it and the closes it. The
> mmaped data is then used. This program works if the file is on a local
> file system, but not if the file is on a remote XP box. If I don't
How is the remote FS mounted ? SMBFS ?
--
Manuel Bouyer <bouyer@antioche.eu.org>
NetBSD: 26 ans d'experience feront toujours la difference
--
From: Lloyd Parkes <lloyd@must-have-coffee.gen.nz>
To: Manuel Bouyer <bouyer@antioche.eu.org>
Cc: gnats-bugs@gnats.NetBSD.org, netbsd-bugs@netbsd.org,
lloyd@ophidian.must-have-coffee.gen.nz
Subject: Re: kern/24516: mmap not fully functional with smbfs
Date: Mon, 23 Feb 2004 18:43:27 +1300
> How is the remote FS mounted ? SMBFS ?
Sure is. I mentioned that in the subject line, but nowhere else in the message (like the problem description field for instance).
From: Tim Robbins <tjr@freebsd.org>
To: gnats-bugs@gnats.netbsd.org
Cc: netbsd-bugs@netbsd.org
Subject: Re: kern/24516: mmap not fully functional with smbfs
Date: Sun, 29 Feb 2004 10:19:29 +1100
This has been fixed in FreeBSD:
http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/48291
http://marc.theaimsgroup.com/?l=freebsd-cvs-all&m=106741759426858&w=2
The fix is (basically) to delay sending the close SMB to the server
until VOP_INACTIVE - the reference counting that smbfs does in
VOP_OPEN and VOP_CLOSE does not account for mmap()'d regions.
It's kinda hard to service a page fault reading from a file that
has already been closed on the server :-)
Also note that even though I had no real plans to merge it into
FreeBSD RELENG_4, I ended up doing it due to demand. Some of this
patchset might be useful to NetBSD (it includes the mmap fix):
http://marc.theaimsgroup.com/?l=freebsd-cvs-all&m=107370830511420&w=2
Tim
Responsible-Changed-From-To: kern-bug-people->jdolecek
Responsible-Changed-By: jdolecek
Responsible-Changed-When: Sun Feb 29 08:39:36 UTC 2004
Responsible-Changed-Why:
I'm respoinsible for smbfs.
From: Jaromir Dolecek <jdolecek@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: pr/24516 CVS commit: src/sys/fs/smbfs
Date: Sun, 29 Feb 2004 11:47:08 +0000 (UTC)
Module Name: src
Committed By: jdolecek
Date: Sun Feb 29 11:47:08 UTC 2004
Modified Files:
src/sys/fs/smbfs: smbfs_node.c smbfs_node.h smbfs_vnops.c
Log Message:
close the SMB handle when vnode is inactivated, rather than on file close,
so that mmap()ped regions remain accessible even when the file descriptor
is closed
g/c smbnode's n_opencount, and have single NOPEN flag instead
fixes PR kern/24516 by Lloyd Parkes
change obtained from FreeBSD, with only minor adjustments
To generate a diff of this commit:
cvs rdiff -r1.19 -r1.20 src/sys/fs/smbfs/smbfs_node.c
cvs rdiff -r1.8 -r1.9 src/sys/fs/smbfs/smbfs_node.h
cvs rdiff -r1.33 -r1.34 src/sys/fs/smbfs/smbfs_vnops.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->feedback
State-Changed-By: jdolecek
State-Changed-When: Sun Feb 29 11:48:04 UTC 2004
State-Changed-Why:
Fix for this problem was committed to smbfs. Can you please
check with kernel built from updated sources and report
whether the problem was fixed for you?
From: Lloyd Parkes <lloyd@must-have-coffee.gen.nz>
To: gnats-bugs@gnats.netbsd.org
Cc: jdolecek@netbsd.org
Subject: Re: kern/24516
Date: Tue, 02 Mar 2004 19:03:44 +1300
I have rebuilt my kernel with the latest sources and it all seems to
work now.
Thanks,
Lloyd
State-Changed-From-To: feedback->closed
State-Changed-By: jdolecek
State-Changed-When: Tue Mar 2 11:45:12 UTC 2004
State-Changed-Why:
Problem confirmed fixed. Thanks for report, and sorry for my initial mistake.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.