[NFS] [NFS PATCH] Fix the issue of writing data over NFS concurrently both on client and Server uncorrectly
Trond Myklebust
trond.myklebust at fys.uio.no
Tue Jun 26 23:39:52 EDT 2007
On Wed, 2007-06-27 at 11:33 +0800, shichao wrote:
> Hi everybody,
>
> When I write data on file over NFS (mounted aync) both on client and on Server,
> sometimes the client seems to miss the server's updated data and commit the stale cache data to the nfs server. This
> leads to a file writed uncorrectly.
>
> Example on a local dir /local/testdir/foo NFS-exported to the localhost on /nfs/foo:
> The exportfs option in server is: /nfs/ *(rw,sync,root_no_squash)
>
> [root at rhel5~]# mount server:/nfs /local/testdir
>
> My test program's main flow is as follows:
> 1) fd = open("/local/testdir/foo", oflags, CHMOD_RW )
> 2) wbuf="testmsg-1-"; write(fd, wbuf, strlen(wbuf))
> 3) On nfs Server: echo "testmsg-2-" >> /nfs/foo (using rsh)
> 4) sleep(6); lseek(fd, 0L, SEEK_END)
> 5) wbuf="testmsg-3-"; write(fd, wbuf, strlen(wbuf))
> 6) lseek(fd, 0L, 0); read(fd, rbuf, MAX_DATA_SIZE)
>
> It is expected that the file data should be "testmsg-1-testmsg-2-testmsg-3",
No. The expectation in this case is precisely what you saw. You should
not be changing the file on the server unless you are using file locking
or some other synchronisation mechanism.
Please read the NFS FAQ on close-to-open cache consistency:
http://nfs.sourceforge.net/#faq_a8
Trond
More information about the NFSv4
mailing list