From owner-svn-src-all@FreeBSD.ORG Wed Dec 31 01:29:45 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5F21A9B1; Wed, 31 Dec 2014 01:29:45 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 322FF3F1D; Wed, 31 Dec 2014 01:29:45 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sBV1TjxO092659; Wed, 31 Dec 2014 01:29:45 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sBV1TjNi092658; Wed, 31 Dec 2014 01:29:45 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201412310129.sBV1TjNi092658@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Wed, 31 Dec 2014 01:29:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r276440 - stable/9/sys/kern X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 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, 31 Dec 2014 01:29:45 -0000 Author: rmacklem Date: Wed Dec 31 01:29:44 2014 New Revision: 276440 URL: https://svnweb.freebsd.org/changeset/base/276440 Log: MFC: r276192, r276200 Modify vop_stdadvlock{async}() so that it only locks/unlocks the vnode and does a VOP_GETATTR() for the SEEK_END case. This is safe to do, since lf_advlock{async}() only uses the size argument for the SEEK_END case. The NFSv4 server needs this when vfs.nfsd.enable_locallocks!=0 since locking the vnode results in a LOR that can cause a deadlock for the nfsd threads. Modified: stable/9/sys/kern/vfs_default.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/vfs_default.c ============================================================================== --- stable/9/sys/kern/vfs_default.c Wed Dec 31 00:54:38 2014 (r276439) +++ stable/9/sys/kern/vfs_default.c Wed Dec 31 01:29:44 2014 (r276440) @@ -399,17 +399,24 @@ int vop_stdadvlock(struct vop_advlock_args *ap) { struct vnode *vp; - struct ucred *cred; struct vattr vattr; int error; vp = ap->a_vp; - cred = curthread->td_ucred; - vn_lock(vp, LK_SHARED | LK_RETRY); - error = VOP_GETATTR(vp, &vattr, cred); - VOP_UNLOCK(vp, 0); - if (error) - return (error); + if (ap->a_fl->l_whence == SEEK_END) { + /* + * The NFSv4 server must avoid doing a vn_lock() here, since it + * can deadlock the nfsd threads, due to a LOR. Fortunately + * the NFSv4 server always uses SEEK_SET and this code is + * only required for the SEEK_END case. + */ + vn_lock(vp, LK_SHARED | LK_RETRY); + error = VOP_GETATTR(vp, &vattr, curthread->td_ucred); + VOP_UNLOCK(vp, 0); + if (error) + return (error); + } else + vattr.va_size = 0; return (lf_advlock(ap, &(vp->v_lockf), vattr.va_size)); } @@ -418,17 +425,19 @@ int vop_stdadvlockasync(struct vop_advlockasync_args *ap) { struct vnode *vp; - struct ucred *cred; struct vattr vattr; int error; vp = ap->a_vp; - cred = curthread->td_ucred; - vn_lock(vp, LK_SHARED | LK_RETRY); - error = VOP_GETATTR(vp, &vattr, cred); - VOP_UNLOCK(vp, 0); - if (error) - return (error); + if (ap->a_fl->l_whence == SEEK_END) { + /* The size argument is only needed for SEEK_END. */ + vn_lock(vp, LK_SHARED | LK_RETRY); + error = VOP_GETATTR(vp, &vattr, curthread->td_ucred); + VOP_UNLOCK(vp, 0); + if (error) + return (error); + } else + vattr.va_size = 0; return (lf_advlockasync(ap, &(vp->v_lockf), vattr.va_size)); }