From owner-svn-src-all@FreeBSD.ORG Wed Nov 11 15:43:08 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 41C55106566B; Wed, 11 Nov 2009 15:43:08 +0000 (UTC) (envelope-from jh@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1745E8FC13; Wed, 11 Nov 2009 15:43:08 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nABFh7kt099308; Wed, 11 Nov 2009 15:43:07 GMT (envelope-from jh@svn.freebsd.org) Received: (from jh@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nABFh7NU099306; Wed, 11 Nov 2009 15:43:07 GMT (envelope-from jh@svn.freebsd.org) Message-Id: <200911111543.nABFh7NU099306@svn.freebsd.org> From: Jaakko Heinonen Date: Wed, 11 Nov 2009 15:43:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r199189 - head/sys/fs/nfsclient X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Nov 2009 15:43:08 -0000 Author: jh Date: Wed Nov 11 15:43:07 2009 New Revision: 199189 URL: http://svn.freebsd.org/changeset/base/199189 Log: Create verifier used by FreeBSD NFS client is suboptimal because the first part of a verifier is set to the first IP address from V_in_ifaddrhead list. This address is typically the loopback address making the first part of the verifier practically non-unique. The second part of the verifier is initialized to zero making its initial value non-unique too. This commit changes the strategy for create verifier initialization: just initialize it to a random value. Also move verifier handling into its own function and use a mutex to protect the variable. This change is a candidate for porting to sys/nfsclient. Reviewed by: jhb, rmacklem Approved by: trasz (mentor) Modified: head/sys/fs/nfsclient/nfs_clvnops.c Modified: head/sys/fs/nfsclient/nfs_clvnops.c ============================================================================== --- head/sys/fs/nfsclient/nfs_clvnops.c Wed Nov 11 15:21:06 2009 (r199188) +++ head/sys/fs/nfsclient/nfs_clvnops.c Wed Nov 11 15:43:07 2009 (r199189) @@ -1365,7 +1365,30 @@ nfs_mknod(struct vop_mknod_args *ap) return (nfs_mknodrpc(ap->a_dvp, ap->a_vpp, ap->a_cnp, ap->a_vap)); } -static u_long create_verf; +static struct mtx nfs_cverf_mtx; +MTX_SYSINIT(nfs_cverf_mtx, &nfs_cverf_mtx, "NFS create verifier mutex", + MTX_DEF); + +static nfsquad_t +nfs_get_cverf(void) +{ + static nfsquad_t cverf; + nfsquad_t ret; + static int cverf_initialized = 0; + + mtx_lock(&nfs_cverf_mtx); + if (cverf_initialized == 0) { + cverf.lval[0] = arc4random(); + cverf.lval[1] = arc4random(); + cverf_initialized = 1; + } else + cverf.qval++; + ret = cverf; + mtx_unlock(&nfs_cverf_mtx); + + return (ret); +} + /* * nfs file create call */ @@ -1405,19 +1428,7 @@ again: } mtx_unlock(&dnp->n_mtx); -#ifdef INET - CURVNET_SET(CRED_TO_VNET(cnp->cn_cred)); - IN_IFADDR_RLOCK(); - if (!TAILQ_EMPTY(&V_in_ifaddrhead)) - cverf.lval[0] = IA_SIN(TAILQ_FIRST(&V_in_ifaddrhead))->sin_addr.s_addr; - else -#endif - cverf.lval[0] = create_verf; -#ifdef INET - IN_IFADDR_RUNLOCK(); - CURVNET_RESTORE(); -#endif - cverf.lval[1] = ++create_verf; + cverf = nfs_get_cverf(); error = nfsrpc_create(dvp, cnp->cn_nameptr, cnp->cn_namelen, vap, cverf, fmode, cnp->cn_cred, cnp->cn_thread, &dnfsva, &nfsva, &nfhp, &attrflag, &dattrflag, NULL);