From owner-svn-src-head@FreeBSD.ORG Fri Sep 10 23:49:33 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E9166106566C; Fri, 10 Sep 2010 23:49:33 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D88D98FC1E; Fri, 10 Sep 2010 23:49:33 +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 o8ANnX51001848; Fri, 10 Sep 2010 23:49:33 GMT (envelope-from rmacklem@svn.freebsd.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8ANnXxp001846; Fri, 10 Sep 2010 23:49:33 GMT (envelope-from rmacklem@svn.freebsd.org) Message-Id: <201009102349.o8ANnXxp001846@svn.freebsd.org> From: Rick Macklem Date: Fri, 10 Sep 2010 23:49:33 +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: r212443 - head/sys/fs/nfsserver X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Sep 2010 23:49:34 -0000 Author: rmacklem Date: Fri Sep 10 23:49:33 2010 New Revision: 212443 URL: http://svn.freebsd.org/changeset/base/212443 Log: This patch applies one of the two fixes suggested by zack.kirsch at isilon.com for a race between nfsrv_freeopen() and nfsrv_getlockfile() in the experimental NFS server that he found during testing. Although nfsrv_freeopen() holds a sleep lock on the lock file structure when called with cansleep != 0, nfsrv_getlockfile() could still search the list, once it acquired the NFSLOCKSTATE() mutex. I believe that acquiring the mutex in nfsrv_freeopen() fixes the race. MFC after: 2 weeks Modified: head/sys/fs/nfsserver/nfs_nfsdstate.c Modified: head/sys/fs/nfsserver/nfs_nfsdstate.c ============================================================================== --- head/sys/fs/nfsserver/nfs_nfsdstate.c Fri Sep 10 23:38:18 2010 (r212442) +++ head/sys/fs/nfsserver/nfs_nfsdstate.c Fri Sep 10 23:49:33 2010 (r212443) @@ -1085,8 +1085,11 @@ nfsrv_freeopen(struct nfsstate *stp, vno * associated with the open. * If there are locks associated with the open, the * nfslockfile structure can be freed via nfsrv_freelockowner(). - * (That is why the call must be here instead of after the loop.) + * Acquire the state mutex to avoid races with calls to + * nfsrv_getlockfile(). */ + if (cansleep != 0) + NFSLOCKSTATE(); if (lfp != NULL && LIST_EMPTY(&lfp->lf_open) && LIST_EMPTY(&lfp->lf_deleg) && LIST_EMPTY(&lfp->lf_lock) && LIST_EMPTY(&lfp->lf_locallock) && LIST_EMPTY(&lfp->lf_rollback) && @@ -1096,6 +1099,8 @@ nfsrv_freeopen(struct nfsstate *stp, vno ret = 1; } else ret = 0; + if (cansleep != 0) + NFSUNLOCKSTATE(); FREE((caddr_t)stp, M_NFSDSTATE); newnfsstats.srvopens--; nfsrv_openpluslock--;