Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp807686rdh; Thu, 23 Nov 2023 20:33:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSc9s2t1r5tHj+1B3d/MH32VeWmgwTba0oFJYSJaxKqjPrpM/t40nROmjYF4ZAYPB/u/qt X-Received: by 2002:a05:6871:4104:b0:1d5:b2ba:bc93 with SMTP id la4-20020a056871410400b001d5b2babc93mr1872546oab.13.1700800426032; Thu, 23 Nov 2023 20:33:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700800425; cv=none; d=google.com; s=arc-20160816; b=iMk0+XhrSzEDfS92NeTfNLEB1GqEJE0A3aZLZIihTZxwYNFb1vuv0zf4OFzP1THG82 W5xUT9fSECVoZoJ7hxWoVU/KJBF0pNRXQ9nXowKOJnWPL7ws/nm/FPNSNoUoO/ueNL4A PPwUND+4wyP2YEcLXBay45Y+r05WYnkGnb9YODY70Ic34Y4c/rT2SeNTAQDfRYg5YPvd Avnln24BkdLOGKqvquS+hDwcztgcswDjGs7o0BbKqGmRtoc15z8bWIaVVTHWaeaKIkvk aUGFh8tdccJSTk2YwLCNjXE6bQ4736f1Nl86WPfz9GMMFhWOM3spTBetPuRiCygy8s++ 8Qxw== 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; bh=UGY6RGOCWdNOQ3nFzwRDvUTojkd9ggzROlVflQ3bZd4=; fh=1UvAp7GUQSaqrdARWG8zoUWPhj4hWkACxxyVSa4vxWY=; b=ReNP/LiqFECGPOHHFatKJv5AUpnh6V7IA25s12PJHUw73zShVRdQMM+nBrDfYCBcgY gefZ1EhfIAhnlVjsbvoJPgjrxryNdL7Ml7il87OyhdEzFzFGK6jXOjngdimvtntmR+Dc qqWiksxyBCH8NS+TpuTMepwBdokLwbOm+/eO7p6R9blS59UoH6H2/VpTDow1ZtMsj9fT SvaqvH9CUX4XhhDoSEF5yD/qfA2yB5tWORzqz0WDlLXMMmIF7ObwrydU566gqU+xfVuR iM8oRteEhG/ncV4fFlZwU1ClLYlehUlbqfY2tLYr9lHsdxnek0g/rtPgaVYTcgMLq724 3vRg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id a5-20020a056a000c8500b006bd9c159a98si2829724pfv.186.2023.11.23.20.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 20:33:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 4DD2E82DEE51; Thu, 23 Nov 2023 20:33:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbjKXEdW (ORCPT + 99 others); Thu, 23 Nov 2023 23:33:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231217AbjKXEdQ (ORCPT ); Thu, 23 Nov 2023 23:33:16 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B67CD10DB; Thu, 23 Nov 2023 20:33:19 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DD4681FCE1; Thu, 23 Nov 2023 14:48:12 +0000 (UTC) Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 2A2B513AB6; Thu, 23 Nov 2023 12:22:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id I9YGCglEX2VMaAAAn2gu4w (envelope-from ); Thu, 23 Nov 2023 12:22:33 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 6B31FA07E2; Thu, 23 Nov 2023 10:53:03 +0100 (CET) Date: Thu, 23 Nov 2023 10:53:03 +0100 From: Jan Kara To: Al Viro Cc: linux-fsdevel@vger.kernel.org, Linus Torvalds , Mo Zou , Jan Kara , linux-kernel@vger.kernel.org Subject: Re: [PATCH 8/9] kill lock_two_inodes() Message-ID: <20231123095303.klmdrsi2yw3mv7zc@quack3> References: <20231122193028.GE38156@ZenIV> <20231122193652.419091-1-viro@zeniv.linux.org.uk> <20231122193652.419091-8-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231122193652.419091-8-viro@zeniv.linux.org.uk> X-Spam-Level: Authentication-Results: smtp-out2.suse.de; none X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Score: -4.00 X-Rspamd-Queue-Id: DD4681FCE1 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 23 Nov 2023 20:33:43 -0800 (PST) On Wed 22-11-23 19:36:51, Al Viro wrote: > There's only one caller left (lock_two_nondirectories()), and it > needs less complexity. Fold lock_two_inodes() in there and > simplify. > > Signed-off-by: Al Viro Looks good. Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/inode.c | 49 ++++++------------------------------------------- > fs/internal.h | 2 -- > 2 files changed, 6 insertions(+), 45 deletions(-) > > diff --git a/fs/inode.c b/fs/inode.c > index edcd8a61975f..453d5be1a014 100644 > --- a/fs/inode.c > +++ b/fs/inode.c > @@ -1087,48 +1087,6 @@ 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) { > - /* > - * 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; > - } > - > - /* > - * If one object is directory and the other is not, we must make sure > - * to lock directory first as the other object may be its child. > - */ > - if (S_ISDIR(inode2->i_mode) == S_ISDIR(inode1->i_mode)) { > - if (inode1 > inode2) > - swap(inode1, inode2); > - } else if (!S_ISDIR(inode1->i_mode)) > - swap(inode1, inode2); > -lock: > - if (inode1) > - inode_lock_nested(inode1, subclass1); > - if (inode2 && inode2 != inode1) > - inode_lock_nested(inode2, subclass2); > -} > - > /** > * lock_two_nondirectories - take two i_mutexes on non-directory objects > * > @@ -1144,7 +1102,12 @@ void lock_two_nondirectories(struct inode *inode1, struct inode *inode2) > WARN_ON_ONCE(S_ISDIR(inode1->i_mode)); > if (inode2) > WARN_ON_ONCE(S_ISDIR(inode2->i_mode)); > - lock_two_inodes(inode1, inode2, I_MUTEX_NORMAL, I_MUTEX_NONDIR2); > + if (inode1 > inode2) > + swap(inode1, inode2); > + if (inode1) > + inode_lock(inode1); > + if (inode2 && inode2 != inode1) > + inode_lock_nested(inode2, I_MUTEX_NONDIR2); > } > EXPORT_SYMBOL(lock_two_nondirectories); > > diff --git a/fs/internal.h b/fs/internal.h > index 58e43341aebf..de67b02226e5 100644 > --- a/fs/internal.h > +++ b/fs/internal.h > @@ -196,8 +196,6 @@ extern long prune_icache_sb(struct super_block *sb, struct shrink_control *sc); > int dentry_needs_remove_privs(struct mnt_idmap *, struct dentry *dentry); > bool in_group_or_capable(struct mnt_idmap *idmap, > const struct inode *inode, vfsgid_t vfsgid); > -void lock_two_inodes(struct inode *inode1, struct inode *inode2, > - unsigned subclass1, unsigned subclass2); > > /* > * fs-writeback.c > -- > 2.39.2 > -- Jan Kara SUSE Labs, CR