From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6306EC77B7E for ; Thu, 1 Jun 2023 15:25:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233818AbjFAPZN (ORCPT ); Thu, 1 Jun 2023 11:25:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234227AbjFAPYx (ORCPT ); Thu, 1 Jun 2023 11:24:53 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADE8F136; Thu, 1 Jun 2023 08:24:51 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 439421FDAF; Thu, 1 Jun 2023 15:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1685633090; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NMMC3ehgaWslWeASfjcmQ+SuyyB+zQPCwx9GtXbqe3Y=; b=WjHviSuQYqQL5ww/WGZrxQ9IaSK+faKZeFG2YF8j1TneF9hscLLx1tqg0Bx8EgldewEIHi PBEV92dYJc9WiX/PL/Fl3kvtNUHQ7iVPTlmwqgOKI3ucMytqhW2aWsSuZSvUhP7hf/zFKn KNnBc370aTHSrj3tbsurPTnkkfqoXmA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1685633090; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NMMC3ehgaWslWeASfjcmQ+SuyyB+zQPCwx9GtXbqe3Y=; b=9kcmzqr/0hZ1iA49qNNzf1cUeGB4/rjsaKBaQ3EqCfnWgDiqMRyj80AFflpKW9e0YgPeZl nKRmR487X7h99zBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3109D139B7; Thu, 1 Jun 2023 15:24:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7FLvC0K4eGQuawAAMHmgww (envelope-from ); Thu, 01 Jun 2023 15:24:50 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 91EB1A0754; Thu, 1 Jun 2023 17:24:49 +0200 (CEST) Date: Thu, 1 Jun 2023 17:24:49 +0200 From: Jan Kara To: Christian Brauner Cc: Jan Kara , Al Viro , linux-fsdevel@vger.kernel.org, Miklos Szeredi , "Darrick J. Wong" , Ted Tso , Jaegeuk Kim , linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, stable@vger.kernel.org Subject: Re: [PATCH v2 4/6] fs: Establish locking order for unrelated directories Message-ID: <20230601152449.h4ur5zrfqjqygujd@quack3> References: <20230601104525.27897-1-jack@suse.cz> <20230601105830.13168-4-jack@suse.cz> <20230601-gebracht-gesehen-c779a56b3bf3@brauner> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230601-gebracht-gesehen-c779a56b3bf3@brauner> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu 01-06-23 15:58:58, Christian Brauner wrote: > On Thu, Jun 01, 2023 at 12:58:24PM +0200, Jan Kara wrote: > > Currently the locking order of inode locks for directories that are not > > in ancestor relationship is not defined because all operations that > > needed to lock two directories like this were serialized by > > sb->s_vfs_rename_mutex. However some filesystems need to lock two > > subdirectories for RENAME_EXCHANGE operations and for this we need the > > locking order established even for two tree-unrelated directories. > > Provide a helper function lock_two_inodes() that establishes lock > > ordering for any two inodes and use it in lock_two_directories(). > > > > CC: stable@vger.kernel.org > > Signed-off-by: Jan Kara > > --- > > fs/inode.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > > fs/internal.h | 2 ++ > > fs/namei.c | 4 ++-- > > 3 files changed, 46 insertions(+), 2 deletions(-) > > > > diff --git a/fs/inode.c b/fs/inode.c > > index 577799b7855f..4000ab08bbc0 100644 > > --- a/fs/inode.c > > +++ b/fs/inode.c > > @@ -1103,6 +1103,48 @@ void discard_new_inode(struct inode *inode) > > } > > EXPORT_SYMBOL(discard_new_inode); > > > > +/** > > + * lock_two_inodes - lock two inodes (may be regular files but also dirs) > > + * > > + * Lock any non-NULL argument. The caller must make sure that if he is passing > > + * in two directories, one is not ancestor of the other. Zero, one or two > > + * objects may be locked by this function. > > + * > > + * @inode1: first inode to lock > > + * @inode2: second inode to lock > > + * @subclass1: inode lock subclass for the first lock obtained > > + * @subclass2: inode lock subclass for the second lock obtained > > + */ > > +void lock_two_inodes(struct inode *inode1, struct inode *inode2, > > + unsigned subclass1, unsigned subclass2) > > +{ > > + if (!inode1 || !inode2) > > I think you forgot the opening bracket... > I can just fix this up for you though. Oh, yes. Apparently I forgot to rerun git-format-patch after fixing up this bit. I'm sorry for that. The patch series has survived full ext4 fstests run on my end. Honza -- Jan Kara SUSE Labs, CR