From: Matthew Wilcox Subject: Re: race with i_flock? Date: Thu, 18 Jul 2002 02:07:27 +0100 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <20020718020727.J13352@parcelfarce.linux.theplanet.co.uk> References: <3D34D5F4.2060008@us.ibm.com> <20020717125533.Z27706@parcelfarce.linux.theplanet.co.uk> <3D35F032.9040408@us.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Matthew Wilcox , linux-fsdevel@vger.kernel.org, Stephen Rothwell Return-path: To: Dave Hansen Content-Disposition: inline In-Reply-To: <3D35F032.9040408@us.ibm.com>; from haveblue@us.ibm.com on Wed, Jul 17, 2002 at 03:31:14PM -0700 List-Id: linux-fsdevel.vger.kernel.org On Wed, Jul 17, 2002 at 03:31:14PM -0700, Dave Hansen wrote: > Matthew Wilcox wrote: > > static inline int get_lease(struct inode *inode, unsigned int mode) > > { > > if (inode->i_flock) > > return __get_lease(inode, mode); > > return 0; > > } > > > > __get_lease in 2.5.x has sufficient checks in it already; 2.4 does not > > and needs something like this: > > > > > > lock_kernel(); > > flock = inode->i_flock; > > + if (!flock || (flock->fl_flags & FL_LEASE) == 0) > > + goto out; > > if (flock->fl_type & F_INPROGRESS) { > > if ((mode & O_NONBLOCK) > > > > This must be a 1-insn wide race. I'm very impressed you managed to hit > > it ;-) > > You have no idea :) > > How about this patch? I can't believe that I'm spreading the BKL, but > it is needed in this case. And, you _are_ removing it from flocking > in 2.5, right? Hang on, I don't see that it's required. We're entitled to check the condition when not holding a lock, since assignments are atomic. Then we go back to check the condition still exists while holding the lock. -- Revolutions do not require corporate support.