Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp16680rdb; Mon, 4 Dec 2023 18:25:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHeBuhYvTE6gUrqbLeTd/FhnA99Tz0q4AjfS0NAv2GFCnmAdh9ZQaR1YhU6o9Z4DlEmRuTc X-Received: by 2002:a05:6a00:3317:b0:6cb:a0dc:3d56 with SMTP id cq23-20020a056a00331700b006cba0dc3d56mr564118pfb.0.1701743129374; Mon, 04 Dec 2023 18:25:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701743129; cv=none; d=google.com; s=arc-20160816; b=hqEKLgZPrpBZZ0gCTSR2YWgqX1K0qz9hb63wuMp+eehzm/M6rfuqRHn7HbXPCwN5Nn lLjV770BaOWAy2ZbQaO8CWwPWnXP05+N2Dkt3ZfI2zzdPosI+xMYstitsmddUl9aJiXT wVDU9j++OIBbloFAOcoNc0od6bh/Lp/lRM5/UBwSgmug9x8K9MWH00GInnEgUkr8HS9D 4I6bbWQClXBn0SG0HsVnLEAe3EVOtD6PL0Dep/9yf5Kb6FOqmfeSO239GhbsHllDcjKa zc306PMCVQDRblBNdl5ssTII94kqNyfNCbZtRGJUjGHCeRZ1PDDioQula2ijhSX+0J5+ Rw/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MXd1D7yrhiKOU6TnSrHtQJWPS/0VvoZfIFu1ppuy74Y=; fh=DgGXwGbnyiv1Rvt/NkXbEKOXDvWVLBCb4IpCdacEJoI=; b=Vq9fWaVWq69Zp13iHcNhDeA+nWbmq7xPCVZfIvr5Jj7FEU49KNJqE7rorgkvDY7hAd GQ1wDA0PTK29whuH30LaeXvKFXWMLtAnxkJOswq6dpjsY8Q8MoDHuMTgbDZlSC0y+OMQ EacqW3JJaxV2hSBx28hoIeskWzElI3Wccj/MFfgLgSuwrW3O7tcdeGYOr45fwzH9bqiU 74p4MI+0mIFYXhKW7Wcnz9SKnM46uBwFfpCJEmZ7iscK5SirG2Up7nDy867Tpqz3uKSV vXJMG4QWYr/zFes+odZ4ZAMDudGNTLoT/Gasf84GWbzg6B96/2VWCkS3F2liVhtt87GA V78g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=HU7imc8M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id t42-20020a056a0013aa00b006ce27153bfbsi5085041pfg.372.2023.12.04.18.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 18:25:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=HU7imc8M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 5FD5E8051143; Mon, 4 Dec 2023 18:25:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344058AbjLECYW (ORCPT + 99 others); Mon, 4 Dec 2023 21:24:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234837AbjLECYQ (ORCPT ); Mon, 4 Dec 2023 21:24:16 -0500 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49311119; Mon, 4 Dec 2023 18:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=MXd1D7yrhiKOU6TnSrHtQJWPS/0VvoZfIFu1ppuy74Y=; b=HU7imc8MVTYmCfuLopTpwdRiVO ZY5qEnjq7pFb1Iq9nr8VSEW7F7WYt8ZFkc/uctjVk6OI0feqjHi05XDaV6I7nz+0tFQzyhH4Ol8C+ vyibxRJczNvuLDegkk7gfBB1DARvN5LOh6otyTax/3v0XkSCGwuflm7wQ4EKlAKiN71JKYMfOdvsR 0DjC1rVe97oZK42zTON+8mIE9d55myiaQ9B07km9jirHB7cfhgvW+8hUNYrzMvPjC/cIhsh9tonkc zN0BO6Ng7jMlrRnceS13ThyUchQl/eg0qQ9uQRUyHIhg2zOq+6aNOzdG4WsVEtQG0T+zxjMiqtlGK eDsffV5Q==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1rAL6j-00792z-1t; Tue, 05 Dec 2023 02:24:21 +0000 From: Al Viro To: linux-arch@vger.kernel.org Cc: gus Gusenleitner Klaus , Al Viro , Thomas Gleixner , lkml , Ingo Molnar , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "x86@kernel.org" , "David S. Miller" , "dsahern@kernel.org" , "kuba@kernel.org" , Paolo Abeni , Eric Dumazet Subject: [PATCH v2 8/9] kill lock_two_inodes() Date: Tue, 5 Dec 2023 02:24:07 +0000 Message-Id: <20231205022418.1703007-16-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231205022418.1703007-1-viro@zeniv.linux.org.uk> References: <20231205022100.GB1674809@ZenIV> <20231205022418.1703007-1-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Al Viro X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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 agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 04 Dec 2023 18:25:22 -0800 (PST) There's only one caller left (lock_two_nondirectories()), and it needs less complexity. Fold lock_two_inodes() in there and simplify. Reviewed-by: Jan Kara Signed-off-by: Al Viro --- 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