svn commit: r198174 - head/sys/nfsclient

John Baldwin jhb at freebsd.org
Fri Oct 16 19:51:52 UTC 2009


On Friday 16 October 2009 3:30:49 pm John Baldwin wrote:
> Author: jhb
> Date: Fri Oct 16 19:30:48 2009
> New Revision: 198174
> URL: http://svn.freebsd.org/changeset/base/198174
> 
> Log:
>   Close a race with caching of -ve name lookups in the NFS client.
>   Specifically, clients only trust -ve cache entries while the directory
>   remains unchanged and discard any -ve cache entries for a directory when
>   they notice that the modification time of a directory entry changes.  The
>   race involves two concurrent lookups as follows:
>   - Thread A does a lookup for file 'foo' which sends a lookup RPC to the
>     server.  The lookup fails and the server replies.
>   - The 'foo' file is created (either by the same client or a different
>     client) updating the modification time on the parent directory of 'foo'.
>   - Thread B does a lookup for a different file 'bar' which updates the
>     cached attributes of the parent directory of 'foo' to reflect the new
>     modification time after 'foo' was created.
>   - Thread A finally resumes execution to parse the reply from the NFS
>     server.  It adds a -ve cache entry and sets the cached value of the
>     directory's modification time that is used for invalidating -ve cached
>     lookups to the new modification time set by thread B.

Slight correction, the file has to be created on a different client since the 
local client would exclusively lock the directory vnode while it created the 
file avoiding this race.  I created the file on a separate client when I 
reproduced this during testing (I used a hack to force a 5 second sleep when 
adding -ve cache entries to let thread B do its lookup and update the mtime 
before thread A tried to add its -ve cache entry to "force" the race).

I have seen this in practice in a couple of cases at work where an ls of a 
directory would show a file that was added, but attempting to open the file 
itself or even ls the individual file would fail with ENOENT.

-- 
John Baldwin


More information about the svn-src-all mailing list