Subject: Re: *Very* strange interaction of /bin/cp and NFS reads
To: None <cracauer@wavehh.hanse.de>
From: Mike Long <mike.long@analog.com>
List: netbsd-help
Date: 09/21/1995 13:59:03
cracauer@wavehh.hanse.de (Martin Cracauer) wrote:

>When copying a file from an NFS partition to a local partition,
>/bin/cp from NetBSD-1.0 often gets an older version of that file (That
>means, if the source file has been edited lately, /bin/cp often copies
>what the source file has been before editing).

This looks like another VM vs. buffer cache problem.

If so, the reason for this is that /bin/cp is using mmap() to read the
source file, while cat and GNU cp (I assume) use read().  Your last
update to the file is probably sitting in your local buffer cache, and
hasn't yet propagated to the NFS server.  mmap() bypasses the local
buffer cache, while read() does not.

>Could you please give me some advice whether /bin/cp can be fixed, if
>I can use GNU cp as a full replacement or maybe I'm just doing
>something wrong? Or even better, could you drop me a note what exactly
>is going wrong? Is this a general NFS problem or just /bin/cp trying
>to be too clever?

Fixing the problem requires integrating the VM system and the file
buffer cache, which is heavy-duty kernel hacking (to put it mildly).

One possible workaround would be to hack your editor to fsync() the
file immediately after it is written to disk; there will still be a
window where /bin/cp will see the old file, but it should be much
shorter.  If you don't want to do that, use /bin/sync to flush the
buffer cache directly before trying to copy the file.

(P.S.: I reserve the right to be totally wrong.  I don't use NFS.)
-- 
Mike Long <mike.long@analog.com>           http://www.shore.net/~mikel
VLSI Design Engineer         finger mikel@shore.net for PGP public key
Analog Devices, CPD Division          CCBF225E7D3F7ECB2C8F7ABB15D9BE7B
Norwood, MA 02062 USA                assert(*this!=opinionof(Analog));