From FreeBSD: freebsd-current@ 16 Nov 2007 Re: link() not increasing link count on NFS server Log: Remove hacks from the NFSv2/3 client intended to handle a lack of a server-side RPC retranmission cache for non-idempotent operations: these hacks substituted 0 (success) for the expected EEXIST in the event that a target name already existed for LINK, SYMLINK, and MKDIR operations, under the assumption that EEXIST represented a second application of the original RPC rather than a true failure. Background: certain NFS operations (in this case, LINK, SYMLINK, and MKDIR) are not idempotent, as they leave behind persisting state on the server that prevents them from being replayed without an error; if an UDP RPC reply is lost leading to a retransmission by the client, the second reply will return EEXIST rather than success, as the new object has already been created. The NFS client previously silently mapped the EEXIST return into success to paper over this problem. However, in all modern NFS server implementations, a reply cache is kept in order to retransmit the original reply to a retransmitted request, rather than performing the operation a second time, allowing this hack to be avoided. This allows link()-based filelocking over NFS to operate correctly, as an application requesting the creation of a new link for a file to tell if it succeeded atomically or not. Other NFS clients, including Solaris and Linux, generally follow this behavior for the same reasons. Most clients also now default to TCP, which also helps avoid the issue of retransmitted but non-idempotent requests in most cases. Obtained from: FreeBSD, nfsclient/nfs_vnops.c 1.277 Index: nfs_vnops.c =================================================================== RCS file: /home/dcvs/src/sys/vfs/nfs/nfs_vnops.c,v retrieving revision 1.76 diff -u -p -r1.76 nfs_vnops.c --- nfs_vnops.c 2 Nov 2007 19:52:28 -0000 1.76 +++ nfs_vnops.c 17 Nov 2007 09:11:28 -0000 @@ -1852,11 +1852,6 @@ nfsmout: VTONFS(vp)->n_attrstamp = 0; if (!wccflag) VTONFS(tdvp)->n_attrstamp = 0; - /* - * Kludge: Map EEXIST => 0 assuming that it is a reply to a retry. - */ - if (error == EEXIST) - error = 0; return (error); } @@ -1925,17 +1920,9 @@ nfs_symlink(struct vop_old_symlink_args nfsmout: /* - * If we get an EEXIST error, silently convert it to no-error - * in case of an NFS retry. - */ - if (error == EEXIST) - error = 0; - - /* - * If we do not have (or no longer have) an error, and we could - * not extract the newvp from the response due to the request being - * NFSv2 or the error being EEXIST. We have to do a lookup in order - * to obtain a newvp to return. + * If we do not have an error, and we could not extract the newvp from + * the response due to the request being NFSv2, we have to do a + * lookup in order to obtain a newvp to return. */ if (error == 0 && newvp == NULL) { struct nfsnode *np = NULL; @@ -2013,15 +2000,7 @@ nfsmout: VTONFS(dvp)->n_flag |= NLMODIFIED; if (!wccflag) VTONFS(dvp)->n_attrstamp = 0; - /* - * Kludge: Map EEXIST => 0 assuming that you have a reply to a retry - * if we can succeed in looking up the directory. - */ - if (error == EEXIST || (!error && !gotvp)) { - if (newvp) { - vrele(newvp); - newvp = (struct vnode *)0; - } + if (error == 0 && newvp == NULL) { error = nfs_lookitup(dvp, cnp->cn_nameptr, len, cnp->cn_cred, cnp->cn_td, &np); if (!error) {