From owner-svn-src-all@FreeBSD.ORG Mon Apr 18 21:58:25 2011 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 A5B9F106564A; Mon, 18 Apr 2011 21:58:25 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) Received: from esa-annu.mail.uoguelph.ca (esa-annu.mail.uoguelph.ca [131.104.91.36]) by mx1.freebsd.org (Postfix) with ESMTP id 35FA98FC0A; Mon, 18 Apr 2011 21:58:24 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApwEAACsrE2DaFvO/2dsb2JhbACET6FpiG+sM5B9gSmDTnoEjgA X-IronPort-AV: E=Sophos;i="4.64,235,1301889600"; d="scan'208";a="117867522" Received: from erie.cs.uoguelph.ca (HELO zcs3.mail.uoguelph.ca) ([131.104.91.206]) by esa-annu-pri.mail.uoguelph.ca with ESMTP; 18 Apr 2011 17:29:10 -0400 Received: from zcs3.mail.uoguelph.ca (localhost.localdomain [127.0.0.1]) by zcs3.mail.uoguelph.ca (Postfix) with ESMTP id F006CB3F2D; Mon, 18 Apr 2011 17:29:10 -0400 (EDT) Date: Mon, 18 Apr 2011 17:29:10 -0400 (EDT) From: Rick Macklem To: Kostik Belousov Message-ID: <1505925744.242012.1303162150923.JavaMail.root@erie.cs.uoguelph.ca> In-Reply-To: <20110418080116.GW48734@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [172.17.91.202] X-Mailer: Zimbra 6.0.10_GA_2692 (ZimbraWebClient - IE7 (Win)/6.0.10_GA_2692) Cc: svn-src-head@freebsd.org, Rick Macklem , svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r220761 - 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: Mon, 18 Apr 2011 21:58:25 -0000 > On Sun, Apr 17, 2011 at 11:04:04PM +0000, Rick Macklem wrote: > > Author: rmacklem > > Date: Sun Apr 17 23:04:03 2011 > > New Revision: 220761 > > URL: http://svn.freebsd.org/changeset/base/220761 > > > > Log: > > Add checks for MNTK_UNMOUNTF at the beginning of three > > functions, so that threads don't get stuck in them during > > a forced dismount. nfs_sync/VFS_SYNC() needs this, since it is > > called by dounmount() before VFS_UNMOUNT(). The nfscl_nget() > > case makes sure that a thread doing an VOP_OPEN() or > > VOP_ADVLOCK() call doesn't get blocked before attempting > > the RPC. Attempting RPCs don't block, since they all > > fail once a forced dismount is in progress. > > The third one at the beginning of nfsrpc_close() > > is done so threads don't get blocked while doing VOP_INACTIVE() > > as the vnodes are cleared out. > > With these three changes plus a change to the umount(1) > > command so that it doesn't do "sync()" for the forced case > > seem to make forced dismounts work for the experimental NFS > > client. > > > > MFC after: 2 weeks > > > > Modified: > > head/sys/fs/nfsclient/nfs_clrpcops.c > > head/sys/fs/nfsclient/nfs_clstate.c > > head/sys/fs/nfsclient/nfs_clvfsops.c > > > > Modified: head/sys/fs/nfsclient/nfs_clrpcops.c > > ============================================================================== > > --- head/sys/fs/nfsclient/nfs_clrpcops.c Sun Apr 17 22:31:36 2011 > > (r220760) > > +++ head/sys/fs/nfsclient/nfs_clrpcops.c Sun Apr 17 23:04:03 2011 > > (r220761) > > @@ -567,6 +567,11 @@ nfsrpc_close(vnode_t vp, int doclose, NF > > > > if (vnode_vtype(vp) != VREG) > > return (0); > > + > > + /* For forced unmounts, just return. */ > > + if ((vp->v_mount->mnt_kern_flag & MNTK_UNMOUNTF) != 0) > > + return (0); > > + > Is there anything that would prevent the MNTK_UNMOUNTF flag from being > set immediately after the test returned success ? > > Usually, the tests for MNTK_UNMOUNTF are bugs. I coould see how > terminating > the RPCs would be useful for forced unmounts, but do not think that > preventing entry into close would help. > I think you are correct, in that the one in nfsrpc_close() is harmless, but not needed. (I suspect I added it to fix a crash and then didn't realize that it's the one in nfscl_getcl() that matters.) Basically, ncl_inactive() would call nfsrpc_close() which calls nfscl_doclose() which calls nfscl_getcl(), so when nfscl_getcl() returns failure, that should be sufficient. As for the nfscl_getcl() one, I don't think it is currently quite right either. The problem is a race with nfscl_umount(), which gets called from nfs_unmount(). It goes like this: - for a forced dismount, nfs_unmount(): - cancels all in-progress RPCs plus all new RPC attempts will fail {newnfs_nmcancelreqs() does this } - calls nfscl_umount() --> nfscl_umount() gets the exclusive lock for open/lock state modifications. - igotlock = nfsv4_lock(&clp->nfsc_lock,...); This will delay while any refcnt (shared lock) on nfsc_lock is held. - once this exclusive lock is acquired, it zaps the state information (any RPC attempts simply fail, due to the above) - in nfscl_getcl(), it gets a refcnt (shared lock) on nfsc_lock, so once that happens, the above will block until it is released. --> My mistake was putting the test for MNTK_UNMOUNTF above that point in nfscl_getcl(), so there is a race if it is set after the test, but before acquiring the refcnt on nfsc_lock. Thanks for pointing this out so I took another look. I'll either revert the patch or add one that fixes the above. (ie. move the test in nfscl_getcl() down and probably get rid of the one in nfsrpc_close(), since the test in nfscl_getcl() should be sufficient.) rick