Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2068639rdh; Sat, 25 Nov 2023 12:12:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMKnwHcC8pPEUrQycM+RqHWdxBaF9xsOSaPkc/q160ADkv5ZU+iO4UpVqFCxVWafYHDnN5 X-Received: by 2002:a05:6870:8e18:b0:1e9:b2e2:8754 with SMTP id lw24-20020a0568708e1800b001e9b2e28754mr3464626oab.2.1700943172886; Sat, 25 Nov 2023 12:12:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700943172; cv=none; d=google.com; s=arc-20160816; b=zbqwAvIH2ffQ6cKrvA/5uRfa6EfuF6wavRLb7RXPeIM3h+3nq5KzT1ggoA4eCBrkB7 oxJr4yP9XrinTUMZqzcaf4J8t23waWO3ao/PF1rgPZ7u6gpEUwwm7qCT6vxBwztqKNSR fLEoKzvHkUNLO21dRn7ogNAPBU7Nzr/WTfvAcUhh0JWDdaj8q+SBe+baSOBmRi/1cR2q gCQ2AcKTpyTRp0IY0c8yYinKjKs8ieOnxYXXxkEAjBH+F0ZcI+2Enjfe3w/ul+e4jBFF oe+UZ3Aeax0gb3txe5eDPUOi3dUEgNJjRda8e2KY0S5JDA7+FQ2P7ev8unrL5FIrXDb5 n5jQ== 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=W6BEtqt7iV8phMzKg0C2MCZmXBORzGPTeuIhW3f8iqY=; b=EwbJ0y3eGP9KZvX3CtlEYWUpbI4f7crIyicJvKjFD6dmbym6mF0QulOFtuNLhAcb9x n1eun+gNjDUoR5abqcBg30LusD5XOPR4Oeg4FM2F+HlNfkjZTkjJrLrj0DLz1XjQdQuw jQvBBDW7DU7WcRfDPHhNNYESB0afJkcWUOR9SReJeEi/CNMljqHpC8G2pTphlUS20gO7 k/GwjcnmsXFuMvEECw9UazwkAv6iEumc46RmJYvzEt1/Jks05jSiy5VQaw/RdoyzAs9m GoBz1UAWMUAMrESxdlUI8Ih+513Bq9D9tOKSOUZwXEXq+WeTasdQgZQH8E3fRla7vGT4 WBOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=N14uncTx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id v8-20020a170902b7c800b001cf5cb59a88si6182802plz.173.2023.11.25.12.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 12:12:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=N14uncTx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 790C580966E7; Sat, 25 Nov 2023 12:12:48 -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 S232484AbjKYUMA (ORCPT + 99 others); Sat, 25 Nov 2023 15:12:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229849AbjKYULn (ORCPT ); Sat, 25 Nov 2023 15:11:43 -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 201E8182; Sat, 25 Nov 2023 12:11:50 -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=N14uncTx4JMNyU5OFWglHbH2bZ 0AgVwOC6P/HTaLgEyAMcnsSEHNPqqJ0PSE/6p1B/GZE2P4/ZgTrAigHx/9GIW0ChEIfdFEch7D5fS EGSRaN+92wJ955vDqvPJO9sGjRTxwn+b5xoE0eguizSQCrYL6RyGN/h26EwYfYNQabRqAjVLQcJjH ne+P2/ky55mbFPomJSmnCfz3TC190ihS+5jUc4fpzCMlSYK0S4uMfCzLNdbh7sGP5fopwTkW1XBa4 yXND41vhkQNjTyNM0vHFefNTDc8Dk58QYkXBgpeDW1ZZKTW+Z8a55b68RzQEc3Yn6k/VFoUNJr0EP sful3ZWw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1r6z0G-003A53-2T; Sat, 25 Nov 2023 20:11:48 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Mo Zou , Jan Kara , linux-kernel@vger.kernel.org Subject: [PATCH v2 8/9] kill lock_two_inodes() Date: Sat, 25 Nov 2023 20:11:46 +0000 Message-Id: <20231125201147.753695-8-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231125201147.753695-1-viro@zeniv.linux.org.uk> References: <20231125201015.GA38156@ZenIV> <20231125201147.753695-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 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]); Sat, 25 Nov 2023 12:12:48 -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