From: "J. Bruce Fields" Subject: Re: On setting a lease across a cluster Date: Fri, 4 Jan 2008 16:16:52 -0500 Message-ID: <20080104211652.GB14827@fieldses.org> References: <20080104181415.GE20473@parisc-linux.org> <20080104194718.GK17112@fieldses.org> <20080104203550.GG20473@parisc-linux.org> <20080104205304.GA14827@fieldses.org> <20080104210817.GH20473@parisc-linux.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: "david m. richter" , linux-fsdevel@vger.kernel.org To: Matthew Wilcox Return-path: Received: from mail.fieldses.org ([66.93.2.214]:58613 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756074AbYADVQz (ORCPT ); Fri, 4 Jan 2008 16:16:55 -0500 Content-Disposition: inline In-Reply-To: <20080104210817.GH20473@parisc-linux.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Fri, Jan 04, 2008 at 02:08:18PM -0700, Matthew Wilcox wrote: > On Fri, Jan 04, 2008 at 03:53:04PM -0500, J. Bruce Fields wrote: > > So, the problem is that fcntl_setlease() does > > > > vfs_setlease() > > fasync_helper() > > > > which the bkl held over both, and you want to preserve that? > > > > But what that BKL is doing is a mystery to me--the very first thing that > > fasync_helper() does is kmem_cache_alloc(., GFP_KERNEL). So you won't > > be introducing any new problem if you lock those two operations > > separately. Unless I'm totally missing something. > > A very good point. > > So yet another race caused by using the BKL rather than thinking ... but > maybe it's an inconsequential race. The consequences are that (if the > kmalloc in fasync_helper sleeps) a lease appears that isn't fully set-up > yet (and may be removed if the kmalloc fails). Actually, it seems bad > if the kmalloc eventually succeeds -- there's a window while kmalloc is > sleeping where another process could open the file, break the lease, > fl_fasync will be NULL, so no signal is sent. Then 30 seconds later the > lease is removed without the leaseholder being sent a signal. Bad. > > How can we fix this situation? I think we need a better interface than > fasync_helper() -- fasync_alloc() and fasync_setup() would seem to do > the trick. Or re-check the lease after doing the fasync_helper() setup and remove it if it's been broken in the interim? (Not that fasync_helper() couldn't independently use a little love: - The documentation: /* * fasync_helper() is used by some character device drivers * (mainly mice) to set up the fasync queue. It returns negative * on error, 0 if it did no changes and positive if it * added/deleted the entry. */ could be more helpful. - I find the "on" parameter a little confusing. (Shouldn't we just have two separate functions for those two cases?) - It should return ERR_PTR(-ERRNO) or the fasync_struct rather than using an fasync_struct ** to return the result. - And what's up with FASYNC_MAGIC? I thought the consensus was not to do that kind of thing in the kernel. ) --b.