From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jens Axboe Subject: Re: i_mutex locking in generic_file_splice_write() Date: Sun, 15 Oct 2006 22:08:28 +0200 Message-ID: <20061015200828.GO14399@kernel.dk> References: <20061012190152.GU6485@ca-server1.us.oracle.com> <20061012125409.40bd1fb1.akpm@osdl.org> <20061013001715.GV6485@ca-server1.us.oracle.com> <20061013074516.GY6515@kernel.dk> <20061013011129.42a757fb.akpm@osdl.org> <20061013081855.GG6515@kernel.dk> <20061013194442.GA2954@ca-server1.us.oracle.com> <20061015180520.GC14399@kernel.dk> <20061015195657.GA13426@ca-server1.us.oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Andrew Morton , linux-fsdevel@vger.kernel.org, Michael Halcrow Return-path: Received: from brick.kernel.dk ([62.242.22.158]:46686 "EHLO kernel.dk") by vger.kernel.org with ESMTP id S1422881AbWJOUIB (ORCPT ); Sun, 15 Oct 2006 16:08:01 -0400 To: Mark Fasheh Content-Disposition: inline In-Reply-To: <20061015195657.GA13426@ca-server1.us.oracle.com> Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Sun, Oct 15 2006, Mark Fasheh wrote: > On Sun, Oct 15, 2006 at 08:05:20PM +0200, Jens Axboe wrote: > > This wont fly, it's completely tailored to splice in that one one inode > > can be NULL. It also requires the 2nd inode to be that potentially NULL > > pointer. > *shrug* from my memory, 1st pointer always valid, 2nd possibly NULL seemed > to be a common paradigm, though I can't really point to any code, now that I > think of it. > > > > The function should work for any of the inodes to be NULL, if exported > > as a helper. > Here's a version that also handles both inodes being the same. We're quickly > approaching an elevated level of scariness in inode_double_lock :) Also, > things have been un-inlined. Hmm, it doesn't seem any different :-). Bad diff attached? > +void inode_double_lock(struct inode *inode1, struct inode *inode2) > +{ > + if (!inode2) { > + mutex_lock(&inode1->i_mutex); > + return; > + } > + > + if (inode1 < inode2) { > + mutex_lock_nested(&inode1->i_mutex, I_MUTEX_PARENT); > + mutex_lock_nested(&inode2->i_mutex, I_MUTEX_CHILD); > + } else { > + mutex_lock_nested(&inode2->i_mutex, I_MUTEX_PARENT); > + mutex_lock_nested(&inode1->i_mutex, I_MUTEX_CHILD); > + } > +} -- Jens Axboe