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 20:05:20 +0200 Message-ID: <20061015180520.GC14399@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> 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]:30499 "EHLO kernel.dk") by vger.kernel.org with ESMTP id S1422644AbWJOSEy (ORCPT ); Sun, 15 Oct 2006 14:04:54 -0400 To: Mark Fasheh Content-Disposition: inline In-Reply-To: <20061013194442.GA2954@ca-server1.us.oracle.com> Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Fri, Oct 13 2006, Mark Fasheh wrote: > /* > + * We rarely want to lock two inodes that do not have a parent/child > + * relationship (such as directory, child inode) simultaneously. The > + * vast majority of file systems should be able to get along fine > + * without this. Do not use these functions except as a last resort. > + */ > +static inline 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); > + } > +} 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. The function should work for any of the inodes to be NULL, if exported as a helper. -- Jens Axboe