Re: Regression, bisected: NFS O_EXCL breakage in 2.6.37 client.

From: Trond Myklebust
Date: Wed Jan 12 2011 - 13:28:34 EST


On Wed, 2011-01-12 at 11:10 -0500, Nick Bowler wrote:
> With 2.6.37 (client), opens on NFS with O_CREAT | O_EXCL are
> occasionally succeeding when the file already exists, apparently
> depending on the state of the filesystem cache. The issue was observed
> because mplayer would randomly overwrite its config file...
>
> Using the test program (./nfsbreak) included in this mail, I can
> reproduce it as follows (/home/nbowler is the NFS mount point). No
> interesting kernel messages appear on either the client or server
> machines during the test:
>
> % mkdir /home/nbowler/nfsexcl
> % ./nfsbreak
> nfsbreak: File opened <<< This is OK
> % ./nfsbreak
> nfsbreak: File exists
> % ./nfsbreak
> nfsbreak: File exists
> % su -c 'echo 2 > /proc/sys/vm/drop_caches'
> % ./nfsbreak
> nfsbreak: File opened <<< Uhoh!
> % ./nfsbreak
> nfsbreak: File exists
>
> Here's the nfsbreak C source:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <fcntl.h>
>
> int main(void)
> {
> int fd;
>
> /* /home/nbowler is the NFS mount point */
> fd = open("/home/nbowler/nfsexcl/nfsexcl", O_WRONLY|O_CREAT|O_EXCL);
> if (fd == -1) {
> perror("nfsbreak");
> return EXIT_FAILURE;
> }
>
> puts("nfsbreak: File opened");
> return 0;
> }
>
> This is a regression from 2.6.36; bisection implicates the following,
> which unfortunately does not revert cleanly.

Confirmed. The breakage does not affect NFSv4, but is limited to NFSv3.
The following patch should therefore suffice to fix it.

Cheers
Trond

8<---------------------------------------------------------------------