Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp829088rwd; Thu, 1 Jun 2023 07:07:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5+FKiYiHboY35dd7S7dmtNlF2OiPWyhhEtP9IolSzuOSdWeD8CP3CaAfgbDC2/Ps7TKv0S X-Received: by 2002:a17:902:c20d:b0:1ac:a887:d344 with SMTP id 13-20020a170902c20d00b001aca887d344mr6632025pll.19.1685628474832; Thu, 01 Jun 2023 07:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685628474; cv=none; d=google.com; s=arc-20160816; b=Ofvwl7PxkirQgnSFxvMiz8ROV1cb8xardRhNaTPoE48qbXk9BvOgigVpSnEA92NBkt EfcdJMrwDYuiRTMoZ3ylhn4zC34vdpKdC7g4fzBnBvb93KgiusUuKOVFZeJjK/4eRLKi HXrCV24UVsbsMUJqIsNy7Py340gRwQ2ybjWeILwMAzk78/JWQb29Wk9qiOCkDY6lf6+N BSGyVGWUQOQbqW2VF/tyktr9V9mpQjWAr9TvhoJqZKWOSJD6RLjehag6EGTGIdT/noV+ 9zT9IMTonYkWo2dEla2qlkJHLNXo0gGsZvZSPjFh+RFrLxi1ntp3oL5ZeHCSp24IZRV+ +Itg== 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; bh=qpZIpmK9fjJHsaOKDIRYf2ea22IcnS/Fi9ymODAuSLc=; b=UG0QGqRQPDQ5q103OWiu1NF3rIB/5sWtkcpEGJTNSFvRnMiXZ2cfsEtOj1euSeH5QX VyC9mT/jSS9zTtSM1yC49T62BvzPIfas2eoTmtODIU9/yar/EB18qiaHtEdpAqrEbZtZ Be5Tc4/p3lp/CdCqrMEyqdox9peqGNoCpPaxFi64vrfxWd8yerQZiZze1gxbJotJU1BV 6KdM+aOWHA2l1IswMJKCmhZz+yReqZs9dTYXiSnaOzdvvQHMCzLQ74cCmFvXI3Flc2pN QovQbtyBK6AePmFOeARaGIP6+8028RA2STM3mrp7sQuyf21OSZuWqy/a8UQgUVzOQqb8 xwSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RSKNSdL1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ju3-20020a170903428300b001a63e4ff6fbsi2755747plb.178.2023.06.01.07.07.29; Thu, 01 Jun 2023 07:07:54 -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=@kernel.org header.s=k20201202 header.b=RSKNSdL1; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232340AbjFAN7H (ORCPT + 99 others); Thu, 1 Jun 2023 09:59:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbjFAN7G (ORCPT ); Thu, 1 Jun 2023 09:59:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F523FC; Thu, 1 Jun 2023 06:59:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1B53A617EA; Thu, 1 Jun 2023 13:59:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA843C433D2; Thu, 1 Jun 2023 13:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685627944; bh=hrvO0WffTuYX0l8xl6Ve6qY34By3qmMdYk7DH/2LqV4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RSKNSdL1EwbgZ3EVAsPXSCUcGmPXrtGiZ7K/mcXuispwQXsqu4hHi1HU0/cfChTLi FQHMIEttwLeBHGVThYBwKqodAMzYKLybFe/dsKnlmr8pUS8XikF8TzqxZ4WLw/4vd2 Bu7Ra/G6Fr0QhIZ+J7sOiFYzuSObtGZ+4gKtaCoW1oyIaUGmHuR7vvQeb3pqdyxNuL WOG2hgBVDtBfNi2JCBHf8fNlyZmgqz4zF1H/e+Dw9ghxjjnWNs7roFT4qRlFRoQXGy SC+pdwA/NUF6kJm0TcyB2A6vZJnbbT+waoLD1pNjxbIIIkcg7KXeRvZguOFip43Qhq Usx4NRM/X1d6Q== Date: Thu, 1 Jun 2023 15:58:58 +0200 From: Christian Brauner To: Jan Kara Cc: 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: <20230601-gebracht-gesehen-c779a56b3bf3@brauner> References: <20230601104525.27897-1-jack@suse.cz> <20230601105830.13168-4-jack@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230601105830.13168-4-jack@suse.cz> X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 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. > + /* > + * Make sure @subclass1 will be used for the acquired lock. > + * This is not strictly necessary (no current caller cares) but > + * let's keep things consistent. > + */ > + if (!inode1) > + swap(inode1, inode2); > + goto lock; > + }