Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3325552rwd; Mon, 29 May 2023 08:47:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5giq2N5DRsIiG7+RQYLVRkMuC5dPGjB1x1cuz16cJvC+dZub4oWaG1rzRKZG4ESX775e69 X-Received: by 2002:a05:6a00:21d3:b0:63d:4752:4da3 with SMTP id t19-20020a056a0021d300b0063d47524da3mr44462pfj.25.1685375233136; Mon, 29 May 2023 08:47:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685375233; cv=none; d=google.com; s=arc-20160816; b=E1XNRZhoUg77Fyu1rhbqX749Z8wOPQMA9SiHlQHqveynTz/XzPeQHan3EE4XRuENxp Pq5oAucO9PisIDk2w9uyv8UNKm1oqS4o2obG+ONHxdccE4axpj90E57k84ygQEL4bvJn wpMOvYHsPFd2KxEiiXzsp176QHevmxY2OFiRwID80WCcHBM9jWvVe1y7Cuka92lRIwtb dtFUCbzRrMYzaWcJ5q8g+dxXjfz8zpkWiJQ41gWDQDa+R2EIhtgH7USFaPJjDqvtTtEu kcjGElpuhCahDzc4MZ4IOU6izhMNl9Nqpi6lILf/Cil+wqllGgJBfW7VUzBZw25a0K4Q fGew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=VfC2IdpO+7uEiBHhtf+jBby1eH6FWQ5ChsH/O7pLur0=; b=P7SHy0PD/gN3dRDpKrbZvuhz8K+dlqlS/TzQOVMTMGf6O0dNHOTaXml5udMTC+7kcn k/+P+lvmlhgSiEe9gOBmOoJkGbrNjispmXTpGHH3x7IdvoqOej+cOofRcPwbYuTch7Kl +jV/MvEZz6Q5jDrrk58/G5WljZKLbk/9u8N4hMiOktgMYn0v8jr0FDzY1kgiCAYCONxP GgkLH1oS9iIqmumklicbHCHP3ruChvt3HZ06K9JcDYAyg2zq4XVqFsekhL+zxM/DhJFc TpQOBfbGhNVB0b2n1V1VL+uE6a0RN+ffrJ8oXlab8fKd0EgCgRgtLnn0MtULcR5y12Qx reuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=gSf0t+vZ; dkim=neutral (no key) header.i=@suse.cz header.b=2+2tMQky; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z128-20020a626586000000b0063b8ab7f91csi81173pfb.365.2023.05.29.08.46.58; Mon, 29 May 2023 08:47:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=gSf0t+vZ; dkim=neutral (no key) header.i=@suse.cz header.b=2+2tMQky; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229977AbjE2PiC (ORCPT + 99 others); Mon, 29 May 2023 11:38:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbjE2PiB (ORCPT ); Mon, 29 May 2023 11:38:01 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F59DF3; Mon, 29 May 2023 08:37:56 -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 A8E621F8B5; Mon, 29 May 2023 15:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1685374674; 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=VfC2IdpO+7uEiBHhtf+jBby1eH6FWQ5ChsH/O7pLur0=; b=gSf0t+vZ0B4myh9SviD61zCj1EH1uc1YlVGhNUgb/MCZXxzHgA8J3XifwVyza2KRq20hWr pZGc6AXCETQnP8jb+U91N20w7vIA7f5VobiHfL+/HbuvYR4sGOy/Qvb7o1ZnPBWqac7LBg kZfgvCRZqV9R20JgWvdDd1kIZir+lK0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1685374674; 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=VfC2IdpO+7uEiBHhtf+jBby1eH6FWQ5ChsH/O7pLur0=; b=2+2tMQkyipmhcoqtqPAlHCSakWLZKRrkGMRW/G1J4HZuo+ZsFqLS2sYv/igpPh23T0GX71 4QMmBZeR6OW2F3DA== 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 87AAC13A36; Mon, 29 May 2023 15:37:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id BKs+INLGdGQrSAAAMHmgww (envelope-from ); Mon, 29 May 2023 15:37:54 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 0BA32A06F2; Mon, 29 May 2023 14:41:31 +0200 (CEST) Date: Mon, 29 May 2023 14:41:31 +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-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 4/6] fs: Establish locking order for unrelated directories Message-ID: <20230529124131.gbb3fmhrspl332i6@quack3> References: <20230525100654.15069-1-jack@suse.cz> <20230525101624.15814-4-jack@suse.cz> <20230526-polarstern-herrichten-32fc46c63bfc@brauner> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230526-polarstern-herrichten-32fc46c63bfc@brauner> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Fri 26-05-23 11:45:15, Christian Brauner wrote: > On Thu, May 25, 2023 at 12:16:10PM +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 | 34 ++++++++++++++++++++++++++++++++++ > > fs/internal.h | 2 ++ > > fs/namei.c | 4 ++-- > > 3 files changed, 38 insertions(+), 2 deletions(-) > > > > diff --git a/fs/inode.c b/fs/inode.c > > index 577799b7855f..2015fa50d34a 100644 > > --- a/fs/inode.c > > +++ b/fs/inode.c > > @@ -1103,6 +1103,40 @@ 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) > > + goto lock; > > Before this change in > > lock_two_nondirectories(struct inode *inode1, struct inode *inode2) > > the swap() would cause the non-NULL inode to always be locked with > I_MUTEX_NONDIR2. Now it can be either I_MUTEX_NORMAL or I_MUTEX_NONDIR2. > Is that change intentional? Kind of. I don't think we really care so I didn't bother to complicate the code for this. If you think keeping the lockdep class consistent is worth it, I can modify the patch... Honza -- Jan Kara SUSE Labs, CR